@superjackfruitlabs/salaam 0.0.3 → 0.0.5

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 (172) hide show
  1. package/CHANGELOG.md +86 -0
  2. package/README.md +12 -11
  3. package/dist/src/acp-desk.js +140 -0
  4. package/dist/src/acp-outcome.js +182 -18
  5. package/dist/src/acp.js +296 -15
  6. package/dist/src/agent-profiles.js +45 -0
  7. package/dist/src/agentpod-authority.js +169 -11
  8. package/dist/src/agentpod-default-config.js +12 -0
  9. package/dist/src/agentpod-work-decision-protocol.js +40 -6
  10. package/dist/src/agentpod-work-decisions.js +108 -4
  11. package/dist/src/agentpod-work.js +1214 -127
  12. package/dist/src/approval-rules.js +287 -0
  13. package/dist/src/attach.js +3 -1
  14. package/dist/src/autonomy.js +80 -9
  15. package/dist/src/board-reads.js +106 -0
  16. package/dist/src/children.js +83 -0
  17. package/dist/src/cli-help.js +61 -6
  18. package/dist/src/cli.js +140 -4
  19. package/dist/src/command-danger.js +797 -0
  20. package/dist/src/command-network.js +200 -0
  21. package/dist/src/command-sandbox.js +327 -0
  22. package/dist/src/custom-commands.js +159 -0
  23. package/dist/src/danger-classifier.js +286 -0
  24. package/dist/src/execution-evidence.js +33 -1
  25. package/dist/src/git-helpers.js +160 -0
  26. package/dist/src/hooks.js +351 -0
  27. package/dist/src/host-bind.js +111 -0
  28. package/dist/src/host-breaker.js +88 -0
  29. package/dist/src/host-start.js +41 -1
  30. package/dist/src/host.js +284 -6
  31. package/dist/src/house-extension.js +292 -61
  32. package/dist/src/local-coding.js +726 -35
  33. package/dist/src/local-edit-helper.js +25 -0
  34. package/dist/src/local-edits.js +168 -6
  35. package/dist/src/local-undo.js +25 -16
  36. package/dist/src/managed.js +1 -1
  37. package/dist/src/mentions.js +277 -0
  38. package/dist/src/operator-mcp-cli.js +107 -0
  39. package/dist/src/operator-mcp.js +342 -0
  40. package/dist/src/persona.js +31 -0
  41. package/dist/src/pi-sessions.js +5 -1
  42. package/dist/src/pi.js +22 -1
  43. package/dist/src/project-instructions.js +195 -0
  44. package/dist/src/protocol.js +9 -3
  45. package/dist/src/rate-limit-retries.js +62 -0
  46. package/dist/src/recurring-work.js +1 -0
  47. package/dist/src/repository-snapshots.js +5 -2
  48. package/dist/src/run-grants.js +62 -0
  49. package/dist/src/service.js +482 -10
  50. package/dist/src/session-pick.js +77 -0
  51. package/dist/src/shell-passthrough.js +39 -0
  52. package/dist/src/station-checkpoints.js +139 -0
  53. package/dist/src/station-config.js +8 -1
  54. package/dist/src/station-files.js +20 -1
  55. package/dist/src/station-task-verification.js +6 -3
  56. package/dist/src/station-work.js +315 -22
  57. package/dist/src/store.js +70 -4
  58. package/dist/src/supervisor.js +408 -25
  59. package/dist/src/task-budget.js +39 -3
  60. package/dist/src/task-context.js +8 -2
  61. package/dist/src/task-critic.js +115 -0
  62. package/dist/src/task-driver.js +46 -2
  63. package/dist/src/task-policy.js +44 -12
  64. package/dist/src/task-verification.js +42 -9
  65. package/dist/src/task-work.js +47 -0
  66. package/dist/src/terminal-status.js +88 -0
  67. package/dist/src/tool-identity.js +69 -0
  68. package/dist/src/tui-activity.js +99 -0
  69. package/dist/src/tui-classifier.js +25 -0
  70. package/dist/src/tui-client.js +186 -5
  71. package/dist/src/tui-commands.js +23 -5
  72. package/dist/src/tui-composer.js +113 -0
  73. package/dist/src/tui-keymap.js +116 -0
  74. package/dist/src/tui-mentions.js +38 -0
  75. package/dist/src/tui-modals.js +157 -34
  76. package/dist/src/tui-notify.js +62 -0
  77. package/dist/src/tui-review.js +55 -0
  78. package/dist/src/tui-turn-keys.js +52 -0
  79. package/dist/src/tui-view.js +243 -69
  80. package/dist/src/tui.js +875 -118
  81. package/dist/src/turn-checkpoints.js +221 -0
  82. package/dist/src/turn-rewind.js +168 -0
  83. package/dist/src/usage.js +1 -1
  84. package/dist/src/web-fetch.js +114 -0
  85. package/dist/src/web-guard.js +163 -0
  86. package/dist/src/web-search.js +302 -0
  87. package/npm-shrinkwrap.json +2 -2
  88. package/package.json +1 -1
  89. package/src/acp-desk.ts +155 -0
  90. package/src/acp-outcome.ts +174 -20
  91. package/src/acp.ts +386 -30
  92. package/src/agent-profiles.ts +48 -0
  93. package/src/agentpod-authority.ts +234 -15
  94. package/src/agentpod-default-config.ts +16 -0
  95. package/src/agentpod-work-decision-protocol.ts +69 -8
  96. package/src/agentpod-work-decisions.ts +123 -5
  97. package/src/agentpod-work.ts +1455 -152
  98. package/src/approval-rules.ts +360 -0
  99. package/src/attach.ts +4 -1
  100. package/src/autonomy.ts +111 -10
  101. package/src/board-reads.ts +148 -0
  102. package/src/children.ts +112 -0
  103. package/src/cli-help.ts +60 -6
  104. package/src/cli.ts +174 -4
  105. package/src/command-danger.ts +886 -0
  106. package/src/command-network.ts +215 -0
  107. package/src/command-sandbox.ts +393 -0
  108. package/src/custom-commands.ts +175 -0
  109. package/src/danger-classifier.ts +321 -0
  110. package/src/execution-evidence.ts +31 -1
  111. package/src/git-helpers.ts +177 -0
  112. package/src/hooks.ts +425 -0
  113. package/src/host-bind.ts +156 -0
  114. package/src/host-breaker.ts +89 -0
  115. package/src/host-start.ts +51 -1
  116. package/src/host.ts +365 -6
  117. package/src/house-extension.ts +313 -60
  118. package/src/local-coding.ts +894 -43
  119. package/src/local-edit-helper.ts +26 -0
  120. package/src/local-edits.ts +191 -8
  121. package/src/local-undo.ts +29 -14
  122. package/src/managed.ts +2 -2
  123. package/src/mentions.ts +304 -0
  124. package/src/operator-mcp-cli.ts +108 -0
  125. package/src/operator-mcp.ts +420 -0
  126. package/src/persona.ts +37 -0
  127. package/src/pi-sessions.ts +9 -1
  128. package/src/pi.ts +23 -1
  129. package/src/project-instructions.ts +229 -0
  130. package/src/protocol.ts +25 -3
  131. package/src/rate-limit-retries.ts +69 -0
  132. package/src/recurring-work.ts +1 -0
  133. package/src/repository-snapshots.ts +5 -2
  134. package/src/run-grants.ts +107 -0
  135. package/src/service.ts +709 -10
  136. package/src/session-pick.ts +102 -0
  137. package/src/shell-passthrough.ts +38 -0
  138. package/src/station-checkpoints.ts +183 -0
  139. package/src/station-config.ts +10 -1
  140. package/src/station-files.ts +20 -1
  141. package/src/station-task-verification.ts +6 -3
  142. package/src/station-work.ts +369 -20
  143. package/src/store.ts +70 -3
  144. package/src/supervisor.ts +463 -26
  145. package/src/task-budget.ts +48 -3
  146. package/src/task-context.ts +9 -2
  147. package/src/task-critic.ts +171 -0
  148. package/src/task-driver.ts +49 -2
  149. package/src/task-policy.ts +65 -13
  150. package/src/task-verification.ts +53 -9
  151. package/src/task-work.ts +75 -0
  152. package/src/terminal-status.ts +103 -0
  153. package/src/tool-identity.ts +110 -0
  154. package/src/tui-activity.ts +133 -0
  155. package/src/tui-classifier.ts +38 -0
  156. package/src/tui-client.ts +239 -8
  157. package/src/tui-commands.ts +49 -10
  158. package/src/tui-composer.ts +124 -0
  159. package/src/tui-keymap.ts +152 -0
  160. package/src/tui-mentions.ts +43 -0
  161. package/src/tui-modals.ts +173 -43
  162. package/src/tui-notify.ts +77 -0
  163. package/src/tui-review.ts +76 -0
  164. package/src/tui-turn-keys.ts +77 -0
  165. package/src/tui-view.ts +341 -88
  166. package/src/tui.ts +1047 -137
  167. package/src/turn-checkpoints.ts +253 -0
  168. package/src/turn-rewind.ts +258 -0
  169. package/src/usage.ts +1 -1
  170. package/src/web-fetch.ts +140 -0
  171. package/src/web-guard.ts +195 -0
  172. package/src/web-search.ts +402 -0
