@aiwg/cli 2026.10.16 → 2026.10.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/agentic/code/providers/capability-matrix.yaml +51 -0
- package/agentic/code/providers/flue/README.md +62 -0
- package/agentic/code/providers/flue/templates/aiwg/tools.ts +120 -0
- package/agentic/code/providers/model-capabilities.v1.json +23 -0
- package/agentic/code/providers/model-catalog.v1.json +9 -0
- package/dist/src/artifacts/corpus-tools/resolve.js +28 -6
- 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/help.js +1 -1
- package/dist/src/cli/handlers/init.js +1 -0
- 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/handlers/use.js +11 -5
- package/dist/src/cli/scope-resolver.js +1 -142
- package/dist/src/cli/services/deployment-verification.js +3 -0
- 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/memory/provider-memory-adapter.js +1 -0
- package/dist/src/mission-protocol/worker-review-gate.js +7 -0
- package/dist/src/models/model-capabilities.v1.json +23 -0
- package/dist/src/models/model-catalog.v1.json +9 -0
- package/dist/src/models/policy-resources.js +1 -1
- 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/capability-matrix.yaml +51 -0
- package/dist/src/providers/context-output-ownership.js +26 -0
- package/dist/src/providers/deployment-ownership.d.mts +20 -0
- package/dist/src/providers/deployment-ownership.mjs +236 -0
- package/dist/src/providers/deployment-removal.js +222 -0
- package/dist/src/providers/provider-context-contracts.js +8 -0
- package/dist/src/providers/provider-definition-schema.js +1 -0
- package/dist/src/providers/provider-definitions.js +1 -0
- package/dist/src/providers/provider-seeds-3.js +18 -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 +20 -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 +66 -8
- 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/skills/deployment-ownership.js +2 -2
- package/dist/src/skills/deployment-policy.js +9 -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/flue-context.js +25 -0
- package/dist/src/smiths/context-pipeline/generator.js +7 -2
- package/dist/src/smiths/context-pipeline/workspace-bootstrap.js +9 -7
- package/dist/src/smiths/hook-bridge/index.js +9 -0
- package/package.json +5 -1
- package/schemas/decision/D17StudyProtocol.v1.schema.json +39 -67
- package/tools/agents/deploy-agents.mjs +21 -680
- package/tools/agents/deploy-command-mirrors.mjs +229 -0
- package/tools/agents/deploy-options.mjs +267 -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/flue-project.mjs +79 -0
- package/tools/agents/providers/flue-specialists.mjs +64 -0
- package/tools/agents/providers/flue.mjs +50 -0
- 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 +33 -5
- package/tools/agents/providers/rule-deployment-commit.mjs +19 -15
- package/tools/agents/providers/rule-deployment-prepare.mjs +13 -3
- package/tools/agents/providers/rule-projection.mjs +3 -0
- package/tools/agents/providers/rule-startup.mjs +3 -3
- package/tools/agents/use-rule-selection.mjs +17 -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,194 @@
|
|
|
1
|
+
// Render show metadata cards, sections, and companion resources.
|
|
2
|
+
import * as fs from 'node:fs';
|
|
3
|
+
import * as path from 'node:path';
|
|
4
|
+
import { isCorpusBundleInstalled } from './framework-capabilities.js';
|
|
5
|
+
import { extractMarkdownLinks, parseFlowDoc, parseFrontmatter } from './index-builder.js';
|
|
6
|
+
import { buildRunHint, discoveryIdForEntry, normalizeIndexedPath } from './query-engine-entries.js';
|
|
7
|
+
import { RULE_CHECK_OBLIGATION, statsText } from './query-engine-rules.js';
|
|
8
|
+
import { emptyRuleStats } from './relations.js';
|
|
9
|
+
/** Sections include their nested headings, stopping at the next peer/ancestor. */
|
|
10
|
+
export function showSections(content) {
|
|
11
|
+
const body = parseFrontmatter(content).body;
|
|
12
|
+
const headings = [];
|
|
13
|
+
let offset = 0;
|
|
14
|
+
let fence = '';
|
|
15
|
+
const lines = body.match(/[^\n]*\n|[^\n]+$/g) ?? [];
|
|
16
|
+
for (let i = 0; i < lines.length; i++) {
|
|
17
|
+
const line = lines[i];
|
|
18
|
+
const marker = line.match(/^ {0,3}(`{3,}|~{3,})/);
|
|
19
|
+
if (marker) {
|
|
20
|
+
if (!fence)
|
|
21
|
+
fence = marker[1];
|
|
22
|
+
else if (marker[1][0] === fence[0] && marker[1].length >= fence.length)
|
|
23
|
+
fence = '';
|
|
24
|
+
}
|
|
25
|
+
else if (!fence) {
|
|
26
|
+
const atx = line.match(/^ {0,3}(#{1,6})\s+(.+?)(?:\s+#+)?\s*$/);
|
|
27
|
+
const setext = i + 1 < lines.length && lines[i + 1].match(/^ {0,3}(=+|-+)\s*$/);
|
|
28
|
+
if (atx)
|
|
29
|
+
headings.push({ heading: atx[2], level: atx[1].length, start: offset });
|
|
30
|
+
else if (line.trim() && setext)
|
|
31
|
+
headings.push({ heading: line.trim(), level: setext[1][0] === '=' ? 1 : 2, start: offset });
|
|
32
|
+
}
|
|
33
|
+
offset += line.length;
|
|
34
|
+
}
|
|
35
|
+
return headings.map((heading, i) => {
|
|
36
|
+
const end = headings.slice(i + 1).find(next => next.level <= heading.level)?.start ?? body.length;
|
|
37
|
+
const text = body.slice(heading.start, end);
|
|
38
|
+
return { heading: heading.heading, level: heading.level, bytes: Buffer.byteLength(text),
|
|
39
|
+
lines: text.split('\n').length - (text.endsWith('\n') ? 1 : 0), text };
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
/** List companion directories and explicitly linked resources within the owning bundle.
|
|
43
|
+
* Resolve paths against that boundary and exclude symlink components. */
|
|
44
|
+
export function showResources(filePath, source, release) {
|
|
45
|
+
if (release) {
|
|
46
|
+
const base = path.posix.dirname(filePath);
|
|
47
|
+
const linked = new Set(extractMarkdownLinks(source).map(link => path.posix.normalize(path.posix.join(base, link))));
|
|
48
|
+
const boundary = filePath.match(/^(raw\/agentic\/code\/(?:frameworks|addons|extensions)\/[^/]+)\//)?.[1];
|
|
49
|
+
return [...release.descriptors.values()].filter(descriptor => {
|
|
50
|
+
const relative = path.posix.relative(base, descriptor.path);
|
|
51
|
+
const category = /(?:^|\/)(?:templates|scripts|references|resources|assets)\//.test(relative);
|
|
52
|
+
const inside = relative !== '..' && !relative.startsWith('../');
|
|
53
|
+
return (inside && category || linked.has(descriptor.path) && (inside || category))
|
|
54
|
+
&& (!boundary || descriptor.path.startsWith(`${boundary}/`));
|
|
55
|
+
}).map(descriptor => ({ path: path.posix.relative(base, descriptor.path), bytes: descriptor.size }))
|
|
56
|
+
.sort((a, b) => a.path.localeCompare(b.path));
|
|
57
|
+
}
|
|
58
|
+
const base = path.dirname(filePath);
|
|
59
|
+
const normalizedBase = normalizeIndexedPath(base);
|
|
60
|
+
const boundary = normalizedBase.match(/^(.*\/(?:frameworks|addons|extensions)\/[^/]+)(?:\/|$)/)?.[1]
|
|
61
|
+
?? normalizedBase.match(/^(.*\/\.aiwg)(?:\/|$)/)?.[1] ?? base;
|
|
62
|
+
const resources = new Map();
|
|
63
|
+
const walk = (relative) => {
|
|
64
|
+
const absolute = path.resolve(base, relative);
|
|
65
|
+
const contained = path.relative(boundary, absolute);
|
|
66
|
+
if (contained === '..' || contained.startsWith(`..${path.sep}`) || path.isAbsolute(contained))
|
|
67
|
+
return;
|
|
68
|
+
let cursor = boundary;
|
|
69
|
+
let stat;
|
|
70
|
+
try {
|
|
71
|
+
for (const component of contained.split(path.sep)) {
|
|
72
|
+
cursor = path.join(cursor, component);
|
|
73
|
+
stat = fs.lstatSync(cursor);
|
|
74
|
+
if (stat.isSymbolicLink())
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
catch {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
if (stat?.isDirectory()) {
|
|
82
|
+
for (const name of fs.readdirSync(absolute).sort())
|
|
83
|
+
walk(path.join(relative, name));
|
|
84
|
+
}
|
|
85
|
+
else if (stat?.isFile() && absolute !== filePath) {
|
|
86
|
+
const key = normalizeIndexedPath(path.relative(base, absolute));
|
|
87
|
+
resources.set(key, { path: key, bytes: stat.size });
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
for (const directory of ['templates', 'scripts', 'references', 'resources', 'assets'])
|
|
91
|
+
walk(directory);
|
|
92
|
+
const { data } = parseFrontmatter(source);
|
|
93
|
+
const declared = Array.isArray(data.resources) ? data.resources.filter((value) => typeof value === 'string') : [];
|
|
94
|
+
for (const link of [...extractMarkdownLinks(source), ...declared]) {
|
|
95
|
+
if (path.isAbsolute(link) || /^[a-z]+:/i.test(link))
|
|
96
|
+
continue;
|
|
97
|
+
const relative = path.relative(base, path.resolve(base, link));
|
|
98
|
+
// Outside the artifact directory, only declared companion categories qualify.
|
|
99
|
+
if ((relative === '..' || relative.startsWith(`..${path.sep}`)) && !/(?:^|\/)(?:templates|scripts|references|resources|assets)\//.test(normalizeIndexedPath(relative)))
|
|
100
|
+
continue;
|
|
101
|
+
walk(relative);
|
|
102
|
+
}
|
|
103
|
+
return [...resources.values()].sort((a, b) => a.path.localeCompare(b.path));
|
|
104
|
+
}
|
|
105
|
+
export async function emitShowCard(cwd, aiwgRoot, entry, filePath, source, params, bindings, extra, local, release) {
|
|
106
|
+
const { data } = parseFrontmatter(source);
|
|
107
|
+
const flow = entry.type === 'flow' || entry.type === 'runbook' ? parseFlowDoc(source, entry.path) : null;
|
|
108
|
+
const sections = showSections(source);
|
|
109
|
+
const selected = (params.sections ?? []).map(heading => {
|
|
110
|
+
const exact = sections.filter(section => section.heading === heading);
|
|
111
|
+
const matches = exact.length ? exact : sections.filter(section => section.heading.toLowerCase() === heading.toLowerCase());
|
|
112
|
+
if (matches.length !== 1)
|
|
113
|
+
throw new Error(`${matches.length ? 'Ambiguous' : 'Unknown'} heading "${heading}". Headings: ${sections.map(section => section.heading).join(', ') || '(none)'}`);
|
|
114
|
+
return matches[0].text;
|
|
115
|
+
});
|
|
116
|
+
const owner = normalizeIndexedPath(entry.path).match(/(?:^|\/)(?:agentic\/code|\.aiwg)\/(frameworks|addons|extensions)\/([^/]+)\//);
|
|
117
|
+
const kind = owner ? { frameworks: 'framework', addons: 'addon', extensions: 'extension' }[owner[1]] : null;
|
|
118
|
+
const installed = local && (owner && aiwgRoot
|
|
119
|
+
? await isCorpusBundleInstalled(cwd, aiwgRoot, kind, owner[2]) : true);
|
|
120
|
+
const resources = local || release ? showResources(filePath, source, release) : [];
|
|
121
|
+
const resource = params.resource ? resources.find(resource => resource.path === params.resource) : undefined;
|
|
122
|
+
if (params.resource && !resource)
|
|
123
|
+
throw new Error(`Unknown resource "${params.resource}". Resources: ${resources.map(resource => resource.path).join(', ') || '(none)'}`);
|
|
124
|
+
const quote = (value) => '"' + value.replace(/["\\$`]/g, '\\$&') + '"';
|
|
125
|
+
const command = `aiwg show ${entry.type} ${extra.hint ? params.name : discoveryIdForEntry(entry)}`
|
|
126
|
+
+ (params.graph ? ` --graph ${quote(params.graph)}` : '')
|
|
127
|
+
+ (params.backend ? ` --backend ${params.backend}` : '')
|
|
128
|
+
+ (params.resourceSource ? ` --resource-source ${params.resourceSource}` : '')
|
|
129
|
+
+ (params.aiwgVersion ? ` --aiwg-version ${quote(params.aiwgVersion)}` : '')
|
|
130
|
+
+ (params.offline ? ' --offline' : '');
|
|
131
|
+
let resourceBody;
|
|
132
|
+
if (resource) {
|
|
133
|
+
if (local)
|
|
134
|
+
resourceBody = fs.readFileSync(path.join(path.dirname(filePath), resource.path), 'utf8');
|
|
135
|
+
else if (release) {
|
|
136
|
+
const { fetchVerifiedRawResource } = await import('../resources/web-release.js');
|
|
137
|
+
resourceBody = (await fetchVerifiedRawResource(release, path.posix.normalize(path.posix.join(path.posix.dirname(filePath), resource.path)), { ...params.webReleaseOptions, offline: params.offline })).toString('utf8');
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
const localPin = extra.local_pin;
|
|
141
|
+
const pinNote = localPin ? `Pinned locally: kernel (canonical ${localPin.canonical_activation}; ${localPin.matches.map(match => match.source).join(', ')}).` : '';
|
|
142
|
+
const contentNotice = 'This is a metadata card. The component body has not been fetched. Before deciding or applying its workflow, read the needed sections or --body using the drill-in commands below. Read full governing rules before governed work; --rules alone lists checks.';
|
|
143
|
+
const card = {
|
|
144
|
+
id: discoveryIdForEntry(entry), type: entry.type, name: entry.name ?? String(data.name ?? entry.title),
|
|
145
|
+
title: entry.title, path: filePath, description: String(data.description ?? data.summary ?? flow?.description ?? entry.capability ?? entry.ruleSummary ?? entry.summary ?? ''),
|
|
146
|
+
capability: owner ? { kind, name: owner[2] } : null, installed, kernel: entry.kernel ?? false,
|
|
147
|
+
...(['rule', 'behavior'].includes(entry.type) ? {
|
|
148
|
+
activation: localPin ? 'kernel' : entry.activation ?? data.activation ?? null, enforcement: data.enforcement ?? entry.ruleEnforcement ?? null,
|
|
149
|
+
bound_to: data.bound_to ?? entry.bound_to ?? {},
|
|
150
|
+
} : {}),
|
|
151
|
+
bound_rules: [], rule_stats: emptyRuleStats(), required_rule_checks: [], rule_check_obligation: RULE_CHECK_OBLIGATION,
|
|
152
|
+
...bindings.fields,
|
|
153
|
+
outline: sections.map(({ text: _text, ...metadata }) => metadata), resources,
|
|
154
|
+
...(!params.body && !selected.length ? { content_notice: contentNotice } : {}),
|
|
155
|
+
drill_in: {
|
|
156
|
+
sections: sections.map(section => `${command} --section ${quote(section.heading)}`),
|
|
157
|
+
rules: `${command} --rules`, rule_bodies: `${command} --rules --with-rule-bodies`,
|
|
158
|
+
resources: `${command} --resources`, resource: resources.map(resource => `${command} --resource ${quote(resource.path)}`),
|
|
159
|
+
body: `${command} --body`,
|
|
160
|
+
},
|
|
161
|
+
...extra,
|
|
162
|
+
...(params.body || selected.length ? { content: params.body ? source : selected.join('\n') } : {}),
|
|
163
|
+
...(resource ? { resource: { ...resource, body: resourceBody } } : {}),
|
|
164
|
+
};
|
|
165
|
+
if (params.json) {
|
|
166
|
+
console.log(JSON.stringify(card, null, 2));
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
if ('content' in card) {
|
|
170
|
+
if (extra.hint)
|
|
171
|
+
process.stdout.write(`<!-- AIWG: ${card.installed ? 'installed bundle artifact — not in the selected index.' : 'corpus-only artifact — not in the indexed workspace.'}\n ${extra.hint}\n Origin: ${filePath}\n-->\n\n`);
|
|
172
|
+
if (entry.script)
|
|
173
|
+
process.stdout.write(`<!-- AIWG: executable skill — run via: ${buildRunHint(entry)} -->\n`);
|
|
174
|
+
if (pinNote)
|
|
175
|
+
process.stdout.write(`${pinNote}\n`);
|
|
176
|
+
process.stdout.write(card.content);
|
|
177
|
+
if (!card.content.endsWith('\n'))
|
|
178
|
+
process.stdout.write('\n');
|
|
179
|
+
if (bindings.text)
|
|
180
|
+
process.stdout.write(bindings.text);
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
const lines = [`# ${card.type}: ${card.name}`, `ID: ${card.id}`, card.description,
|
|
184
|
+
`Owner: ${card.capability ? `${card.capability.kind}:${card.capability.name}` : 'project/unowned'} | installed: ${card.installed}`, statsText(card.rule_stats)];
|
|
185
|
+
if (pinNote)
|
|
186
|
+
lines.push(pinNote);
|
|
187
|
+
if ('activation' in card)
|
|
188
|
+
lines.push(`Activation: ${card.activation} | enforcement: ${card.enforcement}`, `Bound targets: ${JSON.stringify(card.bound_to)}`);
|
|
189
|
+
lines.push(contentNotice, bindings.text || RULE_CHECK_OBLIGATION, '\n## Outline', ...card.outline.map(section => `- ${section.heading} (${section.bytes} bytes, ${section.lines} lines)`), '\n## Resources', ...resources.map(resource => `- ${resource.path} (${resource.bytes} bytes)`), '\n## Drill in', ...Object.values(card.drill_in).flat().map(command => `- ${command}`));
|
|
190
|
+
if (card.resource)
|
|
191
|
+
lines.push(`\n## Resource: ${card.resource.path}`, card.resource.body);
|
|
192
|
+
console.log(lines.join('\n'));
|
|
193
|
+
}
|
|
194
|
+
//# sourceMappingURL=query-engine-show-card.js.map
|
|
@@ -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
|