@intentic/sandbox-contract 1.376.0 → 1.377.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (124) hide show
  1. package/dist/contracts/access-profiles.contract.d.ts.map +1 -1
  2. package/dist/contracts/access-profiles.contract.js +3 -1
  3. package/dist/contracts/access-profiles.contract.js.map +1 -1
  4. package/dist/contracts/accounts.contract.d.ts +4 -0
  5. package/dist/contracts/accounts.contract.d.ts.map +1 -1
  6. package/dist/contracts/accounts.contract.js +6 -5
  7. package/dist/contracts/accounts.contract.js.map +1 -1
  8. package/dist/contracts/agent.contract.d.ts +4 -0
  9. package/dist/contracts/agent.contract.d.ts.map +1 -1
  10. package/dist/contracts/agents.contract.d.ts +76 -0
  11. package/dist/contracts/agents.contract.d.ts.map +1 -1
  12. package/dist/contracts/areas.contract.d.ts.map +1 -1
  13. package/dist/contracts/areas.contract.js +3 -1
  14. package/dist/contracts/areas.contract.js.map +1 -1
  15. package/dist/contracts/compliance.contract.js +1 -1
  16. package/dist/contracts/compliance.contract.js.map +1 -1
  17. package/dist/contracts/git.contract.d.ts +10 -0
  18. package/dist/contracts/git.contract.d.ts.map +1 -1
  19. package/dist/contracts/git.contract.js +11 -2
  20. package/dist/contracts/git.contract.js.map +1 -1
  21. package/dist/contracts/ports.contract.js +1 -1
  22. package/dist/contracts/ports.contract.js.map +1 -1
  23. package/dist/contracts/privacy.contract.d.ts.map +1 -1
  24. package/dist/contracts/privacy.contract.js +6 -5
  25. package/dist/contracts/privacy.contract.js.map +1 -1
  26. package/dist/contracts/runner.contract.d.ts +123 -123
  27. package/dist/contracts/secrets.contract.d.ts.map +1 -1
  28. package/dist/contracts/secrets.contract.js +4 -3
  29. package/dist/contracts/secrets.contract.js.map +1 -1
  30. package/dist/contracts/settings.contract.js +1 -1
  31. package/dist/contracts/settings.contract.js.map +1 -1
  32. package/dist/contracts/system.contract.d.ts +24 -0
  33. package/dist/contracts/system.contract.d.ts.map +1 -1
  34. package/dist/contracts/workspace.contract.d.ts +16 -0
  35. package/dist/contracts/workspace.contract.d.ts.map +1 -1
  36. package/dist/events/system-events.d.ts +16 -0
  37. package/dist/events/system-events.d.ts.map +1 -1
  38. package/dist/index.d.ts +164 -30
  39. package/dist/index.d.ts.map +1 -1
  40. package/dist/policy/command-classes.d.ts.map +1 -1
  41. package/dist/policy/command-classes.js +1 -1
  42. package/dist/policy/command-classes.js.map +1 -1
  43. package/dist/protocol/member-reach.d.ts +2 -1
  44. package/dist/protocol/member-reach.d.ts.map +1 -1
  45. package/dist/protocol/member-reach.js +5 -1
  46. package/dist/protocol/member-reach.js.map +1 -1
  47. package/dist/protocol/raw/raw-json-routes.d.ts +37 -0
  48. package/dist/protocol/raw/raw-json-routes.d.ts.map +1 -1
  49. package/dist/protocol/raw/raw-routes.d.ts +10 -4
  50. package/dist/protocol/raw/raw-routes.d.ts.map +1 -1
  51. package/dist/protocol/raw/raw-routes.js +9 -9
  52. package/dist/protocol/raw/raw-routes.js.map +1 -1
  53. package/dist/protocol/route-meta.d.ts +3 -0
  54. package/dist/protocol/route-meta.d.ts.map +1 -1
  55. package/dist/protocol/route-meta.js +1 -0
  56. package/dist/protocol/route-meta.js.map +1 -1
  57. package/dist/schemas/agent.d.ts +8 -0
  58. package/dist/schemas/agent.d.ts.map +1 -1
  59. package/dist/schemas/agent.js +4 -1
  60. package/dist/schemas/agent.js.map +1 -1
  61. package/dist/schemas/agents-list.d.ts +8 -0
  62. package/dist/schemas/agents-list.d.ts.map +1 -1
  63. package/dist/schemas/agents.d.ts +12 -0
  64. package/dist/schemas/agents.d.ts.map +1 -1
  65. package/dist/schemas/agents.js +4 -1
  66. package/dist/schemas/agents.js.map +1 -1
  67. package/dist/schemas/conversation-links.d.ts +9 -0
  68. package/dist/schemas/conversation-links.d.ts.map +1 -1
  69. package/dist/schemas/conversation-links.js +13 -0
  70. package/dist/schemas/conversation-links.js.map +1 -1
  71. package/dist/schemas/git/git.d.ts +3 -0
  72. package/dist/schemas/git/git.d.ts.map +1 -1
  73. package/dist/schemas/git/git.js +2 -1
  74. package/dist/schemas/git/git.js.map +1 -1
  75. package/dist/schemas/git/index-run.d.ts +1 -0
  76. package/dist/schemas/git/index-run.d.ts.map +1 -1
  77. package/dist/schemas/members.d.ts +60 -1
  78. package/dist/schemas/members.d.ts.map +1 -1
  79. package/dist/schemas/members.js +42 -5
  80. package/dist/schemas/members.js.map +1 -1
  81. package/dist/schemas/providers/account-sharing.d.ts +2 -0
  82. package/dist/schemas/providers/account-sharing.d.ts.map +1 -1
  83. package/dist/schemas/providers/provider-oauth.d.ts +4 -0
  84. package/dist/schemas/providers/provider-oauth.d.ts.map +1 -1
  85. package/dist/schemas/providers/provider-oauth.js +4 -0
  86. package/dist/schemas/providers/provider-oauth.js.map +1 -1
  87. package/dist/schemas/shared.d.ts +7 -0
  88. package/dist/schemas/shared.d.ts.map +1 -1
  89. package/dist/schemas/shared.js +13 -0
  90. package/dist/schemas/shared.js.map +1 -1
  91. package/dist/schemas/workspace/workspace-tree.d.ts +16 -0
  92. package/dist/schemas/workspace/workspace-tree.d.ts.map +1 -1
  93. package/dist/schemas/workspace/workspace-tree.js +4 -0
  94. package/dist/schemas/workspace/workspace-tree.js.map +1 -1
  95. package/dist/text/git-branch-switch.d.ts +2 -0
  96. package/dist/text/git-branch-switch.d.ts.map +1 -0
  97. package/dist/text/git-branch-switch.js +7 -0
  98. package/dist/text/git-branch-switch.js.map +1 -0
  99. package/package.json +5 -5
  100. package/src/contracts/access-profiles.contract.ts +3 -1
  101. package/src/contracts/accounts.contract.ts +9 -5
  102. package/src/contracts/areas.contract.ts +3 -1
  103. package/src/contracts/compliance.contract.ts +1 -1
  104. package/src/contracts/git.contract.ts +12 -2
  105. package/src/contracts/ports.contract.ts +1 -1
  106. package/src/contracts/privacy.contract.ts +10 -8
  107. package/src/contracts/secrets.contract.ts +6 -3
  108. package/src/contracts/settings.contract.ts +1 -1
  109. package/src/policy/command-classes.ts +1 -4
  110. package/src/policy/tests/command-classes.test.ts +23 -0
  111. package/src/protocol/member-reach.test.ts +61 -4
  112. package/src/protocol/member-reach.ts +12 -4
  113. package/src/protocol/raw/raw-routes.ts +19 -16
  114. package/src/protocol/route-meta.ts +5 -0
  115. package/src/schemas/agent.ts +4 -1
  116. package/src/schemas/agents.ts +7 -1
  117. package/src/schemas/conversation-links.ts +25 -0
  118. package/src/schemas/git/git.ts +2 -2
  119. package/src/schemas/members.test.ts +53 -1
  120. package/src/schemas/members.ts +93 -11
  121. package/src/schemas/providers/provider-oauth.ts +6 -0
  122. package/src/schemas/shared.ts +21 -0
  123. package/src/schemas/workspace/workspace-tree.ts +8 -0
  124. package/src/text/git-branch-switch.ts +16 -0