@@ -0,0 +1,102 @@
1
+ import { typedText } from './shell-passthrough.js';
2
+ import { statSync } from 'node:fs';
3
+ import { OFFLINE_ROUTE } from './provider-config.js';
4
+
5
+ /** How `salaam code` opens a folder: continue its latest session (the default), start a new
6
+ * coding session, or pick one from the list. */
7
+ export type CodeStart = 'continue' | 'new' | 'resume';
8
+
9
+ export function parseCodeStart(flags: string[]): CodeStart {
10
+ const chosen = (['continue', 'new', 'resume'] as const).filter((f) => flags.includes('--' + f));
11
+ if (chosen.length > 1) throw new Error('Choose one of --continue, --new or --resume.');
12
+ return chosen[0] ?? 'continue';
13
+ }
14
+
15
+ const folder = (path: string) => (path.length > 1 ? path.replace(/\/+$/, '') : path);
16
+
17
+ /** The most recently created session in this folder; sessions come oldest first. */
18
+ export function latestSessionFor(
19
+ sessions: readonly { id: string; cwd: string }[],
20
+ cwd: string,
21
+ ): string | undefined {
22
+ const want = folder(cwd);
23
+ return [...sessions].reverse().find((s) => folder(s.cwd) === want)?.id;
24
+ }
25
+
26
+ /** Whether a new `salaam code` session should use Anthropic: only when nothing was chosen, the
27
+ * running service defaults to offline (as a TUI-started one does) and a key is stored. */
28
+ export function deskUsesAnthropic(
29
+ chosen: boolean,
30
+ serviceProvider: string | undefined,
31
+ hasAnthropicKey: boolean,
32
+ ): boolean {
33
+ return (
34
+ !chosen &&
35
+ (serviceProvider ?? OFFLINE_ROUTE.provider) === OFFLINE_ROUTE.provider &&
36
+ hasAnthropicKey
37
+ );
38
+ }
39
+
40
+ /** `salaam -c` and `salaam --continue` are short for `salaam code --continue`. */
41
+ export function continueArgs(args: readonly string[]): string[] | undefined {
42
+ if (args[0] !== '-c' && args[0] !== '--continue') return;
43
+ return ['code', '--continue', ...args.slice(1)];
44
+ }
45
+
46
+ interface PickerSession {
47
+ id: string;
48
+ cwd: string;
49
+ last_active_at?: string;
50
+ }
51
+ const activeAt = (s: { last_active_at?: string }) =>
52
+ s.last_active_at ? Date.parse(s.last_active_at) : -Infinity;
53
+
54
+ /** This folder's sessions first, then every other one; newest first within each. */
55
+ export function pickerOrder<T extends PickerSession>(sessions: readonly T[], cwd: string): T[] {
56
+ const want = folder(cwd);
57
+ const newest = (a: T, b: T) => activeAt(b) - activeAt(a);
58
+ const here = sessions.filter((s) => folder(s.cwd) === want).sort(newest);
59
+ return [...here, ...sessions.filter((s) => folder(s.cwd) !== want).sort(newest)];
60
+ }
61
+
62
+ export function relativeTime(at: string | undefined, now = Date.now()): string {
63
+ if (!at) return '';
64
+ const s = Math.max(0, (now - Date.parse(at)) / 1000);
65
+ if (s < 60) return 'just now';
66
+ if (s < 3600) return `${Math.floor(s / 60)} min ago`;
67
+ if (s < 86400) return `${Math.floor(s / 3600)} h ago`;
68
+ if (s < 2 * 86400) return 'yesterday';
69
+ return `${Math.floor(s / 86400)} days ago`;
70
+ }
71
+
72
+ /** One picker row: what you last asked (one short line), when, and where. */
73
+ export function sessionDescription(
74
+ s: { cwd: string; state: string; last_prompt?: string; last_active_at?: string },
75
+ now = Date.now(),
76
+ ): string {
77
+ const prompt = s.last_prompt?.replace(/\s+/g, ' ').trim();
78
+ const quoted = prompt ? `“${prompt.length > 60 ? prompt.slice(0, 59) + '…' : prompt}”` : '';
79
+ return [quoted || s.state, relativeTime(s.last_active_at, now), s.cwd]
80
+ .filter(Boolean)
81
+ .join(' · ');
82
+ }
83
+
84
+ /** What the picker shows for a desk session: its newest prompt (at most 200 characters) and when
85
+ * its transcript last changed. Board and station sessions get nothing extra. */
86
+ export function pickerSummary(
87
+ session: { id: string; capabilities: string[]; pi_session_file: string | null },
88
+ store: { lastPrompt(id: string): string | null },
89
+ ): { last_prompt?: string; last_active_at?: string } {
90
+ if (!session.capabilities.includes('local-coding-reviewed')) return {};
91
+ const prompt = store.lastPrompt(session.id);
92
+ let at: string | undefined;
93
+ try {
94
+ if (session.pi_session_file) at = statSync(session.pi_session_file).mtime.toISOString();
95
+ } catch {
96
+ /* no transcript yet */
97
+ }
98
+ return {
99
+ ...(prompt ? { last_prompt: typedText(prompt).slice(0, 200) } : {}),
100
+ ...(at ? { last_active_at: at } : {}),
101
+ };
102
+ }
@@ -0,0 +1,38 @@
1
+ /**
2
+ * `!command` in a desk session (trial polish #12, 2026-10-31). The terminal never runs the command
3
+ * itself: it asks the model to run exactly that text through salaam_local. The service reads the
4
+ * same fixed prompt back from the turn's submission and binds the turn to the typed command, so a
5
+ * model that runs anything else is refused, whatever the session's mode.
6
+ */
7
+ const LEAD = 'I want to run this shell command myself. Run exactly this command with salaam_local';
8
+
9
+ export function shellPassthrough(text: string): string | undefined {
10
+ const t = text.trim();
11
+ if (!t.startsWith('!') || t.startsWith('!!')) return undefined;
12
+ const command = t.slice(1).trim();
13
+ if (command === '' || command.includes('\n') || command.includes('```')) return undefined;
14
+ return [
15
+ LEAD,
16
+ '(action "command"), unchanged: no edits, no extra flags, no other commands. Then show me its',
17
+ 'output and exit status, and do nothing else unless I ask.',
18
+ '',
19
+ '```sh',
20
+ command,
21
+ '```',
22
+ ].join('\n');
23
+ }
24
+
25
+ /** The command a turn's prompt binds it to, when the prompt is exactly a `!command` request. */
26
+ export function boundShellCommand(prompt: string): string | undefined {
27
+ if (!prompt.startsWith(LEAD + '\n')) return undefined;
28
+ const lines = prompt.split('\n');
29
+ if (lines.length !== 7 || lines[4] !== '```sh' || lines[6] !== '```') return undefined;
30
+ const command = lines[5]!;
31
+ return shellPassthrough('!' + command) === prompt ? command : undefined;
32
+ }
33
+
34
+ /** What the person typed, for display: `! COMMAND` for a `!command` prompt, else the text. */
35
+ export function typedText(prompt: string): string {
36
+ const command = boundShellCommand(prompt);
37
+ return command === undefined ? prompt : '! ' + command;
38
+ }
@@ -0,0 +1,183 @@
1
+ import type { Store } from './store.js';
2
+ import type { WorkTask } from './task-work.js';
3
+ import { digest, ServiceError } from './protocol.js';
4
+
5
+ /**
6
+ * Checkpoints of a station task, derived from its own recorded writes (item 11). Each completed
7
+ * step ends at a checkpoint: the tree after that step's last returned station patch. A file's
8
+ * content at a checkpoint is known only from the run's own patches; a file that existed before
9
+ * the run and was first written after the checkpoint has no recorded earlier bytes, so it is
10
+ * "unknown" there and cannot be restored. Read-only: nothing here changes the workspace.
11
+ */
12
+ export interface StationCheckpoint {
13
+ id: string;
14
+ step_id: string;
15
+ step_key: string;
16
+ tree_digest: string;
17
+ at: number; // the last patch call rowid at the checkpoint (0: before any write)
18
+ files_changed: string[];
19
+ }
20
+ type Patch = {
21
+ rowid: number;
22
+ path: string;
23
+ content: string | null;
24
+ expected_hash: string | null;
25
+ before_tree: string;
26
+ tree: string;
27
+ sha256: string | null;
28
+ };
29
+ export type FileAtCheckpoint =
30
+ { state: 'content'; content: string } | { state: 'absent' } | { state: 'unknown' };
31
+ /** A file as the workspace holds it now, read through the protected helper's closed verbs. */
32
+ export type FileNow =
33
+ | { state: 'content'; content: string; sha256: string }
34
+ | { state: 'absent' }
35
+ | { state: 'unreadable' };
36
+ /** The live workspace: its tree digest now, and each file's bytes now. */
37
+ export interface LiveTree {
38
+ tree: string;
39
+ file(path: string): Promise<FileNow>;
40
+ }
41
+
42
+ export class StationCheckpoints {
43
+ constructor(private readonly store: Store) {}
44
+ private patches(session: string): Patch[] {
45
+ return this.store.db
46
+ .prepare(
47
+ "SELECT rowid,args_json,result_json,attempt_id FROM station_calls WHERE session_id=? AND kind='patch' AND state='returned' ORDER BY rowid",
48
+ )
49
+ .all(session)
50
+ .map((r) => {
51
+ const args = JSON.parse(String(r.args_json)),
52
+ result = JSON.parse(String(r.result_json));
53
+ return {
54
+ rowid: Number(r.rowid),
55
+ path: String(args.path),
56
+ content: typeof args.content === 'string' ? args.content : null,
57
+ expected_hash: typeof args.expected_hash === 'string' ? args.expected_hash : null,
58
+ before_tree: String(result.before_tree_digest),
59
+ tree: String(result.tree_digest),
60
+ sha256: typeof result.sha256 === 'string' ? result.sha256 : null,
61
+ attempt: String(r.attempt_id),
62
+ } as Patch & { attempt: string };
63
+ });
64
+ }
65
+ list(task: WorkTask): StationCheckpoint[] {
66
+ const patches = this.patches(task.session_id) as (Patch & { attempt: string })[];
67
+ const attemptsOf = (step: string) =>
68
+ new Set(
69
+ this.store.db
70
+ .prepare('SELECT attempt_id FROM task_step_attempts WHERE step_id=?')
71
+ .all(step)
72
+ .map((r) => String(r.attempt_id)),
73
+ );
74
+ const out: StationCheckpoint[] = [];
75
+ let at = 0,
76
+ tree = patches[0]?.before_tree ?? '';
77
+ for (const step of task.steps.filter((s) => s.state === 'completed')) {
78
+ const mine = patches.filter((p) => attemptsOf(step.id).has(p.attempt));
79
+ if (mine.length) {
80
+ at = Math.max(at, ...mine.map((p) => p.rowid));
81
+ tree = patches.find((p) => p.rowid === at)!.tree;
82
+ }
83
+ out.push({
84
+ id: digest({ task: task.id, plan_revision: task.plan_revision, step: step.id, at, tree }),
85
+ step_id: step.id,
86
+ step_key: step.key,
87
+ tree_digest: tree,
88
+ at,
89
+ files_changed: [...new Set(mine.map((p) => p.path))].sort(),
90
+ });
91
+ }
92
+ return out;
93
+ }
94
+ get(task: WorkTask, id: string): StationCheckpoint {
95
+ const found = this.list(task).find((c) => c.id === id);
96
+ if (!found) throw new ServiceError('not_found', 'No such checkpoint for this task', 404);
97
+ return found;
98
+ }
99
+ /** A path's content at a checkpoint, from the run's own patches only. */
100
+ fileAt(task: WorkTask, at: number, path: string): FileAtCheckpoint {
101
+ const patches = this.patches(task.session_id).filter((p) => p.path === path);
102
+ const before = patches.filter((p) => p.rowid <= at).at(-1);
103
+ if (before)
104
+ return before.content === null
105
+ ? { state: 'absent' }
106
+ : { state: 'content', content: before.content };
107
+ const first = patches.find((p) => p.rowid > at);
108
+ return first && first.expected_hash === null ? { state: 'absent' } : { state: 'unknown' };
109
+ }
110
+ /**
111
+ * What restoring this checkpoint would do, against the LIVE workspace (never the run's own
112
+ * receipts alone): every path this run wrote is read as it is now, so a change made outside the
113
+ * run since (an edit, a deletion, a file put back) shows as what the restore would undo. The
114
+ * restore digest binds the live tree, so a restore refuses a workspace that moved after review.
115
+ * Files this run never wrote are left as they are; `drift` says when the tree moved outside it.
116
+ */
117
+ async diff(task: WorkTask, id: string, live: LiveTree) {
118
+ const checkpoint = this.get(task, id);
119
+ const patches = this.patches(task.session_id);
120
+ const recorded = patches.at(-1)?.tree ?? checkpoint.tree_digest;
121
+ const paths = [...new Set(patches.map((p) => p.path))].sort();
122
+ const files = [];
123
+ for (const path of paths) {
124
+ const now = await live.file(path);
125
+ const then = this.fileAt(task, checkpoint.at, path);
126
+ const change =
127
+ now.state === 'unreadable' || then.state === 'unknown'
128
+ ? ('not_restorable' as const)
129
+ : then.state === 'absent'
130
+ ? now.state === 'absent'
131
+ ? ('unchanged' as const)
132
+ : ('delete' as const)
133
+ : now.state === 'absent'
134
+ ? ('bring_back' as const)
135
+ : now.content === then.content
136
+ ? ('unchanged' as const)
137
+ : ('revert' as const);
138
+ files.push({
139
+ path,
140
+ current: now.state === 'content' ? now.content : null,
141
+ current_state: now.state,
142
+ at_checkpoint: then,
143
+ change,
144
+ expected_hash: now.state === 'content' ? now.sha256 : null,
145
+ });
146
+ }
147
+ const shown = files.filter((f) => f.change !== 'unchanged');
148
+ const restore_digest = digest({
149
+ task: task.id,
150
+ plan_revision: task.plan_revision,
151
+ checkpoint: checkpoint.id,
152
+ checkpoint_tree: checkpoint.tree_digest,
153
+ recorded_tree: recorded,
154
+ current_tree: live.tree,
155
+ files: shown.map((f) => ({
156
+ path: f.path,
157
+ change: f.change,
158
+ target: f.at_checkpoint,
159
+ expected: f.expected_hash,
160
+ })),
161
+ });
162
+ return {
163
+ checkpoint,
164
+ current_tree: live.tree,
165
+ recorded_tree: recorded,
166
+ drift: live.tree !== recorded,
167
+ restore_digest,
168
+ files: shown.map(({ expected_hash: _, ...f }) => f),
169
+ writes: shown
170
+ .filter((f) => ['revert', 'delete', 'bring_back'].includes(f.change))
171
+ .map((f) => ({
172
+ path: f.path,
173
+ content: f.at_checkpoint.state === 'content' ? f.at_checkpoint.content : null,
174
+ expected_hash: f.expected_hash,
175
+ })),
176
+ };
177
+ }
178
+ /** Item 11b: exactly what a restore of this checkpoint writes, and the digest that binds it. */
179
+ async restorePlan(task: WorkTask, id: string, live: LiveTree) {
180
+ const { restore_digest, current_tree, writes, checkpoint } = await this.diff(task, id, live);
181
+ return { restore_digest, current_tree, writes, checkpoint };
182
+ }
183
+ }
@@ -28,6 +28,8 @@ export interface StationConfig {
28
28
  runtime_root: string;
29
29
  runtime_fingerprint: string;
30
30
  runtime_image_digest: string;
31
+ /** OS user the agent's local tools run as (salaam --tools-user). Optional. */
32
+ tools_user?: string;
31
33
  }
