@aiwg/cli 2026.11.0 → 2026.11.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/agentic/code/addons/aiwg-hooks/canonical/aiwg-prompt-discovery.yaml +9 -0
- package/agentic/code/addons/aiwg-hooks/hooks/aiwg-prompt-discovery.cjs +136 -0
- package/agentic/code/providers/flue/README.md +2 -1
- package/agentic/code/providers/model-capabilities.v1.json +27 -23
- package/agentic/code/providers/model-catalog.v1.json +3 -3
- package/dist/src/artifacts/cli.js +13 -13
- package/dist/src/artifacts/discover-cli-help.js +25 -0
- package/dist/src/artifacts/discover-facets.js +2 -0
- package/dist/src/artifacts/discover-session-facets.js +15 -0
- package/dist/src/artifacts/fortemi-core-prebuilt-freshness.js +28 -0
- package/dist/src/artifacts/fortemi-core-query-adapter.js +4 -4
- package/dist/src/artifacts/fortemi-core-sync.js +3 -0
- package/dist/src/artifacts/framework-capabilities.js +11 -3
- package/dist/src/artifacts/framework-source-digest.js +1 -1
- package/dist/src/artifacts/index-builder.js +12 -13
- package/dist/src/artifacts/index-dependencies.js +72 -0
- package/dist/src/artifacts/query-engine-discover-output.js +13 -5
- package/dist/src/artifacts/query-engine-discover.js +103 -28
- package/dist/src/artifacts/query-engine-entries.js +107 -10
- package/dist/src/artifacts/query-engine-installation.js +27 -0
- package/dist/src/artifacts/query-engine-options.js +14 -1
- package/dist/src/artifacts/query-engine-rules.js +1 -2
- package/dist/src/artifacts/query-engine-scoring.js +38 -32
- package/dist/src/artifacts/query-engine-show-card.js +8 -2
- package/dist/src/artifacts/query-engine-show-load.js +1 -1
- package/dist/src/artifacts/query-engine-show.js +5 -3
- package/dist/src/artifacts/query-engine-templates.js +33 -0
- package/dist/src/artifacts/query-engine-verbose.js +25 -0
- package/dist/src/artifacts/relations-builder.js +49 -4
- package/dist/src/artifacts/relations.js +26 -10
- package/dist/src/artifacts/template-references.js +42 -0
- package/dist/src/artifacts/types.js +1 -1
- package/dist/src/cli/handlers/bundle-reconciliation.js +7 -3
- package/dist/src/cli/handlers/checkpoint-handoff.js +48 -0
- package/dist/src/cli/handlers/checkpoint-record.js +20 -0
- package/dist/src/cli/handlers/checkpoint.js +176 -0
- package/dist/src/cli/handlers/decision.js +1 -1
- package/dist/src/cli/handlers/doctor-args.js +3 -1
- package/dist/src/cli/handlers/doctor-help.js +2 -1
- 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/refresh-bundles.js +2 -1
- package/dist/src/cli/handlers/refresh-managed-deployment.js +196 -0
- package/dist/src/cli/handlers/refresh.js +10 -2
- 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/subcommands-discovery.js +8 -1
- package/dist/src/cli/handlers/use-provider-results.js +17 -0
- package/dist/src/cli/handlers/use.js +19 -18
- package/dist/src/cli/router.js +12 -2
- package/dist/src/cli/services/deployment-verification.js +11 -7
- 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/config/worker-write.js +4 -10
- package/dist/src/decision/ledger.js +15 -15
- package/dist/src/decision/offload.js +6 -7
- package/dist/src/delivery/git.js +62 -0
- package/dist/src/delivery/pr.js +151 -0
- package/dist/src/delivery/template-sections.js +56 -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 +62 -53
- package/dist/src/extensions/loader.js +2 -1
- package/dist/src/extensions/managed-hook-script-state.js +48 -0
- package/dist/src/extensions/muse-managed-hooks.js +49 -0
- package/dist/src/issues/cli.js +15 -3
- package/dist/src/issues/external-cli.js +79 -0
- package/dist/src/issues/live.js +26 -2
- package/dist/src/issues/local.js +5 -1
- package/dist/src/issues/tracker-policy.js +27 -0
- package/dist/src/mcp/json-document.d.mts +2 -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/model-capabilities.v1.json +27 -23
- package/dist/src/models/model-catalog.v1.json +3 -3
- package/dist/src/models/provider-policy.js +8 -0
- package/dist/src/models/worker-health-readiness.js +20 -4
- package/dist/src/models/worker-health-snapshot.js +29 -0
- package/dist/src/models/worker-installation.d.mts +5 -1
- package/dist/src/models/worker-installation.mjs +11 -5
- package/dist/src/models/worker-plan.js +3 -3
- package/dist/src/models/worker-qualification-policy.js +54 -0
- 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/providers/skill-ownership.d.mts +1 -0
- package/dist/src/providers/transformation-receipt-integration.js +4 -2
- package/dist/src/providers/transformation-receipt.js +4 -2
- package/dist/src/serve/worker-invocation-preparation.js +3 -1
- package/dist/src/serve/worker-invocation.js +6 -2
- package/dist/src/skills/run.js +5 -0
- package/dist/src/smiths/context-pipeline/workspace-audit.js +34 -17
- package/dist/src/smiths/context-pipeline/workspace-context-shared.js +12 -6
- package/dist/src/smiths/context-pipeline/workspace-doctor.js +44 -4
- package/dist/src/smiths/context-pipeline/workspace-document.js +5 -2
- package/dist/src/smiths/context-pipeline/workspace-migration.js +2 -1
- package/dist/src/smiths/hook-bridge/codex-translator.js +150 -92
- package/dist/src/smiths/hook-bridge/codex-trust.js +50 -0
- package/dist/src/smiths/hook-bridge/factory-hook-config.js +132 -0
- package/dist/src/smiths/hook-bridge/factory-translator.js +88 -33
- package/dist/src/smiths/hook-bridge/hermes-translator.js +3 -1
- package/dist/src/smiths/hook-bridge/index.js +3 -3
- package/dist/src/smiths/hook-bridge/loader.js +10 -2
- package/dist/src/smiths/hook-bridge/prompt-discovery-gaps.js +5 -0
- package/dist/src/storage/workspace-permissions-health.js +64 -0
- package/dist/src/storage/workspace-permissions.js +51 -0
- package/package.json +9 -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-files.mjs +2 -1
- package/tools/agents/providers/base-flat-artifacts.mjs +6 -3
- package/tools/agents/providers/base-inventory.mjs +35 -13
- package/tools/agents/providers/base-models-platforms.mjs +3 -3
- package/tools/agents/providers/base-skill-copy.mjs +2 -0
- package/tools/agents/providers/base.mjs +1 -1
- package/tools/agents/providers/bound-rules-pointer.mjs +21 -0
- package/tools/agents/providers/claude-post-deploy.mjs +9 -5
- package/tools/agents/providers/codex-post-deploy.mjs +10 -0
- package/tools/agents/providers/conductor-data-guard.mjs +35 -11
- package/tools/agents/providers/factory-hooks.mjs +43 -0
- package/tools/agents/providers/factory.mjs +4 -91
- package/tools/agents/providers/muse-hooks.mjs +6 -41
- package/tools/agents/providers/muse-prompt-discovery.mjs +18 -0
- package/tools/agents/providers/packaged-codex-agents.mjs +48 -0
- package/tools/agents/providers/provider-prepare-coordinator.mjs +15 -10
- package/tools/agents/providers/rule-delivery-surface.mjs +10 -7
- package/tools/agents/providers/rule-deployment-commit.mjs +10 -0
- package/tools/agents/providers/rule-presentation.mjs +6 -5
- package/tools/agents/providers/rule-projection.mjs +10 -2
- package/tools/agents/providers/rule-startup.mjs +8 -1
- package/tools/agents/providers/stale-artifact-prune.mjs +9 -8
- package/tools/cli/decision-offload-report.mjs +7 -2
- package/tools/plugin/issue-template-copies.mjs +24 -0
- package/tools/plugin/package-plugins.mjs +11 -3
- package/tools/ralph-external/lib/factory-adapter.mjs +7 -8
- package/tools/ralph-external/lib/worker-artifacts.mjs +4 -2
- package/tools/ralph-external/lib/worker-capture.mjs +157 -0
- package/tools/ralph-external/lib/worker-final.mjs +43 -8
- 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 +20 -2
- package/tools/ralph-external/lib/worker-process-identity.mjs +30 -0
- package/tools/ralph-external/lib/worker-prompt.mjs +35 -0
- package/tools/ralph-external/lib/worker-retry-evidence.mjs +87 -6
- package/tools/ralph-external/lib/worker-run-directory-refusal.mjs +8 -0
- 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 +53 -36
- package/vscode-extension/schemas/aiwg.config.v1.json +15 -0
|
@@ -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;
|
|
@@ -31,16 +31,110 @@ export function deploymentOutputRoots(provider, target) {
|
|
|
31
31
|
'.windsurfrules', 'models.json', '.aiwg/frameworks', '.aiwg/.aiwg-manifest.json'].map(name => path.join(target, name))])];
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
// Settings files and Flue outputs keep preimage bytes in their receipts.
|
|
35
|
+
const SETTINGS_FILE = /^(?:settings(?:\.local)?|hooks|opencode|config|aiwg\.cordis\.patch)\.(?:json|toml|ya?ml)$/;
|
|
36
|
+
const FLUE_OUTPUT = /[/\\](?:db\.ts|aiwg[/\\](?:(?:tools|specialists|skills)\.ts|remote-specialist\.(?:js|d\.ts)))$/;
|
|
37
|
+
// Timestamps are coarse: a same-size write right after a stat can keep its
|
|
38
|
+
// ctime. Files changed this recently are hashed instead of trusted by stat.
|
|
39
|
+
const RECENT_NS = 2_000_000_000n;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* A snapshot entry for a file whose bytes the recorder never needs: provider
|
|
43
|
+
* homes such as ~/.hermes or ~/.codex hold gigabytes of runtime data (#3846).
|
|
44
|
+
* `hash` is set when the bytes were read; otherwise only the stat is known.
|
|
45
|
+
*/
|
|
46
|
+
export class DeploymentOutputState {
|
|
47
|
+
constructor(signature, digest) { this.signature = signature; this.hash = digest; }
|
|
48
|
+
}
|
|
49
|
+
const signatures = new WeakMap();
|
|
50
|
+
const digests = new WeakMap();
|
|
51
|
+
const digestOf = entry => {
|
|
52
|
+
if (entry == null) return undefined;
|
|
53
|
+
if (entry instanceof DeploymentOutputState) return entry.hash;
|
|
54
|
+
if (!digests.has(entry)) digests.set(entry, hash(entry));
|
|
55
|
+
return digests.get(entry);
|
|
56
|
+
};
|
|
57
|
+
/** sha256 digest of a snapshot entry, or undefined when only its stat is known. */
|
|
58
|
+
export const outputDigest = entry => digestOf(entry);
|
|
59
|
+
/** Content equality; a stat-only entry never equals a different entry. */
|
|
60
|
+
export const sameOutput = (a, b) => a != null && b != null && (a === b || (digestOf(a) !== undefined && digestOf(a) === digestOf(b)));
|
|
61
|
+
const bytesOf = (file, entry) => {
|
|
62
|
+
if (entry == null || Buffer.isBuffer(entry)) return entry;
|
|
63
|
+
throw new Error(`Deployment snapshot did not retain bytes for ${file}`);
|
|
64
|
+
};
|
|
65
|
+
const signature = stat => `${stat.dev}:${stat.ino}:${stat.size}:${stat.mtimeNs}:${stat.ctimeNs}`;
|
|
66
|
+
const receiptBase = (file, receipt) => receipt.scope === 'project' && path.basename(path.dirname(file)) === '.aiwg'
|
|
67
|
+
? path.dirname(path.dirname(file)) : path.dirname(file);
|
|
68
|
+
const claimsOf = (file, bytes, claims) => {
|
|
69
|
+
const receipt = parse(bytes), base = receiptBase(file, receipt);
|
|
70
|
+
for (const name of Object.keys(receipt.managed || {})) {
|
|
71
|
+
const target = path.resolve(base, name);
|
|
72
|
+
if (target.startsWith(`${base}${path.sep}`)) claims.add(target);
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Capture regular output files before this invocation; never follow symlinks.
|
|
78
|
+
* Bytes are kept for receipts, settings, Flue outputs, receipt-claimed files,
|
|
79
|
+
* files beside a receipt and project-root files. Other files are recorded by
|
|
80
|
+
* stat (or digest, when recently changed), so memory does not scale with the
|
|
81
|
+
* size of a provider home. Pass the earlier snapshot as `previous` to reuse
|
|
82
|
+
* entries for files whose stat did not change.
|
|
83
|
+
*/
|
|
84
|
+
export function captureDeploymentOutputs(roots, { previous } = {}) {
|
|
36
85
|
const files = new Map();
|
|
37
|
-
const
|
|
86
|
+
const stats = new Map();
|
|
87
|
+
signatures.set(files, stats);
|
|
88
|
+
const prior = previous && signatures.get(previous);
|
|
89
|
+
const recentFrom = BigInt(Date.now()) * 1_000_000n - RECENT_NS;
|
|
90
|
+
const claims = new Set();
|
|
91
|
+
// A file this process cannot read is not one it wrote; keep its stat only.
|
|
92
|
+
// Live provider homes also delete files mid-walk; those are simply absent.
|
|
93
|
+
const gone = Symbol('gone');
|
|
94
|
+
const readable = file => {
|
|
95
|
+
try { return fs.readFileSync(file); } catch (error) {
|
|
96
|
+
if (error.code === 'EACCES' || error.code === 'EPERM') return null;
|
|
97
|
+
if (error.code === 'ENOENT') return gone;
|
|
98
|
+
throw error;
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
const capture = (file, stat, retain, output) => {
|
|
102
|
+
const sig = signature(stat), recent = stat.ctimeNs >= recentFrom, old = previous?.get(file);
|
|
103
|
+
stats.set(file, sig);
|
|
104
|
+
if (old && !recent && prior?.get(file) === sig && (Buffer.isBuffer(old) || !retain)) { files.set(file, old); return; }
|
|
105
|
+
// The post-deploy pass hashes every file it cannot reuse. The first pass
|
|
106
|
+
// hashes AIWG output kinds (so an identical rewrite is not a change) and
|
|
107
|
+
// recently changed files; provider runtime data keeps only its stat.
|
|
108
|
+
const bytes = retain || previous || recent || output ? readable(file) : null;
|
|
109
|
+
if (bytes === gone) { stats.delete(file); return; }
|
|
110
|
+
files.set(file, retain && bytes ? bytes : new DeploymentOutputState(sig, bytes ? hash(bytes) : undefined));
|
|
111
|
+
};
|
|
112
|
+
// `parent` is 'project' for a project root's direct children and 'managed'
|
|
113
|
+
// for files beside a receipt.
|
|
114
|
+
const visit = (root, file, depth, parent) => {
|
|
38
115
|
let stat;
|
|
39
|
-
try { stat = fs.lstatSync(file); } catch (error) { if (error.code === 'ENOENT') return; throw error; }
|
|
40
|
-
if (stat.isDirectory())
|
|
41
|
-
|
|
116
|
+
try { stat = fs.lstatSync(file, { bigint: true }); } catch (error) { if (error.code === 'ENOENT') return; throw error; }
|
|
117
|
+
if (stat.isDirectory()) {
|
|
118
|
+
let names;
|
|
119
|
+
try { names = fs.readdirSync(file); } catch (error) { if (error.code === 'ENOENT' || error.code === 'ENOTDIR') return; throw error; }
|
|
120
|
+
const managed = names.includes(SIDECAR);
|
|
121
|
+
// Read a directory's receipt before its files so its claims are known.
|
|
122
|
+
if (managed) visit(root, path.join(file, SIDECAR), depth + 1, 'managed');
|
|
123
|
+
const childParent = depth === 0 && names.includes('.aiwg') ? 'project' : managed ? 'managed' : null;
|
|
124
|
+
for (const name of names) if (name !== SIDECAR) visit(root, path.join(file, name), depth + 1, childParent);
|
|
125
|
+
} else if (stat.isFile()) {
|
|
126
|
+
const key = path.resolve(file), base = path.basename(key);
|
|
127
|
+
capture(key, stat, base === SIDECAR || SETTINGS_FILE.test(base) || FLUE_OUTPUT.test(key)
|
|
128
|
+
|| depth === 0 || parent !== null || claims.has(key), artifactKind(path.relative(root, key)) !== 'generated');
|
|
129
|
+
if (base === SIDECAR) claimsOf(key, files.get(key), claims);
|
|
130
|
+
}
|
|
42
131
|
};
|
|
43
|
-
|
|
132
|
+
// Project-scoped receipts claim files outside their own directory.
|
|
133
|
+
for (const root of roots) {
|
|
134
|
+
const receipt = path.basename(String(root)) === SIDECAR ? String(root) : path.join(String(root), '.aiwg', SIDECAR);
|
|
135
|
+
try { claimsOf(path.resolve(receipt), fs.readFileSync(receipt), claims); } catch { /* absent */ }
|
|
136
|
+
}
|
|
137
|
+
for (const root of roots) visit(path.resolve(String(root)), String(root), 0, null);
|
|
44
138
|
// A root-level file's sidecar is itself outside that file's snapshot root.
|
|
45
139
|
for (const file of [...files.keys()]) {
|
|
46
140
|
const receipt = path.join(path.dirname(file), SIDECAR);
|
|
@@ -126,7 +220,7 @@ function artifactKind(file) {
|
|
|
126
220
|
/** Record only writes evidenced by this invocation or newly emitted file receipts. */
|
|
127
221
|
export function recordDeploymentOutputs(before, roots, opts = {}) {
|
|
128
222
|
if (opts.dryRun) return;
|
|
129
|
-
const after = captureDeploymentOutputs(roots);
|
|
223
|
+
const after = captureDeploymentOutputs(roots, { previous: before });
|
|
130
224
|
const owner = deploymentOwner(opts);
|
|
131
225
|
const manifests = new Map();
|
|
132
226
|
const manifest = dir => {
|
|
@@ -148,7 +242,7 @@ export function recordDeploymentOutputs(before, roots, opts = {}) {
|
|
|
148
242
|
const base = receiptRoot(file, receipt);
|
|
149
243
|
const target = path.resolve(base, name);
|
|
150
244
|
if (!target.startsWith(`${base}${path.sep}`) || receipt.managed?.[name]) continue;
|
|
151
|
-
if (!
|
|
245
|
+
if (!sameOutput(after.get(target), before.get(target))) continue;
|
|
152
246
|
receipt.managed ||= {};
|
|
153
247
|
receipt.managed[name] = entry;
|
|
154
248
|
manifests.set(file, receipt);
|
|
@@ -161,8 +255,8 @@ export function recordDeploymentOutputs(before, roots, opts = {}) {
|
|
|
161
255
|
// A receipt rewrite is not evidence of a payload write. Preservation can
|
|
162
256
|
// also restore bytes after a writer/binder marked the file as written.
|
|
163
257
|
// Never bless those edited bytes, even with an explicit write hint.
|
|
164
|
-
if (before.get(target)
|
|
165
|
-
(prior ? prior.hash !==
|
|
258
|
+
if (sameOutput(before.get(target), after.get(target)) &&
|
|
259
|
+
(prior ? prior.hash !== digestOf(before.get(target)) : entry.hash === digestOf(before.get(target)) && !opts.writtenFiles?.includes(target))) {
|
|
166
260
|
if (prior) receipt.managed[name] = prior;
|
|
167
261
|
else delete receipt.managed[name];
|
|
168
262
|
preserved.add(target);
|
|
@@ -176,12 +270,12 @@ export function recordDeploymentOutputs(before, roots, opts = {}) {
|
|
|
176
270
|
if (path.basename(file) === SIDECAR || /(?:^|[/\\])aiwg\.config$/.test(file)
|
|
177
271
|
|| /(?:\.bak\.|\.aiwg-backup-)/.test(path.basename(file))) continue;
|
|
178
272
|
if (preserved.has(file)) continue;
|
|
179
|
-
const changed = !before.get(file)
|
|
273
|
+
const changed = !sameOutput(before.get(file), bytes);
|
|
180
274
|
const declaration = declared.get(file);
|
|
181
275
|
if (opts.onlyDeclared && !declaration) continue;
|
|
182
276
|
if (!changed && !declaration && !opts.writtenFiles?.includes(file)) continue;
|
|
183
277
|
// Existing integrity receipts that disagree with bytes never bless operator edits.
|
|
184
|
-
if (declaration?.entry.hash && declaration.entry.hash !==
|
|
278
|
+
if (declaration?.entry.hash && declaration.entry.hash !== digestOf(bytes)) continue;
|
|
185
279
|
let skillRoot = path.dirname(file);
|
|
186
280
|
while (skillRoot !== path.dirname(skillRoot)) {
|
|
187
281
|
const parentReceipt = parse(after.get(path.join(skillRoot, SIDECAR)));
|
|
@@ -189,7 +283,7 @@ export function recordDeploymentOutputs(before, roots, opts = {}) {
|
|
|
189
283
|
skillRoot = path.dirname(skillRoot);
|
|
190
284
|
}
|
|
191
285
|
const skillReceipt = parse(after.get(path.join(skillRoot, SIDECAR)));
|
|
192
|
-
const projectScoped = projectRoot && (path.dirname(file) === projectRoot || opts.provider === 'flue' &&
|
|
286
|
+
const projectScoped = projectRoot && (path.dirname(file) === projectRoot || opts.provider === 'flue' && FLUE_OUTPUT.test(file));
|
|
193
287
|
const dir = projectScoped ? path.join(projectRoot, '.aiwg') : declaration ? path.dirname(declaration.file) : skillReceipt.managed?.['SKILL.md'] ? skillRoot : path.dirname(file);
|
|
194
288
|
const name = declaration?.name || portable(path.relative(projectScoped ? projectRoot : dir, file));
|
|
195
289
|
const existing = manifests.get(path.join(dir, SIDECAR)) || parse(after.get(path.join(dir, SIDECAR)));
|
|
@@ -197,10 +291,10 @@ export function recordDeploymentOutputs(before, roots, opts = {}) {
|
|
|
197
291
|
const current = existing.managed?.[name] || {};
|
|
198
292
|
// A redeploy may preserve operator additions around generated context.
|
|
199
293
|
// Keep the old digest so removal cannot restore a stale preimage over them.
|
|
200
|
-
if (previous?.filePreimage && before.has(file) && previous.hash !==
|
|
294
|
+
if (previous?.filePreimage && before.has(file) && previous.hash !== digestOf(before.get(file))) continue;
|
|
201
295
|
const identity = current.sourcePath || `${declaration?.receipt.skillSource}/SKILL.md`;
|
|
202
296
|
const logicalSource = opts.logicalInputPath?.(identity) || identity;
|
|
203
|
-
const sourceOwner = (declaration || current.hash ===
|
|
297
|
+
const sourceOwner = (declaration || current.hash === digestOf(bytes)) && (current.frameworkSlug || bundleOwner(logicalSource))
|
|
204
298
|
|| skillReceipt.managed?.['SKILL.md']?.frameworkSlug;
|
|
205
299
|
const generatedIndex = /^RULES-(?:INDEX|ONDEMAND)\.(?:md|mdc)$/.test(path.basename(file));
|
|
206
300
|
const kind = generatedIndex ? 'rule-index' : current.kind || artifactKind(file);
|
|
@@ -211,12 +305,12 @@ export function recordDeploymentOutputs(before, roots, opts = {}) {
|
|
|
211
305
|
}
|
|
212
306
|
const receipt = manifest(dir);
|
|
213
307
|
if (projectScoped) receipt.scope = 'project';
|
|
214
|
-
const record = mergeArtifactOwnership(previous, { ...current, hash:
|
|
308
|
+
const record = mergeArtifactOwnership(previous, { ...current, hash: digestOf(bytes), owners: opts.provider === 'flue' ? [] : current.hash === digestOf(bytes) ? current.owners : [], kind }, selectedOwner);
|
|
215
309
|
// Flue's composed context and generated database/ignore outputs support
|
|
216
310
|
// exact restoration. Never infer a preimage for another provider's files.
|
|
217
311
|
if (opts.provider === 'flue' && (projectScoped || /[/\\]db\.ts$/.test(file))) {
|
|
218
312
|
record.filePreimage = previous?.filePreimage || { present: before.has(file),
|
|
219
|
-
...(before.has(file) ? { bytes: before.get(file).toString('base64'), hash:
|
|
313
|
+
...(before.has(file) ? { bytes: bytesOf(file, before.get(file)).toString('base64'), hash: digestOf(before.get(file)) } : {}) };
|
|
220
314
|
}
|
|
221
315
|
// Structural rule indexes are generated outputs; their assembly scratch
|
|
222
316
|
// directory is not a durable source identity.
|
|
@@ -225,14 +319,14 @@ export function recordDeploymentOutputs(before, roots, opts = {}) {
|
|
|
225
319
|
record.kind = 'rule-index';
|
|
226
320
|
}
|
|
227
321
|
// Settings have key/value receipts in the same entry, never a separate store.
|
|
228
|
-
if (
|
|
322
|
+
if (SETTINGS_FILE.test(path.basename(file))) {
|
|
229
323
|
record.kind = 'settings';
|
|
230
324
|
record.settingsPreimage = previous?.settingsPreimage || (!previous?.settings ? {
|
|
231
|
-
present: before.has(file), ...(before.has(file) ? { bytes: before.get(file).toString('base64'), hash:
|
|
325
|
+
present: before.has(file), ...(before.has(file) ? { bytes: bytesOf(file, before.get(file)).toString('base64'), hash: digestOf(before.get(file)) } : {})
|
|
232
326
|
} : undefined);
|
|
233
327
|
const claimUnchanged = opts.claimUnchangedSettings !== false
|
|
234
328
|
&& !/(?:agentic\/code|\.aiwg)\/(?:addons|extensions)\//.test((opts.logicalInputPath?.(opts.srcRoot) || opts.srcRoot)?.replaceAll('\\', '/') || '');
|
|
235
|
-
record.settings = settingsRecords(settingsDocument(file, before.get(file)), settingsDocument(file, bytes), previous?.settings, selectedOwner, claimUnchanged);
|
|
329
|
+
record.settings = settingsRecords(settingsDocument(file, bytesOf(file, before.get(file))), settingsDocument(file, bytesOf(file, bytes)), previous?.settings, selectedOwner, claimUnchanged);
|
|
236
330
|
const settingsOwners = Object.values(record.settings).flatMap(entry => entry.owners);
|
|
237
331
|
record.owners = [...new Set(settingsOwners.length ? settingsOwners
|
|
238
332
|
: [...(previous?.owners || []), ...(changed ? [selectedOwner] : [])])].sort();
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { AiwgConfig } from '../config/aiwg-config.js';
|
|
2
|
+
import type { DeploymentOutputSnapshot } from './deployment-ownership.mjs';
|
|
2
3
|
export function providerCopyMode(project: string, provider: string, owner?: string, config?: AiwgConfig, indexOwner?: string): boolean;
|
|
3
4
|
export function automaticRemovalAllowed(project: string, provider: string, file: string, config?: AiwgConfig): boolean;
|
|
4
|
-
export function preserveDeploymentOutputs(before:
|
|
5
|
+
export function preserveDeploymentOutputs(before: DeploymentOutputSnapshot, roots: string[], opts?: Record<string, unknown>): void;
|
|
5
6
|
export function deploymentEditWarnings(project: string, provider: string): string[];
|
|
@@ -54,6 +54,9 @@ export function preserveDeploymentOutputs(before, roots, opts = {}) {
|
|
|
54
54
|
const restored = [];
|
|
55
55
|
for (const [file, bytes] of before) {
|
|
56
56
|
if (path.basename(file) === sidecar) continue;
|
|
57
|
+
// Snapshots keep bytes for receipt-claimed and receipt-adjacent files only;
|
|
58
|
+
// provider runtime data recorded by stat or digest is never restored (#3846).
|
|
59
|
+
if (!Buffer.isBuffer(bytes)) continue;
|
|
57
60
|
const exists = fs.existsSync(file);
|
|
58
61
|
if (!exists && opts.replacedSkillCopies?.has(file)) continue;
|
|
59
62
|
const claim = claims.get(file);
|
|
@@ -71,6 +71,10 @@ function assertNoDuplicateAliases(definitions) {
|
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
|
+
/** Deployment paths do not require loading the optional capability corpus. */
|
|
75
|
+
export function listProviderDeploymentLayouts() {
|
|
76
|
+
return BUILT_IN_SEEDS.map(({ paths, smithPaths }) => ({ paths, smithPaths }));
|
|
77
|
+
}
|
|
74
78
|
export function listProviderDefinitions() {
|
|
75
79
|
if (!cachedRegistry) {
|
|
76
80
|
const definitions = BUILT_IN_SEEDS.map(buildDefinition);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { workspaceFileMode, workspaceDirectoryMode, preserveReplacementMode } from '../storage/workspace-permissions.js';
|
|
1
2
|
import { createHash, randomUUID } from 'node:crypto';
|
|
2
3
|
import { access, mkdir, readFile, rename, rm, writeFile } from 'node:fs/promises';
|
|
3
4
|
import { homedir } from 'node:os';
|
|
@@ -37,7 +38,7 @@ function validateEvidenceState(value) {
|
|
|
37
38
|
async function writeEvidenceState(options, disposition) {
|
|
38
39
|
const provider = normalizeProviderDefinitionId(options.provider) ?? options.provider;
|
|
39
40
|
const target = providerTransformationEvidenceStatePath(options.projectRoot, provider, options.scope);
|
|
40
|
-
await mkdir(path.dirname(target), { recursive: true, mode:
|
|
41
|
+
await mkdir(path.dirname(target), { recursive: true, mode: workspaceDirectoryMode(path.dirname(target)) });
|
|
41
42
|
const temporary = path.join(path.dirname(target), `.${path.basename(target)}.${randomUUID()}.tmp`);
|
|
42
43
|
const state = {
|
|
43
44
|
schemaVersion: PROVIDER_TRANSFORMATION_EVIDENCE_STATE_SCHEMA,
|
|
@@ -47,7 +48,8 @@ async function writeEvidenceState(options, disposition) {
|
|
|
47
48
|
disposition,
|
|
48
49
|
};
|
|
49
50
|
try {
|
|
50
|
-
await writeFile(temporary, `${JSON.stringify(state, null, 2)}\n`, { encoding: 'utf8', mode:
|
|
51
|
+
await writeFile(temporary, `${JSON.stringify(state, null, 2)}\n`, { encoding: 'utf8', mode: workspaceFileMode(target), flag: 'wx' });
|
|
52
|
+
await preserveReplacementMode(temporary, target);
|
|
51
53
|
await rename(temporary, target);
|
|
52
54
|
}
|
|
53
55
|
catch (error) {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { workspaceFileMode, workspaceDirectoryMode, preserveReplacementMode } from '../storage/workspace-permissions.js';
|
|
1
2
|
import { createHash, randomUUID } from 'node:crypto';
|
|
2
3
|
import { lstat, mkdir, readFile, realpath, rename, rm, writeFile } from 'node:fs/promises';
|
|
3
4
|
import path from 'node:path';
|
|
@@ -110,7 +111,7 @@ export async function createProviderTransformationReceipt(options) {
|
|
|
110
111
|
export async function writeProviderTransformationReceipt(projectRoot, receipt) {
|
|
111
112
|
validateProviderTransformationReceipt(receipt);
|
|
112
113
|
const destination = projectAiwgWritePath(projectRoot, 'receipts', 'providers', `${receipt.provider}.${receipt.scope}.json`);
|
|
113
|
-
await mkdir(path.dirname(destination), { recursive: true });
|
|
114
|
+
await mkdir(path.dirname(destination), { recursive: true, mode: workspaceDirectoryMode(path.dirname(destination)) });
|
|
114
115
|
try {
|
|
115
116
|
const existing = validateProviderTransformationReceipt(JSON.parse(await readFile(destination, 'utf8')));
|
|
116
117
|
const semantic = (value) => JSON.stringify({ ...value, generatedAt: undefined });
|
|
@@ -123,8 +124,9 @@ export async function writeProviderTransformationReceipt(projectRoot, receipt) {
|
|
|
123
124
|
const temporary = `${destination}.${randomUUID()}.tmp`;
|
|
124
125
|
try {
|
|
125
126
|
await writeFile(temporary, `${JSON.stringify(receipt, null, 2)}\n`, {
|
|
126
|
-
encoding: 'utf8', mode:
|
|
127
|
+
encoding: 'utf8', mode: workspaceFileMode(destination), flag: 'wx',
|
|
127
128
|
});
|
|
129
|
+
await preserveReplacementMode(temporary, destination);
|
|
128
130
|
await rename(temporary, destination);
|
|
129
131
|
}
|
|
130
132
|
catch (error) {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/** Validate and render a prepared invocation against trusted installation controls. */
|
|
2
2
|
import path from 'node:path';
|
|
3
|
+
import { directWorkerEnvironment } from '../config/worker-attribution.mjs';
|
|
3
4
|
import { createHash } from 'node:crypto';
|
|
4
5
|
import { fileURLToPath } from 'node:url';
|
|
5
6
|
import { validateWorkerArtifacts } from './worker-artifacts.mjs';
|
|
@@ -106,7 +107,8 @@ export async function prepareWorkerInvocation(invocation, qualification) {
|
|
|
106
107
|
// (worker-stdin-frame.mjs), so brief text never enters any argv.
|
|
107
108
|
const deadline = qualification.ceilings?.wallSeconds === undefined ? ''
|
|
108
109
|
: `timeout --signal=KILL ${quote(`${Math.min(result.health?.hardTimeoutSeconds ?? Infinity, result.limits.wallSeconds)}s`)} `;
|
|
109
|
-
const
|
|
110
|
+
const markers = Object.entries(directWorkerEnvironment(result)).map(([name, value]) => `${name}=${quote(value)}`).join(' ');
|
|
111
|
+
const worker = `${deadline}env -i${environment ? ` ${environment}` : ''} ${markers} ${result.argv.map(quote).join(' ')}`;
|
|
110
112
|
const outputs = `> ${quote(result.stdoutPath)} 2> ${quote(result.stderrPath)}`;
|
|
111
113
|
if (result.stdin === 'brief-json') {
|
|
112
114
|
const framer = fileURLToPath(new URL('./worker-stdin-frame.mjs', import.meta.url));
|
|
@@ -12,7 +12,7 @@ import { assertValidWorkerPayload } from '../mission-protocol/codecs.js';
|
|
|
12
12
|
import { qualificationDigest } from '../models/qualification-digest.mjs';
|
|
13
13
|
import { prepareWorkerInvocation } from './worker-invocation-preparation.js';
|
|
14
14
|
export { prepareWorkerInvocation, mcpToolSchemaDigest } from './worker-invocation-preparation.js';
|
|
15
|
-
import { isOperatorQualifiedWorkerAdapter, assertOperatorWorkerNativeArgv, assertWorkerLaunchMode, WorkerRoleEffortError, requiredWorkerControls, isCanonicalWorkerModelKey, WorkerPolicyError, DEFAULT_WORKER_SELECTION } from '../models/provider-policy.js';
|
|
15
|
+
import { isOperatorQualifiedWorkerAdapter, assertOperatorWorkerNativeArgv, assertWorkerLaunchMode, WorkerRoleEffortError, WorkerQualificationPolicyError, requiredWorkerControls, isCanonicalWorkerModelKey, WorkerPolicyError, DEFAULT_WORKER_SELECTION } from '../models/provider-policy.js';
|
|
16
16
|
/** Frozen per-attempt windows; parent/transport ceilings include time already spent. */
|
|
17
17
|
export function resolveWorkerEffectiveHealth(config, input) {
|
|
18
18
|
const roleDefaults = { efficiency: 1, coding: 1, reasoning: 2 };
|
|
@@ -374,8 +374,10 @@ export async function resolveWorkerInvocation(snapshot, request, drivers, now =
|
|
|
374
374
|
return plan;
|
|
375
375
|
}
|
|
376
376
|
}
|
|
377
|
-
/** Public diagnostics contain fixed summaries or explicit typed
|
|
377
|
+
/** Public diagnostics contain fixed summaries or explicit typed policy and path details. */
|
|
378
378
|
export function workerInvocationDiagnostic(error, pointer, fallback = 'OG_CONFIG_REFERENCE') {
|
|
379
|
+
if (error instanceof WorkerQualificationPolicyError)
|
|
380
|
+
return { code: error.code, pointer: error.pointer, message: error.message };
|
|
379
381
|
if (error instanceof WorkerRoleEffortError)
|
|
380
382
|
return { code: error.code, pointer: error.pointer, message: error.message };
|
|
381
383
|
if (error instanceof WorkerPathScopeError || error instanceof WorkerRequestArgumentError) {
|
|
@@ -402,6 +404,8 @@ export function workerInvocationDiagnostic(error, pointer, fallback = 'OG_CONFIG
|
|
|
402
404
|
OG_MODEL_UNAPPROVED: 'The selected model lacks current approved observation evidence.',
|
|
403
405
|
OG_EFFORT_DENIED: 'The selected effort is denied by the resolved worker policy.',
|
|
404
406
|
OG_DATA_POLICY: 'The selected model does not satisfy the resolved data policy.',
|
|
407
|
+
OG_HOST_ATTRIBUTION: 'Host capacity includes unattributed workers. Inspect aiwg doctor --resources --json before retrying.',
|
|
408
|
+
OG_HOST_CAPACITY: 'Worker capacity is exhausted. Inspect aiwg doctor --resources --json before retrying.',
|
|
405
409
|
OG_ADAPTER_UNQUALIFIED: 'The installation or invocation could not be revalidated. Run aiwg doctor --probe-workers --qualify to qualify this workspace.',
|
|
406
410
|
OG_POLICY_RELAXATION: 'The request would relax the resolved worker policy.',
|
|
407
411
|
OG_BUDGET_UNMEASURABLE: 'The requested worker budget cannot be enforced.',
|
package/dist/src/skills/run.js
CHANGED
|
@@ -165,6 +165,11 @@ export async function runSkill(opts) {
|
|
|
165
165
|
const audit = await import('../issues/audit-cli.js');
|
|
166
166
|
return audit.main(opts.args, runCwd, { env });
|
|
167
167
|
}
|
|
168
|
+
if (/agentic\/code\/(addons\/aiwg-utils|plugins\/utils)\/skills\/aiwg-pr\/SKILL\.md$/.test(entry.path.replaceAll('\\', '/'))
|
|
169
|
+
&& entry.script.entrypoint === 'scripts/deliver.mjs') {
|
|
170
|
+
const delivery = await import('../delivery/pr.js');
|
|
171
|
+
return delivery.main(opts.args, runCwd);
|
|
172
|
+
}
|
|
168
173
|
const fullArgs = [...invocation.prefixArgs, entrypointPath, ...opts.args];
|
|
169
174
|
return new Promise((resolve) => {
|
|
170
175
|
const child = spawn(invocation.command, fullArgs, {
|
|
@@ -27,17 +27,43 @@ export function directivePolarity(directive) {
|
|
|
27
27
|
return /^(?:never|do not|don't|avoid)\b/i.test(directive) ? 'negative' : 'positive';
|
|
28
28
|
}
|
|
29
29
|
export function sensitiveEvidence(content) {
|
|
30
|
+
return sensitiveLineEvidence(content).map((finding) => finding.evidence);
|
|
31
|
+
}
|
|
32
|
+
function sensitiveLineEvidence(content) {
|
|
30
33
|
const findings = [];
|
|
31
|
-
for (const line of content.split('\n')) {
|
|
34
|
+
for (const [index, line] of content.split('\n').entries()) {
|
|
32
35
|
if (/-----BEGIN (?:RSA |EC |OPENSSH )?PRIVATE KEY-----/.test(line)) {
|
|
33
|
-
findings.push(`private-key material (${sha256(line).slice(0, 12)})`);
|
|
36
|
+
findings.push({ line: index + 1, evidence: `private-key material (${sha256(line).slice(0, 12)})` });
|
|
34
37
|
}
|
|
35
|
-
|
|
36
|
-
|
|
38
|
+
// Inspect whole values before applying the length threshold: ellipses and
|
|
39
|
+
// redaction characters are documentation, including inside quoted agent bodies.
|
|
40
|
+
const assignments = line.matchAll(/\b(?:api[_-]?key|token|secret|password)\s*[:=]\s*["']?([A-Za-z0-9_\-/.+=…*]+)/gi);
|
|
41
|
+
for (const [, value] of assignments) {
|
|
42
|
+
if (value.length < 12 || /(?:\.{3}|…)$/.test(value)
|
|
43
|
+
|| /^(?:example|placeholder|\*{3})/i.test(value) || /^x+$/i.test(value)
|
|
44
|
+
|| (value.match(/\./g)?.length ?? 0) > value.length / 2)
|
|
45
|
+
continue;
|
|
46
|
+
findings.push({ line: index + 1, evidence: `credential-like assignment (${sha256(line).slice(0, 12)})` });
|
|
47
|
+
break;
|
|
37
48
|
}
|
|
38
49
|
}
|
|
39
50
|
return findings;
|
|
40
51
|
}
|
|
52
|
+
function operatorContext(relativePath, content, preserveLines = false) {
|
|
53
|
+
if (relativePath === 'WORKSPACE.md') {
|
|
54
|
+
const start = content.indexOf(WORKSPACE_OPERATOR_START);
|
|
55
|
+
const end = content.indexOf(WORKSPACE_OPERATOR_END);
|
|
56
|
+
if (start >= 0 && end > start) {
|
|
57
|
+
const offset = start + WORKSPACE_OPERATOR_START.length;
|
|
58
|
+
const body = content.slice(offset, end);
|
|
59
|
+
return preserveLines
|
|
60
|
+
? '\n'.repeat(content.slice(0, offset).split('\n').length - 1) + stripGeneratedBlocks(body, true)
|
|
61
|
+
: body.trim();
|
|
62
|
+
}
|
|
63
|
+
return stripGeneratedBlocks(content, preserveLines);
|
|
64
|
+
}
|
|
65
|
+
return isGeneratedRootContext(relativePath, content) ? '' : stripGeneratedBlocks(content, preserveLines);
|
|
66
|
+
}
|
|
41
67
|
// Directory names the context-graph walk always skips, regardless of where
|
|
42
68
|
// the walk root is: VCS/build output that is never hand-authored project
|
|
43
69
|
// content (#277, pre-existing) plus two reserved, self-identifying names
|
|
@@ -194,19 +220,10 @@ export async function auditWorkspaceContext(projectPath) {
|
|
|
194
220
|
const content = await readOptional(path.join(projectPath, relativePath));
|
|
195
221
|
if (content === null)
|
|
196
222
|
continue;
|
|
197
|
-
const operatorContent = relativePath
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
return start >= 0 && end > start
|
|
202
|
-
? content.slice(start + WORKSPACE_OPERATOR_START.length, end).trim()
|
|
203
|
-
: stripGeneratedBlocks(content);
|
|
204
|
-
})()
|
|
205
|
-
: isGeneratedRootContext(relativePath, content)
|
|
206
|
-
? ''
|
|
207
|
-
: stripGeneratedBlocks(content);
|
|
208
|
-
for (const evidence of sensitiveEvidence(operatorContent))
|
|
209
|
-
sensitiveFindings.push({ path: relativePath, evidence });
|
|
223
|
+
const operatorContent = operatorContext(relativePath, content);
|
|
224
|
+
for (const finding of sensitiveLineEvidence(operatorContext(relativePath, content, true))) {
|
|
225
|
+
sensitiveFindings.push({ path: relativePath, ...finding });
|
|
226
|
+
}
|
|
210
227
|
sources.push({
|
|
211
228
|
path: relativePath,
|
|
212
229
|
provider: providerForPath(relativePath),
|
|
@@ -85,20 +85,26 @@ export function replaceBlock(content, start, end, block) {
|
|
|
85
85
|
const renderedBlock = withLineEnding(block, dominantLineEnding(content));
|
|
86
86
|
return content.slice(0, startIndex) + renderedBlock + content.slice(endIndex + end.length);
|
|
87
87
|
}
|
|
88
|
-
export function stripGeneratedBlocks(content) {
|
|
88
|
+
export function stripGeneratedBlocks(content, preserveLines = false) {
|
|
89
89
|
let stripped = content;
|
|
90
90
|
for (const [start, end] of GENERATED_BLOCKS) {
|
|
91
91
|
while (stripped.includes(start) || stripped.includes(end)) {
|
|
92
|
-
const
|
|
92
|
+
const startIndex = stripped.indexOf(start);
|
|
93
|
+
const endIndex = stripped.indexOf(end);
|
|
94
|
+
const replacement = preserveLines && startIndex >= 0 && endIndex > startIndex
|
|
95
|
+
? '\n'.repeat(stripped.slice(startIndex, endIndex + end.length).split('\n').length - 1)
|
|
96
|
+
: '';
|
|
97
|
+
const replaced = replaceBlock(stripped, start, end, replacement);
|
|
93
98
|
if (replaced === null)
|
|
94
99
|
break;
|
|
95
100
|
stripped = replaced;
|
|
96
101
|
}
|
|
97
102
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
.replace(
|
|
101
|
-
.
|
|
103
|
+
const removeMetadata = (text) => preserveLines ? text.replace(/[^\n]/g, '') : '';
|
|
104
|
+
stripped = stripped
|
|
105
|
+
.replace(/^(?:\uFEFF)?<!-- aiwg-managed -->[ \t]*(?:\r?\n|$)/, removeMetadata)
|
|
106
|
+
.replace(/^<!-- Generated by AIWG[^\r\n]*-->[ \t]*(?:\r?\n|$)/, removeMetadata);
|
|
107
|
+
return preserveLines ? stripped : stripped.trim();
|
|
102
108
|
}
|
|
103
109
|
export function isGeneratedRootContext(relativePath, content) {
|
|
104
110
|
const head = maskCodeRegions(content.replace(/^\uFEFF/, '')).split('\n').slice(0, 12).join('\n');
|
|
@@ -7,6 +7,7 @@ import { auditWorkspaceContext } from './workspace-audit.js';
|
|
|
7
7
|
import { PROVIDER_BOOTSTRAP_START, readOptional, resolveProjectRelative, WORKSPACE_MANAGED_START, WORKSPACE_OPERATOR_START, WORKSPACE_SIGNATURE, } from './workspace-context-shared.js';
|
|
8
8
|
import { BOOTSTRAP_AUTHORITY_SIGNATURE, WORKSPACE_PRECEDENCE_SIGNATURE, WORKSPACE_PRECEDENCE_SUPERSEDED } from './workspace-document.js';
|
|
9
9
|
import { configuredProviders } from './workspace-migration.js';
|
|
10
|
+
import { diagnoseCodexHookTrust } from '../hook-bridge/codex-trust.js';
|
|
10
11
|
import { maskCodeRegions } from './code-regions.js';
|
|
11
12
|
export { maskCodeRegions } from './code-regions.js';
|
|
12
13
|
export function markdownLinks(content) {
|
|
@@ -36,6 +37,44 @@ export async function workspaceLinkedFiles(projectPath) {
|
|
|
36
37
|
}
|
|
37
38
|
export async function diagnoseWorkspaceContext(projectPath) {
|
|
38
39
|
const diagnostics = [];
|
|
40
|
+
const codexTrust = await diagnoseCodexHookTrust(projectPath);
|
|
41
|
+
if (codexTrust)
|
|
42
|
+
diagnostics.push(codexTrust);
|
|
43
|
+
const root = path.resolve(projectPath);
|
|
44
|
+
const scopes = new Map();
|
|
45
|
+
// Ordinary subdirectories share root policy; repository/project markers start a separate scope.
|
|
46
|
+
function directoryScope(directory) {
|
|
47
|
+
if (directory === root || !directory.startsWith(`${root}${path.sep}`))
|
|
48
|
+
return Promise.resolve(null);
|
|
49
|
+
let scope = scopes.get(directory);
|
|
50
|
+
if (!scope) {
|
|
51
|
+
scope = (async () => {
|
|
52
|
+
const markers = await Promise.all(['.git', '.aiwg/aiwg.config'].map(async (marker) => {
|
|
53
|
+
try {
|
|
54
|
+
await fs.stat(path.join(directory, marker));
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
}));
|
|
61
|
+
return markers.some(Boolean)
|
|
62
|
+
? path.relative(root, directory).replace(/\\/g, '/')
|
|
63
|
+
: directoryScope(path.dirname(directory));
|
|
64
|
+
})();
|
|
65
|
+
scopes.set(directory, scope);
|
|
66
|
+
}
|
|
67
|
+
return scope;
|
|
68
|
+
}
|
|
69
|
+
async function reportSourceDiagnostic(diagnostic, sources) {
|
|
70
|
+
const sourceScopes = await Promise.all(sources.map((source) => directoryScope(path.dirname(path.resolve(root, source)))));
|
|
71
|
+
const nestedOnly = sourceScopes.length > 0 && sourceScopes.every((scope) => scope !== null);
|
|
72
|
+
diagnostics.push(nestedOnly ? {
|
|
73
|
+
...diagnostic,
|
|
74
|
+
severity: diagnostic.severity === 'error' ? 'warning' : diagnostic.severity,
|
|
75
|
+
message: `Advisory for nested project(s) ${[...new Set(sourceScopes)].join(', ')}: ${diagnostic.message}`,
|
|
76
|
+
} : diagnostic);
|
|
77
|
+
}
|
|
39
78
|
const { existing, notes } = await readAiwgOperatorNotes(projectPath);
|
|
40
79
|
if (existing !== null && existing !== notes)
|
|
41
80
|
diagnostics.push({
|
|
@@ -87,7 +126,7 @@ export async function diagnoseWorkspaceContext(projectPath) {
|
|
|
87
126
|
}
|
|
88
127
|
}
|
|
89
128
|
for (const conflict of audit.conflicts) {
|
|
90
|
-
|
|
129
|
+
await reportSourceDiagnostic({ severity: 'error', code: 'directive-conflict', message: `Conflicting duplicate directive group '${conflict.key}' appears in ${conflict.sources.map((source) => source.path).join(', ')}.` }, conflict.sources.map((source) => source.path));
|
|
91
130
|
}
|
|
92
131
|
// One diagnostic per source pair, not one per duplicated line: a shared
|
|
93
132
|
// pointer stub otherwise reports every line as a separate policy conflict
|
|
@@ -102,13 +141,13 @@ export async function diagnoseWorkspaceContext(projectPath) {
|
|
|
102
141
|
const paths = pair.split(', ');
|
|
103
142
|
const bodies = paths.map((item) => operatorBodies.get(item) ?? '');
|
|
104
143
|
const wholeFileDuplicate = bodies.every((body) => body.length > 0 && body === bodies[0]);
|
|
105
|
-
|
|
144
|
+
await reportSourceDiagnostic({
|
|
106
145
|
severity: wholeFileDuplicate ? 'info' : 'warning',
|
|
107
146
|
code: 'duplicate-directive',
|
|
108
147
|
message: wholeFileDuplicate
|
|
109
148
|
? `${pair} carry identical operator content (${count} directive(s)); keep one copy or accept the shared stub.`
|
|
110
149
|
: `${count} identical directive(s) duplicated across ${pair}.`,
|
|
111
|
-
});
|
|
150
|
+
}, paths);
|
|
112
151
|
}
|
|
113
152
|
for (const source of audit.sources) {
|
|
114
153
|
if (!source.path.replace(/\\/g, '/').includes('/context/providers/') || !source.operatorContent.trim())
|
|
@@ -121,7 +160,8 @@ export async function diagnoseWorkspaceContext(projectPath) {
|
|
|
121
160
|
});
|
|
122
161
|
}
|
|
123
162
|
for (const finding of audit.sensitiveFindings) {
|
|
124
|
-
|
|
163
|
+
const location = finding.line ? `${finding.path}:${finding.line}` : finding.path;
|
|
164
|
+
await reportSourceDiagnostic({ severity: 'error', code: 'possible-secret', message: `Possible credential value found in ${location}; remove it.`, path: finding.path }, [finding.path]);
|
|
125
165
|
}
|
|
126
166
|
// #2512 — "points at WORKSPACE.md" is not the same as "carries current policy".
|
|
127
167
|
// Without this, a workspace generated before the precedence correction reads
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Render and preserve the canonical WORKSPACE document and resident memory.
|
|
2
2
|
import * as path from 'node:path';
|
|
3
3
|
import { readAiwgConfigCandidate } from '../../config/aiwg-config.js';
|
|
4
|
-
import { projectControlPath } from '../../config/project-artifacts.js';
|
|
4
|
+
import { isProjectArtifactRootExternal, projectControlPath } from '../../config/project-artifacts.js';
|
|
5
5
|
import { listProviderDefinitions } from '../../providers/provider-definitions.js';
|
|
6
6
|
import { resolveRulesInlineBudget } from '../../rules/inline-budget.mjs';
|
|
7
7
|
import { writeContextFileSync } from './context-file-safety.js';
|
|
@@ -131,7 +131,10 @@ export function buildWorkspaceManagedBlock(projectPath, providerFiles = [], resi
|
|
|
131
131
|
'',
|
|
132
132
|
'- Before any agent or provider writes AIWG payload, run `aiwg artifacts path --json --check-write` and write beneath its `artifact_root`.',
|
|
133
133
|
'- Treat `.aiwg/...` in skills and templates as a logical artifact path, not necessarily a repository-local filesystem path.',
|
|
134
|
-
'-
|
|
134
|
+
'- Configure an external artifact root with a path in `.aiwg-location`; `AIWG_ARTIFACTS_PATH` overrides that pointer.',
|
|
135
|
+
isProjectArtifactRootExternal(projectPath)
|
|
136
|
+
? '- Only `aiwg.config`, `frameworks/registry.json`, and optional operator-only `AIWG.md` notes belong in the repository-local `.aiwg` control plane; generated framework context lives in root `AIWG.md`.'
|
|
137
|
+
: '- With no external artifact root configured, repository-local `.aiwg` stores AIWG payload alongside control-plane files; generated framework context lives in root `AIWG.md`.',
|
|
135
138
|
'- If the configured external artifact root is unavailable, stop with an actionable error; never fall back to repository-local payload.',
|
|
136
139
|
'',
|
|
137
140
|
'### Linked Context',
|
|
@@ -156,7 +156,8 @@ export async function migrateWorkspaceContext(projectPath, options = {}) {
|
|
|
156
156
|
const audit = await auditWorkspaceContext(projectPath);
|
|
157
157
|
const sensitiveFindingCount = audit.sensitiveFindings.length;
|
|
158
158
|
if (sensitiveFindingCount > 0) {
|
|
159
|
-
|
|
159
|
+
const locations = audit.sensitiveFindings.map((finding) => finding.line ? `${finding.path}:${finding.line}` : finding.path);
|
|
160
|
+
throw new Error(`Migration refused: ${sensitiveFindingCount} possible secret/credential value(s) found in ${locations.join(', ')}. Remove them before migration.`);
|
|
160
161
|
}
|
|
161
162
|
if (audit.conflicts.length > 0 && !options.allowConflicts) {
|
|
162
163
|
throw new Error(`Migration refused: ${audit.conflicts.length} ambiguous directive conflict(s). Review the deterministic audit or pass --allow-conflicts to preserve each source separately.`);
|