owenloop 0.5.0 → 0.5.2
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.
- package/CHANGELOG.md +67 -0
- package/README.md +144 -35
- package/bin/owenloop.mjs +49 -1
- package/dist/packages/work/src/agent/brief.d.ts +29 -4
- package/dist/packages/work/src/agent/brief.js +49 -4
- package/dist/packages/work/src/agent/capability-model.d.ts +123 -0
- package/dist/packages/work/src/agent/capability-model.js +148 -0
- package/dist/packages/work/src/agent/loop.d.ts +56 -7
- package/dist/packages/work/src/agent/loop.js +166 -9
- package/dist/packages/work/src/bundle/cache.d.ts +7 -5
- package/dist/packages/work/src/bundle/cache.js +20 -6
- package/dist/packages/work/src/bundle/fetch.d.ts +7 -5
- package/dist/packages/work/src/bundle/fetch.js +27 -7
- package/dist/packages/work/src/bundle/types.d.ts +8 -4
- package/dist/packages/work/src/consumed-verifier.d.ts +45 -0
- package/dist/packages/work/src/consumed-verifier.js +205 -0
- package/dist/packages/work/src/exec/instructions.d.ts +99 -0
- package/dist/packages/work/src/exec/instructions.js +323 -0
- package/dist/packages/work/src/exec/loop.d.ts +29 -1
- package/dist/packages/work/src/exec/loop.js +313 -35
- package/dist/packages/work/src/exec/payload.d.ts +29 -0
- package/dist/packages/work/src/exec/payload.js +54 -0
- package/dist/packages/work/src/exec/receipt.d.ts +9 -6
- package/dist/packages/work/src/exec/receipt.js +12 -1
- package/dist/packages/work/src/exec/runner.d.ts +7 -1
- package/dist/packages/work/src/exec/runner.js +84 -3
- package/dist/packages/work/src/harness/child-env.js +7 -0
- package/dist/packages/work/src/harness/claude.d.ts +20 -8
- package/dist/packages/work/src/harness/claude.js +260 -58
- package/dist/packages/work/src/harness/codex.d.ts +5 -4
- package/dist/packages/work/src/harness/codex.js +169 -41
- package/dist/packages/work/src/harness/contract.d.ts +36 -11
- package/dist/packages/work/src/harness/fake.js +1 -0
- package/dist/packages/work/src/harness/jsonrpc-stdio.js +7 -0
- package/dist/packages/work/src/harness/permissions.d.ts +16 -3
- package/dist/packages/work/src/harness/permissions.js +102 -13
- package/dist/packages/work/src/harness/session-store.d.ts +30 -10
- package/dist/packages/work/src/harness/session-store.js +317 -89
- package/dist/packages/work/src/hold/mcp.d.ts +25 -5
- package/dist/packages/work/src/hold/mcp.js +134 -12
- package/dist/packages/work/src/hub/client.d.ts +8 -1
- package/dist/packages/work/src/hub/client.js +15 -1
- package/dist/packages/work/src/hub/types.d.ts +137 -33
- package/dist/packages/work/src/hub/types.js +8 -10
- package/dist/packages/work/src/mcp/server.js +1 -1
- package/dist/packages/work/src/owenloop-bin.d.ts +1 -0
- package/dist/packages/work/src/owenloop-bin.js +18 -0
- package/dist/packages/work/src/roles/agent-run.d.ts +12 -6
- package/dist/packages/work/src/roles/agent-run.js +115 -34
- package/dist/packages/work/src/roles/exec.d.ts +8 -0
- package/dist/packages/work/src/roles/exec.js +27 -2
- package/dist/packages/work/src/roles/hold.d.ts +6 -0
- package/dist/packages/work/src/roles/hold.js +83 -13
- package/dist/packages/work/src/roles/lint.d.ts +3 -4
- package/dist/packages/work/src/roles/lint.js +41 -7
- package/dist/packages/work/src/roles/settings.js +19 -2
- package/dist/packages/work/src/roles/shift.d.ts +1 -0
- package/dist/packages/work/src/roles/shift.js +36 -2
- package/dist/packages/work/src/settings/settings.d.ts +70 -1
- package/dist/packages/work/src/settings/settings.js +90 -4
- package/dist/packages/work/src/shift/logretention.d.ts +253 -0
- package/dist/packages/work/src/shift/logretention.js +407 -0
- package/dist/packages/work/src/shift/logsink.d.ts +14 -0
- package/dist/packages/work/src/shift/logsink.js +98 -0
- package/dist/packages/work/src/shift/loop.d.ts +32 -4
- package/dist/packages/work/src/shift/loop.js +687 -166
- package/dist/packages/work/src/shift/protocol.d.ts +128 -1
- package/dist/packages/work/src/shift/protocol.js +14 -0
- package/dist/packages/work/src/shift/runtime.d.ts +16 -0
- package/dist/packages/work/src/shift/runtime.js +291 -5
- package/dist/packages/work/src/shift/server.d.ts +13 -0
- package/dist/packages/work/src/shift/server.js +61 -36
- package/dist/packages/work/src/shift/spawn.d.ts +115 -19
- package/dist/packages/work/src/shift/spawn.js +234 -30
- package/dist/packages/work/src/shift/state.d.ts +76 -49
- package/dist/packages/work/src/shift/state.js +350 -103
- package/dist/packages/work/src/shift/truncate.d.ts +35 -0
- package/dist/packages/work/src/shift/truncate.js +73 -0
- package/dist/packages/work/src/submit-proof.d.ts +61 -0
- package/dist/packages/work/src/submit-proof.js +119 -0
- package/dist/packages/work/src/submit-value.d.ts +48 -0
- package/dist/packages/work/src/submit-value.js +118 -0
- package/dist/packages/work/src/usage.d.ts +1 -1
- package/dist/packages/work/src/usage.js +11 -0
- package/dist/src/add.d.ts +64 -259
- package/dist/src/add.js +81 -615
- package/dist/src/archive.d.ts +97 -0
- package/dist/src/archive.js +591 -0
- package/dist/src/bundle/index.d.ts +64 -0
- package/dist/src/bundle/index.js +508 -0
- package/dist/src/bundle/manifest.d.ts +50 -0
- package/dist/src/bundle/manifest.js +435 -0
- package/dist/src/bundle/runtime.d.ts +26 -0
- package/dist/src/bundle/runtime.js +64 -0
- package/dist/src/bundle/tar.d.ts +62 -0
- package/dist/src/bundle/tar.js +238 -0
- package/dist/src/bundle/types.d.ts +105 -0
- package/dist/src/bundle/types.js +21 -0
- package/dist/src/capabilities.d.ts +93 -0
- package/dist/src/capabilities.js +101 -0
- package/dist/src/cli.d.ts +90 -20
- package/dist/src/cli.js +2421 -374
- package/dist/src/credentials.d.ts +4 -3
- package/dist/src/credentials.js +21 -19
- package/dist/src/crypto/allowed-signers.d.ts +68 -0
- package/dist/src/crypto/allowed-signers.js +307 -0
- package/dist/src/crypto/canonical.d.ts +8 -0
- package/dist/src/crypto/canonical.js +92 -0
- package/dist/src/crypto/chain.d.ts +65 -0
- package/dist/src/crypto/chain.js +377 -0
- package/dist/src/crypto/dsse.d.ts +209 -0
- package/dist/src/crypto/dsse.js +282 -0
- package/dist/src/crypto/enrollment.d.ts +78 -0
- package/dist/src/crypto/enrollment.js +186 -0
- package/dist/src/crypto/index.d.ts +48 -0
- package/dist/src/crypto/index.js +44 -0
- package/dist/src/crypto/keys.d.ts +258 -0
- package/dist/src/crypto/keys.js +908 -0
- package/dist/src/crypto/org-root.d.ts +33 -0
- package/dist/src/crypto/org-root.js +78 -0
- package/dist/src/crypto/origin-rules.d.ts +56 -0
- package/dist/src/crypto/origin-rules.js +143 -0
- package/dist/src/crypto/policy-floor.d.ts +98 -0
- package/dist/src/crypto/policy-floor.js +353 -0
- package/dist/src/crypto/records.d.ts +319 -0
- package/dist/src/crypto/records.js +168 -0
- package/dist/src/crypto/scope.d.ts +49 -0
- package/dist/src/crypto/scope.js +83 -0
- package/dist/src/crypto/ssh.d.ts +171 -0
- package/dist/src/crypto/ssh.js +396 -0
- package/dist/src/crypto/submission.d.ts +33 -0
- package/dist/src/crypto/submission.js +47 -0
- package/dist/src/crypto/trust-roots.d.ts +29 -0
- package/dist/src/crypto/trust-roots.js +39 -0
- package/dist/src/crypto/verify-consumed.d.ts +67 -0
- package/dist/src/crypto/verify-consumed.js +259 -0
- package/dist/src/crypto/verify-origin.d.ts +50 -0
- package/dist/src/crypto/verify-origin.js +151 -0
- package/dist/src/crypto/verify-publication.d.ts +60 -0
- package/dist/src/crypto/verify-publication.js +150 -0
- package/dist/src/defs.d.ts +24 -1
- package/dist/src/defs.js +335 -27
- package/dist/src/engine.d.ts +211 -6
- package/dist/src/engine.js +459 -59
- package/dist/src/factory.d.ts +16 -0
- package/dist/src/factory.js +16 -4
- package/dist/src/global-config.d.ts +59 -0
- package/dist/src/global-config.js +84 -0
- package/dist/src/hub.d.ts +102 -32
- package/dist/src/hub.js +147 -58
- package/dist/src/index.d.ts +19 -2
- package/dist/src/index.js +23 -2
- package/dist/src/install.d.ts +538 -0
- package/dist/src/install.js +1981 -0
- package/dist/src/lock.d.ts +15 -57
- package/dist/src/lock.js +251 -143
- package/dist/src/mcp/serve.d.ts +46 -22
- package/dist/src/mcp/serve.js +174 -44
- package/dist/src/mcp/server.js +12 -1
- package/dist/src/model.d.ts +51 -0
- package/dist/src/model.js +157 -1
- package/dist/src/order-resolver.d.ts +184 -0
- package/dist/src/order-resolver.js +252 -0
- package/dist/src/package-version.d.ts +10 -0
- package/dist/src/package-version.js +42 -0
- package/dist/src/paths.d.ts +14 -1
- package/dist/src/paths.js +18 -0
- package/dist/src/schemas/enrollment-grant.v1.schema.json +90 -0
- package/dist/src/schemas/index.d.ts +1433 -0
- package/dist/src/schemas/index.js +31 -0
- package/dist/src/schemas/order.v1.schema.json +120 -0
- package/dist/src/schemas/origin.v1.schema.json +68 -0
- package/dist/src/schemas/policy-floor.v1.schema.json +29 -0
- package/dist/src/schemas/publication.v1.schema.json +31 -0
- package/dist/src/schemas/revocation.v1.schema.json +39 -0
- package/dist/src/schemas/submission.v1.schema.json +61 -0
- package/dist/src/store/def-source.d.ts +52 -0
- package/dist/src/store/def-source.js +335 -0
- package/dist/src/store/index-file.d.ts +69 -0
- package/dist/src/store/index-file.js +151 -0
- package/dist/src/store/index.d.ts +27 -0
- package/dist/src/store/index.js +22 -0
- package/dist/src/store/ingestor.d.ts +43 -0
- package/dist/src/store/ingestor.js +211 -0
- package/dist/src/store/install.d.ts +228 -0
- package/dist/src/store/install.js +555 -0
- package/dist/src/store/instruction-source.d.ts +49 -0
- package/dist/src/store/instruction-source.js +298 -0
- package/dist/src/store/origin-evidence.d.ts +21 -0
- package/dist/src/store/origin-evidence.js +66 -0
- package/dist/src/store/pre-commit-verifier.d.ts +68 -0
- package/dist/src/store/pre-commit-verifier.js +418 -0
- package/dist/src/store/resolve.d.ts +138 -0
- package/dist/src/store/resolve.js +363 -0
- package/dist/src/store/types.d.ts +288 -0
- package/dist/src/store/types.js +356 -0
- package/dist/src/store.d.ts +33 -1
- package/dist/src/store.js +57 -4
- package/dist/src/types.d.ts +146 -12
- package/dist/src/untar.d.ts +8 -23
- package/dist/src/untar.js +10 -136
- package/docs/agent-runner.md +86 -0
- package/docs/authoring.md +64 -6
- package/docs/bundles.md +350 -0
- package/docs/cli.md +1298 -106
- package/docs/crypto.md +832 -0
- package/docs/design.md +342 -20
- package/docs/embedding.md +132 -25
- package/docs/shift-logs.md +642 -0
- package/docs/wire-contracts.md +395 -0
- package/package.json +6 -1
- package/plugins/claude-code/.claude-plugin/marketplace.json +14 -0
- package/plugins/claude-code/plugin/.claude-plugin/plugin.json +8 -0
- package/plugins/claude-code/plugin/.mcp.json +14 -0
- package/plugins/claude-code/plugin/hooks/hooks.json +26 -0
- package/plugins/claude-code/plugin/hooks/session-end.sh +40 -0
- package/plugins/claude-code/plugin/hooks/session-start.sh +52 -0
- package/plugins/claude-code/plugin/skills/author/SKILL.md +181 -0
- package/plugins/claude-code/plugin/skills/conduct/SKILL.md +106 -0
- package/plugins/claude-code/plugin/skills/shift/SKILL.md +105 -0
- package/plugins/codex/.agents/plugins/marketplace.json +21 -0
- package/plugins/codex/plugins/owenloop/.codex-plugin/plugin.json +7 -0
- package/plugins/codex/plugins/owenloop/.mcp.json +20 -0
- package/plugins/codex/plugins/owenloop/hooks/hooks.json +26 -0
- package/plugins/codex/plugins/owenloop/hooks/session-end.sh +40 -0
- package/plugins/codex/plugins/owenloop/hooks/session-start.sh +52 -0
- package/plugins/codex/plugins/owenloop/skills/author/SKILL.md +181 -0
- package/plugins/codex/plugins/owenloop/skills/conduct/SKILL.md +106 -0
- package/plugins/codex/plugins/owenloop/skills/shift/SKILL.md +105 -0
|
@@ -23,10 +23,12 @@
|
|
|
23
23
|
* production importer; importing this module is what fires the module-scope
|
|
24
24
|
* `register(claudeAdapter)` below and puts the adapter in the runtime registry.
|
|
25
25
|
*/
|
|
26
|
+
import { randomUUID } from 'node:crypto';
|
|
26
27
|
import { accessSync, constants, existsSync } from 'node:fs';
|
|
27
28
|
import { delimiter, join } from 'node:path';
|
|
28
29
|
import { register } from "./registry.js";
|
|
29
30
|
import { filterOwenloopEnv } from "./child-env.js";
|
|
31
|
+
import { normalizeStepPermissions, validateHarnessOptions } from "./permissions.js";
|
|
30
32
|
import { ResumeUnavailableError } from "./contract.js";
|
|
31
33
|
/** The registry key — the id a step def names in `x.harness.id`, and the key
|
|
32
34
|
* `harness-versions.json` pins the CLI under. */
|
|
@@ -178,6 +180,98 @@ const PERMISSION_MODES = [
|
|
|
178
180
|
];
|
|
179
181
|
/** The five-value closed union the SDK types `Options.effort` as. */
|
|
180
182
|
const EFFORT_LEVELS = ['low', 'medium', 'high', 'xhigh', 'max'];
|
|
183
|
+
/** Audited built-ins that cannot mutate the filesystem. WebFetch/WebSearch
|
|
184
|
+
* can read the unrestricted network without weakening a read-only filesystem. */
|
|
185
|
+
const READ_ONLY_TOOLS = new Set(['Read', 'Glob', 'Grep', 'WebFetch', 'WebSearch']);
|
|
186
|
+
/** Audited built-ins allowed when only the network is restricted. */
|
|
187
|
+
const OWENLOOP_ONLY_NETWORK_TOOLS = new Set([
|
|
188
|
+
'Read',
|
|
189
|
+
'Glob',
|
|
190
|
+
'Grep',
|
|
191
|
+
'Edit',
|
|
192
|
+
'Write',
|
|
193
|
+
'NotebookEdit',
|
|
194
|
+
'TodoWrite',
|
|
195
|
+
'TaskCreate',
|
|
196
|
+
'TaskUpdate',
|
|
197
|
+
'TaskList',
|
|
198
|
+
'TaskGet',
|
|
199
|
+
]);
|
|
200
|
+
/** The intersection when both restrictions apply: local reads only, with no
|
|
201
|
+
* unrestricted-network readers. */
|
|
202
|
+
const READ_ONLY_OWENLOOP_ONLY_NETWORK_TOOLS = [...READ_ONLY_TOOLS]
|
|
203
|
+
.filter((tool) => OWENLOOP_ONLY_NETWORK_TOOLS.has(tool));
|
|
204
|
+
const BORN_BOUND_OWENLOOP_TOOL_NAMES = ['get_order', 'submit'];
|
|
205
|
+
const BORN_BOUND_OWENLOOP_TOOLS = BORN_BOUND_OWENLOOP_TOOL_NAMES.map((name) => `mcp__owenloop__${name}`);
|
|
206
|
+
const RESTRICTED_OWENLOOP_DENIED_TOOLS = ['mcp__owenloop__reject'];
|
|
207
|
+
const OWENLOOP_CONTROL_TOOLS = new Set([
|
|
208
|
+
...BORN_BOUND_OWENLOOP_TOOLS,
|
|
209
|
+
'mcp__plugin_owenloop_owenloop__get_order',
|
|
210
|
+
'mcp__plugin_owenloop_owenloop__submit',
|
|
211
|
+
]);
|
|
212
|
+
const OWENLOOP_CONTROL_DENY_SPECS = new Set([
|
|
213
|
+
...OWENLOOP_CONTROL_TOOLS,
|
|
214
|
+
'mcp__owenloop',
|
|
215
|
+
'mcp__owenloop__*',
|
|
216
|
+
'mcp__plugin_owenloop_owenloop',
|
|
217
|
+
'mcp__plugin_owenloop_owenloop__*',
|
|
218
|
+
'mcp__*',
|
|
219
|
+
]);
|
|
220
|
+
function claudePreflight(permissions) {
|
|
221
|
+
const issues = [];
|
|
222
|
+
if (permissions.permissionMode !== undefined && !PERMISSION_MODES.includes(permissions.permissionMode)) {
|
|
223
|
+
issues.push({
|
|
224
|
+
field: 'permissionMode',
|
|
225
|
+
message: `permissionMode must be one of ${PERMISSION_MODES.join('|')}`,
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
if (permissions.effort !== undefined && !EFFORT_LEVELS.includes(permissions.effort)) {
|
|
229
|
+
issues.push({ field: 'effort', message: `effort must be one of ${EFFORT_LEVELS.join('|')}` });
|
|
230
|
+
}
|
|
231
|
+
if (permissions.filesystem === 'workspace-write') {
|
|
232
|
+
issues.push({
|
|
233
|
+
field: 'filesystem',
|
|
234
|
+
message: "filesystem 'workspace-write' is unsupported by this adapter; use 'read-only' or 'unrestricted'",
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
const allowed = permissions.tools;
|
|
238
|
+
if (allowed !== undefined) {
|
|
239
|
+
const unsupportedMcp = allowed.filter((tool) => tool.startsWith('mcp__') && !OWENLOOP_CONTROL_TOOLS.has(tool));
|
|
240
|
+
if (unsupportedMcp.length > 0) {
|
|
241
|
+
issues.push({
|
|
242
|
+
field: 'tools',
|
|
243
|
+
message: `external MCP tools cannot be enforced by this adapter's exact allow-list: ` +
|
|
244
|
+
unsupportedMcp.join(', '),
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
if (permissions.filesystem === 'read-only' && allowed !== undefined) {
|
|
249
|
+
const unsafe = allowed.filter((tool) => !READ_ONLY_TOOLS.has(tool) && !OWENLOOP_CONTROL_TOOLS.has(tool));
|
|
250
|
+
if (unsafe.length > 0) {
|
|
251
|
+
issues.push({
|
|
252
|
+
field: 'tools',
|
|
253
|
+
message: `filesystem 'read-only' cannot allow non-read-only tool(s): ${unsafe.join(', ')}`,
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
if (permissions.network === 'owenloop-only' && allowed !== undefined) {
|
|
258
|
+
const unsafe = allowed.filter((tool) => !OWENLOOP_ONLY_NETWORK_TOOLS.has(tool) && !OWENLOOP_CONTROL_TOOLS.has(tool));
|
|
259
|
+
if (unsafe.length > 0) {
|
|
260
|
+
issues.push({
|
|
261
|
+
field: 'tools',
|
|
262
|
+
message: `network 'owenloop-only' cannot allow network-capable or unaudited tool(s): ${unsafe.join(', ')}`,
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
const deniedControl = (permissions.disallowedTools ?? []).filter((tool) => OWENLOOP_CONTROL_DENY_SPECS.has(tool));
|
|
267
|
+
if (deniedControl.length > 0) {
|
|
268
|
+
issues.push({
|
|
269
|
+
field: 'disallowedTools',
|
|
270
|
+
message: `the born-bound Owenloop control plane must retain get_order/submit access; remove: ${deniedControl.join(', ')}`,
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
return issues;
|
|
274
|
+
}
|
|
181
275
|
/**
|
|
182
276
|
* The error text a resume against a token the provider does not know is
|
|
183
277
|
* expected to carry. SECONDARY detection only — `deliver` pre-checks with
|
|
@@ -196,6 +290,15 @@ function isPlainMap(v) {
|
|
|
196
290
|
function owenloopMount(mount) {
|
|
197
291
|
return { type: 'stdio', command: mount.command, args: mount.args, alwaysLoad: true };
|
|
198
292
|
}
|
|
293
|
+
/** Restricted sessions register a positive two-tool subset. The selector is
|
|
294
|
+
* derived from the same names used by `allowedTools`, so the declared exception
|
|
295
|
+
* and the MCP server's actual `tools/list` cannot drift within this adapter. */
|
|
296
|
+
function restrictedOwenloopMount(mount) {
|
|
297
|
+
return owenloopMount({
|
|
298
|
+
command: mount.command,
|
|
299
|
+
args: [...mount.args, `--mcp-tools=${BORN_BOUND_OWENLOOP_TOOL_NAMES.join(',')}`],
|
|
300
|
+
});
|
|
301
|
+
}
|
|
199
302
|
/**
|
|
200
303
|
* `mcpServers`, with the owenloop mount layered ON TOP of whatever the step's
|
|
201
304
|
* bag declared. An author's own `owenloop` entry is overwritten, exactly as the
|
|
@@ -216,11 +319,17 @@ function mergeMcpServers(bagServers, mount) {
|
|
|
216
319
|
*/
|
|
217
320
|
export function buildClaudeOptions(inputs, extra) {
|
|
218
321
|
const { permissions } = inputs;
|
|
322
|
+
const isolated = permissions.tools !== undefined ||
|
|
323
|
+
permissions.filesystem === 'read-only' ||
|
|
324
|
+
permissions.network === 'owenloop-only';
|
|
219
325
|
const options = {
|
|
220
326
|
cwd: inputs.cwd,
|
|
221
327
|
env: extra.env,
|
|
222
328
|
abortController: extra.abortController,
|
|
223
|
-
mcpServers:
|
|
329
|
+
mcpServers: isolated
|
|
330
|
+
? { owenloop: restrictedOwenloopMount(inputs.owenloopMcp) }
|
|
331
|
+
: mergeMcpServers(permissions.extensions['mcpServers'], inputs.owenloopMcp),
|
|
332
|
+
...(isolated ? { settingSources: [], strictMcpConfig: true, skills: [] } : {}),
|
|
224
333
|
stderr: (data) => {
|
|
225
334
|
extra.onEvent({ kind: 'progress', text: `stderr: ${data.trimEnd()}` });
|
|
226
335
|
},
|
|
@@ -273,23 +382,53 @@ export function buildClaudeOptions(inputs, extra) {
|
|
|
273
382
|
// every call waiting on a prompt nobody will answer headless; only
|
|
274
383
|
// `allowedTools` fails to restrict the surface the author asked to restrict.
|
|
275
384
|
//
|
|
276
|
-
// ABSENT means "the step named no tools" and
|
|
277
|
-
// reads `tools: []` as "disable all built-in tools"
|
|
278
|
-
//
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
385
|
+
// ABSENT means "the step named no tools" and normally sets NEITHER key: the
|
|
386
|
+
// SDK reads `tools: []` as "disable all built-in tools". Isolation is the
|
|
387
|
+
// exception: the audited built-in list becomes explicit, and `allowedTools`
|
|
388
|
+
// also auto-allows the born-bound get_order/submit MCP tools so the restricted
|
|
389
|
+
// agent can inspect and finish its order without an unattended permission prompt.
|
|
390
|
+
// The restricted MCP child itself registers exactly those two tools; allowedTools
|
|
391
|
+
// is permission automation, not an MCP visibility filter.
|
|
392
|
+
let effectiveTools = permissions.tools;
|
|
393
|
+
if (effectiveTools === undefined && permissions.filesystem === 'read-only') {
|
|
394
|
+
// Filesystem and network are independent. A read-only filesystem still gets
|
|
395
|
+
// audited network readers unless the step separately restricts the network.
|
|
396
|
+
effectiveTools = permissions.network === 'owenloop-only'
|
|
397
|
+
? READ_ONLY_OWENLOOP_ONLY_NETWORK_TOOLS
|
|
398
|
+
: [...READ_ONLY_TOOLS];
|
|
399
|
+
}
|
|
400
|
+
else if (effectiveTools === undefined && permissions.network === 'owenloop-only') {
|
|
401
|
+
effectiveTools = [...OWENLOOP_ONLY_NETWORK_TOOLS];
|
|
402
|
+
}
|
|
403
|
+
if (effectiveTools !== undefined) {
|
|
404
|
+
options.tools = effectiveTools.filter((tool) => !OWENLOOP_CONTROL_TOOLS.has(tool));
|
|
405
|
+
options.allowedTools = [
|
|
406
|
+
...new Set([...effectiveTools, ...BORN_BOUND_OWENLOOP_TOOLS]),
|
|
407
|
+
];
|
|
408
|
+
}
|
|
409
|
+
if (isolated) {
|
|
410
|
+
// Defense in depth only: the restricted MCP child does not register `reject`
|
|
411
|
+
// at all. The deny protects against SDK/tool-surface regressions without being
|
|
412
|
+
// the visibility boundary.
|
|
413
|
+
options.disallowedTools = [
|
|
414
|
+
...new Set([
|
|
415
|
+
...(permissions.disallowedTools ?? []),
|
|
416
|
+
...RESTRICTED_OWENLOOP_DENIED_TOOLS,
|
|
417
|
+
]),
|
|
418
|
+
];
|
|
419
|
+
}
|
|
420
|
+
else if (permissions.disallowedTools !== undefined) {
|
|
284
421
|
options.disallowedTools = [...permissions.disallowedTools];
|
|
285
422
|
}
|
|
286
423
|
// Normalization already guaranteed a positive integer or absence.
|
|
287
424
|
if (permissions.maxTurns !== undefined)
|
|
288
425
|
options.maxTurns = permissions.maxTurns;
|
|
289
426
|
const skills = permissions.extensions['skills'];
|
|
290
|
-
if (skills === 'all' || (Array.isArray(skills) && skills.every((s) => typeof s === 'string'))) {
|
|
427
|
+
if (!isolated && (skills === 'all' || (Array.isArray(skills) && skills.every((s) => typeof s === 'string')))) {
|
|
291
428
|
options.skills = skills;
|
|
292
429
|
}
|
|
430
|
+
if (extra.sessionId !== undefined)
|
|
431
|
+
options.sessionId = extra.sessionId;
|
|
293
432
|
if (extra.resume !== undefined)
|
|
294
433
|
options.resume = extra.resume;
|
|
295
434
|
// EXTENSIONS KEYS DELIBERATELY NOT MAPPED, so a reviewer reads intent rather
|
|
@@ -303,16 +442,23 @@ export function buildClaudeOptions(inputs, extra) {
|
|
|
303
442
|
// Unknown extension keys are ignored in silence — `owenloop work lint` is the place
|
|
304
443
|
// that warns about them.
|
|
305
444
|
//
|
|
306
|
-
//
|
|
307
|
-
//
|
|
308
|
-
//
|
|
309
|
-
//
|
|
310
|
-
//
|
|
311
|
-
//
|
|
312
|
-
//
|
|
313
|
-
//
|
|
445
|
+
// Outside isolation, `settingSources` and `strictMcpConfig` stay unset so the
|
|
446
|
+
// SDK preserves its normal settings and MCP behavior, including the full
|
|
447
|
+
// get_order/submit/reject work-holder server. Isolation sets `settingSources: []`
|
|
448
|
+
// and `strictMcpConfig: true` above, mounts the positive two-tool work-holder
|
|
449
|
+
// subset, and removes settings, hooks, skills, or external MCP that could bypass
|
|
450
|
+
// the authored restriction.
|
|
451
|
+
// `persistSession` always stays unset: its default is `true`, and disabling it
|
|
452
|
+
// would break resume-on-rejection.
|
|
314
453
|
return options;
|
|
315
454
|
}
|
|
455
|
+
const DEFAULT_START_DEPENDENCIES = {
|
|
456
|
+
createSessionId: randomUUID,
|
|
457
|
+
loadQuery: async () => {
|
|
458
|
+
const { query } = await import('@anthropic-ai/claude-agent-sdk');
|
|
459
|
+
return (args) => query(args);
|
|
460
|
+
},
|
|
461
|
+
};
|
|
316
462
|
/** Module-level, process-wide, keyed by session token. Only reachable from the
|
|
317
463
|
* process that started the session — which is exactly why `stop` is documented
|
|
318
464
|
* as a no-op on a token this process did not start. */
|
|
@@ -323,9 +469,9 @@ const SESSIONS = new Map();
|
|
|
323
469
|
* Resolves at the `result` message — turn end, per the contract — not at process
|
|
324
470
|
* exit, and regardless of whether the result reports an error.
|
|
325
471
|
*
|
|
326
|
-
* `onInit` fires
|
|
327
|
-
* `{kind:'started'}`
|
|
328
|
-
*
|
|
472
|
+
* `onInit` fires after a matching `system/init` confirms the preselected cold-
|
|
473
|
+
* start session id. `startClaude` emits `{kind:'started'}` before query creation;
|
|
474
|
+
* this callback marks the later provider confirmation, not the persistence gate.
|
|
329
475
|
*
|
|
330
476
|
* PHASE 6, ITEM 1 — EXPORTED, AND TYPED ON `AsyncIterable` RATHER THAN `Query`.
|
|
331
477
|
* This is the one function that maps the SDK's message stream onto this
|
|
@@ -336,10 +482,13 @@ const SESSIONS = new Map();
|
|
|
336
482
|
* what it uses is what lets a fixture drive it. A live `Query` still satisfies
|
|
337
483
|
* the narrower type, so nothing at the call sites changes.
|
|
338
484
|
*/
|
|
339
|
-
export async function consumeTurn(q, onEvent, onInit) {
|
|
485
|
+
export async function consumeTurn(q, onEvent, onInit, expectedSessionId) {
|
|
340
486
|
let sessionId;
|
|
341
487
|
for await (const message of q) {
|
|
342
488
|
if (message.type === 'system' && message.subtype === 'init') {
|
|
489
|
+
if (expectedSessionId !== undefined && message.session_id !== expectedSessionId) {
|
|
490
|
+
throw new Error(`provider session id mismatch: expected ${expectedSessionId}, received ${message.session_id}`);
|
|
491
|
+
}
|
|
343
492
|
sessionId = message.session_id;
|
|
344
493
|
// The ONLY place these are observable. The live smoke asserts on the
|
|
345
494
|
// `apiKeySource` here (subscription OAuth vs. an API key), and a later
|
|
@@ -376,36 +525,91 @@ export async function consumeTurn(q, onEvent, onInit) {
|
|
|
376
525
|
function errText(err) {
|
|
377
526
|
return err instanceof Error ? err.message : String(err);
|
|
378
527
|
}
|
|
379
|
-
async function
|
|
528
|
+
export async function startClaude(args, onEvent, dependencies = DEFAULT_START_DEPENDENCIES) {
|
|
529
|
+
// The provider token exists before any SDK work. `started` is synchronous by
|
|
530
|
+
// contract, so the caller's fsynced active-row append must return before the
|
|
531
|
+
// query factory can initialize a process or receive prompt bytes.
|
|
532
|
+
const sessionId = dependencies.createSessionId();
|
|
533
|
+
const ref = { harness: HARNESS_ID, token: sessionId };
|
|
534
|
+
try {
|
|
535
|
+
onEvent({ kind: 'started', ref });
|
|
536
|
+
}
|
|
537
|
+
catch (err) {
|
|
538
|
+
try {
|
|
539
|
+
onEvent({ kind: 'exited', exitCode: null, error: errText(err) });
|
|
540
|
+
}
|
|
541
|
+
catch {
|
|
542
|
+
// Preserve the durable-persistence failure that closed the start gate.
|
|
543
|
+
}
|
|
544
|
+
throw err;
|
|
545
|
+
}
|
|
380
546
|
const env = buildChildEnv(process.env, { allowApiBilling: allowApiBillingFrom(process.env) });
|
|
381
547
|
const abortController = new AbortController();
|
|
382
|
-
const options = buildClaudeOptions(args, { env, abortController, onEvent });
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
548
|
+
const options = buildClaudeOptions(args, { env, abortController, onEvent, sessionId });
|
|
549
|
+
let q;
|
|
550
|
+
try {
|
|
551
|
+
// A plain STRING prompt, not an AsyncIterable. Query construction is the
|
|
552
|
+
// provider-delivery boundary in the pinned SDK, so it must remain after the
|
|
553
|
+
// `started` callback above. Streaming input buys this adapter nothing else.
|
|
554
|
+
const query = await dependencies.loadQuery();
|
|
555
|
+
q = query({ prompt: args.brief, options });
|
|
556
|
+
}
|
|
557
|
+
catch (err) {
|
|
558
|
+
try {
|
|
559
|
+
abortController.abort();
|
|
560
|
+
}
|
|
561
|
+
catch {
|
|
562
|
+
// An already-aborted controller is equivalent to success.
|
|
563
|
+
}
|
|
564
|
+
onEvent({ kind: 'exited', exitCode: null, error: errText(err) });
|
|
565
|
+
throw err;
|
|
566
|
+
}
|
|
567
|
+
SESSIONS.set(sessionId, { query: q, abortController, options });
|
|
568
|
+
let initVerified = false;
|
|
391
569
|
let outcome;
|
|
392
570
|
try {
|
|
393
|
-
outcome = await consumeTurn(q, onEvent, (
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
onEvent({ kind: 'started', ref });
|
|
397
|
-
});
|
|
571
|
+
outcome = await consumeTurn(q, onEvent, () => {
|
|
572
|
+
initVerified = true;
|
|
573
|
+
}, sessionId);
|
|
398
574
|
}
|
|
399
575
|
catch (err) {
|
|
576
|
+
// An init mismatch or pre-init failure must not leave the preselected token
|
|
577
|
+
// resumable. A post-init provider failure keeps the same registry behavior as
|
|
578
|
+
// before; `stop()` can still find and idempotently close that verified session.
|
|
579
|
+
if (!initVerified)
|
|
580
|
+
SESSIONS.delete(sessionId);
|
|
581
|
+
try {
|
|
582
|
+
abortController.abort();
|
|
583
|
+
}
|
|
584
|
+
catch {
|
|
585
|
+
// An already-aborted controller is equivalent to success.
|
|
586
|
+
}
|
|
587
|
+
try {
|
|
588
|
+
q.close();
|
|
589
|
+
}
|
|
590
|
+
catch {
|
|
591
|
+
// Preserve the provider or session-integrity error that caused the abort.
|
|
592
|
+
}
|
|
400
593
|
onEvent({ kind: 'exited', exitCode: null, error: errText(err) });
|
|
401
594
|
throw err;
|
|
402
595
|
}
|
|
403
|
-
if (
|
|
404
|
-
|
|
405
|
-
|
|
596
|
+
if (outcome.sessionId === undefined) {
|
|
597
|
+
SESSIONS.delete(sessionId);
|
|
598
|
+
try {
|
|
599
|
+
abortController.abort();
|
|
600
|
+
}
|
|
601
|
+
catch {
|
|
602
|
+
// An already-aborted controller is equivalent to success.
|
|
603
|
+
}
|
|
604
|
+
try {
|
|
605
|
+
q.close();
|
|
606
|
+
}
|
|
607
|
+
catch {
|
|
608
|
+
// The missing-init error below is authoritative.
|
|
609
|
+
}
|
|
406
610
|
const why = outcome.sawResult
|
|
407
|
-
? 'the turn ended without
|
|
408
|
-
: 'the stream ended before
|
|
611
|
+
? 'the turn ended without confirming the supplied session id'
|
|
612
|
+
: 'the stream ended before confirming the supplied session id';
|
|
409
613
|
onEvent({ kind: 'exited', exitCode: null, error: why });
|
|
410
614
|
throw new Error(`harness start failed: ${why}`);
|
|
411
615
|
}
|
|
@@ -523,6 +727,8 @@ const KNOWN_FIELDS = new Set([
|
|
|
523
727
|
'description',
|
|
524
728
|
'tools',
|
|
525
729
|
'disallowedTools',
|
|
730
|
+
'filesystem',
|
|
731
|
+
'network',
|
|
526
732
|
'model',
|
|
527
733
|
'permissionMode',
|
|
528
734
|
'maxTurns',
|
|
@@ -544,11 +750,6 @@ function typeName(v) {
|
|
|
544
750
|
return 'array';
|
|
545
751
|
return typeof v;
|
|
546
752
|
}
|
|
547
|
-
function isStringOrStringArray(v) {
|
|
548
|
-
if (typeof v === 'string')
|
|
549
|
-
return true;
|
|
550
|
-
return Array.isArray(v) && v.every((e) => typeof e === 'string');
|
|
551
|
-
}
|
|
552
753
|
/**
|
|
553
754
|
* Check one step's `x.harness` option map against this harness's vocabulary.
|
|
554
755
|
*
|
|
@@ -558,7 +759,15 @@ function isStringOrStringArray(v) {
|
|
|
558
759
|
* are ERRORS. Never throws — a malformed bag produces findings.
|
|
559
760
|
*/
|
|
560
761
|
function lintStep(bag, step) {
|
|
561
|
-
const findings = [
|
|
762
|
+
const findings = [
|
|
763
|
+
...validateHarnessOptions(bag, step),
|
|
764
|
+
...claudePreflight(normalizeStepPermissions(bag)).map((issue) => ({
|
|
765
|
+
severity: 'error',
|
|
766
|
+
step,
|
|
767
|
+
message: issue.message,
|
|
768
|
+
...(issue.field !== undefined ? { field: issue.field } : {}),
|
|
769
|
+
})),
|
|
770
|
+
];
|
|
562
771
|
const err = (message, field) => {
|
|
563
772
|
findings.push({ severity: 'error', step, message, ...(field !== undefined ? { field } : {}) });
|
|
564
773
|
};
|
|
@@ -579,18 +788,10 @@ function lintStep(bag, step) {
|
|
|
579
788
|
err(`${field} must be ${expected}, got ${typeName(bag[field])}`, field);
|
|
580
789
|
}
|
|
581
790
|
};
|
|
582
|
-
check('
|
|
583
|
-
check('disallowedTools', isStringOrStringArray, 'a string or string[]');
|
|
584
|
-
check('model', (v) => typeof v === 'string', 'a string');
|
|
585
|
-
check('effort', (v) => typeof v === 'string', 'a string');
|
|
586
|
-
check('skills', (v) => Array.isArray(v) && v.every((e) => typeof e === 'string'), 'a string[]');
|
|
791
|
+
check('skills', (v) => v === 'all' || (Array.isArray(v) && v.every((e) => typeof e === 'string')), "'all' or a string[]");
|
|
587
792
|
check('background', (v) => typeof v === 'boolean', 'a boolean');
|
|
588
793
|
check('mcpServers', isPlainMap, 'a map');
|
|
589
794
|
check('hooks', isPlainMap, 'a map');
|
|
590
|
-
check('maxTurns', (v) => typeof v === 'number' && Number.isInteger(v) && v > 0, 'a positive integer');
|
|
591
|
-
if ('permissionMode' in bag && !PERMISSION_MODES.includes(bag['permissionMode'])) {
|
|
592
|
-
err(`permissionMode must be one of ${PERMISSION_MODES.join('|')}`, 'permissionMode');
|
|
593
|
-
}
|
|
594
795
|
if ('memory' in bag && !MEMORY_SCOPES.has(bag['memory'])) {
|
|
595
796
|
err(`memory must be one of ${[...MEMORY_SCOPES].join('|')}`, 'memory');
|
|
596
797
|
}
|
|
@@ -623,7 +824,8 @@ export const claudeAdapter = {
|
|
|
623
824
|
// The provider stores the session and resumes it from the opaque token this
|
|
624
825
|
// adapter puts in `HarnessSessionRef.token`.
|
|
625
826
|
resumeTier: 'native-token',
|
|
626
|
-
|
|
827
|
+
preflight: claudePreflight,
|
|
828
|
+
start: startClaude,
|
|
627
829
|
deliver,
|
|
628
830
|
stop,
|
|
629
831
|
lintStep,
|
|
@@ -37,8 +37,9 @@ export interface McpServerSpec {
|
|
|
37
37
|
* Deliberately unmapped, so a reader sees intent rather than oversight:
|
|
38
38
|
* - `permissions.tools` / `permissions.disallowedTools`: 0.146.0 has no
|
|
39
39
|
* per-thread built-in-tool allow-list; the sandbox and the approval policy
|
|
40
|
-
* are the levers it does have.
|
|
40
|
+
* are the levers it does have. Adapter preflight refuses both fields.
|
|
41
41
|
* - `permissions.maxTurns`: no `thread/start` or `turn/start` equivalent.
|
|
42
|
+
* Adapter preflight and this direct-call boundary both refuse the field.
|
|
42
43
|
* - `permissions.effort`: not a `ThreadStartParams` field — it is a
|
|
43
44
|
* `turn/start` param, so it lands in `buildTurnStartParams`.
|
|
44
45
|
* - every `extensions` key other than `mcpServers`, `codexConfig` and
|
|
@@ -63,9 +64,9 @@ export declare function buildTurnStartParams(threadId: string, text: string, eff
|
|
|
63
64
|
* `sandbox`, `model` and `config`, and a resumed thread that does not re-supply
|
|
64
65
|
* them reverts to the server's defaults.
|
|
65
66
|
*
|
|
66
|
-
* PHASE 4 CLOSED CONTRACT OBSERVATION 1. `deliver`'s third argument
|
|
67
|
-
* only `cwd` and `owenloopMcp`, so a resume in a different process from
|
|
68
|
-
*
|
|
67
|
+
* PHASE 4 CLOSED CONTRACT OBSERVATION 1. `deliver`'s third argument originally
|
|
68
|
+
* carried only `cwd` and `owenloopMcp`, so a resume in a different process from
|
|
69
|
+
* the start had nothing to rebuild `approvalPolicy`
|
|
69
70
|
* / `sandbox` / `model` from and silently reverted to server defaults. It now
|
|
70
71
|
* carries the normalized `StepPermissions`, so this function derives the SAME
|
|
71
72
|
* params `buildThreadStartParams` would, and `args` WINS over `base` on every
|