@aiwg/cli 2026.11.5 → 2026.11.7
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/agentic/code/providers/model-capabilities.v1.json +9 -9
- package/bin/aiwg.mjs +6 -4
- package/dist/src/activity-log/cli.js +1 -1
- package/dist/src/agents/agent-deployer.js +1 -1
- package/dist/src/artifacts/audit/types.js +1 -1
- package/dist/src/artifacts/browser-export.js +1 -0
- package/dist/src/artifacts/discover-facets.js +1 -1
- package/dist/src/artifacts/enrichment/prompt.js +1 -1
- package/dist/src/artifacts/enrichment/types.js +1 -1
- package/dist/src/artifacts/fortemi-core-query-adapter.js +2 -0
- package/dist/src/artifacts/index-builder.js +1 -0
- package/dist/src/artifacts/query-engine-discover-output.js +1 -0
- package/dist/src/artifacts/query-engine-discover.js +2 -2
- package/dist/src/artifacts/query-engine-scoring.js +7 -0
- package/dist/src/artifacts/template-output-kind.js +10 -0
- package/dist/src/artifacts/types.js +1 -1
- package/dist/src/artifacts/views/definition.js +1 -1
- package/dist/src/artifacts/views/types.js +1 -1
- package/dist/src/catalog/cli.js +1 -1
- package/dist/src/catalog/cli.mjs +1 -1
- package/dist/src/catalog/loader.js +1 -1
- package/dist/src/catalog/loader.mjs +1 -1
- package/dist/src/catalog/types.js +1 -1
- package/dist/src/cli/cli-extension-loader.js +19 -5
- package/dist/src/cli/cli-extension-paths.js +65 -0
- package/dist/src/cli/handlers/best-practices-audit.js +1 -1
- package/dist/src/cli/handlers/dataset.js +11 -2
- package/dist/src/cli/handlers/help.js +3 -4
- package/dist/src/cli/handlers/index.js +1 -1
- package/dist/src/cli/handlers/marketplace-plugin-search.js +37 -0
- package/dist/src/cli/handlers/marketplace.js +3 -1
- package/dist/src/cli/handlers/models.js +1 -1
- package/dist/src/cli/handlers/ralph-launcher.js +8 -2
- package/dist/src/cli/handlers/ralph.js +1 -1
- package/dist/src/cli/handlers/runtime-info.js +1 -1
- package/dist/src/cli/handlers/scaffolding.js +2 -2
- package/dist/src/cli/handlers/script-runner.js +1 -1
- package/dist/src/cli/handlers/sdlc-accelerate.js +1 -1
- package/dist/src/cli/handlers/subcommands-bundles.js +1 -1
- package/dist/src/cli/handlers/subcommands-list-format.js +19 -1
- package/dist/src/cli/handlers/types.js +1 -1
- package/dist/src/cli/handlers/update.js +26 -12
- package/dist/src/cli/handlers/use.js +6 -5
- package/dist/src/cli/handlers/utilities.js +1 -1
- package/dist/src/cli/handlers/version.js +1 -1
- package/dist/src/cli/handlers/workspace.js +1 -1
- package/dist/src/cli/handlers/writing.js +7 -1
- package/dist/src/cli/help-generator.js +9 -11
- package/dist/src/cli/hooks/builtin/activity-log-hook.js +1 -1
- package/dist/src/cli/router.js +1 -1
- package/dist/src/cli/workflow-orchestrator.js +1 -1
- package/dist/src/config/worker-context.js +37 -7
- package/dist/src/config/worker-parallelism.js +11 -0
- package/dist/src/contributors/detect.js +1 -1
- package/dist/src/contributors/discover.js +1 -1
- package/dist/src/contributors/heuristic.js +1 -1
- package/dist/src/contributors/index.js +1 -1
- package/dist/src/contributors/types.js +1 -1
- package/dist/src/contributors/validation.js +1 -1
- package/dist/src/dataset/backend-selection.d.ts +3 -0
- package/dist/src/dataset/backend-selection.js +11 -0
- package/dist/src/dataset/contract-range.d.ts +7 -0
- package/dist/src/dataset/contract-range.js +55 -0
- package/dist/src/dataset/fortemi-execution-bridge.d.ts +2 -0
- package/dist/src/dataset/fortemi-execution-bridge.js +12 -1
- package/dist/src/dataset/index.d.ts +2 -0
- package/dist/src/dataset/index.js +2 -0
- package/dist/src/dataset/orchestration-service.d.ts +1 -1
- package/dist/src/dataset/orchestration-service.js +7 -8
- package/dist/src/dataset/orchestration-types.d.ts +2 -0
- package/dist/src/dataset/service-binding-checkpoints.d.ts +10 -0
- package/dist/src/dataset/service-binding-checkpoints.js +26 -0
- package/dist/src/dataset/service-binding-contract.d.ts +46 -0
- package/dist/src/dataset/service-binding-contract.js +25 -0
- package/dist/src/dataset/service-binding-registry.d.ts +12 -0
- package/dist/src/dataset/service-binding-registry.js +118 -0
- package/dist/src/effects/worker-delivery.js +83 -0
- package/dist/src/extensions/capability-index.js +1 -1
- package/dist/src/extensions/commands/definitions.js +2 -2
- package/dist/src/extensions/deployment-registration.js +1 -1
- package/dist/src/extensions/index.js +1 -1
- package/dist/src/extensions/loader.js +1 -1
- package/dist/src/extensions/manifest.js +27 -9
- package/dist/src/extensions/project-local-activity.js +1 -1
- package/dist/src/extensions/project-local-discovery.js +2 -2
- package/dist/src/extensions/project-local-doctor.js +9 -4
- package/dist/src/extensions/project-local-promote.js +3 -3
- package/dist/src/extensions/project-local-remove.js +3 -3
- package/dist/src/extensions/project-local-scaffold.js +1 -1
- package/dist/src/extensions/project-quickref-discovery.js +11 -0
- package/dist/src/extensions/project-quickref.js +4 -7
- package/dist/src/extensions/registry.js +1 -1
- package/dist/src/extensions/shadow-resolver.js +1 -1
- package/dist/src/extensions/types.js +1 -1
- package/dist/src/extensions/upstream-registry.js +1 -1
- package/dist/src/extensions/validation.js +1 -1
- package/dist/src/intake/git-history-analyzer.js +1 -1
- package/dist/src/kb/cli.js +1 -1
- package/dist/src/marketplace/plugin-directory.js +36 -0
- package/dist/src/marketplace/plugin-search.js +180 -0
- package/dist/src/mcp/cli.mjs +2 -2
- package/dist/src/mcp/helpers.mjs +1 -1
- package/dist/src/mcp/http-tools.mjs +8 -6
- package/dist/src/mcp/http-transport.mjs +3 -1
- package/dist/src/mcp/server.mjs +1 -1
- package/dist/src/mcp/tools/command-run.mjs +1 -1
- package/dist/src/mcp/tools/discovery.mjs +1 -1
- package/dist/src/mcp/tools/subsystems.mjs +1 -1
- package/dist/src/mcp/tools/worker-invoke.mjs +71 -23
- package/dist/src/mcp/tools/worker-launch-ledger.mjs +33 -0
- package/dist/src/mcp/tools/worker-local-only-preflight.mjs +79 -0
- package/dist/src/mcp/tools/worker-recorded-launch.mjs +26 -0
- package/dist/src/mcp/tools/worker-stdin-runtime.mjs +33 -6
- package/dist/src/mcp/tools/worker-verify-deliver-schema.mjs +49 -0
- package/dist/src/mcp/tools/worker-verify-deliver.mjs +25 -0
- package/dist/src/models/catalog-policy.js +2 -2
- package/dist/src/models/conductor-data-policy.mjs +83 -14
- package/dist/src/models/config-loader.js +2 -2
- package/dist/src/models/index.js +2 -2
- package/dist/src/models/local-endpoint-models.js +155 -0
- package/dist/src/models/model-capabilities.v1.json +9 -9
- package/dist/src/models/model-discovery.js +9 -5
- package/dist/src/models/opencode-worker-model.mjs +16 -0
- package/dist/src/models/resolver.js +2 -2
- package/dist/src/models/worker-installation.mjs +5 -3
- package/dist/src/models/worker-plan.js +1 -1
- package/dist/src/plugin/plugin-installer.js +2 -2
- package/dist/src/plugin/registry-validator.js +2 -2
- package/dist/src/plugin/skill-command-translator.js +1 -1
- package/dist/src/providers/deployment-input-session.d.mts +2 -0
- package/dist/src/providers/deployment-input-session.mjs +38 -0
- package/dist/src/rlm/cache/hash.js +1 -1
- package/dist/src/rlm/cache/store.js +1 -1
- package/dist/src/rlm/cache/types.js +1 -1
- package/dist/src/serve/worker-invocation-preparation.js +54 -22
- package/dist/src/serve/worker-invocation.js +25 -8
- package/dist/src/serve/worker-shell-prompt.d.mts +6 -0
- package/dist/src/serve/worker-shell-prompt.mjs +78 -0
- package/dist/src/skills/run.js +0 -11
- package/dist/src/smiths/agentsmith/generator.js +1 -1
- package/dist/src/smiths/context-pipeline/index.js +1 -1
- package/dist/src/smiths/context-pipeline/provider-policy.js +1 -1
- package/dist/src/smiths/context-pipeline/types.js +1 -1
- package/dist/src/smiths/mcpsmith/analyzers/cli-analyzer.js +2 -2
- package/dist/src/smiths/mcpsmith/generator.js +2 -2
- package/dist/src/smiths/mcpsmith/index.js +2 -2
- package/dist/src/smiths/mcpsmith/types.js +2 -2
- package/dist/src/smiths/skillsmith/collision-detector.js +1 -1
- package/dist/src/smiths/skillsmith/namespace-adapter.js +1 -1
- package/dist/src/smiths/toolsmith/runtime-discovery.mjs +2 -2
- package/dist/src/smiths/toolsmith/types.js +2 -2
- package/dist/src/storage/backends/fortemi.js +1 -1
- package/dist/src/storage/backends/fs.js +1 -1
- package/dist/src/storage/backends/logseq.js +1 -1
- package/dist/src/storage/backends/obsidian.js +1 -1
- package/dist/src/storage/cli.js +2 -2
- package/dist/src/storage/config.js +1 -1
- package/dist/src/storage/index.js +1 -1
- package/dist/src/storage/subsystem-cli.js +1 -1
- package/dist/src/storage/types.js +1 -1
- package/dist/src/testing/generators/test-case-generator.js +1 -1
- package/dist/src/writing/campaign-patterns.js +96 -0
- package/dist/src/writing/campaign-report.js +41 -0
- package/dist/src/writing/contextual-diagnostics.js +29 -5
- package/dist/src/writing/current-patterns.catalogue.json +87 -0
- package/dist/src/writing/current-patterns.js +99 -0
- package/dist/src/writing/prose-mask.js +80 -0
- package/dist/src/writing/structural-patterns.js +109 -0
- package/dist/src/writing/validation-campaign.js +19 -0
- package/dist/src/writing/validation-engine.js +18 -11
- package/dist/src/writing/validation-rules.js +4 -3
- package/package.json +11 -1
- package/schemas/dataset/service-binding.v1.schema.json +70 -0
- package/schemas/models/model-catalog.v1.schema.json +6 -3
- package/tools/agents/providers/base-models-platforms.mjs +87 -48
- package/tools/agents/providers/conductor-data-guard.mjs +1 -1
- package/tools/agents/providers/rule-deployment-corpus-inputs.mjs +19 -0
- package/tools/agents/providers/rule-deployment-input-session.mjs +40 -0
- package/tools/agents/providers/rule-deployment-prepare.mjs +15 -6
- package/tools/plugin/package-plugins.mjs +2 -0
- package/tools/ralph-external/lib/mcp-worker-launch.mjs +67 -0
- package/tools/ralph-external/lib/opencode-adapter.mjs +9 -7
- package/tools/ralph-external/lib/trusted-verification.mjs +1021 -0
- package/tools/ralph-external/lib/typed-stop-delivery.mjs +55 -0
- package/tools/ralph-external/lib/verification-isolation.mjs +509 -0
- package/tools/ralph-external/lib/worker-context.mjs +3 -3
- package/tools/ralph-external/lib/worker-delivery-guards.mjs +141 -0
- package/tools/ralph-external/lib/worker-delivery-record.mjs +15 -0
- package/tools/ralph-external/lib/worker-final.mjs +4 -1
- package/tools/ralph-external/lib/worker-isolation-status.mjs +3 -0
- package/tools/ralph-external/lib/worker-launch-cli.mjs +8 -0
- package/tools/ralph-external/lib/worker-local-only-paths.mjs +45 -0
- package/tools/ralph-external/lib/worker-prompt.mjs +4 -1
- package/tools/ralph-external/lib/worker-retry-evidence.mjs +2 -1
- package/tools/ralph-external/lib/worker-run-directory-refusal.mjs +2 -1
- package/tools/ralph-external/lib/worker-run-directory.mjs +45 -0
- package/tools/ralph-external/lib/worker-unit-cleanup.mjs +10 -2
- package/tools/ralph-external/lib/worker-verification-cli.mjs +164 -0
- package/tools/ralph-external/lib/worktree-preparation.mjs +417 -0
- package/tools/ralph-external/session-launcher.mjs +8 -15
- package/vscode-extension/schemas/aiwg.config.v1.json +27 -0
|
@@ -38,6 +38,8 @@ async function readBody(request, response) {
|
|
|
38
38
|
export async function startHttpServer(options) {
|
|
39
39
|
const host = options.host === '[::1]' ? '::1' : options.host ?? '127.0.0.1';
|
|
40
40
|
const loopback = host === '127.0.0.1' || host === '::1' || host === 'localhost';
|
|
41
|
+
const workersEnabled = String(options.toolsets ?? '').split(',').map(value => value.trim()).includes('workers');
|
|
42
|
+
if (!loopback && workersEnabled) throw new Error('The workers toolset requires a localhost HTTP bind');
|
|
41
43
|
if (!loopback && !options.allowRemoteBind) {
|
|
42
44
|
throw new Error('A non-loopback --host requires --allow-remote-bind');
|
|
43
45
|
}
|
|
@@ -58,7 +60,7 @@ export async function startHttpServer(options) {
|
|
|
58
60
|
let closing = false;
|
|
59
61
|
let stopPromise;
|
|
60
62
|
const buildServer = async () => {
|
|
61
|
-
const policy = remoteToolPolicy(projectDir, options.tools);
|
|
63
|
+
const policy = remoteToolPolicy(projectDir, options.tools, { verifiedDeliveryOnly: workersEnabled });
|
|
62
64
|
const mcp = await createServer({ projectDir, artifactStore, toolsets: options.toolsets ?? '', configureTool: policy.configureTool });
|
|
63
65
|
try { policy.validate(); } catch (error) { await mcp.close(); throw error; }
|
|
64
66
|
policies.set(mcp, policy);
|
package/dist/src/mcp/server.mjs
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* Follows MCP 2025-11-25 specification.
|
|
6
6
|
*
|
|
7
7
|
* @see https://modelcontextprotocol.io/specification/2025-11-25
|
|
8
|
-
* @architecture
|
|
8
|
+
* @architecture @docs/architecture/cli/index.md
|
|
9
9
|
* @reference @docs/references/REF-066-mcp-specification-2025.md
|
|
10
10
|
* @cli @docs/cli/agent-usage.md - mcp serve command
|
|
11
11
|
* @frameworks @agentic/code/frameworks/sdlc-complete/
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
* - `shell: false` enforced in spawn
|
|
12
12
|
* - Destructive commands require `confirmed: true`
|
|
13
13
|
*
|
|
14
|
-
* @architecture
|
|
14
|
+
* @architecture @docs/cli/agent-usage.md
|
|
15
15
|
* @issues #1312 (S1)
|
|
16
16
|
* @rules @token-security, @anti-laziness
|
|
17
17
|
*/
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
*
|
|
18
18
|
* All are global-allowed (#1311) — work without a project root.
|
|
19
19
|
*
|
|
20
|
-
* @architecture
|
|
20
|
+
* @architecture @docs/cli/agent-usage.md
|
|
21
21
|
* @issues #1311 (scope split), #1313 (discover + pairs), #1320 (rule-list/show)
|
|
22
22
|
*/
|
|
23
23
|
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* Default toolset enabled: `core` (already registered by discovery.mjs +
|
|
10
10
|
* command-run.mjs in server.mjs).
|
|
11
11
|
*
|
|
12
|
-
* @architecture
|
|
12
|
+
* @architecture @docs/cli/agent-usage.md
|
|
13
13
|
* @issues #1322 (memory) #1323 (kb) #1324 (provenance) #1325 (activity-log)
|
|
14
14
|
* #1326 (index) #1327 (ralph) #1328 (ops) #1331 (mc) #1332 (dispatch)
|
|
15
15
|
*/
|
|
@@ -156,7 +156,10 @@
|
|
|
156
156
|
* @issues #2892, #2896 (review reference, not reused as-is)
|
|
157
157
|
*/
|
|
158
158
|
|
|
159
|
+
import { registerWorkerVerifyDeliverTool } from './worker-verify-deliver.mjs';
|
|
160
|
+
import { createWorkerLaunchLedger } from './worker-launch-ledger.mjs';
|
|
159
161
|
import { workerFailureDiagnostics } from './worker-failure-diagnostics.mjs';
|
|
162
|
+
import { workerLocalOnlyPreflight } from './worker-local-only-preflight.mjs';
|
|
160
163
|
import { signalChild } from '../../process/signal-child.mjs';
|
|
161
164
|
import { z } from 'zod';
|
|
162
165
|
|
|
@@ -177,6 +180,7 @@ import path from 'node:path';
|
|
|
177
180
|
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
178
181
|
import { mcpError, mcpJson } from '../helpers.mjs';
|
|
179
182
|
import { buildShellStopControl, waitForUnitTermination } from './worker-shell-control.mjs';
|
|
183
|
+
import { recordedShellLauncher } from './worker-recorded-launch.mjs';
|
|
180
184
|
import { launchPreparedShellWorker, sweepWorkerStdin, markWorkerServer } from './worker-stdin-runtime.mjs';
|
|
181
185
|
// NOTE: no static import of ../../config/worker-context.js here. That
|
|
182
186
|
// module is TypeScript: a literal relative import resolves under vitest
|
|
@@ -613,7 +617,39 @@ async function loadRalphExternal(relativeFromToolsRoot) {
|
|
|
613
617
|
* in-process instead of shelling out to `aiwg models resolve`. */
|
|
614
618
|
async function defaultLoadWorkerInputs(servedRoot) {
|
|
615
619
|
const { loadWorkerInputs } = await loadModelsHandlerInternals();
|
|
616
|
-
return loadWorkerInputs(
|
|
620
|
+
return loadWorkerInputs(servedWorkerInputsContext(servedRoot));
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
/** Same context shape as the launcher's in-process loader. A bare `resolve`
|
|
624
|
+
* subcommand made the host-resource sampler parse a request with no flags
|
|
625
|
+
* and fail every real launch with `Missing role` (#4148). */
|
|
626
|
+
/** A shell worker's final file holds either plain workerClaims JSON (what
|
|
627
|
+
* real workers write, and what the launcher's own final collection reads) or
|
|
628
|
+
* a JSONL result stream. Parsing plain claims as JSONL rejected every real
|
|
629
|
+
* worker final with OG_CONTRACT_INVALID (#4151). The adapter still performs
|
|
630
|
+
* the strict decode and schema validation for either framing. */
|
|
631
|
+
export function shellFinalFormat(rawOutput) {
|
|
632
|
+
try {
|
|
633
|
+
const text = typeof rawOutput === 'string' ? rawOutput : Buffer.from(rawOutput).toString('utf8');
|
|
634
|
+
const value = JSON.parse(text);
|
|
635
|
+
return value && typeof value === 'object' && !Array.isArray(value) && !Object.hasOwn(value, 'type') ? 'json' : 'jsonl';
|
|
636
|
+
} catch {
|
|
637
|
+
return 'jsonl';
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
/** systemd collects a unit that exits successfully, so the legacy dispatch path cannot observe a
|
|
642
|
+
* clean exit (#4157). Name the owned-capture route instead of a misleading contract error. */
|
|
643
|
+
export function unobservedSystemdExit(invocation, outcome) {
|
|
644
|
+
if (invocation?.isolation !== 'systemd-unit' || outcome?.termination !== 'confirmed' || outcome.exitCode !== null
|
|
645
|
+
|| outcome.timedOut || outcome.stopped || outcome.neverExecuted) return null;
|
|
646
|
+
return { code: 'OG_WORKER_EXIT_UNOBSERVED',
|
|
647
|
+
message: 'The systemd worker unit ended but its exit status could not be observed (systemd collects units that exit successfully); its result is unknown and the worker tree is retained.',
|
|
648
|
+
remedy: 'Pass run_dir to worker-invoke so the launcher owns capture and records the exit status and final output.' };
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
export function servedWorkerInputsContext(servedRoot) {
|
|
652
|
+
return { cwd: servedRoot, args: [], rawArgs: [], frameworkRoot: findOwnPackageRoot() };
|
|
617
653
|
}
|
|
618
654
|
|
|
619
655
|
/** #2892 D1: the registry's default `maxActive` respects the project's own
|
|
@@ -666,7 +702,7 @@ async function loadWorkerContextModule() {
|
|
|
666
702
|
* provider's bootstrap is missing; an unmappable CLI refuses with the
|
|
667
703
|
* typed diagnostic, since no deploy could target it. */
|
|
668
704
|
async function ensureWorkerContextForInvocation({ invocation, config }) {
|
|
669
|
-
const { ensureWorkerContextBootstrap, mapCliToProviderId,
|
|
705
|
+
const { ensureWorkerContextBootstrap, mapCliToProviderId, WorkerContextBootstrapError } =
|
|
670
706
|
await loadWorkerContextModule();
|
|
671
707
|
const cli = invocation?.selected?.cli;
|
|
672
708
|
const mapped = mapCliToProviderId(cli, config?.parallelism);
|
|
@@ -677,13 +713,7 @@ async function ensureWorkerContextForInvocation({ invocation, config }) {
|
|
|
677
713
|
{ workdir: invocation?.cwd },
|
|
678
714
|
);
|
|
679
715
|
}
|
|
680
|
-
|
|
681
|
-
try {
|
|
682
|
-
providers = [...new Set([...resolveWorkerContextProvidersFromConfig(config).providers, mapped.provider])];
|
|
683
|
-
} catch {
|
|
684
|
-
providers = [mapped.provider];
|
|
685
|
-
}
|
|
686
|
-
return ensureWorkerContextBootstrap({ workdir: invocation?.cwd, provider: mapped.provider, providers });
|
|
716
|
+
return ensureWorkerContextBootstrap({ workdir: invocation?.cwd, provider: mapped.provider, providers: [mapped.provider], projectLocal: true });
|
|
687
717
|
}
|
|
688
718
|
|
|
689
719
|
/** Refuse a failed bootstrap ensure as a typed blocked diagnostic that
|
|
@@ -733,7 +763,7 @@ async function defaultLaunchShellWorkerBaseline(invocation, { memoryMaxGb = DEFA
|
|
|
733
763
|
return launchIsolatedWorker({
|
|
734
764
|
command: invocation?.argv?.[0], args: invocation?.argv?.slice(1) ?? [], cwd,
|
|
735
765
|
stdoutPath: invocation?.stdoutPath, stderrPath: invocation?.stderrPath, envNames: invocation?.envNames,
|
|
736
|
-
...launchOptions, gate,
|
|
766
|
+
...launchOptions, workerGroup: invocation?.selected?.group, gate,
|
|
737
767
|
});
|
|
738
768
|
},
|
|
739
769
|
};
|
|
@@ -1595,6 +1625,7 @@ async function defaultCallMcpWorker(mcpBinding, server, options = {}) {
|
|
|
1595
1625
|
function publicStatus(entry, healthHook) {
|
|
1596
1626
|
const base = {
|
|
1597
1627
|
invocationId: entry.invocationId,
|
|
1628
|
+
run_dir: entry.run_dir ?? null,
|
|
1598
1629
|
requestId: entry.requestId,
|
|
1599
1630
|
status: entry.status ?? (entry.terminalAt === null ? 'running' : 'uncertain'),
|
|
1600
1631
|
termination: entry.termination ?? 'running',
|
|
@@ -1625,6 +1656,7 @@ const inputSchema = z.strictObject({
|
|
|
1625
1656
|
// authorized reconciliation operation on this SAME handler (never a
|
|
1626
1657
|
// mailbox file, never a new breaker) — see `reconcileStopped` below.
|
|
1627
1658
|
operation: z.enum(['run', 'status', 'cancel', 'reconcile_stopped', 'reset_recovery_scope']),
|
|
1659
|
+
run_dir: z.string().startsWith('/').max(4096).refine(value => !value.includes('\0')).optional(),
|
|
1628
1660
|
invocation_id: invocationUuid().optional(),
|
|
1629
1661
|
scope_id: z.string().min(1).max(512).optional(),
|
|
1630
1662
|
request_id: z.string().min(1).max(128).regex(/^[a-zA-Z0-9_.:-]+$/).optional(),
|
|
@@ -1661,6 +1693,11 @@ export async function registerWorkerInvokeToolset(server, options = {}) {
|
|
|
1661
1693
|
return;
|
|
1662
1694
|
}
|
|
1663
1695
|
const servedRootReal = await resolveServedProjectRoot(options.projectRoot);
|
|
1696
|
+
const launches = createWorkerLaunchLedger();
|
|
1697
|
+
registerWorkerVerifyDeliverTool(server, { projectRoot: servedRootReal,
|
|
1698
|
+
assertPath: candidate => assertServedPath(servedRootReal, candidate),
|
|
1699
|
+
verify: async input => (await loadRalphExternal('lib/worker-verification-cli.mjs')).verifyWorkerRun(input, { recordedLaunches: launches.count }),
|
|
1700
|
+
});
|
|
1664
1701
|
await sweepWorkerStdin(options.stdinRuntimeRoot);
|
|
1665
1702
|
// Pinned once, here, at registration — never re-resolved per request, and
|
|
1666
1703
|
// never re-derived from `process.cwd()` (#2892 B1).
|
|
@@ -1673,8 +1710,11 @@ export async function registerWorkerInvokeToolset(server, options = {}) {
|
|
|
1673
1710
|
const ttlMs = options.ttlMs ?? resolveServerTerminalTtlMs();
|
|
1674
1711
|
const registry = options.registry ?? createInvocationRegistry({ now: options.now, maxActive, ttlMs });
|
|
1675
1712
|
const loadWorkerInputsImpl = options.loadWorkerInputs ?? defaultLoadWorkerInputs;
|
|
1676
|
-
const
|
|
1677
|
-
|
|
1713
|
+
const recordedShell = recordedShellLauncher({ loadRalphExternal, loadInputs: () => loadWorkerInputsImpl(servedRootReal),
|
|
1714
|
+
assertPath: candidate => assertServedPath(servedRootReal, candidate), registry, now: options.now ?? (() => new Date()) });
|
|
1715
|
+
const launchShellWorkerImpl = launches.track(options.launchShellWorker ?? ((invocation, context) => recordedShell.requested(invocation)
|
|
1716
|
+
? recordedShell.launch(invocation, context) : defaultLaunchShellWorker(invocation, context)), 'shell');
|
|
1717
|
+
const callMcpWorkerImpl = launches.track(options.callMcpWorker ?? defaultCallMcpWorker, 'mcp');
|
|
1678
1718
|
// Both continuations use the audited observer and hardened stop controls.
|
|
1679
1719
|
const waitForUnitTerminationOverride = options.waitForUnitTermination;
|
|
1680
1720
|
// #2915 review 5 ("a second worker over unresolved execution"): the
|
|
@@ -1810,17 +1850,13 @@ export async function registerWorkerInvokeToolset(server, options = {}) {
|
|
|
1810
1850
|
const root = await servedRoot();
|
|
1811
1851
|
const { snapshot, drivers } = await loadWorkerInputsImpl(root);
|
|
1812
1852
|
const { resolveWorkerInvocation } = await loadServeWorkerInvocation();
|
|
1813
|
-
|
|
1853
|
+
let plan = await resolveWorkerInvocation(snapshot, request, drivers, now().toISOString());
|
|
1854
|
+
plan = await recordedShell.bindPlan(plan, { resolve: resolveWorkerInvocation, snapshot, drivers, at: now().toISOString(), invocationId: entry.invocationId, input });
|
|
1814
1855
|
if (plan.invocation?.readiness !== 'launchable') {
|
|
1815
1856
|
return markTerminal({ status: 'blocked', termination: 'confirmed', diagnostics: plan.diagnostics ?? [] });
|
|
1816
1857
|
}
|
|
1817
|
-
if (plan.invocation.isolation === 'native-sandbox') {
|
|
1818
|
-
return markTerminal({ status: 'blocked', termination: 'confirmed', diagnostics: [{
|
|
1819
|
-
code: 'OG_POLICY_RELAXATION', pointer: '/worker/isolation',
|
|
1820
|
-
message: 'MCP worker-invoke run does not support pinned native-sandbox isolation',
|
|
1821
|
-
}] });
|
|
1822
|
-
}
|
|
1823
1858
|
prefix = { root, snapshot, drivers, invocation: plan.invocation };
|
|
1859
|
+
recordedShell.prepare(plan.invocation, { plan, input, invocationId: entry.invocationId, releaseOutput: cleanupReservation });
|
|
1824
1860
|
} catch (error) {
|
|
1825
1861
|
return markTerminal({ status: 'blocked', termination: 'confirmed', diagnostics: [error.message] });
|
|
1826
1862
|
}
|
|
@@ -1844,6 +1880,11 @@ export async function registerWorkerInvokeToolset(server, options = {}) {
|
|
|
1844
1880
|
}
|
|
1845
1881
|
}
|
|
1846
1882
|
|
|
1883
|
+
try {
|
|
1884
|
+
const diagnostic = await workerLocalOnlyPreflight({ root, snapshot, invocation, drivers });
|
|
1885
|
+
if (diagnostic) return markTerminal({ status: 'blocked', termination: 'confirmed', diagnostics: [diagnostic] });
|
|
1886
|
+
} catch (error) { return markTerminal({ status: 'blocked', termination: 'confirmed', diagnostics: [error.message] }); }
|
|
1887
|
+
|
|
1847
1888
|
// =========================================================================
|
|
1848
1889
|
// #2915 round 8 (D6): ONE decision, immediately after the prefix, from
|
|
1849
1890
|
// the launcher's own pure eligibility predicate,
|
|
@@ -2020,7 +2061,7 @@ export async function registerWorkerInvokeToolset(server, options = {}) {
|
|
|
2020
2061
|
// M2: a live stop handle for the duration of this call, so an
|
|
2021
2062
|
// explicit `cancel` can actually stop the isolated unit / kill the
|
|
2022
2063
|
// child, not just record that cancellation was requested.
|
|
2023
|
-
const control = buildShellStopControl(launch, {
|
|
2064
|
+
const control = launch.control ?? buildShellStopControl(launch, {
|
|
2024
2065
|
waitForUnit: (waitForUnitTerminationOverride ?? waitForUnitTerminationBaseline),
|
|
2025
2066
|
stopUnit: options.stopWorkerUnit,
|
|
2026
2067
|
killUnit: options.killWorkerUnit,
|
|
@@ -2062,6 +2103,8 @@ export async function registerWorkerInvokeToolset(server, options = {}) {
|
|
|
2062
2103
|
status: registry.get(entry.invocationId)?.cancelRequested ? 'cancelled' : 'failed',
|
|
2063
2104
|
diagnostics: [outcome.timedOut ? 'worker deadline exceeded; termination confirmed' : 'worker stopped; termination confirmed'] });
|
|
2064
2105
|
}
|
|
2106
|
+
const unobserved1 = unobservedSystemdExit(invocation, outcome);
|
|
2107
|
+
if (unobserved1) return registry.markTerminal(entry.invocationId, { status: 'failed', termination: 'confirmed', diagnostics: [unobserved1] });
|
|
2065
2108
|
try { rawOutput = await readBoundedFile(invocation.finalPath, invocation.maxOutputBytes, root); } catch {
|
|
2066
2109
|
return registry.markTerminal(entry.invocationId, { status: 'failed', termination: 'confirmed', diagnostics: ['worker final output was not written'] });
|
|
2067
2110
|
}
|
|
@@ -2114,7 +2157,7 @@ export async function registerWorkerInvokeToolset(server, options = {}) {
|
|
|
2114
2157
|
let claims;
|
|
2115
2158
|
try {
|
|
2116
2159
|
claims = await new (class extends ProviderAdapter {})().parseWorkerFinal(rawOutput, {
|
|
2117
|
-
format: invocation.transport === 'shell' ?
|
|
2160
|
+
format: invocation.transport === 'shell' ? shellFinalFormat(rawOutput) : 'mcp', observation, maxOutputBytes: invocation.maxOutputBytes,
|
|
2118
2161
|
});
|
|
2119
2162
|
} catch (error) {
|
|
2120
2163
|
// M5: bounded, fixed-vocabulary diagnostic only — never the raw
|
|
@@ -2405,7 +2448,7 @@ export async function registerWorkerInvokeToolset(server, options = {}) {
|
|
|
2405
2448
|
// "remaining from right now" so time already spent launching is
|
|
2406
2449
|
// never double-counted.
|
|
2407
2450
|
let deadlineMs = Math.max(0, deadlineAtMs - deadlineClockNow());
|
|
2408
|
-
const control = buildShellStopControl(launch, {
|
|
2451
|
+
const control = launch.control ?? buildShellStopControl(launch, {
|
|
2409
2452
|
waitForUnit: (unit, budgetMs, observerOptions) => (waitForUnitTerminationOverride ?? waitForUnitTermination)(unit,
|
|
2410
2453
|
budgetMs, { ...observerOptions, clock: deadlineClockNow }),
|
|
2411
2454
|
nowMs: deadlineClockNow,
|
|
@@ -2501,6 +2544,11 @@ export async function registerWorkerInvokeToolset(server, options = {}) {
|
|
|
2501
2544
|
status: registry.get(entry.invocationId)?.cancelRequested ? 'cancelled' : 'failed',
|
|
2502
2545
|
diagnostics: [outcome.timedOut ? 'worker deadline exceeded; termination confirmed' : 'worker stopped; termination confirmed'] });
|
|
2503
2546
|
}
|
|
2547
|
+
const unobserved2 = unobservedSystemdExit(invocation, outcome);
|
|
2548
|
+
if (unobserved2) {
|
|
2549
|
+
settleRecovery({ kind: 'failed', confirmedStop });
|
|
2550
|
+
return registry.markTerminal(entry.invocationId, { status: 'failed', termination: 'confirmed', diagnostics: [unobserved2] });
|
|
2551
|
+
}
|
|
2504
2552
|
try { rawOutput = await readBoundedFile(invocation.finalPath, invocation.maxOutputBytes, root); } catch {
|
|
2505
2553
|
// #2915 review 5 (finding 1a): a confirmed clean exit that never
|
|
2506
2554
|
// produced a readable final output is not a success -- settle
|
|
@@ -2671,7 +2719,7 @@ export async function registerWorkerInvokeToolset(server, options = {}) {
|
|
|
2671
2719
|
let claims;
|
|
2672
2720
|
try {
|
|
2673
2721
|
claims = await new (class extends ProviderAdapter {})().parseWorkerFinal(rawOutput, {
|
|
2674
|
-
format: invocation.transport === 'shell' ?
|
|
2722
|
+
format: invocation.transport === 'shell' ? shellFinalFormat(rawOutput) : 'mcp', observation, maxOutputBytes: invocation.maxOutputBytes,
|
|
2675
2723
|
});
|
|
2676
2724
|
} catch (error) {
|
|
2677
2725
|
// #2915 review 5 (finding 1a): the strict parse itself rejected the
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// Retain cumulative server-session launch counts independently of registry pruning.
|
|
2
|
+
export function createWorkerLaunchLedger() {
|
|
3
|
+
let count = 0;
|
|
4
|
+
return {
|
|
5
|
+
count: () => count,
|
|
6
|
+
track(launch, transport) {
|
|
7
|
+
return async (...args) => {
|
|
8
|
+
let recorded = false;
|
|
9
|
+
const record = () => { if (!recorded) { recorded = true; count++; } };
|
|
10
|
+
// MCP calls can remain pending long after their process starts.
|
|
11
|
+
// A registered non-null stop control is already launch evidence.
|
|
12
|
+
const context = args[2];
|
|
13
|
+
if (transport === 'mcp' && typeof context?.registerControl === 'function') {
|
|
14
|
+
args[2] = { ...context, registerControl(control) {
|
|
15
|
+
if (control) record();
|
|
16
|
+
return context.registerControl(control);
|
|
17
|
+
} };
|
|
18
|
+
}
|
|
19
|
+
let result;
|
|
20
|
+
try { result = await launch(...args); }
|
|
21
|
+
catch (error) {
|
|
22
|
+
if (error.launchAttempted) record();
|
|
23
|
+
throw error;
|
|
24
|
+
}
|
|
25
|
+
const launched = transport === 'shell'
|
|
26
|
+
? result.launched || result.launchAttempted || result.dispatchState === 'submission-uncertain'
|
|
27
|
+
: result.dispatchState ? result.dispatchState !== 'never-began' : result.outcome !== 'blocked';
|
|
28
|
+
if (launched) record();
|
|
29
|
+
return result;
|
|
30
|
+
};
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// Refuse dispatch when a prepared worker tree exposes declared local-only inputs.
|
|
2
|
+
import { stat, realpath, readdir } from 'node:fs/promises';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { collectLocalOnlyPaths } from '../../models/conductor-data-policy.mjs';
|
|
5
|
+
|
|
6
|
+
const contains = (base, file) => {
|
|
7
|
+
const relative = path.relative(base, file);
|
|
8
|
+
return relative === '' || relative !== '..' && !relative.startsWith(`..${path.sep}`) && !path.isAbsolute(relative);
|
|
9
|
+
};
|
|
10
|
+
async function existing(file) {
|
|
11
|
+
try {
|
|
12
|
+
const info = await stat(file);
|
|
13
|
+
return info.isFile() || info.isDirectory() ? await realpath(file) : null;
|
|
14
|
+
} catch (error) {
|
|
15
|
+
if (error.code === 'ENOENT' || error.code === 'ENOTDIR') return null;
|
|
16
|
+
throw error;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// Enumerate aliases without traversing their targets or opening any file contents.
|
|
21
|
+
async function symlinkTargets(tree) {
|
|
22
|
+
const targets = [], pending = [tree];
|
|
23
|
+
while (pending.length) {
|
|
24
|
+
const directory = pending.pop();
|
|
25
|
+
for (const entry of await readdir(directory, { withFileTypes: true })) {
|
|
26
|
+
const file = path.join(directory, entry.name);
|
|
27
|
+
if (entry.isDirectory()) pending.push(file);
|
|
28
|
+
else if (entry.isSymbolicLink()) {
|
|
29
|
+
const target = await existing(file);
|
|
30
|
+
if (target) targets.push(target);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return targets;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export async function workerLocalOnlyPreflight({ root, snapshot, invocation, drivers }) {
|
|
38
|
+
const paths = collectLocalOnlyPaths(snapshot.models.defaults.workerSelection, snapshot.config.parallelism);
|
|
39
|
+
if (!paths.length) return null;
|
|
40
|
+
const selected = invocation.selected;
|
|
41
|
+
const rows = snapshot.catalog.discovery?.instances?.[selected.cli]?.models ?? [];
|
|
42
|
+
const observation = rows.find(row => (row.id === selected.model || row.apiModelId === selected.model)
|
|
43
|
+
&& row.llmProvider === selected.inferenceProvider)?.worker;
|
|
44
|
+
// Locality is an observed execution-path fact, never inferred from a CLI or class name.
|
|
45
|
+
if (observation?.qualification?.status === 'qualified' && observation.dataUse?.processing === 'local') return null;
|
|
46
|
+
const trees = [invocation.cwd];
|
|
47
|
+
if (invocation.transport === 'mcp') {
|
|
48
|
+
const server = await drivers[selected.cli]?.mcpRegistry?.get(invocation.mcp.serverRef);
|
|
49
|
+
if (server?.cwd) trees.push(server.cwd);
|
|
50
|
+
}
|
|
51
|
+
const exposed = [], protectedTargets = new Map();
|
|
52
|
+
const planned = (invocation.artifacts ?? []).filter(artifact => artifact.location === 'workspace-relative')
|
|
53
|
+
.map(artifact => path.resolve(invocation.cwd, artifact.relativePath));
|
|
54
|
+
for (const file of paths) {
|
|
55
|
+
const projectPath = path.resolve(root, file);
|
|
56
|
+
const projectTarget = await existing(projectPath);
|
|
57
|
+
if (projectTarget) protectedTargets.set(file, projectTarget);
|
|
58
|
+
for (const tree of new Set(trees)) {
|
|
59
|
+
const canonicalTree = await realpath(tree);
|
|
60
|
+
// Check project-relative copies as well as a workdir inside a protected subtree.
|
|
61
|
+
if (await existing(path.resolve(tree, file))
|
|
62
|
+
|| planned.some(target => contains(path.resolve(tree, file), target)) || projectTarget && (
|
|
63
|
+
contains(tree, projectPath) || contains(projectPath, tree)
|
|
64
|
+
|| contains(canonicalTree, projectTarget) || contains(projectTarget, canonicalTree))) {
|
|
65
|
+
exposed.push(file);
|
|
66
|
+
break;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
if ([...protectedTargets.keys()].some(file => !exposed.includes(file))) {
|
|
71
|
+
for (const tree of new Set(trees)) for (const target of await symlinkTargets(tree)) {
|
|
72
|
+
for (const [file, protectedTarget] of protectedTargets) {
|
|
73
|
+
if (!exposed.includes(file) && (contains(target, protectedTarget) || contains(protectedTarget, target))) exposed.push(file);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return exposed.length ? { code: 'LOCAL_ONLY_PATH_EXPOSED', paths: exposed.sort(),
|
|
78
|
+
message: `Worker tree exposes local-only paths to a tuple without qualified local processing: ${exposed.sort().join(', ')}; remove them from the worker tree before launch, use a worker with qualified local processing, or deny the task` } : null;
|
|
79
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// Bind resolved MCP shell requests to the installed launcher's capture owner.
|
|
2
|
+
export function recordedShellLauncher({ loadRalphExternal, loadInputs, assertPath, registry, now }) {
|
|
3
|
+
const requests = new WeakMap();
|
|
4
|
+
return {
|
|
5
|
+
async bindPlan(plan, { resolve, snapshot, drivers, at, invocationId, input }) {
|
|
6
|
+
if (plan.invocation?.readiness !== 'launchable'
|
|
7
|
+
|| (plan.invocation.isolation !== 'native-sandbox' && input.run_dir === undefined)) return plan;
|
|
8
|
+
return resolve(snapshot, plan.request, drivers, at, { digests: plan.digests,
|
|
9
|
+
briefDigest: plan.invocation.briefDigest, invocationId });
|
|
10
|
+
},
|
|
11
|
+
requested(invocation) { return invocation.isolation === 'native-sandbox' || requests.get(invocation)?.input.run_dir !== undefined; },
|
|
12
|
+
prepare(invocation, request) { requests.set(invocation, request); },
|
|
13
|
+
async launch(invocation, options) {
|
|
14
|
+
const request = requests.get(invocation);
|
|
15
|
+
try {
|
|
16
|
+
const runDir = request.input.run_dir && await assertPath(request.input.run_dir);
|
|
17
|
+
const { launchMcpShellWorker } = await loadRalphExternal('lib/mcp-worker-launch.mjs');
|
|
18
|
+
return await launchMcpShellWorker(invocation, { ...options, ...request, runDir, loadInputs, now,
|
|
19
|
+
onRunDir: run_dir => registry.update(request.invocationId, { run_dir }) });
|
|
20
|
+
} catch (error) {
|
|
21
|
+
if (!error.launchAttempted) error.workerNotLaunched = true;
|
|
22
|
+
throw error;
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Prepare worker stdin and internal attribution for shell and spawned MCP transports.
|
|
2
2
|
import { directWorkerEnvironment } from '../../config/worker-attribution.mjs';
|
|
3
|
-
import { createHash } from 'node:crypto';
|
|
3
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
4
4
|
import { mkdtemp, mkdir, writeFile, rm, readdir, lstat } from 'node:fs/promises';
|
|
5
5
|
import { tmpdir } from 'node:os';
|
|
6
6
|
import path from 'node:path';
|
|
@@ -60,29 +60,56 @@ export async function launchPreparedShellWorker(invocation, { allowDegraded, con
|
|
|
60
60
|
throw new Error('Worker prompt digest changed');
|
|
61
61
|
}
|
|
62
62
|
const { workerStdinBytes } = await importImpl('serve/worker-stdin-frame.mjs');
|
|
63
|
+
// Same final-output contract the launcher adds (#4156): stdin profiles get the wrapped brief, and
|
|
64
|
+
// file-based profiles get a derived brief through the launcher's own artifact materializer.
|
|
65
|
+
const { workerPromptBrief } = await loadRalphExternal('lib/worker-prompt.mjs');
|
|
66
|
+
if (invocation.stdin === 'closed' && (invocation.argv ?? []).includes(invocation.briefPath)) {
|
|
67
|
+
const { materializeWorkerArtifacts } = await loadRalphExternal('lib/worker-artifacts.mjs');
|
|
68
|
+
// The materializer needs its quarantine outside the worker tree but on the same filesystem
|
|
69
|
+
// (atomic rename; /tmp is often a separate tmpfs), so it sits beside the worker tree.
|
|
70
|
+
const artifactRoot = await mkdtemp(path.join(path.dirname(invocation.cwd), '.aiwg-worker-artifacts-'));
|
|
71
|
+
cleanup = () => rm(artifactRoot, { recursive: true, force: true });
|
|
72
|
+
const materialized = await materializeWorkerArtifacts(invocation, artifactRoot,
|
|
73
|
+
{ brief, invocationId: invocationId ?? invocation.invocationId ?? randomUUID() });
|
|
74
|
+
invocation = { ...invocation, argv: materialized.argv };
|
|
75
|
+
}
|
|
63
76
|
let stdinPath;
|
|
64
|
-
const bytes = workerStdinBytes(invocation, brief, driver);
|
|
77
|
+
const bytes = workerStdinBytes(invocation, workerPromptBrief(brief, invocation.finalPath), driver);
|
|
65
78
|
if (bytes !== null) {
|
|
66
|
-
|
|
79
|
+
const artifactCleanup = cleanup;
|
|
80
|
+
const prepared = await prepareWorkerStdin(bytes, stdinRuntimeRoot);
|
|
81
|
+
stdinPath = prepared.stdinPath;
|
|
82
|
+
cleanup = () => Promise.all([prepared.cleanup(), artifactCleanup()]);
|
|
67
83
|
}
|
|
68
84
|
const markers = directWorkerEnvironment({ ...invocation, ...(invocationId ? { invocationId } : {}) });
|
|
69
85
|
const launch = await planDirectWorkerLaunch({ invocation, config, allowDegraded, name, live, readers,
|
|
70
86
|
env: { ...Object.fromEntries((invocation.envNames ?? []).filter(name => process.env[name] !== undefined)
|
|
71
87
|
.map(name => [name, process.env[name]])), ...markers },
|
|
72
88
|
envNames: [...new Set([...(invocation.envNames ?? []), ...Object.keys(markers)])],
|
|
73
|
-
thresholdOverlay, memoryMaxGb, stdinPath, ownedGroup: true,
|
|
89
|
+
thresholdOverlay, memoryMaxGb, stdinPath, ownedGroup: true,
|
|
90
|
+
isolation: invocation.isolation === 'native-sandbox' ? { mode: 'native-sandbox' } : isolation,
|
|
91
|
+
...(invocation.isolation === 'native-sandbox' ? { attached: true, stdin: bytes === null ? 'closed' : 'open' } : {}),
|
|
92
|
+
admission, invocationId, dispatchGuard,
|
|
74
93
|
spawn, spawnAsync, onSpawnAttempt: value => {
|
|
75
94
|
attempt = value;
|
|
76
95
|
value.child?.once('close', (exitCode, signalCode) => { Object.assign(value, { closed: true, exitCode, signalCode }); });
|
|
77
96
|
},
|
|
78
97
|
});
|
|
98
|
+
if (launch.mode === 'native-sandbox' && launch.child) {
|
|
99
|
+
// The native CLI owns its sandbox; the existing owned-group wrapper
|
|
100
|
+
// supplies stdin and stop authority outside the conductor unit.
|
|
101
|
+
launch.child.stdout?.resume();
|
|
102
|
+
launch.child.stderr?.resume();
|
|
103
|
+
launch.child.stdin?.on('error', () => {});
|
|
104
|
+
launch.child.stdin?.end(bytes ?? undefined);
|
|
105
|
+
}
|
|
79
106
|
const launchAttempted = !!(attempt?.unit || attempt?.pid);
|
|
80
107
|
if (!launch.launched && !launchAttempted) await cleanup();
|
|
81
|
-
return { ...launch, launchAttempted, spawnObservation: attempt, ownedGroup: launch.mode
|
|
108
|
+
return { ...launch, launchAttempted, spawnObservation: attempt, ownedGroup: ['degraded', 'native-sandbox'].includes(launch.mode) && !!launch.pid, cleanup,
|
|
82
109
|
diagnostic: launch.diagnostic ?? describeGateFailures(launch.failures) };
|
|
83
110
|
} catch (error) {
|
|
84
111
|
if (attempt?.unit || attempt?.pid) {
|
|
85
|
-
return { ...attempt, spawnObservation: attempt, ownedGroup:
|
|
112
|
+
return { ...attempt, spawnObservation: attempt, ownedGroup: ['degraded', 'native-sandbox'].includes(attempt.mode), launched: false, launchAttempted: true, cleanup, diagnostic: error.message };
|
|
86
113
|
}
|
|
87
114
|
error.workerNotLaunched = true;
|
|
88
115
|
await cleanup();
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// Own the two mutually exclusive publication request shapes.
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
const absolute = z.string().startsWith('/').max(4096).refine(value => !value.includes('\0'));
|
|
5
|
+
const check = z.strictObject({
|
|
6
|
+
id: z.string().min(1).max(256), command: absolute,
|
|
7
|
+
args: z.array(z.string().max(65536).refine(value => !value.includes('\0'))).max(256).optional(),
|
|
8
|
+
cwd: absolute.optional(),
|
|
9
|
+
envNames: z.array(z.string().regex(/^[A-Za-z_][A-Za-z0-9_]*$/)).max(128).optional(),
|
|
10
|
+
timeoutMs: z.number().int().positive().max(86400000).optional(),
|
|
11
|
+
});
|
|
12
|
+
export const typedStopSchema = z.strictObject({
|
|
13
|
+
status: z.enum(['denied', 'blocked']),
|
|
14
|
+
code: z.string().regex(/^[A-Z][A-Z0-9_]{2,63}$/),
|
|
15
|
+
blocking_rule: z.string().min(1).max(2000).refine(value => value.trim().length > 0),
|
|
16
|
+
launch_count: z.literal(0),
|
|
17
|
+
uncertainty_statement: z.string().max(4000).optional(),
|
|
18
|
+
reason: z.string().max(4000).optional(),
|
|
19
|
+
});
|
|
20
|
+
export const typedStopDeliverySchema = z.strictObject({ deliverablePath: absolute, typedStop: typedStopSchema });
|
|
21
|
+
const workerPublication = z.strictObject({ run_dir: absolute, artifact_path: absolute.optional(), deliverable_path: absolute, checks: z.array(check).min(1).max(32) });
|
|
22
|
+
const stopPublication = z.strictObject({ deliverable_path: absolute, typed_stop: typedStopSchema });
|
|
23
|
+
export const publicationSchema = z.union([workerPublication, stopPublication]);
|
|
24
|
+
|
|
25
|
+
// Select by presence, including null/undefined stops, so malformed requests
|
|
26
|
+
// receive only the relevant branch's remedies rather than a union dump.
|
|
27
|
+
export function parsePublication(input) {
|
|
28
|
+
const isStop = input !== null && typeof input === 'object' && Object.hasOwn(input, 'typed_stop');
|
|
29
|
+
const parsed = (isStop ? stopPublication : workerPublication).safeParse(input);
|
|
30
|
+
if (parsed.success) return parsed.data;
|
|
31
|
+
const code = isStop ? 'TYPED_STOP_INVALID' : 'PUBLICATION_INVALID';
|
|
32
|
+
const shape = isStop ? 'a typed stop' : 'a worker publication';
|
|
33
|
+
const findings = parsed.error.issues.flatMap(issue => {
|
|
34
|
+
const key = issue.path.join('.');
|
|
35
|
+
if (issue.code === 'unrecognized_keys') return issue.keys.map(unknown => `${code}: ${[...issue.path, unknown].join('.')} is unknown for ${shape}`);
|
|
36
|
+
const missing = issue.path.length && issue.path.reduce((value, part) => value?.[part], input) === undefined;
|
|
37
|
+
return [`${code}: ${key || 'request'} ${missing ? `is required for ${shape}` : issue.message}`];
|
|
38
|
+
});
|
|
39
|
+
throw Object.assign(new Error(findings.join('\n')), { code, findings });
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// The SDK advertises only object schemas. Preserve the strict union in both
|
|
43
|
+
// its advertised JSON Schema and validation, with a stable refusal code.
|
|
44
|
+
export const publicationInputSchema = z.looseObject({}).superRefine((input, context) => {
|
|
45
|
+
try { parsePublication(input); }
|
|
46
|
+
catch (error) { for (const message of error.findings) context.addIssue({ code: 'custom', message }); }
|
|
47
|
+
}).meta({ anyOf: z.toJSONSchema(publicationSchema).anyOf });
|
|
48
|
+
|
|
49
|
+
export const invalidTypedStop = message => Object.assign(new Error(`TYPED_STOP_INVALID: ${message}`), { code: 'TYPED_STOP_INVALID' });
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// Narrow workers-toolset adapter: protected checks and publication share one verifier call.
|
|
2
|
+
import { mcpError, mcpJson } from '../helpers.mjs';
|
|
3
|
+
import { publicationInputSchema, parsePublication } from './worker-verify-deliver-schema.mjs';
|
|
4
|
+
|
|
5
|
+
export function registerWorkerVerifyDeliverTool(server, { projectRoot, assertPath, verify }) {
|
|
6
|
+
server.registerTool('worker-verify-deliver', {
|
|
7
|
+
title: 'Verify and Deliver a Worker Artifact or Typed Stop',
|
|
8
|
+
description: 'Publish a checked stopped-worker artifact, or a typed denied/blocked stop with launch_count 0 and no run_dir/artifact_path/checks. Malformed publications return PUBLICATION_INVALID; malformed typed stops return TYPED_STOP_INVALID. launch_count is checked against this MCP server session\'s recorded worker-invoke launches; undercounts return TYPED_STOP_LAUNCH_MISMATCH. A typed stop can only be published before any worker launch in this session; after a launch, the conductor must retry the worker or publish a verified worker artifact. Both produce signed delivery records. The server must run outside conductor confinement.',
|
|
9
|
+
inputSchema: publicationInputSchema,
|
|
10
|
+
annotations: { readOnlyHint: false, destructiveHint: true, openWorldHint: false },
|
|
11
|
+
}, async input => {
|
|
12
|
+
try {
|
|
13
|
+
const request = parsePublication(input);
|
|
14
|
+
const deliverablePath = await assertPath(request.deliverable_path);
|
|
15
|
+
if ('typed_stop' in request) return mcpJson(await verify({ projectDir: projectRoot, deliverablePath, typedStop: request.typed_stop }));
|
|
16
|
+
if (new Set(request.checks.map(entry => entry.id)).size !== request.checks.length) throw new Error('Protected check IDs must be unique');
|
|
17
|
+
const runDir = await assertPath(request.run_dir);
|
|
18
|
+
const artifactPath = request.artifact_path && await assertPath(request.artifact_path);
|
|
19
|
+
return mcpJson(await verify({ projectDir: projectRoot, runDir, artifactPath, deliverablePath, checks: request.checks }));
|
|
20
|
+
} catch (error) {
|
|
21
|
+
if (['PUBLICATION_INVALID', 'TYPED_STOP_INVALID', 'TYPED_STOP_LAUNCH_MISMATCH'].includes(error.code)) return { ...mcpJson({ status: 'rejected', errorCode: error.code, code: error.code, findings: error.findings ?? [error.message] }), isError: true };
|
|
22
|
+
return mcpError(`worker-verify-deliver: ${error.message}`);
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
}
|
|
@@ -46,12 +46,12 @@ const DiscoveredWorkerModelSchema = z.looseObject({
|
|
|
46
46
|
context.addIssue({ code: 'custom', path: ['worker', 'efforts'], message: 'Conflicting effort evidence' });
|
|
47
47
|
});
|
|
48
48
|
const ProviderDiscoverySchema = z.looseObject({
|
|
49
|
-
provider: z.string(), source: z.enum(['native', 'cache', 'remote', 'static']), observedAt: dateTime({ offset: true }),
|
|
49
|
+
provider: z.string(), source: z.enum(['native', 'cache', 'remote', 'static', 'local-endpoint']), observedAt: dateTime({ offset: true }),
|
|
50
50
|
runtimeVersion: z.string().optional(), accountScope: z.enum(['local-account', 'local-runtime', 'public-feed', 'static']),
|
|
51
51
|
accountBinding: z.string().min(1).optional(), models: z.array(DiscoveredWorkerModelSchema),
|
|
52
52
|
});
|
|
53
53
|
const DiscoverySchema = z.strictObject({
|
|
54
|
-
source: z.enum(['native', 'cache', 'remote', 'static']), upstreamSource: z.enum(['native', 'remote', 'static']).optional(),
|
|
54
|
+
source: z.enum(['native', 'cache', 'remote', 'static', 'local-endpoint']), upstreamSource: z.enum(['native', 'remote', 'static', 'local-endpoint']).optional(),
|
|
55
55
|
fetchedAt: dateTime({ offset: true }), remoteUrl: url().optional(), remoteError: z.string().optional(),
|
|
56
56
|
inventorySignature: z.string().optional(), providers: z.record(z.string(), ProviderDiscoverySchema),
|
|
57
57
|
instances: z.record(z.string(), ProviderDiscoverySchema).optional(),
|