@intentic/sandbox-contract 1.363.0 → 1.364.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 (139) hide show
  1. package/README.md +4 -0
  2. package/dist/contracts/access-profiles.contract.d.ts +91 -0
  3. package/dist/contracts/access-profiles.contract.d.ts.map +1 -0
  4. package/dist/contracts/access-profiles.contract.js +33 -0
  5. package/dist/contracts/access-profiles.contract.js.map +1 -0
  6. package/dist/contracts/agent.contract.d.ts +18 -0
  7. package/dist/contracts/agent.contract.d.ts.map +1 -1
  8. package/dist/contracts/agents.contract.d.ts +7 -0
  9. package/dist/contracts/agents.contract.d.ts.map +1 -1
  10. package/dist/contracts/automations.contract.d.ts +5 -0
  11. package/dist/contracts/automations.contract.d.ts.map +1 -1
  12. package/dist/contracts/extensions.contract.d.ts +6 -0
  13. package/dist/contracts/extensions.contract.d.ts.map +1 -1
  14. package/dist/contracts/needs.contract.d.ts +14 -0
  15. package/dist/contracts/needs.contract.d.ts.map +1 -1
  16. package/dist/contracts/org.contract.d.ts +49 -0
  17. package/dist/contracts/org.contract.d.ts.map +1 -1
  18. package/dist/contracts/runner.contract.d.ts +6 -0
  19. package/dist/contracts/runner.contract.d.ts.map +1 -1
  20. package/dist/contracts/services.contract.d.ts +26 -0
  21. package/dist/contracts/services.contract.d.ts.map +1 -0
  22. package/dist/contracts/services.contract.js +33 -0
  23. package/dist/contracts/services.contract.js.map +1 -0
  24. package/dist/contracts/sessions.contract.d.ts +2 -0
  25. package/dist/contracts/sessions.contract.d.ts.map +1 -1
  26. package/dist/contracts/system.contract.d.ts +3 -0
  27. package/dist/contracts/system.contract.d.ts.map +1 -1
  28. package/dist/events/agent-events.d.ts +8 -0
  29. package/dist/events/agent-events.d.ts.map +1 -1
  30. package/dist/events/agent-transcript.d.ts +2 -0
  31. package/dist/events/agent-transcript.d.ts.map +1 -1
  32. package/dist/events/transcript.d.ts +10 -0
  33. package/dist/events/transcript.d.ts.map +1 -1
  34. package/dist/index.d.ts +219 -0
  35. package/dist/index.d.ts.map +1 -1
  36. package/dist/index.js +4 -0
  37. package/dist/index.js.map +1 -1
  38. package/dist/models/model-setups.d.ts.map +1 -1
  39. package/dist/models/model-setups.js.map +1 -1
  40. package/dist/policy/control-scopes.d.ts +3 -0
  41. package/dist/policy/control-scopes.d.ts.map +1 -1
  42. package/dist/policy/control-scopes.js +2 -0
  43. package/dist/policy/control-scopes.js.map +1 -1
  44. package/dist/policy/org-locks.d.ts +1 -1
  45. package/dist/policy/org-locks.d.ts.map +1 -1
  46. package/dist/policy/org-locks.js +3 -1
  47. package/dist/policy/org-locks.js.map +1 -1
  48. package/dist/protocol/raw/raw-json-routes.d.ts +309 -1
  49. package/dist/protocol/raw/raw-json-routes.d.ts.map +1 -1
  50. package/dist/protocol/raw/raw-json-routes.js +3 -1
  51. package/dist/protocol/raw/raw-json-routes.js.map +1 -1
  52. package/dist/protocol/raw/raw-routes.d.ts +2 -0
  53. package/dist/protocol/raw/raw-routes.d.ts.map +1 -1
  54. package/dist/protocol/raw/raw-routes.js +2 -0
  55. package/dist/protocol/raw/raw-routes.js.map +1 -1
  56. package/dist/schemas/access-profiles.d.ts +153 -0
  57. package/dist/schemas/access-profiles.d.ts.map +1 -0
  58. package/dist/schemas/access-profiles.js +56 -0
  59. package/dist/schemas/access-profiles.js.map +1 -0
  60. package/dist/schemas/agents-list.d.ts +1 -0
  61. package/dist/schemas/agents-list.d.ts.map +1 -1
  62. package/dist/schemas/automations.d.ts +10 -0
  63. package/dist/schemas/automations.d.ts.map +1 -1
  64. package/dist/schemas/automations.js +7 -0
  65. package/dist/schemas/automations.js.map +1 -1
  66. package/dist/schemas/dev-rebuild-log.d.ts +16 -0
  67. package/dist/schemas/dev-rebuild-log.d.ts.map +1 -1
  68. package/dist/schemas/dev-rebuild-log.js +38 -2
  69. package/dist/schemas/dev-rebuild-log.js.map +1 -1
  70. package/dist/schemas/device-commands.d.ts +7 -1
  71. package/dist/schemas/device-commands.d.ts.map +1 -1
  72. package/dist/schemas/device-commands.js +14 -2
  73. package/dist/schemas/device-commands.js.map +1 -1
  74. package/dist/schemas/environment.d.ts +27 -0
  75. package/dist/schemas/environment.d.ts.map +1 -1
  76. package/dist/schemas/environment.js +9 -0
  77. package/dist/schemas/environment.js.map +1 -1
  78. package/dist/schemas/extension-updates.d.ts +12 -0
  79. package/dist/schemas/extension-updates.d.ts.map +1 -1
  80. package/dist/schemas/links.d.ts +6 -1
  81. package/dist/schemas/links.d.ts.map +1 -1
  82. package/dist/schemas/links.js +8 -1
  83. package/dist/schemas/links.js.map +1 -1
  84. package/dist/schemas/members.d.ts +75 -0
  85. package/dist/schemas/members.d.ts.map +1 -1
  86. package/dist/schemas/members.js +17 -0
  87. package/dist/schemas/members.js.map +1 -1
  88. package/dist/schemas/needs.d.ts +16 -0
  89. package/dist/schemas/needs.d.ts.map +1 -1
  90. package/dist/schemas/organisation.d.ts +164 -0
  91. package/dist/schemas/organisation.d.ts.map +1 -1
  92. package/dist/schemas/organisation.js +17 -0
  93. package/dist/schemas/organisation.js.map +1 -1
  94. package/dist/schemas/personas.d.ts.map +1 -1
  95. package/dist/schemas/personas.js +2 -2
  96. package/dist/schemas/personas.js.map +1 -1
  97. package/dist/schemas/services.d.ts +24 -0
  98. package/dist/schemas/services.d.ts.map +1 -0
  99. package/dist/schemas/services.js +19 -0
  100. package/dist/schemas/services.js.map +1 -0
  101. package/dist/schemas/settings.d.ts.map +1 -1
  102. package/dist/schemas/settings.js +3 -3
  103. package/dist/schemas/settings.js.map +1 -1
  104. package/dist/schemas/tool-ceiling.d.ts +24 -0
  105. package/dist/schemas/tool-ceiling.d.ts.map +1 -0
  106. package/dist/schemas/tool-ceiling.js +86 -0
  107. package/dist/schemas/tool-ceiling.js.map +1 -0
  108. package/dist/state/locked-folders.d.ts +2 -0
  109. package/dist/state/locked-folders.d.ts.map +1 -0
  110. package/dist/state/locked-folders.js +11 -0
  111. package/dist/state/locked-folders.js.map +1 -0
  112. package/package.json +5 -5
  113. package/src/contracts/access-profiles.contract.ts +43 -0
  114. package/src/contracts/services.contract.ts +40 -0
  115. package/src/index.ts +4 -0
  116. package/src/models/model-roles.ts +2 -2
  117. package/src/models/model-setups.ts +3 -4
  118. package/src/policy/control-scopes.ts +5 -0
  119. package/src/policy/org-locks.ts +5 -2
  120. package/src/protocol/raw/raw-json-routes.ts +3 -0
  121. package/src/protocol/raw/raw-routes.ts +2 -0
  122. package/src/schemas/access-profiles.test.ts +50 -0
  123. package/src/schemas/access-profiles.ts +104 -0
  124. package/src/schemas/automations.ts +15 -1
  125. package/src/schemas/dev-rebuild-log.test.ts +46 -1
  126. package/src/schemas/dev-rebuild-log.ts +71 -3
  127. package/src/schemas/device-commands.ts +30 -2
  128. package/src/schemas/environment.ts +22 -0
  129. package/src/schemas/links.ts +13 -2
  130. package/src/schemas/members.ts +29 -1
  131. package/src/schemas/organisation.ts +25 -0
  132. package/src/schemas/personas.ts +15 -11
  133. package/src/schemas/services.ts +32 -0
  134. package/src/schemas/settings.test.ts +23 -1
  135. package/src/schemas/settings.ts +5 -4
  136. package/src/schemas/tool-ceiling.test.ts +70 -0
  137. package/src/schemas/tool-ceiling.ts +113 -0
  138. package/src/state/locked-folders.test.ts +29 -0
  139. package/src/state/locked-folders.ts +17 -0