@@ -65,8 +65,9 @@ export const RAW_ROUTES = {
65
65
  "GET /system/desktop-view": { auth: "door", beforeBoot: true, control: "never" },
66
66
  // Deploy-target enrollment, gated by the connect token.
67
67
  "POST /enroll": { auth: "door", control: "never" },
68
- // A server-connect code for the owner's command: its single-use enroll token stands in for the connect token.
69
- "POST /system/enroll/code": { floor: "owner", control: "never" },
68
+ // A server-connect code for the command that connects a server: its single-use enroll token stands in for the connect
69
+ // token. Anybody who operates the sandbox may connect a server to it.
70
+ "POST /system/enroll/code": { control: "never" },
70
71
  // An event automation's webhook, gated by the automation's own token.
71
72
  "POST /automations/{id}/fire": { auth: "door" },
72
73
  // The release gate a pipeline runner waits on, gated by the workflow's minted gate token.
@@ -84,21 +85,22 @@ export const RAW_ROUTES = {
84
85
  "GET /intake/{id}/config": { auth: "door", embedded: true },
85
86
  "GET /intake/{id}/challenge": { auth: "door", embedded: true },
86
87
  "POST /intake/{id}/report": { auth: "door", embedded: true },
87
- // The roster is ownership's to read and change; giving up one's own grant is every tier's. Reading it is floored at
88
- // the owner here as well as in its handler (members.routes.ts), so the editor knows before asking.
89
- "GET /members": { floor: "owner", control: "never" },
90
- "POST /members": { control: "never" },
91
- "DELETE /members": { control: "never" },
88
+ // The roster is for whoever runs people and access (Full access, or the People & access right) to read and change;
89
+ // giving up one's own grant is every tier's. Reading it is floored here as well as in its handler (members.routes.ts),
90
+ // so the editor knows before asking; what someone below Full access may change is the handler's (peopleChangeRefusal).
91
+ "GET /members": { floor: "maintainer", right: "people", control: "never" },
92
+ "POST /members": { right: "people", control: "never" },
93
+ "DELETE /members": { right: "people", control: "never" },
92
94
  "DELETE /members/self": { floor: "viewer", guest: true, control: "never" },
93
95
  // What one's own grant allows, read by the editor to offer only what will be taken.
94
96
  "GET /members/self": { floor: "viewer", guest: true, control: "never" },
95
- // Asking the owner for more access is every member's, a guest's included, from wherever they were refused; reading
96
- // and dismissing the requests is the owner's, beside the roster they are answered on (schemas/members.ts).
97
+ // Asking for more access is every member's, a guest's included, from wherever they were refused; reading and
98
+ // dismissing the requests is for whoever runs people and access, beside the roster they are answered on.
97
99
  "POST /members/requests": { floor: "viewer", guest: true, control: "never" },
98
- "GET /members/requests": { floor: "owner", control: "never" },
99
- "DELETE /members/requests": { floor: "owner", control: "never" },
100
+ "GET /members/requests": { floor: "maintainer", right: "people", control: "never" },
101
+ "DELETE /members/requests": { right: "people", control: "never" },
100
102
  // The owner's Reconnect: register with the platform now, having it adopt the sandbox first when it holds no record.
101
- "POST /platform/relink": { control: "never" },
103
+ "POST /platform/relink": { floor: "owner", control: "never" },
102
104
  "GET /environment": {},
103
105
  "GET /environment/contents": {},
104
106
  "POST /environment/approve": {},
@@ -282,16 +284,17 @@ export const RAW_ROUTES = {
282
284
  "POST /system/control/tokens": { control: "never" },
283
285
  "GET /system/control/tokens": { floor: "maintainer", control: "never" },
284
286
  "DELETE /system/control/tokens/{id}": { control: "never" },
285
- // One's own passkeys are identity, like staying signed in; the policy and recovery codes are ownership's.
287
+ // One's own passkeys are identity, like staying signed in; the policy and recovery codes are the owner's own door, so
288
+ // they stay ownership's whoever else runs the sandbox.
286
289
  "GET /system/passkeys": { guest: true, control: "never" },
287
290
  "POST /system/passkeys/register/options": { floor: "viewer", guest: true, enrolment: true, control: "never" },
288
291
  "POST /system/passkeys/register": { floor: "viewer", guest: true, enrolment: true, control: "never" },
289
292
  // The assertion has no bearer yet, since it is how one is minted.
290
293
  "POST /system/passkeys/assert/options": { auth: "door", beforeBoot: true, control: "never" },
291
294
  "POST /system/passkeys/assert": { auth: "door", beforeBoot: true, control: "never" },
292
- "POST /system/passkeys/policy": { control: "never" },
293
- "POST /system/passkeys/recovery": { control: "never" },
294
- // One's own passkey; the handler holds another member's to the owner.
295
+ "POST /system/passkeys/policy": { floor: "owner", control: "never" },
296
+ "POST /system/passkeys/recovery": { floor: "owner", control: "never" },
297
+ // One's own passkey; the handler holds another member's to whoever runs people and access, and the owner's to the owner.
295
298
  "DELETE /system/passkeys/{id}": { floor: "viewer", guest: true, control: "never" },
296
299
  // Checks its own bearer, since the require-passkey policy would otherwise hold out the owner it exists for.
297
300
  "POST /system/session/recover": { auth: "door", beforeBoot: true, control: "never" },
@@ -1,4 +1,5 @@
1
1
  import { oc } from "@orpc/contract";
2
+ import type { ManageRight } from "../schemas/members.js";
2
3
  import type { MemberRole } from "../schemas/shared.js";
3
4
 
4
5
  // Every route's policy, declared beside it: how a request authenticates, which member tier and which machine
@@ -21,6 +22,9 @@ export interface RouteMeta {
21
22
  readonly stream?: true;
22
23
  // The lowest member role that may call it. Absent: viewer for a read (GET, HEAD), maintainer for anything else.
23
24
  readonly floor?: MemberRole;
25
+ // The part of the sandbox it runs (members.ts `ManageRightSchema`): a person below the floor who was given that part
26
+ // reaches it too. The handler holds anything finer (members.ts `peopleChangeRefusal`).
27
+ readonly right?: ManageRight;
24
28
  // On a guest member's allowlist, which is the whole of what a guest reaches.
25
29
  readonly guest?: true;
26
30
  // Beyond the guest list, for a home-only member (members.ts `agents: "home"`) whose work lands by itself
@@ -61,6 +65,7 @@ const ACCESS = {
61
65
  beforeBoot: (meta) => meta.beforeBoot === true,
62
66
  stream: (meta) => meta.stream === true,
63
67
  floor: (meta, method) => meta.floor ?? defaultFloor(method),
68
+ right: (meta) => meta.right ?? "none",
64
69
  guest: (meta) => meta.guest === true,
65
70
  home: (meta) => meta.home ?? "none",
66
71
  attachmentFloor: (meta) => meta.attachmentFloor ?? "none",
@@ -7,7 +7,8 @@ import { NATIVE_PROVIDERS } from "../models/provider-specs.js";
7
7
  import { AgentPlacementSchema } from "../protocol/doors/runner-protocol.js";
8
8
  import { MENTION_LIMIT } from "../text/mentions.js";
9
9
  import { entryId } from "./internal.js";
10
- import { FRESH_OF_DESCRIPTION, FreshOfSchema, freshOfIssues } from "./conversation-links.js";
10
+ import { FRESH_OF_DESCRIPTION, FreshOfSchema, FROM_BRANCH_DESCRIPTION, freshOfIssues, fromBranchIssues } from "./conversation-links.js";
11
+ import { RepoBranchSchema } from "./shared.js";
11
12
  // Agent runtimes the daemon can serve: native providers have dedicated adapters, `endpoint/<id>` names an installed
12
13
  // endpoint capability, anything else is an ACP agent capability id. A bare string, not an enum, so an unknown id is a
13
14
  // clean error, not a contract change.
@@ -202,6 +203,7 @@ const AgentTurnFieldsSchema = z.object({
202
203
  forkOf: ForkOfSchema.optional().describe("Where this conversation was cut from, on its first turn only. Only the client knows this, so only the client can say it."),
203
204
  // A fresh session's origin, on its first turn only; requires an isolated conversationId the registry has never seen.
204
205
  freshOf: FreshOfSchema.optional().describe(FRESH_OF_DESCRIPTION),
206
+ fromBranch: RepoBranchSchema.optional().describe(FROM_BRANCH_DESCRIPTION),
205
207
  // The browser sends the chosen model per turn; the provider token is the sandbox's own stored credential.
206
208
  model: z.string().optional().describe("Which model to use. Leave it out for the provider's default."),
207
209
  // Audience only, never model routing: `runRole` is what fills a model in. A run somebody pressed and is
@@ -312,6 +314,7 @@ export const AgentTurnSchema = AgentTurnFieldsSchema
312
314
  message: 'forkOf.files "then" requires isolated',
313
315
  })
314
316
  .superRefine(freshOfIssues)
317
+ .superRefine(fromBranchIssues)
315
318
  .refine((turn) => turn.sendAt === undefined || turn.sendAfter === undefined, {
316
319
  message: "sendAt and sendAfter are two different holds: name one",
317
320
  })
@@ -3,6 +3,8 @@ import { LandingDeliverySchema } from "./project-delivery.js";
3
3
  import { AgentNextSchema } from "./agent-next.js";
4
4
  import { z } from "zod";
5
5
  import { AgentHarnessSchema, AgentOriginSchema, AgentProviderSchema, ConversationQueueSchema, ForkedFromSchema, FreshSessionSchema } from "./agent.js";
6
+ import { FROM_BRANCHES_DESCRIPTION } from "./conversation-links.js";
7
+ import { RepoBranchSchema } from "./shared.js";
6
8
  import { LoopStateSchema } from "./loops.js";
7
9
  import { LimitPolicySchema, RetryPolicySchema, RoomPolicySchema, TurnBreakPolicySchema, TurnBreakSchema } from "./turn-break.js";
8
10
  import { KeepWarmSchema } from "./keep-warm.js";
@@ -398,6 +400,8 @@ export const AgentSummarySchema = z.object({
398
400
  fresh: FreshSessionSchema.optional().describe(
399
401
  "Set on a conversation started on another conversation's work without its messages (a code review, a test pass, a person's own ask): which one, for what, and when. Absent for every other conversation.",
400
402
  ),
403
+ // Latched by the opening compose (placement.branches): the repositories it works on a branch of, which its land commits onto.
404
+ branches: z.array(RepoBranchSchema).optional().describe(FROM_BRANCHES_DESCRIPTION),
401
405
  // Latched on the opening turn (ids/conversation-ids.ts homeConversationId). Rides the summary because it decides who
402
406
  // may see the row at all (auth/fleet-scope.ts visibleTo): its owner, and the sandbox's owner.
403
407
  home: z
@@ -524,7 +528,9 @@ export const AgentSummarySchema = z.object({
524
528
  code: z
525
529
  .string()
526
530
  .optional()
527
- .describe("Which kind of failure it was, when the sandbox could tell: unlinked when its copy lost its link to the workspace. Absent otherwise."),
531
+ .describe(
532
+ "Which kind of failure it was, when the sandbox could tell: unlinked when its copy lost its link to the workspace, off_main_line when the shared workspace was moved off its main line and the work waits until it is back. Absent otherwise.",
533
+ ),
528
534
  at: z.number().describe("When it failed, in milliseconds."),
529
535
  })
530
536
  .optional()
@@ -65,3 +65,28 @@ export const freshOfIssues = (
65
65
  ctx.addIssue({ code: "custom", message: "a conversation cannot start fresh on its own work" });
66
66
  }
67
67
  };
68
+
69
+ // A conversation started from a branch of one repository rather than from the main line: cut from the branch's tip there,
70
+ // kept on it, and its finished work committed onto it, while the shared checkout never leaves its main line. Latched by
71
+ // the opening turn as the placement's `branches`.
72
+ export const FROM_BRANCH_DESCRIPTION =
73
+ "Start this conversation from a branch of one repository instead of the main line: its copy of that repository is cut from the branch's tip, kept on it, and its finished work is committed onto that branch rather than landed in the shared workspace. First turn only, only on a private copy here, and never together with `freshOf` or `forkOf`.";
74
+
75
+ // The turn's own rules for `fromBranch`: a new private copy of its own here, one start at a time.
76
+ export const fromBranchIssues = (
77
+ turn: { readonly fromBranch?: unknown; readonly conversationId?: string | undefined; readonly isolated?: boolean | undefined; readonly forkOf?: unknown; readonly freshOf?: unknown },
78
+ ctx: z.RefinementCtx,
79
+ ): void => {
80
+ if (turn.fromBranch === undefined) {
81
+ return;
82
+ }
83
+ if (turn.conversationId === undefined || turn.isolated !== true) {
84
+ ctx.addIssue({ code: "custom", message: "fromBranch requires an isolated conversationId" });
85
+ }
86
+ if (turn.forkOf !== undefined || turn.freshOf !== undefined) {
87
+ ctx.addIssue({ code: "custom", message: "fromBranch is a start of its own: not together with forkOf or freshOf" });
88
+ }
89
+ };
90
+
91
+ export const FROM_BRANCHES_DESCRIPTION =
92
+ "The branches this conversation was started from, one per repository it works on a branch of: its copy of each is kept on that branch, and its land commits onto it instead of reaching the shared workspace. Absent for a conversation on the main line.";
@@ -3,7 +3,7 @@ import { AgentProviderSchema } from "../agent.js";
3
3
  import { LandConflictSchema, LandedMessageSchema } from "../agents.js";
4
4
  import { CommandRunSchema } from "../ci.js";
5
5
  import { RefNameSchema } from "../internal.js";
6
- import { RepoParamSchema } from "../shared.js";
6
+ import { MainBranchSchema, RepoParamSchema } from "../shared.js";
7
7
 
8
8
  // Which of the working tree's diffs a row is about; a path can be both staged and edited again, so a side is never
9
9
  // defaulted.
@@ -293,8 +293,8 @@ export const IGNORED_OUTPUTS_LISTED = 200;
293
293
  export const RepoChangesSchema = z.object({
294
294
  // The {repo} param the per-repo git routes accept: "root" or a repo id (its root-relative dir).
295
295
  repo: z.string(),
296
- // Absent on an unborn HEAD (initialized, never committed).
297
296
  branch: z.string().optional().describe("The checked-out branch. Absent in a repository that has no commits yet."),
297
+ mainBranch: MainBranchSchema,
298
298
  // Staging a conflicted path (`git add`) is how you tell git it is resolved.
299
299
  conflicted: z
300
300
  .array(GitChangeSchema)
@@ -1,4 +1,4 @@
1
- import { accessRefusal, landsHere, memberAccess, tierOf } from "./members.js";
1
+ import { accessRefusal, holdsRight, landsHere, memberAccess, peopleChangeRefusal, tierOf } from "./members.js";
2
2
 
3
3
  // A person's access is three answers, and the tier is what they add up to; a row from before the answers reads as its
4
4
  // role meant, so nobody's access moves when the daemon learns the new fields.
@@ -73,3 +73,55 @@ describe(`home-only access`, () => {
73
73
  expect(landsHere({ manage: false, agents: `run`, lands: true })).toBe(false);
74
74
  });
75
75
  });
76
+
77
+ describe(`rights`, () => {
78
+ test(`the owner and Full access run every part; anyone else what their row names`, () => {
79
+ expect(holdsRight({ role: `owner` }, `people`)).toBe(true);
80
+ expect(holdsRight({ role: `maintainer` }, `secrets`)).toBe(true);
81
+ expect(holdsRight({ role: `collaborator`, manages: [`people`] }, `people`)).toBe(true);
82
+ expect(holdsRight({ role: `collaborator`, manages: [`people`] }, `secrets`)).toBe(false);
83
+ expect(holdsRight({ role: `writer` }, `privacy`)).toBe(false);
84
+ });
85
+
86
+ test(`a row's rights ride on its access, and never make a tier`, () => {
87
+ const access = memberAccess({ role: `collaborator`, agents: `run`, manages: [`people`, `ownAccounts`] });
88
+ expect(access.manages).toEqual([`people`, `ownAccounts`]);
89
+ expect(tierOf(access)).toBe(`collaborator`);
90
+ expect(memberAccess({ role: `collaborator`, agents: `run`, manages: [] }).manages).toBeUndefined();
91
+ });
92
+
93
+ test(`someone who only chats or works through their home holds none`, () => {
94
+ expect(accessRefusal({ manage: false, agents: `chat`, see: [`docs`], edit: `none`, manages: [`people`] })).toContain(`holds no rights`);
95
+ expect(accessRefusal({ manage: false, agents: `home`, see: undefined, edit: `none`, manages: [`secrets`] })).toContain(`holds no rights`);
96
+ expect(accessRefusal({ manage: false, agents: `off`, see: undefined, edit: `none`, manages: [`people`] })).toBeUndefined();
97
+ });
98
+ });
99
+
100
+ describe(`peopleChangeRefusal`, () => {
101
+ const lead = { email: `lead@example.com`, role: `collaborator` as const, manages: [`people` as const, `ownAccounts` as const] };
102
+
103
+ test(`the owner and Full access change anyone, themselves included`, () => {
104
+ expect(peopleChangeRefusal({ email: `o@example.com`, role: `owner` }, { email: `x@example.com`, after: { role: `maintainer` } })).toBeUndefined();
105
+ const full = { email: `m@example.com`, role: `maintainer` as const };
106
+ expect(peopleChangeRefusal(full, { email: `m@example.com`, before: { role: `maintainer` }, after: { role: `collaborator` } })).toBeUndefined();
107
+ expect(peopleChangeRefusal(full, { email: `x@example.com`, before: { role: `maintainer` } })).toBeUndefined();
108
+ });
109
+
110
+ test(`People & access changes anyone below Full access but its holder`, () => {
111
+ expect(peopleChangeRefusal(lead, { email: `new@example.com`, after: { role: `writer` } })).toBeUndefined();
112
+ expect(peopleChangeRefusal(lead, { email: `x@example.com`, before: { role: `viewer` } })).toBeUndefined();
113
+ expect(peopleChangeRefusal(lead, { email: `LEAD@example.com`, before: { role: `collaborator` }, after: { role: `writer` } })).toContain(`your own access`);
114
+ expect(peopleChangeRefusal(lead, { email: `x@example.com`, after: { role: `maintainer` } })).toContain(`Full access is granted`);
115
+ expect(peopleChangeRefusal(lead, { email: `x@example.com`, before: { role: `maintainer` } })).toContain(`Full access person`);
116
+ expect(peopleChangeRefusal({ ...lead, manages: [] }, { email: `x@example.com`, after: { role: `viewer` } })).toContain(`People & access`);
117
+ });
118
+
119
+ test(`it hands out only the rights its holder has, and leaves the ones already held alone`, () => {
120
+ expect(peopleChangeRefusal(lead, { email: `x@example.com`, after: { role: `viewer`, manages: [`people`, `ownAccounts`] } })).toBeUndefined();
121
+ expect(peopleChangeRefusal(lead, { email: `x@example.com`, after: { role: `viewer`, manages: [`secrets`] } })).toContain(`secrets`);
122
+ expect(
123
+ peopleChangeRefusal(lead, { email: `x@example.com`, before: { role: `viewer`, manages: [`secrets`] }, after: { role: `writer`, manages: [`secrets`] } }),
124
+ ).toBeUndefined();
125
+ expect(peopleChangeRefusal(lead, { email: `x@example.com`, before: { role: `viewer`, manages: [`secrets`] }, after: { role: `writer` } })).toBeUndefined();
126
+ });
127
+ });
@@ -2,9 +2,62 @@
2
2
  import { z } from "zod";
3
3
  import type { CapabilityKind } from "./capabilities.js";
4
4
  import { entryId } from "./internal.js";
5
- import { type GrantedRole, GrantedRoleSchema, MemberRoleSchema } from "./shared.js";
5
+ import { type GrantedRole, GrantedRoleSchema, type MemberRole, MemberRoleSchema } from "./shared.js";
6
6
  import { ToolCeilingSchema } from "./tool-ceiling.js";
7
7
 
8
+ // WHAT A PERSON MAY RUN BESIDES THEIR OWN WORK, one part of the sandbox at a time. Full access (the maintainer tier) holds
9
+ // every one; a person with access of their own holds the ones named on their row, so the owner can hand over who gets in
10
+ // without handing over the whole box (docs/architecture/access.md).
11
+ // `people`: who has access and to what (the roster, the requests for more, areas, access profiles, who opens previews,
12
+ // another member's passkeys). Bounded below Full access by `peopleChangeRefusal`.
13
+ // `secrets`: the Secrets page whole: stored secrets, who must approve a use, where a secret may go, and how a command-line
14
+ // tool's credential reaches the agent.
15
+ // `privacy`: the privacy shield: what it masks, reading masked values back, and forgetting a taught dataset.
16
+ // `ownAccounts`: connecting AI accounts of their own. An account a person connected is theirs to run on whatever their
17
+ // `aiAccounts` says, and theirs to rename or disconnect (the daemon's auth/members/account-connectors.ts).
18
+ export const ManageRightSchema = z.enum(["people", "secrets", "privacy", "ownAccounts"]);
19
+ export type ManageRight = z.infer<typeof ManageRightSchema>;
20
+ export const MANAGE_RIGHTS: readonly ManageRight[] = ManageRightSchema.options;
21
+
22
+ /** Whether this person may run one part of the sandbox: the owner and Full access run every part, anyone else what their row names. */
23
+ export const holdsRight = (caller: { readonly role: MemberRole; readonly manages?: readonly ManageRight[] | undefined }, right: ManageRight): boolean =>
24
+ caller.role === "owner" || caller.role === "maintainer" || (caller.manages?.includes(right) ?? false);
25
+
26
+ /**
27
+ * Why someone who manages people may not make this change to one person's access; undefined when they may. The owner and
28
+ * Full access change anyone's, their own included. The People & access right alone changes the access of anyone below
29
+ * Full access but its holder: it never grants Full access, never changes a Full access person's, never its holder's own
30
+ * (that is how a limit set on them holds), and hands out only the rights its holder has. `after` absent is a removal;
31
+ * its `manages` absent keeps the row's, as a grant reads it.
32
+ */
33
+ export const peopleChangeRefusal = (
34
+ manager: { readonly email: string; readonly role: MemberRole; readonly manages?: readonly ManageRight[] | undefined },
35
+ target: {
36
+ readonly email: string;
37
+ readonly before?: { readonly role: GrantedRole; readonly manages?: readonly ManageRight[] | undefined } | undefined;
38
+ readonly after?: { readonly role: GrantedRole; readonly manages?: readonly ManageRight[] | undefined } | undefined;
39
+ },
40
+ ): string | undefined => {
41
+ if (manager.role === "owner" || manager.role === "maintainer") {
42
+ return undefined;
43
+ }
44
+ if (!holdsRight(manager, "people")) {
45
+ return "only the owner, Full access, or someone given People & access changes who has access";
46
+ }
47
+ if (manager.email.toLowerCase() === target.email.toLowerCase()) {
48
+ return "your own access is changed by the owner or someone with Full access";
49
+ }
50
+ if (target.before?.role === "maintainer") {
51
+ return "a Full access person's access is changed by the owner or someone with Full access";
52
+ }
53
+ if (target.after?.role === "maintainer") {
54
+ return "Full access is granted by the owner or someone with Full access";
55
+ }
56
+ const had = new Set(target.before?.manages ?? []);
57
+ const handed = (target.after?.manages ?? []).filter((right) => !had.has(right) && !(manager.manages ?? []).includes(right));
58
+ return handed.length === 0 ? undefined : `you can hand out only the rights you hold yourself, and ${handed.join(", ")} is not one of yours`;
59
+ };
60
+
8
61
  // WHAT A PERSON'S CONVERSATIONS MAY SPEND: the connected capabilities (by id) and the stored secrets (by name) an agent
9
62
  // working for them is handed. Enforced by the daemon, not told to the model: a capability outside it is never mounted
10
63
  // for their turns, its variables and skill are left out, and every exit that spends a credential (a `{{secret:…}}`
@@ -90,6 +143,9 @@ export interface MemberAccess {
90
143
  // A home-only person's answer to whether their home conversation lands what it accepts by itself, and so whether
91
144
  // they may land it (`landsHere`). Absent is no; only `agents: "home"` may carry it.
92
145
  readonly lands?: boolean | undefined;
146
+ // The parts of the sandbox they run besides their own work (`ManageRightSchema`). Full access holds every one, so
147
+ // its rows never list them; absent is none.
148
+ readonly manages?: readonly ManageRight[] | undefined;
93
149
  }
94
150
 
95
151
  // The fields of a row or a grant that decide a person's access.
@@ -99,6 +155,7 @@ interface AccessFields {
99
155
  readonly agents?: AgentAccess | undefined;
100
156
  readonly edit?: EditScope | undefined;
101
157
  readonly lands?: boolean | undefined;
158
+ readonly manages?: readonly ManageRight[] | undefined;
102
159
  }
103
160
 
104
161
  /** A row's access: what it says, and for a row written before `agents` and `edit` existed, what its role meant then. */
@@ -109,7 +166,8 @@ export const memberAccess = (row: AccessFields): MemberAccess => {
109
166
  const agents = row.agents ?? (row.role === "guest" ? "chat" : row.role === "viewer" ? "off" : "run");
110
167
  // A writer from before `edit` changes files where it sees them, which its areas always named.
111
168
  const edit = row.edit ?? (row.role === "writer" && row.areas !== undefined ? [...row.areas] : "none");
112
- const access: MemberAccess = { manage: false, agents, see: row.areas, edit: agents === "chat" || agents === "home" ? "none" : edit };
169
+ const base: MemberAccess = { manage: false, agents, see: row.areas, edit: agents === "chat" || agents === "home" ? "none" : edit };
170
+ const access = row.manages !== undefined && row.manages.length > 0 ? { ...base, manages: [...row.manages] } : base;
113
171
  return row.lands === true ? { ...access, lands: true } : access;
114
172
  };
115
173
 
@@ -135,20 +193,26 @@ export const tierOf = (access: MemberAccess): GrantedRole => {
135
193
  return access.agents === "run" ? "collaborator" : "viewer";
136
194
  };
137
195
 
138
- /** Why an access cannot be granted on its face, before any area or assistant is looked up; undefined when it can. */
139
- export const accessRefusal = (access: MemberAccess): string | undefined => {
140
- if (access.manage) {
141
- return undefined;
142
- }
196
+ // Why a way of working cannot carry what else the access says: landing by itself, rights, areas and hand edits each
197
+ // belong to some ways of working only.
198
+ const workingRefusal = (access: MemberAccess): string | undefined => {
143
199
  if (access.lands === true && access.agents !== "home") {
144
200
  return "landing their own work by itself is a home-only answer; anyone else's work lands when somebody who manages the sandbox lands it";
145
201
  }
202
+ if ((access.manages?.length ?? 0) > 0 && (access.agents === "chat" || access.agents === "home")) {
203
+ return "running part of the sandbox needs someone who sees it: a person who only chats, or works through their home conversation, holds no rights";
204
+ }
146
205
  if (access.agents === "chat" && (access.see?.length ?? 0) === 0) {
147
206
  return "chatting with assistants needs at least one area: the assistants that work there are the ones they talk to";
148
207
  }
149
208
  if (access.agents === "home" && access.edit !== "none") {
150
209
  return "a home-only person changes nothing by hand: their home conversation does the work";
151
210
  }
211
+ return undefined;
212
+ };
213
+
214
+ // Why where a person edits by hand does not fit where they see.
215
+ const editRefusal = (access: MemberAccess): string | undefined => {
152
216
  if (access.edit === "all") {
153
217
  return access.see === undefined ? undefined : "editing everything they see needs the whole workspace; name the areas to edit instead";
154
218
  }
@@ -163,6 +227,9 @@ export const accessRefusal = (access: MemberAccess): string | undefined => {
163
227
  return unseen.length === 0 ? undefined : `they can only edit where they can see: ${unseen.join(", ")} is not among their areas`;
164
228
  };
165
229
 
230
+ /** Why an access cannot be granted on its face, before any area or assistant is looked up; undefined when it can. */
231
+ export const accessRefusal = (access: MemberAccess): string | undefined => (access.manage ? undefined : (workingRefusal(access) ?? editRefusal(access)));
232
+
166
233
  // One person on the roster as the daemon answers it. `areas` fences what of the workspace they reach, and with it which
167
234
  // assistants they may talk to: absent is the whole workspace, empty is nothing.
168
235
  export const MemberSchema = z.object({
@@ -208,6 +275,12 @@ export const MemberSchema = z.object({
208
275
  .describe(
209
276
  "The access profile their answers come from (docs/architecture/access.md). Its answers are written out on this row too, and saving the profile rewrites them. Absent means answers of their own.",
210
277
  ),
278
+ manages: z
279
+ .array(ManageRightSchema)
280
+ .optional()
281
+ .describe(
282
+ "The parts of the sandbox they run besides their own work: people and access, secrets, the privacy shield, AI accounts of their own. Never on a maintainer, who runs every part. Absent means none.",
283
+ ),
211
284
  });
212
285
  export type Member = z.infer<typeof MemberSchema>;
213
286
 
@@ -237,6 +310,10 @@ export type MembersRoster = z.infer<typeof MembersRosterSchema>;
237
310
  // the row and ignores the access fields sent beside it, and the role sent must still be the tier the profile makes.
238
311
  // Absent is answers of the row's own, so a re-grade from an editor that predates profiles unlinks the row, keeping
239
312
  // the answers it carried, rather than leaving a link the grant did not mean. A maintainer is refused one.
313
+ // `manages` reads as `credentials` does: a list sets the rights, `[]` takes them all back, absent keeps the row's, so a
314
+ // profile written over a row and a re-grade from an editor that predates rights keep what the person runs. A maintainer
315
+ // holds every right and stores none. Rights ride beside a profile, never in one: like Full access, running part of the
316
+ // sandbox is handed to a person, never through something shared.
240
317
  export const MemberGrantSchema = z.object({
241
318
  email: z.string(),
242
319
  role: GrantedRoleSchema,
@@ -250,6 +327,7 @@ export const MemberGrantSchema = z.object({
250
327
  tools: z.union([z.literal("all"), ToolCeilingSchema]).optional(),
251
328
  assistants: z.union([z.literal("all"), z.array(entryId).max(50)]).optional(),
252
329
  profile: entryId.optional(),
330
+ manages: z.array(ManageRightSchema).max(10).optional(),
253
331
  });
254
332
  export type MemberGrant = z.infer<typeof MemberGrantSchema>;
255
333
 
@@ -271,6 +349,10 @@ export const MemberSelfSchema = z.object({
271
349
  tools: ToolCeilingSchema.optional().describe("The most their conversations' tools may be. Absent means no limit."),
272
350
  assistants: z.array(entryId).optional().describe("For a guest who chats: the assistants they may talk to. Absent means every one in their areas."),
273
351
  profile: entryId.optional().describe("The access profile their access comes from. Absent means answers of their own."),
352
+ manages: z
353
+ .array(ManageRightSchema)
354
+ .optional()
355
+ .describe("The parts of the sandbox they run besides their own work: every one for the owner and Full access. Absent means none."),
274
356
  askedAt: z
275
357
  .number()
276
358
  .int()
@@ -279,10 +361,10 @@ export const MemberSelfSchema = z.object({
279
361
  });
280
362
  export type MemberSelf = z.infer<typeof MemberSelfSchema>;
281
363
 
282
- // ASKING THE OWNER FOR MORE ACCESS, from where the person was refused: the editor draws an "Ask for access" press on a
283
- // place or an action their access refuses, and the owner sees each open request beside the roster (Access ▸ People),
284
- // where granting the person what they asked for answers it. One open request per person: a later ask replaces theirs.
285
- // `want` is what stood in the way, in the terms a grant answers: a tier (`viewer` is a guest asking to see more),
364
+ // ASKING FOR MORE ACCESS, from where the person was refused: the editor draws an "Ask for access" press on a place or an
365
+ // action their access refuses, and whoever runs people and access sees each open request beside the roster (Access ▸
366
+ // People), where granting the person what they asked for answers it. One open request per person: a later ask replaces
367
+ // theirs. `want` is what stood in the way, in the terms a grant answers: a tier (`viewer` is a guest asking to see more),
286
368
  // running agents (`agents`), or a folder outside their areas (`areas`).
287
369
  // `aiAccounts`: the AI accounts their turns may run on (`aiAccounts` on their row) leave them nothing to run on that they
288
370
  // asked for, asked from a model picker with no model of theirs in it.
@@ -24,6 +24,12 @@ export const OauthAccountSchema = z.object({
24
24
  ),
25
25
  scope: z.string().optional().describe("What the credential is permitted to do, in the provider's terms."),
26
26
  connectedAt: z.number().describe("When it was connected, in milliseconds."),
27
+ connectedBy: z
28
+ .string()
29
+ .optional()
30
+ .describe(
31
+ "Who connected it, by the address they signed in with, where a person on this sandbox did. An account is always its connector's to run on. Absent for one connected before this was recorded, or by the owner's own tools.",
32
+ ),
27
33
  needsReauth: z
28
34
  .boolean()
29
35
  .optional()
@@ -35,3 +35,24 @@ export const RepoParamSchema = object({
35
35
  'Which repository. "root" is the workspace itself; anything else is a repository\'s folder relative to the workspace root, URL-encoded.',
36
36
  ),
37
37
  });
38
+ // A shared checkout's main line (the daemon's git/main-line-lock.ts), named on a repository's changes only when
39
+ // something moved it elsewhere.
40
+ export const MainBranchSchema = string()
41
+ .optional()
42
+ .describe(
43
+ "The branch this shared checkout belongs on, given only when it stands somewhere else: agents' work waits rather than land on the wrong branch until it is back. Absent, the normal case, means it is on its main line.",
44
+ );
45
+ // One branch of one workspace repository, for what looks at it or starts from it while the shared checkout stays on its
46
+ // main line: the Workspace's per-person view of it, an agent started from it. A remote-only branch is named by its
47
+ // short name; the daemon makes the local one at the remote's tip the first time it is needed.
48
+ export const BranchNameSchema = string()
49
+ .regex(/^[A-Za-z0-9][A-Za-z0-9._/-]*$/)
50
+ .max(200)
51
+ .describe("The branch, by its short name: `feature/login`, not `refs/heads/feature/login` or `origin/feature/login`.");
52
+ export const RepoBranchSchema = object({
53
+ repo: string()
54
+ .min(1)
55
+ .describe('Which repository. "root" is the workspace itself; anything else is a repository\'s folder relative to the workspace root.'),
56
+ branch: BranchNameSchema,
57
+ });
58
+ export type RepoBranch = z.infer<typeof RepoBranchSchema>;
@@ -1,12 +1,20 @@
1
1
  // workspace tree + files
2
2
  import { z } from "zod";
3
3
  import { ConversationIdSchema } from "../agent.js";
4
+ import { BranchNameSchema } from "../shared.js";
4
5
  // Which copy of the workspace a read means: the shared /work tree, or (if `agent` is set) that conversation's own
5
6
  // checkout, resolved in one place so the escape guard, denylist and ignore rules apply the same either way.
6
7
  export const WorkspaceScopeSchema = z.object({
7
8
  agent: ConversationIdSchema.optional().describe(
8
9
  "Read a conversation's own private copy of the workspace rather than the shared tree. Leave it out for the shared tree. A conversation that is not working privately resolves back to the shared tree rather than failing, so a link need not know which mode it runs in.",
9
10
  ),
11
+ // A branch the shared checkout is not on (it stays on its main line): read from a checkout the daemon keeps of it,
12
+ // read-only; inside `repo` from the branch, everywhere else from the shared tree. Never together with `agent`.
13
+ branch: BranchNameSchema.optional()
14
+ .describe(
15
+ "Read a branch of one repository as it stands, without the shared workspace leaving its main line: files inside that repository come from the branch, everything else from the shared tree. Never together with `agent`.",
16
+ ),
17
+ repo: z.string().min(1).optional().describe('With `branch`: which repository it is a branch of, "root" or left out for the workspace itself.'),
10
18
  });
11
19
  export type WorkspaceScope = z.infer<typeof WorkspaceScopeSchema>;
12
20
  // path is root-relative with forward slashes, feeding straight into the file routes. The interface is declared by hand:
@@ -0,0 +1,16 @@
1
+ // What moves a checkout's HEAD, for the `git.branch-switch` class (policy/command-classes.ts). `switch` exists only to move
2
+ // HEAD, so every form of it counts. `checkout` is two commands wearing one name: with `-- <path>` or a bare `.` it
3
+ // restores files and moves nothing, and those are the common ones, so they are cut out; a bare trailing `--` names no
4
+ // path and still switches. `symbolic-ref HEAD refs/…` is
5
+ // the plumbing spelling of the same move; reading it (no target) moves nothing.
6
+ //
7
+ // git's own options may stand between `git` and the verb (`git -C /work checkout x`, `git -c k=v switch x`), and they are
8
+ // read through, or naming a directory would be a way around the class.
9
+
10
+ const GLOBALS = String.raw`(?:\s+(?:-C\s+\S+|-c\s+\S+|--git-dir(?:=|\s+)\S+|--work-tree(?:=|\s+)\S+|--no-pager|--no-optional-locks|-P))*`;
11
+
12
+ export const GIT_BRANCH_SWITCH: readonly RegExp[] = [
13
+ new RegExp(String.raw`\bgit${GLOBALS}\s+switch\b`),
14
+ new RegExp(String.raw`\bgit${GLOBALS}\s+checkout\b(?![^|;&]*\s--\s+[^\s|;&])(?![^|;&]*\s\.(?:\s|$))`),
15
+ new RegExp(String.raw`\bgit${GLOBALS}\s+symbolic-ref\b[^|;&]*\sHEAD\s+refs\/`),
16
+ ];