@aiwg/cli 2026.11.0 → 2026.11.1
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/flue/README.md +2 -1
- package/dist/src/artifacts/cli.js +3 -2
- package/dist/src/artifacts/discover-facets.js +2 -0
- package/dist/src/artifacts/discover-session-facets.js +14 -0
- package/dist/src/artifacts/fortemi-core-query-adapter.js +4 -4
- package/dist/src/artifacts/framework-capabilities.js +7 -3
- package/dist/src/artifacts/index-builder.js +2 -3
- package/dist/src/artifacts/query-engine-discover-output.js +3 -3
- package/dist/src/artifacts/query-engine-discover.js +61 -14
- package/dist/src/artifacts/query-engine-entries.js +52 -9
- package/dist/src/artifacts/query-engine-installation.js +27 -0
- package/dist/src/artifacts/query-engine-rules.js +1 -2
- package/dist/src/artifacts/query-engine-scoring.js +33 -31
- package/dist/src/artifacts/query-engine-show-card.js +6 -2
- package/dist/src/artifacts/query-engine-show.js +2 -2
- package/dist/src/artifacts/relations.js +17 -10
- package/dist/src/cli/handlers/checkpoint.js +143 -0
- package/dist/src/cli/handlers/help.js +1 -0
- package/dist/src/cli/handlers/index.js +4 -2
- package/dist/src/cli/handlers/models-resource-sample.js +7 -3
- package/dist/src/cli/handlers/ralph-launcher.js +1 -1
- package/dist/src/cli/handlers/script-runner.js +2 -1
- package/dist/src/cli/handlers/steward-signing.js +44 -0
- package/dist/src/cli/handlers/steward.js +5 -0
- package/dist/src/cli/handlers/use-provider-results.js +17 -0
- package/dist/src/cli/handlers/use.js +9 -15
- package/dist/src/cli/router.js +12 -2
- package/dist/src/cli/user-scope-mirror.js +3 -1
- package/dist/src/config/aiwg-config.js +5 -1
- package/dist/src/config/cli.js +1 -0
- package/dist/src/config/delivery-validation.js +21 -0
- package/dist/src/config/host-resource-report.d.mts +1 -1
- package/dist/src/config/host-resource-report.mjs +23 -4
- package/dist/src/config/host-resource-runtime.d.mts +8 -0
- package/dist/src/config/host-resource-runtime.mjs +67 -24
- package/dist/src/config/index-graph-overrides.js +4 -0
- package/dist/src/config/worker-attribution.d.mts +7 -0
- package/dist/src/config/worker-attribution.mjs +44 -0
- package/dist/src/delivery/git.js +62 -0
- package/dist/src/delivery/pr.js +149 -0
- package/dist/src/delivery/tracker.js +33 -0
- package/dist/src/discovery/interview.js +1 -1
- package/dist/src/extensions/claude-hooks-installer.js +1 -0
- package/dist/src/extensions/loader.js +2 -1
- package/dist/src/issues/cli.js +12 -3
- package/dist/src/issues/external-cli.js +76 -0
- package/dist/src/issues/live.js +18 -1
- package/dist/src/issues/tracker-policy.js +17 -0
- package/dist/src/mcp/tools/worker-invoke.mjs +2 -1
- package/dist/src/mcp/tools/worker-stdin-runtime.mjs +12 -0
- package/dist/src/models/conductor-data-policy.d.mts +3 -2
- package/dist/src/models/conductor-data-policy.mjs +94 -5
- package/dist/src/models/worker-plan.js +3 -3
- package/dist/src/models/worker-selection-policy.js +2 -1
- package/dist/src/providers/deployment-lock.js +77 -0
- package/dist/src/providers/deployment-ownership.d.mts +12 -2
- package/dist/src/providers/deployment-ownership.mjs +115 -21
- package/dist/src/providers/deployment-preservation.d.mts +2 -1
- package/dist/src/providers/deployment-preservation.mjs +3 -0
- package/dist/src/providers/provider-definitions.js +4 -0
- package/dist/src/serve/worker-invocation-preparation.js +3 -1
- package/dist/src/serve/worker-invocation.js +2 -0
- package/dist/src/skills/run.js +5 -0
- package/dist/src/smiths/hook-bridge/codex-translator.js +3 -1
- package/dist/src/smiths/hook-bridge/hermes-translator.js +3 -1
- package/dist/src/smiths/hook-bridge/prompt-discovery-gaps.js +6 -0
- package/package.json +4 -2
- package/schemas/models/model-config-compatibility.v1.schema.json +4 -0
- package/tools/agents/deploy-agents.mjs +15 -0
- package/tools/agents/providers/base-contract.mjs +7 -1
- package/tools/agents/providers/base-inventory.mjs +35 -13
- package/tools/agents/providers/base.mjs +1 -1
- package/tools/agents/providers/conductor-data-guard.mjs +35 -11
- package/tools/agents/providers/muse-hooks.mjs +4 -0
- package/tools/agents/providers/muse-prompt-discovery.mjs +22 -0
- package/tools/agents/providers/provider-prepare-coordinator.mjs +15 -10
- package/tools/agents/providers/rule-delivery-surface.mjs +6 -3
- package/tools/agents/providers/rule-deployment-commit.mjs +10 -0
- package/tools/agents/providers/stale-artifact-prune.mjs +9 -8
- package/tools/ralph-external/lib/worker-capture.mjs +157 -0
- package/tools/ralph-external/lib/worker-health.mjs +3 -0
- package/tools/ralph-external/lib/worker-invocation-processes.mjs +9 -6
- package/tools/ralph-external/lib/worker-launch-cli.mjs +10 -1
- package/tools/ralph-external/lib/worker-process-identity.mjs +30 -0
- package/tools/ralph-external/lib/worker-retry-evidence.mjs +87 -6
- package/tools/ralph-external/lib/worker-termination.mjs +56 -6
- package/tools/ralph-external/process-monitor.mjs +12 -18
- package/tools/ralph-external/session-launcher.mjs +43 -29
- package/vscode-extension/schemas/aiwg.config.v1.json +15 -0
package/dist/src/issues/cli.js
CHANGED
|
@@ -12,15 +12,20 @@ import path from 'node:path';
|
|
|
12
12
|
import { pathToFileURL } from 'node:url';
|
|
13
13
|
import { getFrameworkRoot } from '../channel/manager.mjs';
|
|
14
14
|
import { readAiwgConfig } from '../config/aiwg-config.js';
|
|
15
|
+
import { externalIssues } from './external-cli.js';
|
|
16
|
+
import { trackerToken } from './tracker-policy.js';
|
|
15
17
|
import { sensitiveInputOptions } from '../auth/sensitive-input.js';
|
|
16
|
-
import { LocalIssueProviderCore, buildExternalIssueSnapshotFromLocal, buildLocalIssueConflictReport, createLiveIssueClient,
|
|
18
|
+
import { LocalIssueProviderCore, buildExternalIssueSnapshotFromLocal, buildLocalIssueConflictReport, createLiveIssueClient, localIssueRoot, parseCommentIdMappings, parseExternalIssueSnapshot, } from './index.js';
|
|
17
19
|
export async function main(args, cwd = process.cwd()) {
|
|
18
20
|
const parsed = parseArgs(args);
|
|
21
|
+
parsed.cwd = cwd;
|
|
19
22
|
const subcommand = parsed.positional[0];
|
|
20
23
|
const rest = parsed.positional.slice(1);
|
|
21
24
|
if (parsed.flags.has('backend')) {
|
|
22
25
|
throw new Error('aiwg issue commands use the local issue provider; --backend is not supported');
|
|
23
26
|
}
|
|
27
|
+
if (await externalIssues(parsed, cwd, async () => ({ plan: await buildIssuePlan(parsed, cwd), composer: await loadIssueComposer() })))
|
|
28
|
+
return;
|
|
24
29
|
const provider = stringFlag(parsed, 'provider');
|
|
25
30
|
if (provider && provider !== 'local') {
|
|
26
31
|
throw new Error(`aiwg issue is for local issue storage only; configured external trackers use their tracker tools (${provider})`);
|
|
@@ -317,8 +322,9 @@ async function handleIndex(issues, rest, args) {
|
|
|
317
322
|
}
|
|
318
323
|
async function liveClient(args, provider) {
|
|
319
324
|
const repo = requiredStringFlag(args, 'repo');
|
|
320
|
-
const
|
|
321
|
-
|
|
325
|
+
const actor = (await readAiwgConfig(args.cwd ?? process.cwd()))?.remotes?.tracker_actor;
|
|
326
|
+
const token = await trackerToken(provider, actor, sensitiveInputOptions(args.raw, 'token'));
|
|
327
|
+
return createLiveIssueClient({ provider, repo, apiUrl: stringFlag(args, 'api-url'), token, actor });
|
|
322
328
|
}
|
|
323
329
|
function requiredStringFlag(args, flag) {
|
|
324
330
|
const value = stringFlag(args, flag);
|
|
@@ -401,6 +407,9 @@ function csvFlag(args, name) {
|
|
|
401
407
|
}
|
|
402
408
|
function printUsage() {
|
|
403
409
|
console.log(`Usage:
|
|
410
|
+
aiwg issues create --title "..." --body-file path (configured external tracker)
|
|
411
|
+
aiwg issues comment|close <number> [--body-file path] (configured external tracker)
|
|
412
|
+
Use --provider local for local writes when an external tracker is configured.
|
|
404
413
|
aiwg issue init [--prefix KEY] [--padding N]
|
|
405
414
|
aiwg issue plan --title "..." [--body "..."] [--body-file path] [--json]
|
|
406
415
|
aiwg issue new --title "..." [--body "..."] [--body-file path] [--authorize-policy DIGEST]
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// Route explicit/configured external issue writes through actor verification and existing issue composition.
|
|
2
|
+
import { readFile } from 'node:fs/promises';
|
|
3
|
+
import { readAiwgConfig } from '../config/aiwg-config.js';
|
|
4
|
+
import { sensitiveInputOptions } from '../auth/sensitive-input.js';
|
|
5
|
+
import { deliveryTracker } from '../delivery/tracker.js';
|
|
6
|
+
export async function externalIssues(args, cwd, composition) {
|
|
7
|
+
const [operation, number] = args.positional;
|
|
8
|
+
if (!['create', 'new', 'comment', 'close'].includes(operation) || args.flags.get('provider') === 'local')
|
|
9
|
+
return false;
|
|
10
|
+
const config = await readAiwgConfig(cwd);
|
|
11
|
+
if (!config || config.remotes?.issue_provider === 'local' || config.remotes?.issue_tracker === 'local')
|
|
12
|
+
return false;
|
|
13
|
+
if (!config.remotes?.issue_tracker && !['gitea', 'github'].includes(String(config.remotes?.issue_provider)))
|
|
14
|
+
return false;
|
|
15
|
+
const value = (key) => typeof args.flags.get(key) === 'string' ? args.flags.get(key) : undefined;
|
|
16
|
+
if (value('provider') && value('provider') !== config.remotes?.issue_provider)
|
|
17
|
+
throw new Error('--provider must match the configured tracker');
|
|
18
|
+
const client = await deliveryTracker(cwd, config, { repo: value('repo'), apiUrl: value('api-url'), source: sensitiveInputOptions(args.raw, 'token') });
|
|
19
|
+
let result;
|
|
20
|
+
if (operation === 'create' || operation === 'new') {
|
|
21
|
+
const { plan, composer } = await composition();
|
|
22
|
+
result = await composer.executeIssuePlan(plan, {
|
|
23
|
+
async findByMarker(marker) {
|
|
24
|
+
for (let page = 1;; page++) {
|
|
25
|
+
const entries = await client.repositoryRequest('GET', `/issues?state=all&per_page=100&limit=100&page=${page}`);
|
|
26
|
+
const entry = entries.find(issue => issue.body?.includes(marker));
|
|
27
|
+
if (entry)
|
|
28
|
+
return { id: String(entry.number), reference: `#${entry.number}`, body: entry.body };
|
|
29
|
+
if (entries.length < 100)
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
async create(draft) {
|
|
34
|
+
let labels = draft.labels;
|
|
35
|
+
if (client.provider === 'gitea' && labels?.length) {
|
|
36
|
+
const available = [];
|
|
37
|
+
for (let page = 1;; page++) {
|
|
38
|
+
const entries = await client.repositoryRequest('GET', `/labels?limit=100&page=${page}`);
|
|
39
|
+
available.push(...entries);
|
|
40
|
+
if (entries.length < 100)
|
|
41
|
+
break;
|
|
42
|
+
}
|
|
43
|
+
labels = labels.map(name => {
|
|
44
|
+
const id = available.find(label => label.name === name)?.id;
|
|
45
|
+
if (id === undefined)
|
|
46
|
+
throw new Error('Issue label is not defined on the configured tracker');
|
|
47
|
+
return id;
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
const issue = await client.repositoryRequest('POST', '/issues', {
|
|
51
|
+
title: draft.title, body: draft.body, labels, assignees: draft.assignees,
|
|
52
|
+
});
|
|
53
|
+
return { id: String(issue.number), reference: `#${issue.number}`, body: issue.body };
|
|
54
|
+
},
|
|
55
|
+
async update(issue, patch) {
|
|
56
|
+
await client.repositoryRequest('PATCH', `/issues/${issue.id}`, patch);
|
|
57
|
+
},
|
|
58
|
+
}, { authorizationDigest: value('authorize-policy') });
|
|
59
|
+
if (result.status !== 'created')
|
|
60
|
+
throw new Error(`Issue creation refused: ${JSON.stringify(result)}`);
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
if (!/^[1-9][0-9]*$/.test(number ?? ''))
|
|
64
|
+
throw new Error(`${operation} requires a positive issue number`);
|
|
65
|
+
const body = value('body-file') ? await readFile(value('body-file'), 'utf8') : value('body') ?? value('reason');
|
|
66
|
+
if (operation === 'comment' && !body)
|
|
67
|
+
throw new Error('comment requires --body or --body-file');
|
|
68
|
+
if (body)
|
|
69
|
+
result = await client.repositoryRequest('POST', `/issues/${number}/comments`, { body });
|
|
70
|
+
if (operation === 'close')
|
|
71
|
+
result = await client.repositoryRequest('PATCH', `/issues/${number}`, { state: 'closed' });
|
|
72
|
+
}
|
|
73
|
+
console.log(JSON.stringify(result, null, 2));
|
|
74
|
+
return true;
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=external-cli.js.map
|
package/dist/src/issues/live.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { resolveSensitiveInput } from '../auth/sensitive-input.js';
|
|
2
|
+
import { checkTrackerActor } from './tracker-policy.js';
|
|
2
3
|
import { isInteractive } from '../cli/env.js';
|
|
3
4
|
export class LiveIssueClient {
|
|
4
5
|
options;
|
|
@@ -48,6 +49,10 @@ export class LiveIssueClient {
|
|
|
48
49
|
const comments = await this.request('GET', this.commentsPath(externalId));
|
|
49
50
|
return comments.map((comment) => normalizeComment(comment));
|
|
50
51
|
}
|
|
52
|
+
get provider() { return this.options.provider; }
|
|
53
|
+
repositoryRequest(method, suffix, body) {
|
|
54
|
+
return this.request(method, `${this.issuesPath().replace(/\/issues$/, '')}${suffix}`, body);
|
|
55
|
+
}
|
|
51
56
|
issuesPath() {
|
|
52
57
|
return `/repos/${encodeURIComponent(this.owner)}/${encodeURIComponent(this.name)}/issues`;
|
|
53
58
|
}
|
|
@@ -57,7 +62,15 @@ export class LiveIssueClient {
|
|
|
57
62
|
commentsPath(externalId) {
|
|
58
63
|
return `${this.issuePath(externalId)}/comments`;
|
|
59
64
|
}
|
|
65
|
+
async verifyActor() {
|
|
66
|
+
if (!this.options.actor)
|
|
67
|
+
return;
|
|
68
|
+
const user = await this.request('GET', '/user');
|
|
69
|
+
checkTrackerActor(this.options.actor, user.login);
|
|
70
|
+
}
|
|
60
71
|
async request(method, path, body) {
|
|
72
|
+
if (method !== 'GET')
|
|
73
|
+
await this.verifyActor();
|
|
61
74
|
const headers = {
|
|
62
75
|
Accept: 'application/json',
|
|
63
76
|
};
|
|
@@ -68,6 +81,7 @@ export class LiveIssueClient {
|
|
|
68
81
|
try {
|
|
69
82
|
const response = await this.fetchFn(`${this.baseUrl}${path}`, {
|
|
70
83
|
method,
|
|
84
|
+
redirect: 'error',
|
|
71
85
|
headers,
|
|
72
86
|
body: body === undefined ? undefined : JSON.stringify(body),
|
|
73
87
|
});
|
|
@@ -75,7 +89,10 @@ export class LiveIssueClient {
|
|
|
75
89
|
const text = await response.text().catch(() => '');
|
|
76
90
|
throw new Error(`${this.options.provider} issue API ${method} ${path} failed: ${response.status}${text ? ` ${redactSecrets(text, this.options.token)}` : ''}`);
|
|
77
91
|
}
|
|
78
|
-
|
|
92
|
+
// Native HTTP responses may be empty (for example Gitea merge success).
|
|
93
|
+
// Preserve the injected fetch contract used by existing in-process clients.
|
|
94
|
+
const payload = typeof response.text === 'function' ? await response.text() : undefined;
|
|
95
|
+
const result = (payload === undefined ? await response.json() : payload.trim() ? JSON.parse(payload) : {});
|
|
79
96
|
// A server can reflect request credentials in issue fields or comments.
|
|
80
97
|
// Scrub them before they reach local storage or CLI output.
|
|
81
98
|
if (!this.options.token)
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { resolveLiveIssueToken } from './live.js';
|
|
2
|
+
export async function trackerToken(provider, actor, source = {}, dependencies = {}) {
|
|
3
|
+
if (actor?.credential && Object.keys(source).some(key => key !== 'prefix')) {
|
|
4
|
+
throw new Error('Configured tracker_actor.credential cannot be overridden by token flags');
|
|
5
|
+
}
|
|
6
|
+
return resolveLiveIssueToken(provider, actor?.credential ?? source, dependencies);
|
|
7
|
+
}
|
|
8
|
+
export function checkTrackerActor(actor, login) {
|
|
9
|
+
if (typeof login !== 'string' || !login)
|
|
10
|
+
throw new Error('Tracker API did not identify an authenticated actor');
|
|
11
|
+
const normalized = login.toLowerCase();
|
|
12
|
+
if (actor.forbid_actors?.some(value => value.toLowerCase() === normalized))
|
|
13
|
+
throw new Error('Tracker actor is forbidden by remotes.tracker_actor.forbid_actors');
|
|
14
|
+
if (actor.login && actor.login.toLowerCase() !== normalized)
|
|
15
|
+
throw new Error('Tracker API user does not match remotes.tracker_actor.login');
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=tracker-policy.js.map
|
|
@@ -177,7 +177,7 @@ import path from 'node:path';
|
|
|
177
177
|
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
178
178
|
import { mcpError, mcpJson } from '../helpers.mjs';
|
|
179
179
|
import { buildShellStopControl, waitForUnitTermination } from './worker-shell-control.mjs';
|
|
180
|
-
import { launchPreparedShellWorker, sweepWorkerStdin } from './worker-stdin-runtime.mjs';
|
|
180
|
+
import { launchPreparedShellWorker, sweepWorkerStdin, markWorkerServer } from './worker-stdin-runtime.mjs';
|
|
181
181
|
// NOTE: no static import of ../../config/worker-context.js here. That
|
|
182
182
|
// module is TypeScript: a literal relative import resolves under vitest
|
|
183
183
|
// but throws ERR_MODULE_NOT_FOUND under raw node (e.g. `node
|
|
@@ -1032,6 +1032,7 @@ async function defaultLaunchMcpWorkerProcessBaseline(server, { allowDegraded, co
|
|
|
1032
1032
|
}
|
|
1033
1033
|
|
|
1034
1034
|
async function defaultLaunchMcpWorkerProcess(server, { allowDegraded, config, name, cwd, memoryMaxGb = DEFAULT_MCP_WORKER_MEMORY_MAX_GB, live, readers, thresholdOverlay, admission, invocation, invocationId, dispatchGuard }) {
|
|
1035
|
+
server = markWorkerServer(server, invocation, invocationId);
|
|
1035
1036
|
// #2915 round 8 (D6): see `defaultLaunchShellWorker`'s identical guard —
|
|
1036
1037
|
// `admission` is only ever present when this attempt is actually gated.
|
|
1037
1038
|
if (admission === undefined) {
|
|
@@ -1,8 +1,16 @@
|
|
|
1
|
+
// Prepare worker stdin and internal attribution for shell and spawned MCP transports.
|
|
2
|
+
import { directWorkerEnvironment } from '../../config/worker-attribution.mjs';
|
|
1
3
|
import { createHash } from 'node:crypto';
|
|
2
4
|
import { mkdtemp, mkdir, writeFile, rm, readdir, lstat } from 'node:fs/promises';
|
|
3
5
|
import { tmpdir } from 'node:os';
|
|
4
6
|
import path from 'node:path';
|
|
5
7
|
|
|
8
|
+
export function markWorkerServer(server, invocation, invocationId) {
|
|
9
|
+
if (!invocation?.cwd || !invocation?.selected?.group) return server;
|
|
10
|
+
return { ...server, env: { ...server.env,
|
|
11
|
+
...directWorkerEnvironment({ ...invocation, ...(invocationId ? { invocationId } : {}) }) } };
|
|
12
|
+
}
|
|
13
|
+
|
|
6
14
|
/** Sweep old private directories only for dead conductors; PID reuse retains
|
|
7
15
|
* them. Runtime files keep prompts out of git, but cannot isolate same-user workers. */
|
|
8
16
|
export async function sweepWorkerStdin(root = tmpdir(), { staleMs = 86400000, now = Date.now(),
|
|
@@ -57,7 +65,11 @@ export async function launchPreparedShellWorker(invocation, { allowDegraded, con
|
|
|
57
65
|
if (bytes !== null) {
|
|
58
66
|
({ stdinPath, cleanup } = await prepareWorkerStdin(bytes, stdinRuntimeRoot));
|
|
59
67
|
}
|
|
68
|
+
const markers = directWorkerEnvironment({ ...invocation, ...(invocationId ? { invocationId } : {}) });
|
|
60
69
|
const launch = await planDirectWorkerLaunch({ invocation, config, allowDegraded, name, live, readers,
|
|
70
|
+
env: { ...Object.fromEntries((invocation.envNames ?? []).filter(name => process.env[name] !== undefined)
|
|
71
|
+
.map(name => [name, process.env[name]])), ...markers },
|
|
72
|
+
envNames: [...new Set([...(invocation.envNames ?? []), ...Object.keys(markers)])],
|
|
61
73
|
thresholdOverlay, memoryMaxGb, stdinPath, ownedGroup: true, isolation, admission, invocationId, dispatchGuard,
|
|
62
74
|
spawn, spawnAsync, onSpawnAttempt: value => {
|
|
63
75
|
attempt = value;
|
|
@@ -4,5 +4,6 @@ import type { ParallelismConfig } from '../config/aiwg-config.js';
|
|
|
4
4
|
export const LOCAL_ONLY_PATH_PATTERN: string;
|
|
5
5
|
export function validLocalOnlyPath(value: unknown): boolean;
|
|
6
6
|
export function collectLocalOnlyPaths(policy?: WorkerSelectionPolicy, parallelism?: ParallelismConfig): string[];
|
|
7
|
-
export function
|
|
8
|
-
export function
|
|
7
|
+
export function conductorWorkerTrees(root: string): string[];
|
|
8
|
+
export function conductorToolDenial(event: { tool_name?: string; tool_input?: Record<string, unknown>; cwd?: string }, root: string, paths: string[], workerTrees?: string[]): string | null;
|
|
9
|
+
export function runConductorDataHook(root: string, paths: string[], denyWorkerExecution?: boolean): void;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
// Refuse
|
|
2
|
-
import { realpathSync, readFileSync, statSync } from 'node:fs';
|
|
1
|
+
// Refuse local-only reads and direct execution of worker output by the conductor.
|
|
2
|
+
import { realpathSync, readFileSync, readdirSync, statSync } from 'node:fs';
|
|
3
3
|
import { resolve, dirname, relative, isAbsolute, sep, matchesGlob, basename } from 'node:path';
|
|
4
4
|
|
|
5
5
|
// Literal project-relative files or directory subtrees; no globs, traversal or rule syntax.
|
|
@@ -144,7 +144,95 @@ function recursiveRoots(words) {
|
|
|
144
144
|
return roots.length ? roots : ['.'];
|
|
145
145
|
}
|
|
146
146
|
|
|
147
|
-
|
|
147
|
+
// Read Git's existing worktree metadata, never invoke Git or a worker-owned helper.
|
|
148
|
+
// Retained worktrees stay untrusted after the worker stops, until integration.
|
|
149
|
+
export function conductorWorkerTrees(root) {
|
|
150
|
+
const trees = [resolve(root, '.aiwg/working/worktrees')];
|
|
151
|
+
try {
|
|
152
|
+
let git = resolve(root, '.git');
|
|
153
|
+
if (!statSync(git).isDirectory()) {
|
|
154
|
+
git = resolve(root, readFileSync(git, 'utf8').trim().replace(/^gitdir: /, ''));
|
|
155
|
+
}
|
|
156
|
+
try { git = resolve(git, readFileSync(resolve(git, 'commondir'), 'utf8').trim()); } catch { /* Main checkout. */ }
|
|
157
|
+
for (const entry of readdirSync(resolve(git, 'worktrees'))) {
|
|
158
|
+
try {
|
|
159
|
+
const metadata = resolve(git, 'worktrees', entry);
|
|
160
|
+
const tree = dirname(resolve(metadata, readFileSync(resolve(metadata, 'gitdir'), 'utf8').trim()));
|
|
161
|
+
if (canonical(tree) !== canonical(root)) trees.push(tree);
|
|
162
|
+
} catch { /* A stale entry must not hide other registered workers. */ }
|
|
163
|
+
}
|
|
164
|
+
} catch { /* Projects without Git metadata still protect the standard worker directory. */ }
|
|
165
|
+
return [...new Set(trees)];
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const workerExecutionDenial = 'AIWG: conductor must not execute or import worker-written code; use aiwg ralph-external --verify-worker instead';
|
|
169
|
+
const runtime = /^(?:node(?:js)?|python(?:\d+(?:\.\d+)*)?|npm|npx|pnpm|yarn|bun|deno|vitest|jest|pytest|py\.test|mocha|ava|tap|tsx|ts-node|make|cmake|ctest|cargo|go|ruby|perl|php|java)$/;
|
|
170
|
+
const shells = new Set(['sh', 'bash', 'dash', 'zsh']);
|
|
171
|
+
const wrappers = new Set(['env', 'nice', 'timeout', 'systemd-run', 'sudo', 'command', 'exec', 'nohup']);
|
|
172
|
+
const wrapperValues = new Set(['-n', '--adjustment', '-p', '--property', '-u', '--user', '-g', '--group',
|
|
173
|
+
'-C', '--chdir', '--working-directory', '--unit', '--description', '--slice', '--kill-after', '-k', '-s', '--signal']);
|
|
174
|
+
|
|
175
|
+
function workerExecution(command, initialCwd, trees, depth = 0) {
|
|
176
|
+
if (depth > 4) return true;
|
|
177
|
+
const protectedTrees = trees.flatMap(tree => [resolve(tree), canonical(resolve(tree))]);
|
|
178
|
+
const copies = [];
|
|
179
|
+
let cwd = initialCwd;
|
|
180
|
+
const untrusted = candidate => {
|
|
181
|
+
const file = resolve(cwd, candidate.replace(/^file:\/\//, ''));
|
|
182
|
+
return [...protectedTrees, ...copies].some(base => contains(base, file) || contains(base, canonical(file)));
|
|
183
|
+
};
|
|
184
|
+
const references = value => (value.match(/[^\s"'`;&|<>()\[\]{},]+/g) ?? [])
|
|
185
|
+
.some(token => untrusted(token.split('=').at(-1)));
|
|
186
|
+
for (const words of shellCommands(command)) {
|
|
187
|
+
let index = 0;
|
|
188
|
+
while (/^[A-Za-z_][A-Za-z0-9_]*=/.test(words[index]?.value ?? '')) index++;
|
|
189
|
+
let name = basename(words[index]?.value ?? '');
|
|
190
|
+
while (wrappers.has(name)) {
|
|
191
|
+
// Common resource/process wrappers confer no verification authority.
|
|
192
|
+
const wrapper = name;
|
|
193
|
+
index++;
|
|
194
|
+
while (index < words.length) {
|
|
195
|
+
const arg = words[index].value;
|
|
196
|
+
if (arg === '--') { index++; break; }
|
|
197
|
+
if (wrapper === 'env' && /^[A-Za-z_][A-Za-z0-9_]*=/.test(arg)) { index++; continue; }
|
|
198
|
+
if (!arg.startsWith('-')) break;
|
|
199
|
+
const [option, assigned] = arg.split('=');
|
|
200
|
+
const takesValue = wrapperValues.has(option) && !(wrapper === 'systemd-run' && option === '--user');
|
|
201
|
+
const value = assigned ?? (takesValue ? words[index + 1]?.value : undefined);
|
|
202
|
+
if (['-C', '--chdir', '--working-directory'].includes(option) && value) cwd = resolve(cwd, value);
|
|
203
|
+
index += takesValue && assigned === undefined ? 2 : 1;
|
|
204
|
+
}
|
|
205
|
+
if (wrapper === 'timeout') index++; // Duration follows timeout's options.
|
|
206
|
+
name = basename(words[index]?.value ?? '');
|
|
207
|
+
}
|
|
208
|
+
const args = words.slice(index + 1).map(word => word.value);
|
|
209
|
+
if (name === 'cd') {
|
|
210
|
+
const target = args.find(arg => arg !== '--' && arg !== '-P' && arg !== '-L');
|
|
211
|
+
if (target) cwd = resolve(cwd, target);
|
|
212
|
+
continue;
|
|
213
|
+
}
|
|
214
|
+
if (['cp', 'mv', 'install'].includes(name)) {
|
|
215
|
+
const operands = args.filter(arg => !arg.startsWith('-'));
|
|
216
|
+
const destination = operands.at(-1);
|
|
217
|
+
for (const source of operands.slice(0, -1)) if (destination && untrusted(source)) {
|
|
218
|
+
copies.push(resolve(cwd, destination), resolve(cwd, destination, basename(source)));
|
|
219
|
+
}
|
|
220
|
+
continue;
|
|
221
|
+
}
|
|
222
|
+
if (words[index]?.value.includes('/') && untrusted(words[index].value)) return true;
|
|
223
|
+
if (shells.has(name)) {
|
|
224
|
+
const inline = args.findIndex(arg => /^-[^-]*c/.test(arg));
|
|
225
|
+
if (inline >= 0 && args[inline + 1] !== undefined) {
|
|
226
|
+
if (workerExecution(args[inline + 1], cwd, [...protectedTrees, ...copies], depth + 1)) return true;
|
|
227
|
+
continue;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
if ((runtime.test(name) || shells.has(name)) && (untrusted('.') || words.some(word => references(word.value)))) return true;
|
|
231
|
+
}
|
|
232
|
+
return false;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
export function conductorToolDenial(event, root, paths, workerTrees = conductorWorkerTrees(root)) {
|
|
148
236
|
const input = event.tool_input ?? {};
|
|
149
237
|
const cwd = typeof event.cwd === 'string' && isAbsolute(event.cwd) ? event.cwd : root;
|
|
150
238
|
const protectedPaths = paths.flatMap(file => [resolve(root, file), canonical(resolve(root, file))]);
|
|
@@ -155,6 +243,7 @@ export function conductorToolDenial(event, root, paths) {
|
|
|
155
243
|
};
|
|
156
244
|
if ([input.file_path, input.path].some(denied)) return 'AIWG: local-only task input is unavailable to this conductor';
|
|
157
245
|
if (typeof input.command === 'string') {
|
|
246
|
+
if (workerTrees.length && workerExecution(input.command, cwd, workerTrees)) return workerExecutionDenial;
|
|
158
247
|
// Covers literal/quoted paths, compound commands and common redirections. This is
|
|
159
248
|
// deliberately conservative, not a shell interpreter or a filesystem sandbox.
|
|
160
249
|
const command = input.command;
|
|
@@ -172,14 +261,14 @@ export function conductorToolDenial(event, root, paths) {
|
|
|
172
261
|
return null;
|
|
173
262
|
}
|
|
174
263
|
|
|
175
|
-
export function runConductorDataHook(root, paths) {
|
|
264
|
+
export function runConductorDataHook(root, paths, denyWorkerExecution = false) {
|
|
176
265
|
try {
|
|
177
266
|
const raw = readFileSync(0, 'utf8');
|
|
178
267
|
if (Buffer.byteLength(raw) > 1024 * 1024) throw new Error('oversized event');
|
|
179
268
|
const event = JSON.parse(raw);
|
|
180
269
|
if (!event || typeof event !== 'object' || typeof event.tool_name !== 'string'
|
|
181
270
|
|| !event.tool_input || typeof event.tool_input !== 'object') throw new Error('invalid event');
|
|
182
|
-
const reason = conductorToolDenial(event, root, paths);
|
|
271
|
+
const reason = conductorToolDenial(event, root, paths, denyWorkerExecution ? conductorWorkerTrees(root) : []);
|
|
183
272
|
if (reason) process.stdout.write(JSON.stringify({ hookSpecificOutput: {
|
|
184
273
|
hookEventName: 'PreToolUse', permissionDecision: 'deny', permissionDecisionReason: reason,
|
|
185
274
|
} }) + '\n');
|
|
@@ -295,11 +295,11 @@ export function resolveWorkerPlan(snapshot, request, ceilingDefaults = {}) {
|
|
|
295
295
|
plan.slots = resources.slots;
|
|
296
296
|
}
|
|
297
297
|
if (!resources.ok)
|
|
298
|
-
deny('
|
|
298
|
+
deny(resources.failures.some(failure => failure.code === 'OG_HOST_ATTRIBUTION') ? 'OG_HOST_ATTRIBUTION' : 'OG_HOST_CAPACITY', '/parallelism/admission/hostResources', resources.failures.map(failure => `${failure.signal}: ${failure.reason}`).join('; '));
|
|
299
299
|
}
|
|
300
300
|
const effectiveMaxParallel = caps.length ? Math.min(...caps) : null;
|
|
301
301
|
if (effectiveMaxParallel === 0)
|
|
302
|
-
deny('
|
|
302
|
+
deny('OG_HOST_CAPACITY', '/constraints/maxParallel', 'Current capacity ceiling is zero');
|
|
303
303
|
if (!reasons.some(reason => reason.blocking !== false))
|
|
304
304
|
plan.eligible.push({ ...tuple, cli: member.cli,
|
|
305
305
|
inferenceProvider: row.llmProvider, modelKey: key, family: observation.family, identityEvidence: binding.identityEvidence,
|
|
@@ -336,7 +336,7 @@ export function resolveWorkerPlan(snapshot, request, ceilingDefaults = {}) {
|
|
|
336
336
|
...(request.substitution && matchesChoice(plan.selected, request.substitution) ? { substitution: structuredClone(request.substitution) } : {}) };
|
|
337
337
|
}
|
|
338
338
|
if (!plan.selected && plan.resources?.slots === 0) {
|
|
339
|
-
block('
|
|
339
|
+
block(plan.resources.failures.some(failure => failure.code === 'OG_HOST_ATTRIBUTION') ? 'OG_HOST_ATTRIBUTION' : 'OG_HOST_CAPACITY', '/parallelism/admission/hostResources', plan.resources.failures.map(failure => `${failure.signal}: ${failure.reason}`).join('; '));
|
|
340
340
|
}
|
|
341
341
|
plan.alternatives = plan.eligible.filter(tuple => tuple !== plan.selected);
|
|
342
342
|
return plan;
|
|
@@ -41,6 +41,7 @@ export const WorkerSelectionPolicySchema = z.strictObject({
|
|
|
41
41
|
deniedEfforts: uniqueStrings.optional(),
|
|
42
42
|
deniedModels: uniqueStrings.optional(),
|
|
43
43
|
denySelfDelegation: z.boolean().optional(),
|
|
44
|
+
denyConductorWorkerExecution: z.boolean().optional(),
|
|
44
45
|
requireExactModel: z.boolean().optional(),
|
|
45
46
|
allowedVisibility: z.array(z.enum(['listed', 'hidden'])).refine(v => new Set(v).size === v.length).optional(),
|
|
46
47
|
allowedLifecycle: z.array(z.enum(['active', 'deprecated'])).refine(v => new Set(v).size === v.length).optional(),
|
|
@@ -150,7 +151,7 @@ export function mergeWorkerSelection(layers) {
|
|
|
150
151
|
relaxation = value.some((v) => !previous.includes(v));
|
|
151
152
|
effective = previous.filter((v) => value.includes(v));
|
|
152
153
|
}
|
|
153
|
-
else if (['denySelfDelegation', 'requireExactModel'].includes(key)) {
|
|
154
|
+
else if (['denySelfDelegation', 'denyConductorWorkerExecution', 'requireExactModel'].includes(key)) {
|
|
154
155
|
relaxation = previous === true && value === false;
|
|
155
156
|
effective = previous || value;
|
|
156
157
|
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
// Serialize provider snapshots and writes that share user-home deployment state.
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
4
|
+
import { readFile } from 'node:fs/promises';
|
|
5
|
+
import { acquireDirectoryLock, DirectoryLockContentionError } from '../artifacts/prebuilt-build-lock.js';
|
|
6
|
+
import { getUserStateDir } from '../config/user-state.js';
|
|
7
|
+
const ownerVariable = 'AIWG_PROVIDER_DEPLOYMENT_LOCK_OWNER';
|
|
8
|
+
const held = new AsyncLocalStorage();
|
|
9
|
+
/** Forward ownership only to children launched from the owning async operation. */
|
|
10
|
+
export function providerDeploymentLockEnvironment() {
|
|
11
|
+
const owner = held.getStore();
|
|
12
|
+
return owner ? { [ownerVariable]: owner.token } : {};
|
|
13
|
+
}
|
|
14
|
+
export async function acquireProviderDeploymentLock() {
|
|
15
|
+
const lockPath = path.join(getUserStateDir(), 'provider-deployment.lock');
|
|
16
|
+
const local = held.getStore();
|
|
17
|
+
const inherited = local?.lockPath === lockPath ? local.token : process.env[ownerVariable];
|
|
18
|
+
const readOwner = () => readFile(path.join(lockPath, 'owner'), 'utf8').then(value => value.trim());
|
|
19
|
+
let release;
|
|
20
|
+
let token;
|
|
21
|
+
// A stale or forged marker cannot bypass the on-disk lease. Borrowers never
|
|
22
|
+
// remove the parent's lock; only the original acquisition may release it.
|
|
23
|
+
if (inherited && await readOwner().catch(() => undefined) === inherited) {
|
|
24
|
+
token = inherited;
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
release = await acquireSharedLock(lockPath);
|
|
28
|
+
try {
|
|
29
|
+
token = await readOwner();
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
await release();
|
|
33
|
+
throw error;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
let active = true;
|
|
37
|
+
return Object.assign(async () => {
|
|
38
|
+
if (!active)
|
|
39
|
+
return;
|
|
40
|
+
active = false;
|
|
41
|
+
await release?.();
|
|
42
|
+
}, {
|
|
43
|
+
async run(work) {
|
|
44
|
+
if (!active)
|
|
45
|
+
throw new Error('Provider deployment lock is released');
|
|
46
|
+
return held.run({ lockPath, token }, work);
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
async function acquireSharedLock(lockPath) {
|
|
51
|
+
try {
|
|
52
|
+
return await acquireDirectoryLock(lockPath, { timeoutMs: 0, reclaimDeadOwner: true });
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
if (!(error instanceof DirectoryLockContentionError))
|
|
56
|
+
throw error;
|
|
57
|
+
}
|
|
58
|
+
console.warn(`Waiting for shared user-home provider deployment lock: ${lockPath}`);
|
|
59
|
+
try {
|
|
60
|
+
return await acquireDirectoryLock(lockPath, { timeoutMs: 120_000, reclaimDeadOwner: true });
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
if (!(error instanceof DirectoryLockContentionError))
|
|
64
|
+
throw error;
|
|
65
|
+
throw new Error(`Timed out waiting for shared user-home provider deployment lock: ${lockPath}`);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
export async function withProviderDeploymentLock(work) {
|
|
69
|
+
const release = await acquireProviderDeploymentLock();
|
|
70
|
+
try {
|
|
71
|
+
return await release.run(work);
|
|
72
|
+
}
|
|
73
|
+
finally {
|
|
74
|
+
await release();
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=deployment-lock.js.map
|
|
@@ -13,8 +13,18 @@ export interface DeploymentOwnershipOptions {
|
|
|
13
13
|
logicalInputPath?: (file: string) => string;
|
|
14
14
|
}
|
|
15
15
|
export function deploymentOutputRoots(provider: { name: string; paths?: Record<string, string>; kernelSkillsPath?: string; deploymentFiles?: (target: string) => string[] }, target: string): string[];
|
|
16
|
-
|
|
17
|
-
export
|
|
16
|
+
/** A file recorded without its bytes: stat signature, plus a digest when it was read. */
|
|
17
|
+
export class DeploymentOutputState {
|
|
18
|
+
constructor(signature: string, digest?: string);
|
|
19
|
+
readonly signature: string;
|
|
20
|
+
readonly hash: string | undefined;
|
|
21
|
+
}
|
|
22
|
+
/** Receipts, settings and receipt-claimed files are Buffers; other files are states. */
|
|
23
|
+
export type DeploymentOutputSnapshot = Map<string, Buffer | DeploymentOutputState>;
|
|
24
|
+
export function outputDigest(entry: Buffer | DeploymentOutputState | undefined): string | undefined;
|
|
25
|
+
export function sameOutput(a: Buffer | DeploymentOutputState | undefined, b: Buffer | DeploymentOutputState | undefined): boolean;
|
|
26
|
+
export function captureDeploymentOutputs(roots: PathLike[], options?: { previous?: DeploymentOutputSnapshot }): DeploymentOutputSnapshot;
|
|
27
|
+
export function recordDeploymentOutputs(before: DeploymentOutputSnapshot, roots: PathLike[], opts?: DeploymentOwnershipOptions): void;
|
|
18
28
|
export function refreshSettingsDigests(record: { settings?: Record<string, unknown> }): void;
|
|
19
29
|
|
|
20
30
|
export function deploymentOwner(opts: DeploymentOwnershipOptions): string | undefined;
|