32
34
  const hashShape = /^[a-f0-9]{64}$/;
33
35
  export const stationHash = (bytes: Uint8Array): string =>
@@ -149,9 +151,15 @@ export function readStationConfig(
149
151
  ): StationConfig {
150
152
  try {
151
153
  const v = object(JSON.parse(stationPrivateFile(path, 16384).toString('utf8')));
154
+ const keys = Object.keys(v)
155
+ .filter((k) => k !== 'tools_user')
156
+ .sort()
157
+ .join(',');
152
158
  if (
153
- Object.keys(v).sort().join(',') !==
159
+ keys !==
154
160
  'files,kind,runtime_fingerprint,runtime_image_digest,runtime_root,systemctl,systemd_run,version,workspace,workspace_identity' ||
161
+ (Object.hasOwn(v, 'tools_user') &&
162
+ (typeof v.tools_user !== 'string' || !/^[a-z_][a-z0-9_-]{0,31}$/.test(v.tools_user))) ||
155
163
  v.version !== 1 ||
156
164
  v.kind !== 'linux-systemd-station-v1' ||
157
165
  v.workspace !== workspace ||
@@ -174,6 +182,7 @@ export function readStationConfig(
174
182
  runtime_root: v.runtime_root,
175
183
  runtime_fingerprint: v.runtime_fingerprint,
176
184
  runtime_image_digest: v.runtime_image_digest,
185
+ ...(Object.hasOwn(v, 'tools_user') ? { tools_user: v.tools_user as string } : {}),
177
186
  };
178
187
  if (
179
188
  workspace
@@ -22,9 +22,14 @@ export function stationFileResult(
22
22
  };
23
23
  const fields = keys[String(request.action)];
24
24
  if (!fields) bad();
25
+ // A new file's missing parent directories, created beneath the root, are part of its effect.
26
+ const extra =
27
+ request.action === 'patch' && 'created_directories' in v ? ['created_directories'] : [];
25
28
  if (
26
29
  Object.keys(v).sort().join(',') !==
27
- ['version', 'ok', 'tree_digest', 'files', 'root_identity', ...fields!].sort().join(',') ||
30
+ ['version', 'ok', 'tree_digest', 'files', 'root_identity', ...fields!, ...extra]
31
+ .sort()
32
+ .join(',') ||
28
33
  v.version !== 1 ||
29
34
  v.ok !== true ||
30
35
  v.root_identity !== request.root_identity ||
@@ -47,6 +52,8 @@ export function stationFileResult(
47
52
  )
48
53
  bad();
49
54
  }
55
+ if (extra.length && !createdParents(String(request.path), v.created_directories, request.content))
56
+ bad();
50
57
  if (request.action === 'patch') {
51
58
  if (
52
59
  v.path !== request.path ||
@@ -102,3 +109,15 @@ export function stationFileResult(
102
109
  }
103
110
  return v;
104
111
  }
112
+
113
+ /** The created directories must be a non-empty, in-order run of the path's own
114
+ * ancestors ending at its parent: each one beneath the last, nothing else. Only a
115
+ * new file creates them. */
116
+ function createdParents(path: string, dirs: unknown, content: unknown): boolean {
117
+ if (typeof content !== 'string' || !Array.isArray(dirs) || dirs.length === 0) return false;
118
+ const parts = path.split('/');
119
+ if (parts.length < 2 || parts.some((p) => p === '' || p === '.' || p === '..')) return false;
120
+ const ancestors = parts.slice(0, -1).map((_, i) => parts.slice(0, i + 1).join('/'));
121
+ const tail = ancestors.slice(ancestors.length - dirs.length);
122
+ return dirs.length <= ancestors.length && dirs.every((d, i) => d === tail[i]);
123
+ }
@@ -1,3 +1,4 @@
1
+ import { requiredChecks } from './task-policy.js';
1
2
  import type { Store } from './store.js';
2
3
  import type { TaskWork, WorkTask } from './task-work.js';
3
4
  import type { TaskVerification, CheckReceipt } from './task-verification.js';
@@ -163,7 +164,7 @@ export class StationTaskVerification {
163
164
  private async dispatchOwned(id: string): Promise<void> {
164
165
  const receipt = this.verification.get(id),
165
166
  task = this.tasks.get(receipt.task_id);
166
- const configured = task.acceptance.find((c) => c.key === receipt.check_key);
167
+ const configured = requiredChecks(task).find((c) => c.key === receipt.check_key);
167
168
  if (!configured || configured.cwd !== '.') this.fail();
168
169
  const binding = this.station.ready(task.session_id);
169
170
  const validate = (inspection?: string) => {
@@ -265,6 +266,7 @@ export class StationTaskVerification {
265
266
  objective: task.objective,
266
267
  constraints: task.constraints,
267
268
  acceptance: task.acceptance,
269
+ ...(task.completion_gate ? { completion_gate: task.completion_gate } : {}),
268
270
  deliverables: task.deliverables,
269
271
  limits: task.limits,
270
272
  steps: task.steps.map(({ key, title, instruction, depends_on, checks }) => ({
@@ -300,7 +302,7 @@ export class StationTaskVerification {
300
302
  });
301
303
  }
302
304
  private matches(check: CheckReceipt, task: WorkTask, call: StationCall): void {
303
- const configured = task.acceptance.find((c) => c.key === check.check_key);
305
+ const configured = requiredChecks(task).find((c) => c.key === check.check_key);
304
306
  const args = JSON.parse(call.args_json);
305
307
  if (
306
308
  check.task_id !== task.id ||
@@ -526,7 +528,8 @@ export class StationTaskVerification {
526
528
  result.root_identity !== this.station.config.workspace_identity
527
529
  )
528
530
  this.fail();
529
- deliverables.push({ path, sha256: result.sha256 });
531
+ // The verified bytes travel with the digest; completion keeps them as an artifact.
532
+ deliverables.push({ path, sha256: result.sha256, content: result.content });
530
533
  }
531
534
  const final = await this.observe(
532
535
  evidence[0]!.call_id,