@@ -0,0 +1,70 @@
1
+ import { PersonaPowersSchema } from "./personas.js";
2
+ import { capPowers, ceilingLimits, ceilingWithholds, ceilingWords, intersectCeilings } from "./tool-ceiling.js";
3
+
4
+ // A ceiling is an upper bound per shelf: an answer left out limits nothing, and two held together keep the lower of each.
5
+
6
+ const FULL = PersonaPowersSchema.parse({});
7
+
8
+ describe(`intersectCeilings`, () => {
9
+ it(`keeps the lower answer of each shelf`, () => {
10
+ expect(intersectCeilings({ files: `read`, shell: false }, { files: `none`, web: false })).toEqual({ files: `none`, shell: false, web: false });
11
+ expect(intersectCeilings({ files: `write` }, { files: `read` })).toEqual({ files: `read` });
12
+ });
13
+
14
+ it(`reads undefined as no ceiling at all`, () => {
15
+ expect(intersectCeilings(undefined, { shell: false })).toEqual({ shell: false });
16
+ expect(intersectCeilings({ code: false }, undefined)).toEqual({ code: false });
17
+ expect(intersectCeilings(undefined, undefined)).toBeUndefined();
18
+ });
19
+
20
+ it(`drops a shelf both answer true, since true is no limit`, () => {
21
+ expect(intersectCeilings({ shell: true }, { shell: true })).toEqual({});
22
+ });
23
+ });
24
+
25
+ describe(`capPowers`, () => {
26
+ it(`lowers a persona's shelves to the ceiling and keeps its connector lists`, () => {
27
+ const powers = { ...FULL, connectors: [`github`] };
28
+ expect(capPowers(powers, { files: `read`, shell: false, delegate: false })).toEqual({
29
+ ...powers,
30
+ files: `read`,
31
+ shell: false,
32
+ delegate: false,
33
+ });
34
+ });
35
+
36
+ it(`never raises a shelf the persona switched off`, () => {
37
+ const readOnly = { ...FULL, files: `read` as const, shell: false };
38
+ expect(capPowers(readOnly, { files: `write`, shell: true })).toEqual(readOnly);
39
+ });
40
+
41
+ it(`returns the persona's own shelves when the ceiling limits nothing`, () => {
42
+ expect(capPowers(FULL, undefined)).toBe(FULL);
43
+ expect(capPowers(FULL, { files: `write`, web: true })).toBe(FULL);
44
+ });
45
+ });
46
+
47
+ describe(`ceilingLimits and ceilingWithholds`, () => {
48
+ it(`counts only an answer below the top as a limit`, () => {
49
+ expect(ceilingLimits(undefined)).toBe(false);
50
+ expect(ceilingLimits({ files: `write`, shell: true })).toBe(false);
51
+ expect(ceilingLimits({ files: `read` })).toBe(true);
52
+ expect(ceilingLimits({ browser: false })).toBe(true);
53
+ });
54
+
55
+ it(`withholds files below write, and a switch answered false`, () => {
56
+ expect(ceilingWithholds({ files: `read` }, `files`)).toBe(true);
57
+ expect(ceilingWithholds({ files: `write` }, `files`)).toBe(false);
58
+ expect(ceilingWithholds({ shell: false }, `shell`)).toBe(true);
59
+ expect(ceilingWithholds({ shell: false }, `web`)).toBe(false);
60
+ expect(ceilingWithholds(undefined, `shell`)).toBe(false);
61
+ });
62
+ });
63
+
64
+ describe(`ceilingWords`, () => {
65
+ it(`names each limit in the order the shelves are listed`, () => {
66
+ expect(ceilingWords({ files: `read`, shell: false, sandbox: false })).toEqual([`read-only files`, `no commands`, `no sandbox settings`]);
67
+ expect(ceilingWords({ files: `none` })).toEqual([`no files`]);
68
+ expect(ceilingWords(undefined)).toEqual([]);
69
+ });
70
+ });
@@ -0,0 +1,113 @@
1
+ import { z } from "zod";
2
+ import type { PersonaPowers } from "./personas.js";
3
+
4
+ // THE MOST A TURN'S TOOLS MAY BE, as the principals it acts for are held to it (docs/architecture/access.md): one answer
5
+ // per persona shelf, each an upper bound. A shelf left out is not limited. A persona's own shelves are posture and only
6
+ // narrow inside this; a conversation grant lifts what a persona withheld and never what a ceiling did.
7
+ // The same names and order as a persona's shelves (schemas/personas.ts PersonaPowersSchema), so one vocabulary covers
8
+ // both, with no defaults: an absent answer here is "no limit", where an absent shelf on a card is "on".
9
+ export const ToolCeilingSchema = z.object({
10
+ files: z.enum(["none", "read", "write"]).optional().describe("The most it may do with files: nothing, look and search, or also create and change."),
11
+ shell: z
12
+ .boolean()
13
+ .optional()
14
+ .describe("False takes commands away, and with them the terminals and every tool on the image. The switch the strength of the others depends on."),
15
+ code: z.boolean().optional().describe("False takes away writing and running a script."),
16
+ web: z.boolean().optional().describe("False takes away fetching a page and searching the web."),
17
+ browser: z.boolean().optional().describe("False takes away the credential-free browser."),
18
+ delegate: z.boolean().optional().describe("False takes away spawning subagents and running workflows."),
19
+ sandbox: z.boolean().optional().describe("False takes away changing the sandbox's own settings, manifests and public outbox."),
20
+ });
21
+ export type ToolCeiling = z.infer<typeof ToolCeilingSchema>;
22
+
23
+ // The shelves a ceiling answers, other than `files`, which is ranked rather than switched.
24
+ export const CEILING_SWITCHES = ["shell", "code", "web", "browser", "delegate", "sandbox"] as const;
25
+ export type CeilingSwitch = (typeof CEILING_SWITCHES)[number];
26
+
27
+ const FILES_RANK = { none: 0, read: 1, write: 2 } as const;
28
+ type FilesAnswer = keyof typeof FILES_RANK;
29
+
30
+ const lowerFiles = (left: FilesAnswer | undefined, right: FilesAnswer | undefined): FilesAnswer | undefined => {
31
+ if (left === undefined) {
32
+ return right;
33
+ }
34
+ if (right === undefined) {
35
+ return left;
36
+ }
37
+ return FILES_RANK[left] <= FILES_RANK[right] ? left : right;
38
+ };
39
+
40
+ /** Whether a ceiling limits anything at all; undefined and an empty one do not. */
41
+ export const ceilingLimits = (ceiling: ToolCeiling | undefined): boolean =>
42
+ ceiling !== undefined && ((ceiling.files !== undefined && ceiling.files !== "write") || CEILING_SWITCHES.some((shelf) => ceiling[shelf] === false));
43
+
44
+ /**
45
+ * Two ceilings held together: the lower answer of each shelf, so a turn acting for several principals is held to what
46
+ * every one of them may. Undefined is no ceiling, and holding it beside another changes nothing.
47
+ */
48
+ export const intersectCeilings = (left: ToolCeiling | undefined, right: ToolCeiling | undefined): ToolCeiling | undefined => {
49
+ if (left === undefined) {
50
+ return right;
51
+ }
52
+ if (right === undefined) {
53
+ return left;
54
+ }
55
+ const files = lowerFiles(left.files, right.files);
56
+ const held: ToolCeiling = files === undefined ? {} : { files };
57
+ for (const shelf of CEILING_SWITCHES) {
58
+ if (left[shelf] === false || right[shelf] === false) {
59
+ held[shelf] = false;
60
+ }
61
+ }
62
+ return held;
63
+ };
64
+
65
+ /** A persona's shelves held under a ceiling: each shelf the lower of the two, connector lists untouched. */
66
+ export const capPowers = (powers: PersonaPowers, ceiling: ToolCeiling | undefined): PersonaPowers => {
67
+ if (!ceilingLimits(ceiling) || ceiling === undefined) {
68
+ return powers;
69
+ }
70
+ const capped: PersonaPowers = { ...powers, files: lowerFiles(powers.files, ceiling.files) ?? powers.files };
71
+ for (const shelf of CEILING_SWITCHES) {
72
+ if (ceiling[shelf] === false) {
73
+ capped[shelf] = false;
74
+ }
75
+ }
76
+ return capped;
77
+ };
78
+
79
+ /** Whether a ceiling holds one shelf below what a grant would open it to (`files` opens to write). */
80
+ export const ceilingWithholds = (ceiling: ToolCeiling | undefined, shelf: "files" | CeilingSwitch): boolean => {
81
+ if (ceiling === undefined) {
82
+ return false;
83
+ }
84
+ return shelf === "files" ? ceiling.files !== undefined && ceiling.files !== "write" : ceiling[shelf] === false;
85
+ };
86
+
87
+ const SWITCH_WORDS = {
88
+ shell: "no commands",
89
+ code: "no scripts",
90
+ web: "no web",
91
+ browser: "no browser",
92
+ delegate: "no subagents",
93
+ sandbox: "no sandbox settings",
94
+ } as const satisfies Record<CeilingSwitch, string>;
95
+
96
+ /** What a ceiling withholds, in words its owner would recognise; empty when it limits nothing. */
97
+ export const ceilingWords = (ceiling: ToolCeiling | undefined): string[] => {
98
+ if (ceiling === undefined) {
99
+ return [];
100
+ }
101
+ const words: string[] = [];
102
+ if (ceiling.files === "none") {
103
+ words.push("no files");
104
+ } else if (ceiling.files === "read") {
105
+ words.push("read-only files");
106
+ }
107
+ for (const shelf of CEILING_SWITCHES) {
108
+ if (ceiling[shelf] === false) {
109
+ words.push(SWITCH_WORDS[shelf]);
110
+ }
111
+ }
112
+ return words;
113
+ };
@@ -0,0 +1,29 @@
1
+ import { holdsLockedWorkspacePath } from "./locked-folders.js";
2
+ import { PLAN_DOCUMENTS_DIR } from "./workspace-state.js";
3
+
4
+ // The folders the lock reaches through: deleting or moving one would carry the locked entries inside it.
5
+ describe(`holdsLockedWorkspacePath`, () => {
6
+ it(`holds the root state dir and every group in it, whichever slash`, () => {
7
+ expect(
8
+ [`.intentic`, `./.intentic/`, `.intentic/config`, `.intentic/identity`, `.intentic/secrets`, `.intentic/records`, `.intentic\\local`].map(
9
+ holdsLockedWorkspacePath,
10
+ ),
11
+ ).toEqual([true, true, true, true, true, true, true]);
12
+ });
13
+
14
+ it(`leaves ordinary state, the locked entries themselves, and anyone else's .intentic alone`, () => {
15
+ expect(
16
+ [
17
+ `.intentic/config/approvals`,
18
+ `.intentic/records/artifacts`,
19
+ PLAN_DOCUMENTS_DIR,
20
+ `.intentic/secrets/auth`,
21
+ `.intentic/records/sessions`,
22
+ `myrepo/.intentic`,
23
+ `.git`,
24
+ ``,
25
+ `src`,
26
+ ].map(holdsLockedWorkspacePath),
27
+ ).toEqual([false, false, false, false, false, false, false, false, false]);
28
+ });
29
+ });
@@ -0,0 +1,17 @@
1
+ import { STATE_DIR } from "@intentic/constants";
2
+ import { LOCKED_STATE_ENTRIES } from "./workspace-state.js";
3
+
4
+ // Whether a path is a folder a locked entry sits in (workspace-state.ts): the root's `.intentic` and each of its groups.
5
+ // Such a folder is opened, read and written inside like any other, but never deleted, moved, renamed or copied onto,
6
+ // for anyone. Deleting or moving it would carry the locked bytes out from under the lock, and the sandbox's settings,
7
+ // sign-ins and history with them, and the file trash sits in `.intentic/local`, so it would leave no Undo either. A
8
+ // copy onto it merges, overwriting the locked files. The file API refuses all of these and the explorer leaves them
9
+ // out. Accepts either slash.
10
+ export const holdsLockedWorkspacePath = (relPath: string): boolean => {
11
+ const segments = relPath.split(/[\\/]/).filter((segment) => segment !== "" && segment !== ".");
12
+ if (segments[0] !== STATE_DIR) {
13
+ return false;
14
+ }
15
+ const inside = segments.slice(1).join("/");
16
+ return inside === "" || [...LOCKED_STATE_ENTRIES].some((entry) => entry.startsWith(`${inside}/`));
17
+ };