@aiwg/cli 2026.10.16 → 2026.10.18
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/dist/src/artifacts/corpus-tools/resolve.js +21 -4
- package/dist/src/artifacts/query-engine-corpus.js +217 -0
- package/dist/src/artifacts/query-engine-discover-output.js +229 -0
- package/dist/src/artifacts/query-engine-discover.js +285 -0
- package/dist/src/artifacts/query-engine-entries.js +188 -0
- package/dist/src/artifacts/query-engine-index.js +249 -0
- package/dist/src/artifacts/query-engine-matching.js +143 -0
- package/dist/src/artifacts/query-engine-options.js +2 -0
- package/dist/src/artifacts/query-engine-rules.js +202 -0
- package/dist/src/artifacts/query-engine-scoring.js +436 -0
- package/dist/src/artifacts/query-engine-show-card.js +194 -0
- package/dist/src/artifacts/query-engine-show-load.js +211 -0
- package/dist/src/artifacts/query-engine-show.js +300 -0
- package/dist/src/artifacts/query-engine.js +7 -2576
- package/dist/src/cli/handlers/mc-agents.js +111 -0
- package/dist/src/cli/handlers/mc-args.js +54 -0
- package/dist/src/cli/handlers/mc-control.js +227 -0
- package/dist/src/cli/handlers/mc-dispatch.js +203 -0
- package/dist/src/cli/handlers/mc-help.js +171 -0
- package/dist/src/cli/handlers/mc-run.js +343 -0
- package/dist/src/cli/handlers/mc-session.js +138 -0
- package/dist/src/cli/handlers/mc-status.js +258 -0
- package/dist/src/cli/handlers/mc-summary.js +43 -0
- package/dist/src/cli/handlers/mc-types.js +3 -0
- package/dist/src/cli/handlers/mc-worker.js +205 -0
- package/dist/src/cli/handlers/mc.js +12 -1665
- package/dist/src/cli/handlers/models-refusal.js +13 -0
- package/dist/src/cli/handlers/models.js +2 -1
- package/dist/src/cli/handlers/remove-bundled.js +133 -0
- package/dist/src/cli/handlers/remove-options.js +31 -0
- package/dist/src/cli/handlers/remove-user.js +174 -0
- package/dist/src/cli/handlers/remove.js +201 -0
- package/dist/src/cli/handlers/subcommands-bundles.js +257 -0
- package/dist/src/cli/handlers/subcommands-discovery.js +165 -0
- package/dist/src/cli/handlers/subcommands-list-format.js +129 -0
- package/dist/src/cli/handlers/subcommands-list.js +250 -0
- package/dist/src/cli/handlers/subcommands-plugins.js +213 -0
- package/dist/src/cli/handlers/subcommands-quickref.js +58 -0
- package/dist/src/cli/handlers/subcommands-rlm.js +113 -0
- package/dist/src/cli/handlers/subcommands-services.js +66 -0
- package/dist/src/cli/handlers/subcommands-storage.js +259 -0
- package/dist/src/cli/handlers/subcommands.js +18 -1984
- package/dist/src/cli/scope-resolver.js +1 -142
- package/dist/src/cli/user-scope-mirror.js +173 -0
- package/dist/src/config/dispatch-host-thresholds.js +2 -0
- package/dist/src/config/dispatch-thresholds-runtime.mjs +4 -0
- package/dist/src/config/host-resource-report.d.mts +5 -0
- package/dist/src/config/host-resource-report.mjs +36 -6
- package/dist/src/config/host-resource-runtime.d.mts +3 -0
- package/dist/src/config/host-resource-runtime.mjs +9 -6
- package/dist/src/decision/ensemble-study/artifacts.js +7 -0
- package/dist/src/decision/ensemble-study/gate-policy.js +58 -0
- package/dist/src/decision/ensemble-study/gates.js +78 -0
- package/dist/src/decision/ensemble-study/protocol.js +18 -21
- package/dist/src/decision/ensemble-study/score.js +3 -2
- package/dist/src/decision/ensemble-study/statistics.js +7 -26
- package/dist/src/decision/sensitivity/comparative-gates.js +135 -0
- package/dist/src/decision/sensitivity/comparative.js +18 -41
- package/dist/src/extensions/claude-hooks-installer.js +18 -0
- package/dist/src/gates/evaluate.js +2 -358
- package/dist/src/gates/observations.js +363 -0
- package/dist/src/gates/pack-composition.js +270 -0
- package/dist/src/gates/pack-tightening.js +197 -0
- package/dist/src/gates/pack-validation.js +262 -0
- package/dist/src/gates/registry-error.js +5 -0
- package/dist/src/gates/registry.js +13 -685
- package/dist/src/mcp/json-document.mjs +29 -0
- package/dist/src/mcp/muse-native-config.mjs +1 -28
- package/dist/src/mission-protocol/worker-review-gate.js +7 -0
- package/dist/src/models/worker-plan.js +5 -5
- package/dist/src/plugin/command-ownership.js +34 -0
- package/dist/src/plugin/skill-command-frontmatter.js +197 -0
- package/dist/src/plugin/skill-command-translator.js +6 -232
- package/dist/src/providers/context-output-ownership.js +26 -0
- package/dist/src/providers/deployment-ownership.d.mts +19 -0
- package/dist/src/providers/deployment-ownership.mjs +226 -0
- package/dist/src/providers/deployment-removal.js +200 -0
- package/dist/src/providers/removal-transaction.js +86 -0
- package/dist/src/providers/settings-document.d.mts +3 -0
- package/dist/src/providers/settings-document.mjs +47 -0
- package/dist/src/providers/settings-removal.js +190 -0
- package/dist/src/providers/skill-ownership.d.mts +19 -2
- package/dist/src/providers/skill-ownership.mjs +12 -4
- package/dist/src/providers/transformation-receipt-integration.js +15 -271
- package/dist/src/providers/transformation-receipt-outputs.js +99 -0
- package/dist/src/providers/transformation-receipt-source.js +194 -0
- package/dist/src/research/identity.js +8 -2
- package/dist/src/research/reference-match.js +42 -7
- package/dist/src/rules/activation.mjs +15 -6
- package/dist/src/rules/core-startup.mjs +2 -2
- package/dist/src/serve/mission-conductor.js +4 -0
- package/dist/src/serve/mission-summary.js +56 -0
- package/dist/src/smiths/context-pipeline/aiwg-md.js +23 -0
- package/dist/src/smiths/context-pipeline/context-file-safety.js +3 -0
- package/dist/src/smiths/context-pipeline/generator.js +1 -1
- package/dist/src/smiths/hook-bridge/index.js +9 -0
- package/package.json +4 -1
- package/schemas/decision/D17StudyProtocol.v1.schema.json +39 -67
- package/tools/agents/deploy-agents.mjs +16 -677
- package/tools/agents/deploy-command-mirrors.mjs +229 -0
- package/tools/agents/deploy-options.mjs +258 -0
- package/tools/agents/deploy-support.mjs +165 -0
- package/tools/agents/providers/base-addon-discovery.mjs +139 -0
- package/tools/agents/providers/base-behaviors.mjs +168 -0
- package/tools/agents/providers/base-context.mjs +205 -0
- package/tools/agents/providers/base-contract.mjs +116 -0
- package/tools/agents/providers/base-files.mjs +252 -0
- package/tools/agents/providers/base-flat-artifacts.mjs +233 -0
- package/tools/agents/providers/base-framework-discovery.mjs +309 -0
- package/tools/agents/providers/base-frontmatter.mjs +196 -0
- package/tools/agents/providers/base-inventory.mjs +269 -0
- package/tools/agents/providers/base-kernel-skills.mjs +354 -0
- package/tools/agents/providers/base-migrations.mjs +258 -0
- package/tools/agents/providers/base-models-platforms.mjs +273 -0
- package/tools/agents/providers/base-rule-index.mjs +450 -0
- package/tools/agents/providers/base-runtime.mjs +60 -0
- package/tools/agents/providers/base-skill-copy.mjs +273 -0
- package/tools/agents/providers/base.mjs +16 -3364
- package/tools/agents/providers/claude-post-deploy.mjs +10 -2
- package/tools/agents/providers/hermes-startup.mjs +0 -5
- package/tools/agents/providers/muse.mjs +7 -2
- package/tools/agents/providers/rule-delivery-surface.mjs +31 -4
- package/tools/agents/providers/rule-deployment-commit.mjs +19 -15
- package/tools/agents/providers/rule-deployment-prepare.mjs +11 -2
- package/tools/agents/providers/rule-projection.mjs +3 -0
- package/tools/ralph-external/lib/worker-invocation-processes.mjs +4 -2
- package/tools/ralph-external/lib/worker-termination.mjs +15 -8
- package/vscode-extension/schemas/aiwg.config.v1.json +2 -4
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
// Restore verified settings contributions while retaining unresolved ownership for retries.
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import { createHash } from 'node:crypto';
|
|
4
|
+
import { parseSettings, renderSettings, stableSettings } from './settings-document.mjs';
|
|
5
|
+
const digest = (value) => `sha256:${createHash('sha256').update(stableSettings(value) ?? '').digest('hex')}`;
|
|
6
|
+
const object = (value) => !!value && typeof value === 'object' && !Array.isArray(value);
|
|
7
|
+
const own = (value, key) => object(value) && Object.hasOwn(value, key);
|
|
8
|
+
function lookup(root, keys) {
|
|
9
|
+
let value = root;
|
|
10
|
+
for (const key of keys) {
|
|
11
|
+
if (!own(value, key))
|
|
12
|
+
return { present: false, value: undefined };
|
|
13
|
+
value = value[key];
|
|
14
|
+
}
|
|
15
|
+
return { present: true, value };
|
|
16
|
+
}
|
|
17
|
+
function assign(root, keys, present, value, baseline) {
|
|
18
|
+
let parent = root;
|
|
19
|
+
const parents = [];
|
|
20
|
+
for (const key of keys.slice(0, -1)) {
|
|
21
|
+
if (!own(parent, key) || !object(parent[key]))
|
|
22
|
+
throw new Error('Settings parent was edited');
|
|
23
|
+
parents.push([parent, key]);
|
|
24
|
+
parent = parent[key];
|
|
25
|
+
}
|
|
26
|
+
const key = keys.at(-1);
|
|
27
|
+
if (present)
|
|
28
|
+
Object.defineProperty(parent, key, { value, enumerable: true, configurable: true, writable: true });
|
|
29
|
+
else
|
|
30
|
+
delete parent[key];
|
|
31
|
+
for (let index = parents.length - 1; index >= 0; index--) {
|
|
32
|
+
const [container, name] = parents[index];
|
|
33
|
+
if (Object.keys(container[name]).length)
|
|
34
|
+
break;
|
|
35
|
+
const prior = lookup(baseline, keys.slice(0, index + 1));
|
|
36
|
+
if (prior.present) {
|
|
37
|
+
if (!object(prior.value))
|
|
38
|
+
container[name] = prior.value;
|
|
39
|
+
break;
|
|
40
|
+
}
|
|
41
|
+
delete container[name];
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
const contributions = (entry) => entry.contributions || [{ hash: entry.hash, value: entry.value, owners: entry.owners }];
|
|
45
|
+
export function restoreSettings(file, record, owner) {
|
|
46
|
+
const decisions = [];
|
|
47
|
+
const report = (pointer, action, reason) => decisions.push({
|
|
48
|
+
path: file, pointer, action, reason, kind: 'settings', owned: true,
|
|
49
|
+
});
|
|
50
|
+
let before, document;
|
|
51
|
+
try {
|
|
52
|
+
before = fs.readFileSync(file);
|
|
53
|
+
document = parseSettings(file, before);
|
|
54
|
+
if (!object(document))
|
|
55
|
+
throw new Error('Invalid settings document');
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
report('', 'preserve', 'missing, unreadable or invalid settings; unverifiable');
|
|
59
|
+
return { decisions, retained: true };
|
|
60
|
+
}
|
|
61
|
+
// Older receipts verify leaves, but cannot prove ownership of empty parents.
|
|
62
|
+
let baseline = parseSettings(file, before), original;
|
|
63
|
+
const preimage = record.settingsPreimage;
|
|
64
|
+
try {
|
|
65
|
+
if (preimage?.present === false) {
|
|
66
|
+
baseline = {};
|
|
67
|
+
original = null;
|
|
68
|
+
}
|
|
69
|
+
else if (preimage?.present && typeof preimage.bytes === 'string') {
|
|
70
|
+
const bytes = Buffer.from(preimage.bytes, 'base64');
|
|
71
|
+
if (`sha256:${createHash('sha256').update(bytes).digest('hex')}` === preimage.hash) {
|
|
72
|
+
const parsed = parseSettings(file, bytes);
|
|
73
|
+
if (object(parsed)) {
|
|
74
|
+
baseline = parsed;
|
|
75
|
+
original = bytes;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
catch { /* Leaf preimages can still recover values without a byte preimage. */ }
|
|
81
|
+
if (!Object.keys(record.settings || {}).length && record.owners?.includes(owner)) {
|
|
82
|
+
const others = record.owners.filter(candidate => candidate !== owner);
|
|
83
|
+
const currentHash = `sha256:${createHash('sha256').update(before).digest('hex')}`;
|
|
84
|
+
if (currentHash !== record.hash || original === undefined || stableSettings(document) !== stableSettings(baseline)) {
|
|
85
|
+
report('', 'preserve', 'operator-edited or unverifiable settings bytes preserved');
|
|
86
|
+
return { decisions, retained: true };
|
|
87
|
+
}
|
|
88
|
+
record.owners = others;
|
|
89
|
+
report('', 'release', others.length ? 'shared settings formatting retained' : 'restore verified pre-deploy settings bytes');
|
|
90
|
+
return { decisions, retained: false, ...(!others.length && (original === null || !before.equals(original))
|
|
91
|
+
? { write: { path: file, before, after: original } } : {}) };
|
|
92
|
+
}
|
|
93
|
+
let retained = false, changed = false;
|
|
94
|
+
for (const [pointer, entry] of Object.entries(record.settings || {})) {
|
|
95
|
+
if (!entry.owners?.includes(owner))
|
|
96
|
+
continue;
|
|
97
|
+
const keys = pointer.slice(1).split('/').map(key => key.replaceAll('~1', '/').replaceAll('~0', '~'));
|
|
98
|
+
const preserve = (reason) => { retained = true; report(pointer, 'preserve', reason); };
|
|
99
|
+
if (!pointer.startsWith('/') || keys.some(key => ['__proto__', 'constructor', 'prototype'].includes(key))
|
|
100
|
+
|| entry.previous?.unverifiable || typeof entry.previous?.present !== 'boolean'
|
|
101
|
+
|| entry.hash !== digest(entry.value)) {
|
|
102
|
+
preserve('unverifiable settings contribution or pre-deploy value');
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
const current = lookup(document, keys);
|
|
106
|
+
const items = contributions(entry);
|
|
107
|
+
if (items.some(item => !Array.isArray(item.owners) || item.hash !== digest(item.value))) {
|
|
108
|
+
preserve('unverifiable settings contribution digest');
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
const other = items.flatMap(item => {
|
|
112
|
+
const owners = item.owners.filter(candidate => candidate !== owner);
|
|
113
|
+
return owners.length ? [{ ...item, owners }] : [];
|
|
114
|
+
});
|
|
115
|
+
if (Array.isArray(entry.value)) {
|
|
116
|
+
if (!current.present || !Array.isArray(current.value)) {
|
|
117
|
+
preserve('operator-edited settings value preserved');
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
const value = [...current.value], expected = [...entry.value];
|
|
121
|
+
const unresolved = [];
|
|
122
|
+
for (const item of items.filter(item => item.owners.includes(owner) && item.owners.length === 1)) {
|
|
123
|
+
const index = value.findIndex(candidate => digest(candidate) === item.hash);
|
|
124
|
+
if (index < 0) {
|
|
125
|
+
unresolved.push(item);
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
value.splice(index, 1);
|
|
129
|
+
const expectedIndex = expected.findIndex(candidate => digest(candidate) === item.hash);
|
|
130
|
+
if (expectedIndex >= 0)
|
|
131
|
+
expected.splice(expectedIndex, 1);
|
|
132
|
+
}
|
|
133
|
+
const next = [...other, ...unresolved];
|
|
134
|
+
const restorePrevious = !next.length && digest(current.value) === entry.hash;
|
|
135
|
+
const restoredValue = restorePrevious && entry.previous.present ? entry.previous.value : value;
|
|
136
|
+
const present = restorePrevious ? entry.previous.present : value.length > 0 || entry.previous.present;
|
|
137
|
+
// Preserve an operator's replacement or deletion of a contributed hook.
|
|
138
|
+
if (unresolved.length)
|
|
139
|
+
preserve('operator-edited hook or array entry preserved; contribution retained for retry');
|
|
140
|
+
else
|
|
141
|
+
report(pointer, 'release', digest(current.value) !== entry.hash ? 'remove recorded entries; operator-edited array entries preserved'
|
|
142
|
+
: other.length ? 'shared settings entries retained; release this owner only' : 'restore pre-deploy hook or array entries');
|
|
143
|
+
if (stableSettings(restoredValue) !== stableSettings(current.value) || !present) {
|
|
144
|
+
assign(document, keys, present, restoredValue, baseline);
|
|
145
|
+
changed = true;
|
|
146
|
+
}
|
|
147
|
+
if (next.length) {
|
|
148
|
+
entry.contributions = next;
|
|
149
|
+
entry.owners = [...new Set(next.flatMap(item => item.owners))].sort();
|
|
150
|
+
entry.value = expected;
|
|
151
|
+
entry.hash = digest(expected);
|
|
152
|
+
}
|
|
153
|
+
else
|
|
154
|
+
delete record.settings[pointer];
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
if (!current.present || digest(current.value) !== entry.hash) {
|
|
158
|
+
preserve('operator-edited settings value preserved');
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
161
|
+
const last = other.at(-1);
|
|
162
|
+
const present = !!last || entry.previous.present;
|
|
163
|
+
const value = last ? last.value : entry.previous.value;
|
|
164
|
+
assign(document, keys, present, value, baseline);
|
|
165
|
+
changed ||= !present || stableSettings(value) !== stableSettings(current.value);
|
|
166
|
+
report(pointer, 'release', last ? 'restore remaining framework settings value' : 'restore pre-deploy settings value');
|
|
167
|
+
if (last) {
|
|
168
|
+
entry.contributions = other;
|
|
169
|
+
entry.owners = [...new Set(other.flatMap(item => item.owners))].sort();
|
|
170
|
+
entry.value = value;
|
|
171
|
+
entry.hash = digest(value);
|
|
172
|
+
}
|
|
173
|
+
else
|
|
174
|
+
delete record.settings[pointer];
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
if (!decisions.length)
|
|
178
|
+
report('', 'release', 'no settings contributions remain for this framework');
|
|
179
|
+
record.owners = [...new Set(Object.values(record.settings || {}).flatMap(entry => entry.owners))].sort();
|
|
180
|
+
if (record.frameworkSlug === owner)
|
|
181
|
+
delete record.frameworkSlug;
|
|
182
|
+
let after = before;
|
|
183
|
+
if (changed) {
|
|
184
|
+
after = original !== undefined && `sha256:${createHash('sha256').update(before).digest('hex')}` === record.hash && stableSettings(document) === stableSettings(baseline) ? original
|
|
185
|
+
: renderSettings(file, before, document);
|
|
186
|
+
record.hash = after ? `sha256:${createHash('sha256').update(after).digest('hex')}` : record.hash;
|
|
187
|
+
}
|
|
188
|
+
return { decisions, retained, ...(after === null || !before.equals(after) ? { write: { path: file, before, after } } : {}) };
|
|
189
|
+
}
|
|
190
|
+
//# sourceMappingURL=settings-removal.js.map
|
|
@@ -1,6 +1,22 @@
|
|
|
1
|
+
export interface ArtifactOwnershipRecord {
|
|
2
|
+
hash: string;
|
|
3
|
+
owners?: string[];
|
|
4
|
+
frameworkSlug?: string;
|
|
5
|
+
source?: string;
|
|
6
|
+
sourcePath?: string;
|
|
7
|
+
version?: string;
|
|
8
|
+
kind?: string;
|
|
9
|
+
settings?: Record<string, SettingsOwnershipRecord>;
|
|
10
|
+
settingsPreimage?: { present: boolean; bytes?: string; hash?: string };
|
|
11
|
+
}
|
|
12
|
+
export interface SettingsContribution { hash: string; value: unknown; owners: string[] }
|
|
13
|
+
export interface SettingsOwnershipRecord extends SettingsContribution {
|
|
14
|
+
previous: { present?: boolean; value?: unknown; unverifiable?: boolean };
|
|
15
|
+
contributions?: SettingsContribution[];
|
|
16
|
+
}
|
|
1
17
|
export interface SkillReceipt {
|
|
2
18
|
skillSource?: string;
|
|
3
|
-
managed?: Record<string,
|
|
19
|
+
managed?: Record<string, ArtifactOwnershipRecord>;
|
|
4
20
|
}
|
|
5
21
|
export interface SkillRemovalPlanEntry {
|
|
6
22
|
path: string;
|
|
@@ -13,6 +29,7 @@ export interface SkillRemovalOptions {
|
|
|
13
29
|
}
|
|
14
30
|
export function extractFrameworkSlug(source: string): string | null;
|
|
15
31
|
export function sameSkillOwner(receipt: SkillReceipt | null, skillSource: string, frameworkSlug?: string | null): boolean;
|
|
16
|
-
export function canDeploySkill(receipt: SkillReceipt | null, skillSource: string, opts?: { force?: boolean }): boolean;
|
|
32
|
+
export function canDeploySkill(receipt: SkillReceipt | null, skillSource: string, opts?: { force?: boolean; logicalInputPath?: (file: string) => string }): boolean;
|
|
17
33
|
export function pruneRecordedSkillFiles(skillDir: string, managed: SkillReceipt['managed'], desired: Set<string>, opts?: SkillRemovalOptions): void;
|
|
18
34
|
export function releaseSkillOwnership(skillDir: string, owner: { frameworkSlug?: string; skillSource?: string; sourceRoot?: string }, opts?: SkillRemovalOptions): boolean | null;
|
|
35
|
+
export function mergeArtifactOwnership<T extends ArtifactOwnershipRecord>(previous: ArtifactOwnershipRecord | undefined, current: T, owner: string): T & { owners: string[] };
|
|
@@ -27,11 +27,13 @@ export function sameSkillOwner(receipt, skillSource, frameworkSlug = extractFram
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
/** Frameworks outrank addons; peers retain ownership unless explicitly forced. */
|
|
30
|
-
export function canDeploySkill(receipt, skillSource, { force = false } = {}) {
|
|
30
|
+
export function canDeploySkill(receipt, skillSource, { force = false, logicalInputPath } = {}) {
|
|
31
31
|
const owner = receipt?.managed?.['SKILL.md']?.frameworkSlug || receipt?.skillSource;
|
|
32
|
-
|
|
33
|
-
const
|
|
34
|
-
|
|
32
|
+
const logicalSource = logicalInputPath?.(skillSource) || skillSource;
|
|
33
|
+
const incomingSlug = extractFrameworkSlug(`${logicalSource}/SKILL.md`);
|
|
34
|
+
if (!owner || sameSkillOwner(receipt, skillSource, incomingSlug)) return true;
|
|
35
|
+
const incoming = incomingSlug || skillSource;
|
|
36
|
+
const isFramework = /(?:^|\/)agentic\/code\/frameworks\//.test(logicalSource.replace(/\\/g, '/'));
|
|
35
37
|
const wasAddon = /(?:^|\/)agentic\/code\/addons\//.test((receipt.skillSource || '').replace(/\\/g, '/'));
|
|
36
38
|
const replace = force || (isFramework && wasAddon);
|
|
37
39
|
console.warn(`Skill deploy collision: '${path.basename(skillSource)}' is owned by ${owner}; ${incoming} ${replace ? 'taking ownership' : 'skipped'}`);
|
|
@@ -104,3 +106,9 @@ export function releaseSkillOwnership(skillDir, owner, opts = {}) {
|
|
|
104
106
|
if (opts.dryRun) return false;
|
|
105
107
|
try { fs.rmdirSync(skillDir); return true; } catch { return false; }
|
|
106
108
|
}
|
|
109
|
+
|
|
110
|
+
/** Deploy adds owners; only explicit removal may release a recorded owner. */
|
|
111
|
+
export function mergeArtifactOwnership(previous, current, owner) {
|
|
112
|
+
const owners = previous?.owners || [];
|
|
113
|
+
return { ...(previous?.hash === current.hash ? previous : {}), ...current, owners: [...new Set([...owners, ...(current.owners || []), owner])].sort() };
|
|
114
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createHash, randomUUID } from 'node:crypto';
|
|
2
|
-
import { access,
|
|
2
|
+
import { access, mkdir, readFile, rename, rm, writeFile } from 'node:fs/promises';
|
|
3
3
|
import { homedir } from 'node:os';
|
|
4
4
|
import path from 'node:path';
|
|
5
5
|
import { readAiwgConfig } from '../config/aiwg-config.js';
|
|
@@ -9,22 +9,9 @@ import { getProviderDefinition, getProviderKernelSkillPath, normalizeProviderDef
|
|
|
9
9
|
import { createProviderTransformationReceipt, diagnoseProviderTransformationReceipt, providerTransformationReceiptPath, writeProviderTransformationReceipt, } from './transformation-receipt.js';
|
|
10
10
|
const TRANSFORMER_ID = 'aiwg-provider-transformer';
|
|
11
11
|
const TRANSFORMER_VERSION = '1';
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const FRAMEWORK_BUNDLE_DIRS = {
|
|
16
|
-
all: 'sdlc-complete',
|
|
17
|
-
sdlc: 'sdlc-complete',
|
|
18
|
-
marketing: 'media-marketing-kit',
|
|
19
|
-
'media-curator': 'media-curator',
|
|
20
|
-
research: 'research-complete',
|
|
21
|
-
forensics: 'forensics-complete',
|
|
22
|
-
dfir: 'forensics-complete',
|
|
23
|
-
'security-engineering': 'security-engineering',
|
|
24
|
-
ops: 'ops-complete',
|
|
25
|
-
validation: 'validation-complete',
|
|
26
|
-
'knowledge-base': 'knowledge-base',
|
|
27
|
-
};
|
|
12
|
+
import { collectOwnedDirectory } from './transformation-receipt-outputs.js';
|
|
13
|
+
import { receiptBundles, sourceEvidence } from './transformation-receipt-source.js';
|
|
14
|
+
export { providerReceiptHasLocalSources, sourceVerificationsFromSignedWebRelease } from './transformation-receipt-source.js';
|
|
28
15
|
const PROVIDER_TRANSFORMATION_EVIDENCE_STATE_SCHEMA = 'aiwg.provider-transformation-evidence-state.v1';
|
|
29
16
|
export function providerTransformationEvidenceStatePath(projectRoot, provider, scope) {
|
|
30
17
|
const receiptPath = providerTransformationReceiptPath(projectRoot, provider, scope);
|
|
@@ -102,93 +89,6 @@ function portablePath(root, absolute) {
|
|
|
102
89
|
return null;
|
|
103
90
|
return relative.split(path.sep).join('/');
|
|
104
91
|
}
|
|
105
|
-
async function regularFiles(root) {
|
|
106
|
-
const files = [];
|
|
107
|
-
let entries;
|
|
108
|
-
try {
|
|
109
|
-
entries = await readdir(root, { withFileTypes: true });
|
|
110
|
-
}
|
|
111
|
-
catch {
|
|
112
|
-
return files;
|
|
113
|
-
}
|
|
114
|
-
for (const entry of entries) {
|
|
115
|
-
const candidate = path.join(root, entry.name);
|
|
116
|
-
if (entry.isDirectory())
|
|
117
|
-
files.push(...await regularFiles(candidate));
|
|
118
|
-
else if (entry.isFile())
|
|
119
|
-
files.push(candidate);
|
|
120
|
-
}
|
|
121
|
-
return files;
|
|
122
|
-
}
|
|
123
|
-
async function addEntry(files, candidate) {
|
|
124
|
-
try {
|
|
125
|
-
const metadata = await lstat(candidate);
|
|
126
|
-
if (metadata.isFile())
|
|
127
|
-
files.add(candidate);
|
|
128
|
-
else if (metadata.isDirectory()) {
|
|
129
|
-
for (const file of await regularFiles(candidate))
|
|
130
|
-
files.add(file);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
catch {
|
|
134
|
-
// A registry or sidecar entry can describe a stale partial deployment.
|
|
135
|
-
// Receipt finalization binds only successful on-disk outputs; an existing
|
|
136
|
-
// receipt remains responsible for diagnosing later deletion.
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
async function collectOwnedDirectory(directory, exactEntries, files) {
|
|
140
|
-
for (const entry of exactEntries)
|
|
141
|
-
await addEntry(files, path.join(directory, entry));
|
|
142
|
-
const sidecarPath = path.join(directory, MANAGED_SIDECAR);
|
|
143
|
-
try {
|
|
144
|
-
const sidecar = JSON.parse(await readFile(sidecarPath, 'utf8'));
|
|
145
|
-
const managed = sidecar.managed && typeof sidecar.managed === 'object'
|
|
146
|
-
? Object.keys(sidecar.managed)
|
|
147
|
-
: [];
|
|
148
|
-
if (managed.length > 0)
|
|
149
|
-
files.add(sidecarPath);
|
|
150
|
-
for (const name of managed) {
|
|
151
|
-
if (name === path.basename(name) && name !== MANAGED_SIDECAR) {
|
|
152
|
-
await addEntry(files, path.join(directory, name));
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
catch {
|
|
157
|
-
// Missing or invalid sidecars are not ownership evidence.
|
|
158
|
-
}
|
|
159
|
-
let entries;
|
|
160
|
-
try {
|
|
161
|
-
entries = await readdir(directory, { withFileTypes: true });
|
|
162
|
-
}
|
|
163
|
-
catch {
|
|
164
|
-
return;
|
|
165
|
-
}
|
|
166
|
-
for (const entry of entries) {
|
|
167
|
-
const candidate = path.join(directory, entry.name);
|
|
168
|
-
if (entry.isDirectory()) {
|
|
169
|
-
try {
|
|
170
|
-
const marker = await lstat(path.join(candidate, MANAGED_DIRECTORY_MARKER));
|
|
171
|
-
if (!marker.isFile())
|
|
172
|
-
continue;
|
|
173
|
-
await addEntry(files, candidate);
|
|
174
|
-
}
|
|
175
|
-
catch {
|
|
176
|
-
// Unmarked directories remain operator-owned.
|
|
177
|
-
}
|
|
178
|
-
continue;
|
|
179
|
-
}
|
|
180
|
-
if (!entry.isFile() || entry.name === MANAGED_SIDECAR)
|
|
181
|
-
continue;
|
|
182
|
-
try {
|
|
183
|
-
const content = await readFile(candidate, 'utf8');
|
|
184
|
-
if (MANAGED_FILE_MARKER.test(content))
|
|
185
|
-
files.add(candidate);
|
|
186
|
-
}
|
|
187
|
-
catch {
|
|
188
|
-
// Unreadable files cannot establish an ownership signal.
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
92
|
function artifactPaths(provider, scope) {
|
|
193
93
|
const definition = getProviderDefinition(provider);
|
|
194
94
|
if (!definition)
|
|
@@ -203,7 +103,7 @@ function artifactPaths(provider, scope) {
|
|
|
203
103
|
behaviors: definition.paths.artifacts.behaviors ?? '',
|
|
204
104
|
};
|
|
205
105
|
}
|
|
206
|
-
async function installedEntries(options) {
|
|
106
|
+
export async function installedEntries(options) {
|
|
207
107
|
if (options.scope === 'user' && options.provider !== 'openhuman') {
|
|
208
108
|
return (await readUserRegistry()).installed;
|
|
209
109
|
}
|
|
@@ -220,172 +120,6 @@ function exactUserEntries(installed, bundles, provider, type) {
|
|
|
220
120
|
}
|
|
221
121
|
return [...entries].sort();
|
|
222
122
|
}
|
|
223
|
-
async function sourceBundleFiles(root) {
|
|
224
|
-
const files = [];
|
|
225
|
-
const walk = async (directory) => {
|
|
226
|
-
const entries = await readdir(directory, { withFileTypes: true });
|
|
227
|
-
for (const entry of entries) {
|
|
228
|
-
const candidate = path.join(directory, entry.name);
|
|
229
|
-
if (entry.isSymbolicLink())
|
|
230
|
-
throw new Error(`canonical source bundle contains a symbolic link: ${candidate}`);
|
|
231
|
-
if (entry.isDirectory())
|
|
232
|
-
await walk(candidate);
|
|
233
|
-
else if (entry.isFile())
|
|
234
|
-
files.push(candidate);
|
|
235
|
-
else
|
|
236
|
-
throw new Error(`canonical source bundle contains a non-regular entry: ${candidate}`);
|
|
237
|
-
}
|
|
238
|
-
};
|
|
239
|
-
await walk(root);
|
|
240
|
-
const inventory = await Promise.all(files.map(async (absolutePath) => {
|
|
241
|
-
const content = await readFile(absolutePath);
|
|
242
|
-
return {
|
|
243
|
-
path: path.relative(root, absolutePath).split(path.sep).join('/'),
|
|
244
|
-
sha256: sha256(content),
|
|
245
|
-
bytes: content.byteLength,
|
|
246
|
-
absolutePath,
|
|
247
|
-
};
|
|
248
|
-
}));
|
|
249
|
-
return inventory.sort((left, right) => left.path.localeCompare(right.path));
|
|
250
|
-
}
|
|
251
|
-
async function resolveSourceBundle(options, bundle, entry) {
|
|
252
|
-
const candidates = [];
|
|
253
|
-
if (entry?.source === 'project-local' && entry.localPath) {
|
|
254
|
-
candidates.push(path.resolve(options.projectRoot, entry.localPath, 'manifest.json'));
|
|
255
|
-
}
|
|
256
|
-
const frameworkDir = FRAMEWORK_BUNDLE_DIRS[bundle] ?? bundle;
|
|
257
|
-
candidates.push(path.join(options.frameworkRoot, 'agentic', 'code', 'frameworks', frameworkDir, 'manifest.json'), path.join(options.frameworkRoot, 'agentic', 'code', 'addons', bundle, 'manifest.json'), path.join(options.frameworkRoot, 'agentic', 'code', 'extensions', bundle, 'manifest.json'));
|
|
258
|
-
for (const candidate of candidates) {
|
|
259
|
-
try {
|
|
260
|
-
await access(candidate);
|
|
261
|
-
const root = path.dirname(candidate);
|
|
262
|
-
const files = await sourceBundleFiles(root);
|
|
263
|
-
if (files.length === 0)
|
|
264
|
-
continue;
|
|
265
|
-
return {
|
|
266
|
-
digest: sha256(stable(files.map(({ path: file, sha256: digest, bytes }) => ({ path: file, sha256: digest, bytes })))),
|
|
267
|
-
root,
|
|
268
|
-
files,
|
|
269
|
-
canonicalBytesAvailable: true,
|
|
270
|
-
};
|
|
271
|
-
}
|
|
272
|
-
catch {
|
|
273
|
-
// Continue through the canonical source locations.
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
const recorded = entry?.manifestHash?.replace(/^sha256:/, '');
|
|
277
|
-
return recorded && /^[a-f0-9]{64}$/.test(recorded)
|
|
278
|
-
? { digest: recorded, root: '', files: [], canonicalBytesAvailable: false }
|
|
279
|
-
: null;
|
|
280
|
-
}
|
|
281
|
-
function receiptBundles(installed, options) {
|
|
282
|
-
const deployed = Object.keys(installed)
|
|
283
|
-
.filter(bundle => Boolean(installed[bundle]?.deployedTo[options.provider]))
|
|
284
|
-
.sort();
|
|
285
|
-
return deployed.length > 0 ? deployed : [...new Set(options.requestedBundles)].sort();
|
|
286
|
-
}
|
|
287
|
-
/**
|
|
288
|
-
* Return whether the deployed provider surface includes project-local source
|
|
289
|
-
* material that cannot be authenticated by an AIWG signed web release.
|
|
290
|
-
*/
|
|
291
|
-
export async function providerReceiptHasLocalSources(rawOptions) {
|
|
292
|
-
const provider = normalizeProviderDefinitionId(rawOptions.provider) ?? rawOptions.provider;
|
|
293
|
-
const options = { ...rawOptions, provider };
|
|
294
|
-
const installed = await installedEntries(options);
|
|
295
|
-
return receiptBundles(installed, options)
|
|
296
|
-
.some(bundle => installed[bundle]?.source === 'project-local');
|
|
297
|
-
}
|
|
298
|
-
/**
|
|
299
|
-
* Convert an already signature-verified web release into the stable verifier
|
|
300
|
-
* result contract for the complete canonical bundle consumed by deployment.
|
|
301
|
-
* Every local file must match its signed descriptor; a registry's self-recorded
|
|
302
|
-
* manifestHash is never an authentication boundary.
|
|
303
|
-
*/
|
|
304
|
-
export async function sourceVerificationsFromSignedWebRelease(options, release) {
|
|
305
|
-
const installed = await installedEntries(options);
|
|
306
|
-
const results = {};
|
|
307
|
-
for (const bundle of receiptBundles(installed, options)) {
|
|
308
|
-
const entry = installed[bundle];
|
|
309
|
-
if (entry?.source === 'project-local')
|
|
310
|
-
continue;
|
|
311
|
-
const source = await resolveSourceBundle(options, bundle, entry);
|
|
312
|
-
if (!source?.canonicalBytesAvailable)
|
|
313
|
-
continue;
|
|
314
|
-
let matched = true;
|
|
315
|
-
for (const file of source.files) {
|
|
316
|
-
const relative = path.relative(options.frameworkRoot, file.absolutePath).split(path.sep).join('/');
|
|
317
|
-
if (!relative || relative === '..' || relative.startsWith('../')) {
|
|
318
|
-
matched = false;
|
|
319
|
-
break;
|
|
320
|
-
}
|
|
321
|
-
const descriptor = release.descriptors.get(`raw/${relative}`);
|
|
322
|
-
if (!descriptor || descriptor.sha256 !== file.sha256 || descriptor.size !== file.bytes) {
|
|
323
|
-
matched = false;
|
|
324
|
-
break;
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
if (!matched)
|
|
328
|
-
continue;
|
|
329
|
-
const artifactName = `aiwg:bundle-inventory:${bundle}`;
|
|
330
|
-
results[bundle] = {
|
|
331
|
-
schemaVersion: 'aiwg.verify.result.v1',
|
|
332
|
-
status: 'verified',
|
|
333
|
-
exitCode: 0,
|
|
334
|
-
artifact: { name: artifactName, sha256: source.digest },
|
|
335
|
-
policy: 'aiwg-signed-web-release',
|
|
336
|
-
identities: ['aiwg-release-publisher'],
|
|
337
|
-
...(release.channelSequence === undefined ? {} : {
|
|
338
|
-
freshness: {
|
|
339
|
-
namespace: 'aiwg',
|
|
340
|
-
channel: release.selector,
|
|
341
|
-
sequence: release.channelSequence,
|
|
342
|
-
version: release.version,
|
|
343
|
-
},
|
|
344
|
-
}),
|
|
345
|
-
diagnostics: [{
|
|
346
|
-
code: 'SIGNED_RELEASE_DESCRIPTOR',
|
|
347
|
-
message: `Exact canonical source bytes match signed release manifest ${release.manifestDigest}`,
|
|
348
|
-
}],
|
|
349
|
-
};
|
|
350
|
-
}
|
|
351
|
-
return results;
|
|
352
|
-
}
|
|
353
|
-
async function sourceEvidence(options, installed) {
|
|
354
|
-
const bundles = [...new Set(options.requestedBundles)].sort();
|
|
355
|
-
const materials = [];
|
|
356
|
-
let authenticated = Boolean(options.sourceVerifications);
|
|
357
|
-
for (const bundle of bundles) {
|
|
358
|
-
const entry = installed[bundle];
|
|
359
|
-
const source = await resolveSourceBundle(options, bundle, entry);
|
|
360
|
-
if (!source) {
|
|
361
|
-
return {
|
|
362
|
-
subject: `aiwg:deployment:${sha256(bundles.join('\0')).slice(0, 24)}`,
|
|
363
|
-
sha256: sha256(stable(materials)),
|
|
364
|
-
verification: 'failed',
|
|
365
|
-
};
|
|
366
|
-
}
|
|
367
|
-
const verification = options.sourceVerifications?.[bundle];
|
|
368
|
-
if (!source.canonicalBytesAvailable
|
|
369
|
-
|| verification?.status !== 'verified'
|
|
370
|
-
|| verification.artifact.sha256 !== source.digest) {
|
|
371
|
-
authenticated = false;
|
|
372
|
-
}
|
|
373
|
-
materials.push({
|
|
374
|
-
bundle,
|
|
375
|
-
digest: source.digest,
|
|
376
|
-
source: entry?.source ?? 'unknown',
|
|
377
|
-
version: entry?.version ?? 'unknown',
|
|
378
|
-
});
|
|
379
|
-
}
|
|
380
|
-
const digest = sha256(stable(materials));
|
|
381
|
-
return {
|
|
382
|
-
subject: `aiwg:deployment:${digest.slice(0, 24)}`,
|
|
383
|
-
sha256: digest,
|
|
384
|
-
verification: options.sourceVerifications
|
|
385
|
-
? authenticated ? 'verified' : 'failed'
|
|
386
|
-
: 'policy-exempt',
|
|
387
|
-
};
|
|
388
|
-
}
|
|
389
123
|
function transformerEvidence(provider, scope) {
|
|
390
124
|
const definition = getProviderDefinition(provider);
|
|
391
125
|
const adapterContract = definition
|
|
@@ -415,12 +149,16 @@ export async function resolveProviderReceiptRuntimeEvidence(rawOptions) {
|
|
|
415
149
|
const paths = artifactPaths(provider, options.scope);
|
|
416
150
|
const outputRoot = path.resolve(options.outputRoot ?? (options.scope === 'user' ? homedir() : options.projectRoot));
|
|
417
151
|
const ownedFiles = new Set();
|
|
152
|
+
const receiptDirectories = new Set([outputRoot, path.join(outputRoot, '.aiwg'), path.join(outputRoot, `.${provider}`)]);
|
|
418
153
|
if (paths) {
|
|
419
154
|
for (const type of ['agents', 'commands', 'skills', 'rules', 'behaviors']) {
|
|
420
155
|
const configured = paths[type];
|
|
421
156
|
if (!configured)
|
|
422
157
|
continue;
|
|
423
158
|
const directory = resolveProviderPathValue(configured, outputRoot);
|
|
159
|
+
receiptDirectories.add(path.dirname(directory));
|
|
160
|
+
if (path.basename(path.dirname(directory)) === '.aiwg')
|
|
161
|
+
receiptDirectories.add(path.dirname(path.dirname(directory)));
|
|
424
162
|
const entries = options.scope === 'user'
|
|
425
163
|
? exactUserEntries(installed, evidenceOptions.requestedBundles, provider, type)
|
|
426
164
|
: [];
|
|
@@ -432,6 +170,12 @@ export async function resolveProviderReceiptRuntimeEvidence(rawOptions) {
|
|
|
432
170
|
await collectOwnedDirectory(kernel, [], ownedFiles);
|
|
433
171
|
}
|
|
434
172
|
}
|
|
173
|
+
// Settings, hooks and generated context now have explicit sidecars too.
|
|
174
|
+
for (const directory of receiptDirectories) {
|
|
175
|
+
await collectOwnedDirectory(directory, [], ownedFiles, outputRoot);
|
|
176
|
+
for (const child of ['hooks', 'plugins'])
|
|
177
|
+
await collectOwnedDirectory(path.join(directory, child), [], ownedFiles);
|
|
178
|
+
}
|
|
435
179
|
const outputPaths = [...ownedFiles]
|
|
436
180
|
.map(file => portablePath(outputRoot, file))
|
|
437
181
|
.filter((file) => Boolean(file))
|