@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,211 @@
|
|
|
1
|
+
// Load local or verified web metadata for show lookups.
|
|
2
|
+
import * as fs from 'node:fs';
|
|
3
|
+
import * as path from 'node:path';
|
|
4
|
+
import { projectAiwgPath } from '../config/project-artifacts.js';
|
|
5
|
+
import { refreshFrameworkCapabilities, resolveFrameworkCorpusRoot } from './framework-capabilities.js';
|
|
6
|
+
import { resolveFrameworkIndexRoot } from './framework-index-paths.js';
|
|
7
|
+
import { loadGraphIndexFile, loadMetadataIndex } from './index-reader.js';
|
|
8
|
+
import { DEFAULT_ARTIFACT_SEARCH_BACKEND, defaultCapabilityGraphs, discoveryIdForEntry, isOrdinaryMemoryEntry, normalizeIndexedPath, projectCapabilityFallback, withIndexProvenance, } from './query-engine-entries.js';
|
|
9
|
+
import { findShowMatches } from './query-engine-matching.js';
|
|
10
|
+
import { ensureRelations } from './relations.js';
|
|
11
|
+
import { getGraphIndexDir, OPERATIONAL_SHOW_TYPES } from './types.js';
|
|
12
|
+
export function resolveMetadataPath(cwd, aiwgRoot, entry) {
|
|
13
|
+
if (path.isAbsolute(entry.path))
|
|
14
|
+
return entry.path;
|
|
15
|
+
const normalizedPath = normalizeIndexedPath(entry.path);
|
|
16
|
+
if (aiwgRoot && normalizedPath.startsWith('agentic/code/')) {
|
|
17
|
+
return path.join(aiwgRoot, normalizedPath);
|
|
18
|
+
}
|
|
19
|
+
if (entry.indexScope === 'user' && normalizedPath.startsWith('~/.aiwg/')) {
|
|
20
|
+
return path.join(process.env.HOME ?? '', normalizedPath.slice(2));
|
|
21
|
+
}
|
|
22
|
+
if (normalizedPath.startsWith('.aiwg/')) {
|
|
23
|
+
return projectAiwgPath(cwd, normalizedPath.slice('.aiwg/'.length));
|
|
24
|
+
}
|
|
25
|
+
return path.join(cwd, normalizedPath);
|
|
26
|
+
}
|
|
27
|
+
export async function loadShowEntries(cwd, params, compact = false) {
|
|
28
|
+
const aiwgRoot = resolveFrameworkIndexRoot(cwd);
|
|
29
|
+
const backend = params.backend ?? DEFAULT_ARTIFACT_SEARCH_BACKEND;
|
|
30
|
+
let resourceSource = params.resourceSource ?? 'local';
|
|
31
|
+
let entries = [];
|
|
32
|
+
let relations;
|
|
33
|
+
if (compact && resourceSource !== 'web' && (!params.graph || params.graph === 'framework')) {
|
|
34
|
+
relations = await ensureRelations(cwd) ?? undefined;
|
|
35
|
+
if (relations?.index.artifacts) {
|
|
36
|
+
const reader = relations;
|
|
37
|
+
const matched = findShowMatches(Object.values(reader.index.artifacts), params.typeFilter ?? [...OPERATIONAL_SHOW_TYPES], params.name.trim());
|
|
38
|
+
const frameworkEntries = matched.map(entry => {
|
|
39
|
+
const id = discoveryIdForEntry(entry);
|
|
40
|
+
const rule = reader.index.rules[id];
|
|
41
|
+
return withIndexProvenance({ ...entry, phase: '', tags: [], created: '', updated: '', checksum: '', summary: '', dependencies: [], dependents: [],
|
|
42
|
+
...(rule ? { activation: reader.pinnedRuleIds.has(id) ? 'kernel' : rule.activation ?? undefined,
|
|
43
|
+
ruleSummary: rule.summary, ruleEnforcement: rule.enforcement ?? undefined, bound_to: rule.bound_to } : {}),
|
|
44
|
+
}, 'framework');
|
|
45
|
+
});
|
|
46
|
+
const localEntries = params.graph ? [] : defaultCapabilityGraphs(cwd).filter(graph => graph !== 'framework')
|
|
47
|
+
.flatMap(graph => loadLocalCapabilityEntries(cwd, graph, undefined, true));
|
|
48
|
+
const compactEntries = [...localEntries, ...frameworkEntries];
|
|
49
|
+
if ((params.typeFilter?.every(type => ['skill', 'agent', 'flow', 'command', 'rule', 'behavior'].includes(type)))
|
|
50
|
+
|| findShowMatches(compactEntries, params.typeFilter ?? [...OPERATIONAL_SHOW_TYPES], params.name.trim()).length) {
|
|
51
|
+
return { entries: compactEntries, aiwgRoot, resourceSource: 'local', relations };
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if (resourceSource !== 'web' && (!params.graph || params.graph === 'framework')) {
|
|
56
|
+
const root = resolveFrameworkCorpusRoot(cwd) ?? aiwgRoot;
|
|
57
|
+
if (root) {
|
|
58
|
+
try {
|
|
59
|
+
await refreshFrameworkCapabilities(root, backend === 'fortemi-core' && params.backend !== undefined);
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
console.error(`Warning: capability index refresh failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (resourceSource === 'auto' && backend === 'fortemi-core') {
|
|
67
|
+
const { loadFortemiCoreMetadataEntries } = await import('./fortemi-core-query-adapter.js');
|
|
68
|
+
const localGraphs = params.graph ? [params.graph] : defaultCapabilityGraphs(cwd);
|
|
69
|
+
resourceSource = localGraphs.some((graph) => loadFortemiCoreMetadataEntries(cwd, graph).entries.length > 0) ? 'local' : 'web';
|
|
70
|
+
}
|
|
71
|
+
else if (resourceSource === 'auto') {
|
|
72
|
+
resourceSource = 'local';
|
|
73
|
+
}
|
|
74
|
+
if (resourceSource === 'web') {
|
|
75
|
+
if (backend !== 'fortemi-core') {
|
|
76
|
+
console.error('Error: --resource-source web requires the Fortemi Core query backend; --backend local remains available with local resources.');
|
|
77
|
+
process.exit(1);
|
|
78
|
+
}
|
|
79
|
+
if (params.graph && params.graph !== 'framework') {
|
|
80
|
+
console.error("Error: web-backed show currently supports only the 'framework' graph.");
|
|
81
|
+
process.exit(1);
|
|
82
|
+
}
|
|
83
|
+
try {
|
|
84
|
+
const { resolveWebRelease } = await import('../resources/web-release.js');
|
|
85
|
+
const webRelease = await resolveWebRelease({
|
|
86
|
+
...params.webReleaseOptions,
|
|
87
|
+
selector: params.aiwgVersion ?? 'stable',
|
|
88
|
+
offline: params.offline,
|
|
89
|
+
});
|
|
90
|
+
const sourcePaths = {
|
|
91
|
+
manifestPath: webRelease.fortemiManifestPath,
|
|
92
|
+
exportPath: webRelease.fortemiExportPath,
|
|
93
|
+
manifestSha256: webRelease.fortemiManifestSha256,
|
|
94
|
+
manifestSize: webRelease.fortemiManifestSize,
|
|
95
|
+
exportSha256: webRelease.fortemiExportSha256,
|
|
96
|
+
exportSize: webRelease.fortemiExportSize,
|
|
97
|
+
};
|
|
98
|
+
const { loadFortemiCoreMetadataEntries } = await import('./fortemi-core-query-adapter.js');
|
|
99
|
+
const loaded = loadFortemiCoreMetadataEntries(cwd, 'framework', sourcePaths);
|
|
100
|
+
if (loaded.reason)
|
|
101
|
+
throw new Error(loaded.reason);
|
|
102
|
+
entries = loaded.entries.map((entry) => withIndexProvenance(entry, 'framework'));
|
|
103
|
+
return { entries, aiwgRoot, resourceSource: 'web', webRelease, sourcePaths };
|
|
104
|
+
}
|
|
105
|
+
catch (error) {
|
|
106
|
+
console.error(`Error: AIWG web resource resolution failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
107
|
+
process.exit(1);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
// Preserve the direct API's historical local-index behavior when callers
|
|
111
|
+
// omit `backend`. The CLI always passes its explicit Fortemi default, while
|
|
112
|
+
// an explicit `auto` source also opts into Fortemi-backed availability.
|
|
113
|
+
if (params.backend === 'fortemi-core' || params.resourceSource === 'auto') {
|
|
114
|
+
const { loadFortemiCoreMetadataEntries } = await import('./fortemi-core-query-adapter.js');
|
|
115
|
+
const graphs = params.graph ? [params.graph] : defaultCapabilityGraphs(cwd);
|
|
116
|
+
let unavailableReason;
|
|
117
|
+
for (const graph of graphs) {
|
|
118
|
+
const loaded = loadFortemiCoreMetadataEntries(cwd, graph);
|
|
119
|
+
if (loaded.reason && graph === 'project' && !params.graph) {
|
|
120
|
+
const fallback = projectCapabilityFallback(cwd);
|
|
121
|
+
if (fallback) {
|
|
122
|
+
entries.push(...fallback);
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
if (loaded.reason) {
|
|
127
|
+
unavailableReason ??= loaded.reason;
|
|
128
|
+
if (graph === 'framework' && !params.graph) {
|
|
129
|
+
console.error(`Warning: framework capabilities are unavailable: ${loaded.reason}`);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
entries.push(...loaded.entries.map((entry) => withIndexProvenance(entry, graph)));
|
|
133
|
+
}
|
|
134
|
+
if (entries.length === 0 && unavailableReason) {
|
|
135
|
+
if (params.json) {
|
|
136
|
+
console.log(JSON.stringify({
|
|
137
|
+
backend: 'fortemi-core',
|
|
138
|
+
name: params.name,
|
|
139
|
+
error: unavailableReason,
|
|
140
|
+
}, null, 2));
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
console.error('Error: ' + unavailableReason);
|
|
144
|
+
}
|
|
145
|
+
process.exit(1);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
entries = loadLocalCapabilityEntries(cwd, params.graph, undefined, true);
|
|
150
|
+
}
|
|
151
|
+
return { entries, aiwgRoot, resourceSource: 'local', relations };
|
|
152
|
+
}
|
|
153
|
+
/** Local index inputs shared by show and exact rule-binding validation (#2938). */
|
|
154
|
+
export function loadLocalCapabilityEntries(cwd, graph, snapshot, includeHistory = false) {
|
|
155
|
+
const entries = [];
|
|
156
|
+
for (const selectedGraph of graph ? [graph] : defaultCapabilityGraphs(cwd)) {
|
|
157
|
+
const key = snapshot && `${selectedGraph}:${getGraphIndexDir(cwd, selectedGraph)}`;
|
|
158
|
+
let selected = key ? snapshot.get(key) : undefined;
|
|
159
|
+
if (!selected) {
|
|
160
|
+
const index = loadGraphIndexFile(cwd, 'metadata.json', selectedGraph);
|
|
161
|
+
selected = index ? Object.values(index.entries).map(entry => withIndexProvenance(entry, selectedGraph)) : [];
|
|
162
|
+
if (key)
|
|
163
|
+
snapshot.set(key, selected);
|
|
164
|
+
}
|
|
165
|
+
entries.push(...selected);
|
|
166
|
+
}
|
|
167
|
+
if (!graph && entries.length === 0) {
|
|
168
|
+
const legacy = loadMetadataIndex(cwd);
|
|
169
|
+
if (legacy)
|
|
170
|
+
entries.push(...Object.values(legacy.entries));
|
|
171
|
+
}
|
|
172
|
+
return includeHistory ? entries : entries.filter(entry => isOrdinaryMemoryEntry(entry, cwd));
|
|
173
|
+
}
|
|
174
|
+
/** Project/user inputs only; package artifacts come from a validated compact table. */
|
|
175
|
+
export function loadLocalOverrideCapabilityEntries(cwd) {
|
|
176
|
+
const local = defaultCapabilityGraphs(cwd).filter(graph => graph !== 'framework')
|
|
177
|
+
.flatMap(graph => loadLocalCapabilityEntries(cwd, graph));
|
|
178
|
+
if (local.length)
|
|
179
|
+
return local;
|
|
180
|
+
const canonical = (directory) => {
|
|
181
|
+
try {
|
|
182
|
+
return fs.realpathSync(directory);
|
|
183
|
+
}
|
|
184
|
+
catch {
|
|
185
|
+
return path.resolve(directory);
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
const packageRoot = canonical(resolveFrameworkIndexRoot(cwd));
|
|
189
|
+
// Retain the legacy PROJECT index, never use the package's full index as a fallback.
|
|
190
|
+
if (canonical(cwd) === packageRoot)
|
|
191
|
+
return [];
|
|
192
|
+
const legacy = loadMetadataIndex(cwd);
|
|
193
|
+
return Object.values(legacy?.entries ?? {}).filter(entry => {
|
|
194
|
+
const provenance = entry;
|
|
195
|
+
if (provenance.indexGraph === 'framework' || provenance.indexScope === 'packaged'
|
|
196
|
+
|| normalizeIndexedPath(entry.path).startsWith('agentic/code/'))
|
|
197
|
+
return false;
|
|
198
|
+
const relative = path.relative(packageRoot, path.resolve(cwd, entry.path));
|
|
199
|
+
return relative === '..' || relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative);
|
|
200
|
+
}).map(entry => withIndexProvenance(entry, 'project'));
|
|
201
|
+
}
|
|
202
|
+
export async function fortemiRecordForEntry(cwd, entry, sourcePaths) {
|
|
203
|
+
const graph = (entry.indexGraph ?? 'project');
|
|
204
|
+
const { loadFortemiCoreExport } = await import('./fortemi-core-query-adapter.js');
|
|
205
|
+
const loaded = loadFortemiCoreExport(cwd, graph, sourcePaths);
|
|
206
|
+
if (!loaded.exported)
|
|
207
|
+
return null;
|
|
208
|
+
const id = discoveryIdForEntry(entry);
|
|
209
|
+
return loaded.exported.items.find((record) => record.id === id || record.source.path === entry.path) ?? null;
|
|
210
|
+
}
|
|
211
|
+
//# sourceMappingURL=query-engine-show-load.js.map
|
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
// Serve artifact bodies and metadata through the show surface.
|
|
2
|
+
import * as path from 'node:path';
|
|
3
|
+
import { loadProviderModelMetadata } from '../models/provider-models.js';
|
|
4
|
+
import { isCorpusBundleInstalled } from './framework-capabilities.js';
|
|
5
|
+
import { findCorpusArtifact } from './query-engine-corpus.js';
|
|
6
|
+
import { buildRunHint, DEFAULT_ARTIFACT_SEARCH_BACKEND, discoveryIdForEntry, normalizeIndexedPath, } from './query-engine-entries.js';
|
|
7
|
+
import { findShowMatches } from './query-engine-matching.js';
|
|
8
|
+
import { showBindings } from './query-engine-rules.js';
|
|
9
|
+
import { emitShowCard } from './query-engine-show-card.js';
|
|
10
|
+
import { fortemiRecordForEntry, loadShowEntries, resolveMetadataPath } from './query-engine-show-load.js';
|
|
11
|
+
import { loadGlobalGraphConfigs, OPERATIONAL_SHOW_TYPES } from './types.js';
|
|
12
|
+
/**
|
|
13
|
+
* Emit a metadata card, with opt-in body/section drill-ins for a
|
|
14
|
+
* SKILL.md. Consumers don't need to know where AIWG stores skills —
|
|
15
|
+
* they pass the skill name and the CLI reads the file from the indexed
|
|
16
|
+
* location.
|
|
17
|
+
*
|
|
18
|
+
* Lookup order:
|
|
19
|
+
* 1. Stable discover/Fortemi id
|
|
20
|
+
* 2. Exact path match against any indexed entry's stored path
|
|
21
|
+
* 3. Basename match (e.g. `intake-wizard` matches an entry whose
|
|
22
|
+
* directory basename is `intake-wizard`)
|
|
23
|
+
* 4. Title match (case-insensitive)
|
|
24
|
+
* 5. Corpus fallback under AIWG_ROOT (#1221)
|
|
25
|
+
*
|
|
26
|
+
* On ambiguity, lists all matches and exits with code 2 unless
|
|
27
|
+
* `--first` is supplied.
|
|
28
|
+
*/
|
|
29
|
+
export async function showArtifact(cwd, params) {
|
|
30
|
+
loadGlobalGraphConfigs();
|
|
31
|
+
const { promises: fs } = await import('node:fs');
|
|
32
|
+
const types = params.typeFilter && params.typeFilter.length > 0
|
|
33
|
+
? params.typeFilter
|
|
34
|
+
: [...OPERATIONAL_SHOW_TYPES];
|
|
35
|
+
const { entries, aiwgRoot, resourceSource, webRelease, relations, } = await loadShowEntries(cwd, params, true);
|
|
36
|
+
if (entries.length === 0 && !relations && params.backend !== 'fortemi-core') {
|
|
37
|
+
console.error('Error: No artifact index found.');
|
|
38
|
+
console.error('Run `aiwg index build --graph framework` (or `aiwg use <framework>`) first.');
|
|
39
|
+
process.exit(1);
|
|
40
|
+
}
|
|
41
|
+
const needle = params.name.trim();
|
|
42
|
+
let matches = findShowMatches(entries, types, needle);
|
|
43
|
+
if (matches.length === 0) {
|
|
44
|
+
// Corpus fallback (#1221): when the artifact isn't in any indexed graph,
|
|
45
|
+
// scan the AIWG_ROOT corpus for a likely match and render it with an
|
|
46
|
+
// installation-aware banner. This keeps `aiwg show` useful in workspaces
|
|
47
|
+
// where the operator hasn't run `aiwg use` yet, or where the framework
|
|
48
|
+
// index is stale, rather than exiting with a misleading "not found".
|
|
49
|
+
if (resourceSource === 'local' && aiwgRoot && params.backend !== 'fortemi-core') {
|
|
50
|
+
const corpusMatch = await findCorpusArtifact(aiwgRoot, needle, types);
|
|
51
|
+
if (corpusMatch) {
|
|
52
|
+
let content;
|
|
53
|
+
try {
|
|
54
|
+
content = await fs.readFile(corpusMatch.path, 'utf8');
|
|
55
|
+
}
|
|
56
|
+
catch (err) {
|
|
57
|
+
const e = err;
|
|
58
|
+
console.error(`Error reading ${corpusMatch.path}: ${e.message ?? String(err)}`);
|
|
59
|
+
process.exit(1);
|
|
60
|
+
}
|
|
61
|
+
const localPin = corpusMatch.type === 'rule' ? (await import('../rules/pin-state.js')).rulePinState(cwd, aiwgRoot).rules.find(rule => rule.path === corpusMatch.path) : undefined;
|
|
62
|
+
const installed = await isCorpusBundleInstalled(cwd, aiwgRoot, corpusMatch.bundleKind, corpusMatch.bundleId);
|
|
63
|
+
const installHint = installed
|
|
64
|
+
? 'The installed bundle is missing from this index. Run `aiwg index build --graph framework` to refresh it.'
|
|
65
|
+
: corpusMatch.bundleKind && corpusMatch.bundleId
|
|
66
|
+
? `Run \`aiwg use ${corpusMatch.bundleId}\` to install this ${corpusMatch.bundleKind} into the workspace.`
|
|
67
|
+
: 'Run `aiwg index build --graph framework` to refresh the artifact index.';
|
|
68
|
+
const fallbackEntry = { path: path.relative(aiwgRoot, corpusMatch.path), type: corpusMatch.type, name: needle, title: needle };
|
|
69
|
+
const bindings = await showBindings(entries, fallbackEntry, content, params, rule => fs.readFile(resolveMetadataPath(cwd, aiwgRoot, rule), 'utf8'), relations);
|
|
70
|
+
await emitShowCard(cwd, aiwgRoot, fallbackEntry, corpusMatch.path, content, params, bindings, { uninstalled: !installed, installed, hint: installHint,
|
|
71
|
+
...(localPin ? { local_pin: localPin } : {}) }, true);
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
console.error(`Error: no artifact found matching "${needle}".`);
|
|
76
|
+
console.error('Try `aiwg discover "<phrase>"` to find the right name.');
|
|
77
|
+
process.exit(1);
|
|
78
|
+
}
|
|
79
|
+
// Resolve relative framework-graph paths to absolute paths.
|
|
80
|
+
// Kernel entries are anchored the same way as non-kernel framework entries
|
|
81
|
+
// (#1230) — show reads the source corpus, not platform deploy mirrors.
|
|
82
|
+
const resolvePath = (entry) => resourceSource === 'web'
|
|
83
|
+
? `raw/${normalizeIndexedPath(entry.path)}`
|
|
84
|
+
: resolveMetadataPath(cwd, aiwgRoot, entry);
|
|
85
|
+
if (matches.length > 1 && !params.first) {
|
|
86
|
+
if (params.json) {
|
|
87
|
+
console.log(JSON.stringify({
|
|
88
|
+
ambiguous: true,
|
|
89
|
+
name: needle,
|
|
90
|
+
matches: matches.map(e => ({
|
|
91
|
+
id: discoveryIdForEntry(e),
|
|
92
|
+
path: resolvePath(e),
|
|
93
|
+
type: e.type,
|
|
94
|
+
name: e.name,
|
|
95
|
+
title: e.title,
|
|
96
|
+
kernel: e.kernel ?? false,
|
|
97
|
+
provenance: {
|
|
98
|
+
graph: e.indexGraph ?? null,
|
|
99
|
+
scope: e.indexScope ?? null,
|
|
100
|
+
...(webRelease
|
|
101
|
+
? {
|
|
102
|
+
resource_source: 'web',
|
|
103
|
+
aiwg_selector: webRelease.selector,
|
|
104
|
+
aiwg_version: webRelease.version,
|
|
105
|
+
manifest_sha256: webRelease.manifestDigest,
|
|
106
|
+
manifest_url: webRelease.manifestUrl,
|
|
107
|
+
}
|
|
108
|
+
: {}),
|
|
109
|
+
},
|
|
110
|
+
})),
|
|
111
|
+
}, null, 2));
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
console.error(`Ambiguous: "${needle}" matches ${matches.length} artifacts. Disambiguate with --type or pass the stable id:`);
|
|
115
|
+
for (const e of matches) {
|
|
116
|
+
console.error(` ${e.type.padEnd(7)} ${discoveryIdForEntry(e)} ${e.title}`);
|
|
117
|
+
}
|
|
118
|
+
console.error('');
|
|
119
|
+
console.error('Re-run with `--first` to pick the top match, `--type skill` to filter, or `aiwg show metadata <id>` for paths.');
|
|
120
|
+
}
|
|
121
|
+
process.exit(2);
|
|
122
|
+
}
|
|
123
|
+
const entry = matches[0];
|
|
124
|
+
const filePath = resolvePath(entry);
|
|
125
|
+
let content;
|
|
126
|
+
if (resourceSource === 'web') {
|
|
127
|
+
try {
|
|
128
|
+
if (!webRelease)
|
|
129
|
+
throw new Error('verified web release context is unavailable');
|
|
130
|
+
const { logicalIdFromFirstPartyPath, resolveAiwgResourceBytes } = await import('../resources/resolver.js');
|
|
131
|
+
const logicalId = logicalIdFromFirstPartyPath(entry.path);
|
|
132
|
+
if (!logicalId)
|
|
133
|
+
throw new Error(`indexed path is not a first-party AIWG resource: ${entry.path}`);
|
|
134
|
+
const resolved = await resolveAiwgResourceBytes(logicalId, {
|
|
135
|
+
source: 'web',
|
|
136
|
+
frameworkRoot: aiwgRoot ?? cwd,
|
|
137
|
+
webRelease,
|
|
138
|
+
webReleaseOptions: params.webReleaseOptions,
|
|
139
|
+
offline: params.offline,
|
|
140
|
+
});
|
|
141
|
+
content = resolved.bytes.toString('utf8');
|
|
142
|
+
}
|
|
143
|
+
catch (error) {
|
|
144
|
+
console.error(`Error: AIWG web resource show failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
145
|
+
process.exit(1);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
try {
|
|
150
|
+
content = await fs.readFile(filePath, 'utf8');
|
|
151
|
+
}
|
|
152
|
+
catch (err) {
|
|
153
|
+
const e = err;
|
|
154
|
+
console.error(`Error reading ${filePath}: ${e.message ?? String(err)}`);
|
|
155
|
+
process.exit(1);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
const localPin = entry.type === 'rule' ? (await import('../rules/pin-state.js')).rulePinState(cwd, aiwgRoot ?? cwd).rules.find(rule => rule.path === filePath) : undefined;
|
|
159
|
+
const bindings = await showBindings(entries, entry, content, params, async (rule) => {
|
|
160
|
+
if (resourceSource === 'local')
|
|
161
|
+
return fs.readFile(resolvePath(rule), 'utf8');
|
|
162
|
+
const { logicalIdFromFirstPartyPath, resolveAiwgResourceBytes } = await import('../resources/resolver.js');
|
|
163
|
+
const logicalId = logicalIdFromFirstPartyPath(rule.path);
|
|
164
|
+
if (!logicalId || !webRelease)
|
|
165
|
+
throw new Error(`Cannot resolve bound rule: ${rule.path}`);
|
|
166
|
+
const resolved = await resolveAiwgResourceBytes(logicalId, {
|
|
167
|
+
source: 'web', frameworkRoot: aiwgRoot ?? cwd, webRelease,
|
|
168
|
+
webReleaseOptions: params.webReleaseOptions, offline: params.offline,
|
|
169
|
+
});
|
|
170
|
+
return resolved.bytes.toString('utf8');
|
|
171
|
+
}, relations);
|
|
172
|
+
const providerModels = resourceSource === 'local' ? await loadProviderModelMetadata(cwd, aiwgRoot) : null;
|
|
173
|
+
await emitShowCard(cwd, aiwgRoot, entry, filePath, content, params, bindings, {
|
|
174
|
+
provenance: {
|
|
175
|
+
graph: entry.indexGraph ?? null,
|
|
176
|
+
scope: entry.indexScope ?? null,
|
|
177
|
+
...(webRelease ? { resource_source: 'web', aiwg_selector: webRelease.selector, aiwg_version: webRelease.version,
|
|
178
|
+
manifest_sha256: webRelease.manifestDigest, manifest_url: webRelease.manifestUrl } : {}),
|
|
179
|
+
},
|
|
180
|
+
...(entry.script ? { executable: true, run_hint: buildRunHint(entry) } : {}),
|
|
181
|
+
...(providerModels ? { providerModels } : {}),
|
|
182
|
+
...(localPin ? { local_pin: localPin } : {}),
|
|
183
|
+
}, resourceSource === 'local', webRelease);
|
|
184
|
+
}
|
|
185
|
+
export async function showMetadata(cwd, params) {
|
|
186
|
+
loadGlobalGraphConfigs();
|
|
187
|
+
const types = params.typeFilter && params.typeFilter.length > 0
|
|
188
|
+
? params.typeFilter
|
|
189
|
+
: [...OPERATIONAL_SHOW_TYPES];
|
|
190
|
+
const { entries, aiwgRoot, resourceSource, webRelease, sourcePaths, } = await loadShowEntries(cwd, params);
|
|
191
|
+
if (entries.length === 0 && params.backend !== 'fortemi-core') {
|
|
192
|
+
console.error('Error: No artifact index found.');
|
|
193
|
+
console.error('Run `aiwg index build --graph framework` (or `aiwg use <framework>`) first.');
|
|
194
|
+
process.exit(1);
|
|
195
|
+
}
|
|
196
|
+
const needle = params.name.trim();
|
|
197
|
+
const matches = findShowMatches(entries, types, needle);
|
|
198
|
+
if (matches.length === 0) {
|
|
199
|
+
console.error(`Error: no artifact metadata found matching "${needle}".`);
|
|
200
|
+
console.error('Try `aiwg discover "<phrase>" --json` to find the stable id.');
|
|
201
|
+
process.exit(1);
|
|
202
|
+
}
|
|
203
|
+
const resolvePath = (entry) => resourceSource === 'web'
|
|
204
|
+
? `raw/${normalizeIndexedPath(entry.path)}`
|
|
205
|
+
: resolveMetadataPath(cwd, aiwgRoot, entry);
|
|
206
|
+
if (matches.length > 1 && !params.first) {
|
|
207
|
+
if (params.json) {
|
|
208
|
+
console.log(JSON.stringify({
|
|
209
|
+
ambiguous: true,
|
|
210
|
+
name: needle,
|
|
211
|
+
matches: matches.map((entry) => ({
|
|
212
|
+
id: discoveryIdForEntry(entry),
|
|
213
|
+
type: entry.type,
|
|
214
|
+
name: entry.name,
|
|
215
|
+
title: entry.title,
|
|
216
|
+
provenance: {
|
|
217
|
+
graph: entry.indexGraph ?? null,
|
|
218
|
+
scope: entry.indexScope ?? null,
|
|
219
|
+
...(webRelease
|
|
220
|
+
? {
|
|
221
|
+
resource_source: 'web',
|
|
222
|
+
aiwg_selector: webRelease.selector,
|
|
223
|
+
aiwg_version: webRelease.version,
|
|
224
|
+
manifest_sha256: webRelease.manifestDigest,
|
|
225
|
+
manifest_url: webRelease.manifestUrl,
|
|
226
|
+
}
|
|
227
|
+
: {}),
|
|
228
|
+
},
|
|
229
|
+
})),
|
|
230
|
+
}, null, 2));
|
|
231
|
+
}
|
|
232
|
+
else {
|
|
233
|
+
console.error(`Ambiguous: "${needle}" matches ${matches.length} artifacts. Disambiguate with the stable id:`);
|
|
234
|
+
for (const entry of matches) {
|
|
235
|
+
console.error(` ${entry.type.padEnd(7)} ${discoveryIdForEntry(entry)} ${entry.title}`);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
process.exit(2);
|
|
239
|
+
}
|
|
240
|
+
const entry = matches[0];
|
|
241
|
+
const absolutePath = resolvePath(entry);
|
|
242
|
+
const backend = params.backend ?? DEFAULT_ARTIFACT_SEARCH_BACKEND;
|
|
243
|
+
const record = backend === 'fortemi-core'
|
|
244
|
+
? await fortemiRecordForEntry(cwd, entry, sourcePaths)
|
|
245
|
+
: null;
|
|
246
|
+
const payload = {
|
|
247
|
+
id: discoveryIdForEntry(entry),
|
|
248
|
+
backend,
|
|
249
|
+
type: entry.type,
|
|
250
|
+
name: entry.name,
|
|
251
|
+
title: entry.title,
|
|
252
|
+
paths: {
|
|
253
|
+
absolute: absolutePath,
|
|
254
|
+
indexed: entry.path,
|
|
255
|
+
repo_relative: record?.source.repo_relative_path ?? entry.path,
|
|
256
|
+
locator: record?.source.locator ?? entry.name ?? entry.title,
|
|
257
|
+
},
|
|
258
|
+
provenance: {
|
|
259
|
+
graph: entry.indexGraph ?? null,
|
|
260
|
+
scope: entry.indexScope ?? null,
|
|
261
|
+
...(webRelease
|
|
262
|
+
? {
|
|
263
|
+
resource_source: 'web',
|
|
264
|
+
aiwg_selector: webRelease.selector,
|
|
265
|
+
aiwg_version: webRelease.version,
|
|
266
|
+
manifest_sha256: webRelease.manifestDigest,
|
|
267
|
+
manifest_url: webRelease.manifestUrl,
|
|
268
|
+
}
|
|
269
|
+
: {}),
|
|
270
|
+
},
|
|
271
|
+
metadata: record ?? entry,
|
|
272
|
+
providerModels: resourceSource === 'local'
|
|
273
|
+
? await loadProviderModelMetadata(cwd, aiwgRoot)
|
|
274
|
+
: null,
|
|
275
|
+
};
|
|
276
|
+
if (params.json) {
|
|
277
|
+
console.log(JSON.stringify(payload, null, 2));
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
console.log(`${payload.type} ${payload.title}`);
|
|
281
|
+
console.log(` id: ${payload.id}`);
|
|
282
|
+
if (payload.name)
|
|
283
|
+
console.log(` name: ${payload.name}`);
|
|
284
|
+
console.log(` graph: ${payload.provenance.graph ?? 'unknown'}`);
|
|
285
|
+
console.log(` scope: ${payload.provenance.scope ?? 'unknown'}`);
|
|
286
|
+
console.log(` path: ${payload.paths.absolute}`);
|
|
287
|
+
console.log(` indexed_path: ${payload.paths.indexed}`);
|
|
288
|
+
if (payload.providerModels) {
|
|
289
|
+
console.log(' provider_models:');
|
|
290
|
+
for (const [provider, hints] of Object.entries(payload.providerModels.providers)) {
|
|
291
|
+
console.log(` ${provider}:`);
|
|
292
|
+
for (const hint of hints) {
|
|
293
|
+
console.log(` ${hint.role}: ${hint.model} (wrapper: ${hint.wrapper}, status: ${hint.status})`);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
console.log('');
|
|
298
|
+
console.log(JSON.stringify(payload.metadata, null, 2));
|
|
299
|
+
}
|
|
300
|
+
//# sourceMappingURL=query-engine-show.js.map
|