feat(identity): seed a narrow agent identity and run shipped workflows as it

This commit is contained in:
sam committed 2026-10-17 17:04:43 +11:00
1 parent 784b01b6f0
commit b96e432841
11 files changed
+42 -7

No files matched your search

+8
View File
@@ -305,6 +305,14 @@ func (s *Store) UpgradeDefaultOrg(ctx context.Context) error {
{name: "operator", stamps: []func(context.Context, *postgresdb.Queries) (int64, error){
ensureOrgOperator,
}},
// Its own phase so installs that recorded the operator phase before
// the agent existed still get it. The final assignment below puts it
// in org-sys, and every agent's developer membership grants run.
{name: "agent", stamps: []func(context.Context, *postgresdb.Queries) (int64, error){
func(ctx context.Context, q *postgresdb.Queries) (int64, error) {
return q.EnsureOrgAgentIdentity(ctx, string(identity.AgentID()))
},
}},
}
for _, p := range phases {
if _, err := s.queries().GetOrgUpgradePhase(ctx, p.name); err == nil {
@@ -42,6 +42,21 @@ func (q *Queries) EnsureDefaultWorkspace(ctx context.Context) error {
return err
}
const ensureOrgAgentIdentity = `-- name: EnsureOrgAgentIdentity :execrows
INSERT INTO identities (id, kind, display_name, lifecycle, version, created_at, updated_at)
VALUES ($1, 'bot', 'Agent', 'active', 1, now(), now())
ON CONFLICT (id) DO NOTHING
`
// The bot identity the shipped workflows run as.
func (q *Queries) EnsureOrgAgentIdentity(ctx context.Context, id string) (int64, error) {
result, err := q.db.Exec(ctx, ensureOrgAgentIdentity, id)
if err != nil {
return 0, err
}
return result.RowsAffected(), nil
}
const ensureOrgOperatorIdentity = `-- name: EnsureOrgOperatorIdentity :execrows
INSERT INTO identities (id, kind, display_name, lifecycle, version, created_at, updated_at)
@@ -83,4 +83,10 @@ WHERE NOT EXISTS (
JOIN identities i ON i.id = m.identity_id
WHERE m.org_id = $2 AND m.workspace_id IS NULL AND m.role = 'owner' AND i.kind = 'user'
)
ON CONFLICT DO NOTHING;
ON CONFLICT DO NOTHING;
-- name: EnsureOrgAgentIdentity :execrows
-- The bot identity the shipped workflows run as.
INSERT INTO identities (id, kind, display_name, lifecycle, version, created_at, updated_at)
VALUES ($1, 'bot', 'Agent', 'active', 1, now(), now())
ON CONFLICT (id) DO NOTHING;