@aiwg/cli 2026.11.0 → 2026.11.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/agentic/code/addons/aiwg-hooks/canonical/aiwg-prompt-discovery.yaml +9 -0
- package/agentic/code/addons/aiwg-hooks/hooks/aiwg-prompt-discovery.cjs +136 -0
- package/agentic/code/providers/flue/README.md +2 -1
- package/agentic/code/providers/model-capabilities.v1.json +27 -23
- package/agentic/code/providers/model-catalog.v1.json +3 -3
- package/dist/src/artifacts/cli.js +13 -13
- package/dist/src/artifacts/discover-cli-help.js +25 -0
- package/dist/src/artifacts/discover-facets.js +2 -0
- package/dist/src/artifacts/discover-session-facets.js +15 -0
- package/dist/src/artifacts/fortemi-core-prebuilt-freshness.js +28 -0
- package/dist/src/artifacts/fortemi-core-query-adapter.js +4 -4
- package/dist/src/artifacts/fortemi-core-sync.js +3 -0
- package/dist/src/artifacts/framework-capabilities.js +11 -3
- package/dist/src/artifacts/framework-source-digest.js +1 -1
- package/dist/src/artifacts/index-builder.js +12 -13
- package/dist/src/artifacts/index-dependencies.js +72 -0
- package/dist/src/artifacts/query-engine-discover-output.js +13 -5
- package/dist/src/artifacts/query-engine-discover.js +103 -28
- package/dist/src/artifacts/query-engine-entries.js +107 -10
- package/dist/src/artifacts/query-engine-installation.js +27 -0
- package/dist/src/artifacts/query-engine-options.js +14 -1
- package/dist/src/artifacts/query-engine-rules.js +1 -2
- package/dist/src/artifacts/query-engine-scoring.js +38 -32
- package/dist/src/artifacts/query-engine-show-card.js +8 -2
- package/dist/src/artifacts/query-engine-show-load.js +1 -1
- package/dist/src/artifacts/query-engine-show.js +5 -3
- package/dist/src/artifacts/query-engine-templates.js +33 -0
- package/dist/src/artifacts/query-engine-verbose.js +25 -0
- package/dist/src/artifacts/relations-builder.js +49 -4
- package/dist/src/artifacts/relations.js +26 -10
- package/dist/src/artifacts/template-references.js +42 -0
- package/dist/src/artifacts/types.js +1 -1
- package/dist/src/cli/handlers/bundle-reconciliation.js +7 -3
- package/dist/src/cli/handlers/checkpoint-handoff.js +48 -0
- package/dist/src/cli/handlers/checkpoint-record.js +20 -0
- package/dist/src/cli/handlers/checkpoint.js +176 -0
- package/dist/src/cli/handlers/decision.js +1 -1
- package/dist/src/cli/handlers/doctor-args.js +3 -1
- package/dist/src/cli/handlers/doctor-help.js +2 -1
- package/dist/src/cli/handlers/help.js +1 -0
- package/dist/src/cli/handlers/index.js +4 -2
- package/dist/src/cli/handlers/models-resource-sample.js +7 -3
- package/dist/src/cli/handlers/ralph-launcher.js +1 -1
- package/dist/src/cli/handlers/refresh-bundles.js +2 -1
- package/dist/src/cli/handlers/refresh-managed-deployment.js +196 -0
- package/dist/src/cli/handlers/refresh.js +10 -2
- package/dist/src/cli/handlers/script-runner.js +2 -1
- package/dist/src/cli/handlers/steward-signing.js +44 -0
- package/dist/src/cli/handlers/steward.js +5 -0
- package/dist/src/cli/handlers/subcommands-discovery.js +8 -1
- package/dist/src/cli/handlers/use-provider-results.js +17 -0
- package/dist/src/cli/handlers/use.js +19 -18
- package/dist/src/cli/router.js +12 -2
- package/dist/src/cli/services/deployment-verification.js +11 -7
- package/dist/src/cli/user-scope-mirror.js +3 -1
- package/dist/src/config/aiwg-config.js +5 -1
- package/dist/src/config/cli.js +1 -0
- package/dist/src/config/delivery-validation.js +21 -0
- package/dist/src/config/host-resource-report.d.mts +1 -1
- package/dist/src/config/host-resource-report.mjs +23 -4
- package/dist/src/config/host-resource-runtime.d.mts +8 -0
- package/dist/src/config/host-resource-runtime.mjs +67 -24
- package/dist/src/config/index-graph-overrides.js +4 -0
- package/dist/src/config/worker-attribution.d.mts +7 -0
- package/dist/src/config/worker-attribution.mjs +44 -0
- package/dist/src/config/worker-write.js +4 -10
- package/dist/src/decision/ledger.js +15 -15
- package/dist/src/decision/offload.js +6 -7
- package/dist/src/delivery/git.js +62 -0
- package/dist/src/delivery/pr.js +151 -0
- package/dist/src/delivery/template-sections.js +56 -0
- package/dist/src/delivery/tracker.js +33 -0
- package/dist/src/discovery/interview.js +1 -1
- package/dist/src/extensions/claude-hooks-installer.js +62 -53
- package/dist/src/extensions/loader.js +2 -1
- package/dist/src/extensions/managed-hook-script-state.js +48 -0
- package/dist/src/extensions/muse-managed-hooks.js +49 -0
- package/dist/src/issues/cli.js +15 -3
- package/dist/src/issues/external-cli.js +79 -0
- package/dist/src/issues/live.js +26 -2
- package/dist/src/issues/local.js +5 -1
- package/dist/src/issues/tracker-policy.js +27 -0
- package/dist/src/mcp/json-document.d.mts +2 -0
- package/dist/src/mcp/tools/worker-invoke.mjs +2 -1
- package/dist/src/mcp/tools/worker-stdin-runtime.mjs +12 -0
- package/dist/src/models/conductor-data-policy.d.mts +3 -2
- package/dist/src/models/conductor-data-policy.mjs +94 -5
- package/dist/src/models/model-capabilities.v1.json +27 -23
- package/dist/src/models/model-catalog.v1.json +3 -3
- package/dist/src/models/provider-policy.js +8 -0
- package/dist/src/models/worker-health-readiness.js +20 -4
- package/dist/src/models/worker-health-snapshot.js +29 -0
- package/dist/src/models/worker-installation.d.mts +5 -1
- package/dist/src/models/worker-installation.mjs +11 -5
- package/dist/src/models/worker-plan.js +3 -3
- package/dist/src/models/worker-qualification-policy.js +54 -0
- package/dist/src/models/worker-selection-policy.js +2 -1
- package/dist/src/providers/deployment-lock.js +77 -0
- package/dist/src/providers/deployment-ownership.d.mts +12 -2
- package/dist/src/providers/deployment-ownership.mjs +115 -21
- package/dist/src/providers/deployment-preservation.d.mts +2 -1
- package/dist/src/providers/deployment-preservation.mjs +3 -0
- package/dist/src/providers/provider-definitions.js +4 -0
- package/dist/src/providers/skill-ownership.d.mts +1 -0
- package/dist/src/providers/transformation-receipt-integration.js +4 -2
- package/dist/src/providers/transformation-receipt.js +4 -2
- package/dist/src/serve/worker-invocation-preparation.js +3 -1
- package/dist/src/serve/worker-invocation.js +6 -2
- package/dist/src/skills/run.js +5 -0
- package/dist/src/smiths/context-pipeline/workspace-audit.js +34 -17
- package/dist/src/smiths/context-pipeline/workspace-context-shared.js +12 -6
- package/dist/src/smiths/context-pipeline/workspace-doctor.js +44 -4
- package/dist/src/smiths/context-pipeline/workspace-document.js +5 -2
- package/dist/src/smiths/context-pipeline/workspace-migration.js +2 -1
- package/dist/src/smiths/hook-bridge/codex-translator.js +150 -92
- package/dist/src/smiths/hook-bridge/codex-trust.js +50 -0
- package/dist/src/smiths/hook-bridge/factory-hook-config.js +132 -0
- package/dist/src/smiths/hook-bridge/factory-translator.js +88 -33
- package/dist/src/smiths/hook-bridge/hermes-translator.js +3 -1
- package/dist/src/smiths/hook-bridge/index.js +3 -3
- package/dist/src/smiths/hook-bridge/loader.js +10 -2
- package/dist/src/smiths/hook-bridge/prompt-discovery-gaps.js +5 -0
- package/dist/src/storage/workspace-permissions-health.js +64 -0
- package/dist/src/storage/workspace-permissions.js +51 -0
- package/package.json +9 -2
- package/schemas/models/model-config-compatibility.v1.schema.json +4 -0
- package/tools/agents/deploy-agents.mjs +15 -0
- package/tools/agents/providers/base-contract.mjs +7 -1
- package/tools/agents/providers/base-files.mjs +2 -1
- package/tools/agents/providers/base-flat-artifacts.mjs +6 -3
- package/tools/agents/providers/base-inventory.mjs +35 -13
- package/tools/agents/providers/base-models-platforms.mjs +3 -3
- package/tools/agents/providers/base-skill-copy.mjs +2 -0
- package/tools/agents/providers/base.mjs +1 -1
- package/tools/agents/providers/bound-rules-pointer.mjs +21 -0
- package/tools/agents/providers/claude-post-deploy.mjs +9 -5
- package/tools/agents/providers/codex-post-deploy.mjs +10 -0
- package/tools/agents/providers/conductor-data-guard.mjs +35 -11
- package/tools/agents/providers/factory-hooks.mjs +43 -0
- package/tools/agents/providers/factory.mjs +4 -91
- package/tools/agents/providers/muse-hooks.mjs +6 -41
- package/tools/agents/providers/muse-prompt-discovery.mjs +18 -0
- package/tools/agents/providers/packaged-codex-agents.mjs +48 -0
- package/tools/agents/providers/provider-prepare-coordinator.mjs +15 -10
- package/tools/agents/providers/rule-delivery-surface.mjs +10 -7
- package/tools/agents/providers/rule-deployment-commit.mjs +10 -0
- package/tools/agents/providers/rule-presentation.mjs +6 -5
- package/tools/agents/providers/rule-projection.mjs +10 -2
- package/tools/agents/providers/rule-startup.mjs +8 -1
- package/tools/agents/providers/stale-artifact-prune.mjs +9 -8
- package/tools/cli/decision-offload-report.mjs +7 -2
- package/tools/plugin/issue-template-copies.mjs +24 -0
- package/tools/plugin/package-plugins.mjs +11 -3
- package/tools/ralph-external/lib/factory-adapter.mjs +7 -8
- package/tools/ralph-external/lib/worker-artifacts.mjs +4 -2
- package/tools/ralph-external/lib/worker-capture.mjs +157 -0
- package/tools/ralph-external/lib/worker-final.mjs +43 -8
- package/tools/ralph-external/lib/worker-health.mjs +3 -0
- package/tools/ralph-external/lib/worker-invocation-processes.mjs +9 -6
- package/tools/ralph-external/lib/worker-launch-cli.mjs +20 -2
- package/tools/ralph-external/lib/worker-process-identity.mjs +30 -0
- package/tools/ralph-external/lib/worker-prompt.mjs +35 -0
- package/tools/ralph-external/lib/worker-retry-evidence.mjs +87 -6
- package/tools/ralph-external/lib/worker-run-directory-refusal.mjs +8 -0
- package/tools/ralph-external/lib/worker-termination.mjs +56 -6
- package/tools/ralph-external/process-monitor.mjs +12 -18
- package/tools/ralph-external/session-launcher.mjs +53 -36
- package/vscode-extension/schemas/aiwg.config.v1.json +15 -0
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
import { minimatch } from 'minimatch';
|
|
3
3
|
import * as path from 'node:path';
|
|
4
4
|
import { inferRuleActivation } from '../rules/activation.mjs';
|
|
5
|
-
import { parseFrontmatter } from './index-builder.js';
|
|
6
5
|
import { discoveryIdForEntry, normalizeIndexedPath } from './query-engine-entries.js';
|
|
7
6
|
import { emptyRuleStats } from './relations.js';
|
|
8
7
|
/** Build an ephemeral reverse lookup from the already-loaded rule metadata. */
|
|
@@ -159,7 +158,7 @@ export async function showBindings(entries, target, content, params, read, relat
|
|
|
159
158
|
})));
|
|
160
159
|
// Parse the selected rule for reverse lookup, including corpus-only rules.
|
|
161
160
|
const targets = target.type === 'rule' || target.type === 'behavior'
|
|
162
|
-
? parseFrontmatter(content).data.bound_to : undefined;
|
|
161
|
+
? (await import('./index-builder.js')).parseFrontmatter(content).data.bound_to : undefined;
|
|
163
162
|
const boundTo = targets && typeof targets === 'object' && !Array.isArray(targets)
|
|
164
163
|
? Object.fromEntries(['skills', 'agents', 'flows'].flatMap(key => {
|
|
165
164
|
const values = targets[key];
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// Tokenize discovery phrases and score metadata matches with lexical diagnostics.
|
|
2
2
|
import { diagnoseFacetActivations } from './discover-facets.js';
|
|
3
|
+
import { verboseQueryProfile } from './query-engine-verbose.js';
|
|
3
4
|
export function containsTokenSequence(haystack, needle) {
|
|
4
5
|
if (needle.length === 0 || haystack.length < needle.length)
|
|
5
6
|
return false;
|
|
@@ -68,12 +69,23 @@ export function tokenize(text) {
|
|
|
68
69
|
? token.slice(0, -1)
|
|
69
70
|
: token);
|
|
70
71
|
}
|
|
72
|
+
const fieldTokenCache = new Map();
|
|
73
|
+
function fieldTokens(field) {
|
|
74
|
+
let tokens = fieldTokenCache.get(field);
|
|
75
|
+
if (!tokens) {
|
|
76
|
+
tokens = tokenize(field);
|
|
77
|
+
fieldTokenCache.set(field, tokens);
|
|
78
|
+
if (fieldTokenCache.size > 20_000)
|
|
79
|
+
fieldTokenCache.clear();
|
|
80
|
+
}
|
|
81
|
+
return tokens;
|
|
82
|
+
}
|
|
71
83
|
export function matchedFieldTokens(queryTokens, field) {
|
|
72
|
-
const
|
|
73
|
-
return queryTokens.filter(token =>
|
|
84
|
+
const available = new Set(fieldTokens(field));
|
|
85
|
+
return queryTokens.filter(token => available.has(token));
|
|
74
86
|
}
|
|
75
87
|
export function fieldContainsQuery(field, queryTokens) {
|
|
76
|
-
return containsTokenSequence(
|
|
88
|
+
return containsTokenSequence(fieldTokens(field), queryTokens);
|
|
77
89
|
}
|
|
78
90
|
/**
|
|
79
91
|
* Score a metadata entry against a keyword query.
|
|
@@ -154,23 +166,19 @@ export function nearNameMatch(query, name) {
|
|
|
154
166
|
});
|
|
155
167
|
}
|
|
156
168
|
export function scoreEntryDetailed(entry, text, opts = {}) {
|
|
157
|
-
const tokens = tokenize(text);
|
|
158
169
|
// Field substring matching uses the stopword-stripped CONTENT phrase, not the
|
|
159
|
-
// raw query (#1581)
|
|
160
|
-
//
|
|
161
|
-
//
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
// tokens restores the invariant that a single content token IS the phrase, and
|
|
165
|
-
// for multi-token queries gives a tighter (content-only) phrase to match.
|
|
166
|
-
// Pure-stopword queries fall back to the raw text.
|
|
170
|
+
// raw query (#1581): a query that reduces to one content token ("intake skill"
|
|
171
|
+
// -> ["intake"]) must still match that token. Pure-stopword queries fall back
|
|
172
|
+
// to the raw text. Tokens are de-duplicated so a repeated word is credited once.
|
|
173
|
+
const tokens = [...new Set(tokenize(text))];
|
|
174
|
+
const verbose = verboseQueryProfile(text, tokens, tokenize);
|
|
167
175
|
const lower = tokens.length > 0 ? tokens.join(' ') : text.toLowerCase().trim();
|
|
168
176
|
const rawLower = text.toLowerCase().trim();
|
|
169
|
-
const personaIdentitySuppressed = diagnoseFacetActivations(text).some((activation) => activation.facet === 'persona-identity' && activation.status === 'suppressed');
|
|
177
|
+
const personaIdentitySuppressed = opts.personaIdentitySuppressed ?? diagnoseFacetActivations(text).some((activation) => activation.facet === 'persona-identity' && activation.status === 'suppressed');
|
|
170
178
|
let score = 0;
|
|
171
179
|
const matches = [];
|
|
172
|
-
const creditedTokens = new
|
|
173
|
-
const finish = (uncappedScore = score, cap = 1) => ({
|
|
180
|
+
const creditedTokens = new Map();
|
|
181
|
+
const finish = (uncappedScore = score, cap = verbose?.coverage(matches) ?? 1) => ({
|
|
174
182
|
score: Math.min(uncappedScore, cap),
|
|
175
183
|
diagnostic: {
|
|
176
184
|
content_tokens: tokens,
|
|
@@ -181,31 +189,29 @@ export function scoreEntryDetailed(entry, text, opts = {}) {
|
|
|
181
189
|
},
|
|
182
190
|
});
|
|
183
191
|
const addMatch = (contribution, match) => {
|
|
192
|
+
contribution *= verbose?.weight(match.matched_tokens ?? tokens) ?? 1;
|
|
184
193
|
score += contribution;
|
|
185
194
|
matches.push({ ...match, contribution });
|
|
186
195
|
};
|
|
187
196
|
const addTokenMatch = (contributionPerToken, hits, match) => {
|
|
188
|
-
|
|
197
|
+
// Short queries discount sparse trigger overlap. Verbose queries instead
|
|
198
|
+
// apply token weights and the shared coverage cap across all fields.
|
|
199
|
+
const denominator = !verbose && match.field === 'trigger' && (hits.length === 1 || hits.length < Math.ceil(tokens.length / 2))
|
|
200
|
+
? Math.max(1, tokens.length) : 1;
|
|
201
|
+
const weight = contributionPerToken / denominator;
|
|
202
|
+
const newlyMatched = hits.filter(token => weight > (creditedTokens.get(token) ?? 0));
|
|
189
203
|
if (newlyMatched.length === 0)
|
|
190
204
|
return;
|
|
191
|
-
newlyMatched.
|
|
192
|
-
|
|
205
|
+
const contribution = newlyMatched.reduce((sum, token) => sum + weight - (creditedTokens.get(token) ?? 0), 0);
|
|
206
|
+
newlyMatched.forEach(token => creditedTokens.set(token, weight));
|
|
207
|
+
addMatch(contribution, {
|
|
193
208
|
...match,
|
|
194
209
|
matched_tokens: newlyMatched,
|
|
195
210
|
query_token_coverage: tokens.length > 0 ? newlyMatched.length / tokens.length : 0,
|
|
196
211
|
});
|
|
197
212
|
};
|
|
198
|
-
// Exact-name
|
|
199
|
-
//
|
|
200
|
-
// for and it must surface at the top regardless of how cluttered the
|
|
201
|
-
// rest of the corpus scoring gets. Hyphens, underscores, and whitespace
|
|
202
|
-
// are interchangeable in the comparison so `aiwg-doctor`, `aiwg doctor`,
|
|
203
|
-
// and `aiwg_doctor` all match a kernel skill with `name: aiwg-doctor`.
|
|
204
|
-
//
|
|
205
|
-
// Returns 1.001 (not 1.0) so an exact-name hit sorts above the many
|
|
206
|
-
// capped-at-1.0 substring matches that share generic words like "use".
|
|
207
|
-
// Display rounding (Math.round(score * 100) / 100) hides the offset, so
|
|
208
|
-
// the user still sees `score: 1.0` while sort order is preserved.
|
|
213
|
+
// Exact and near-name floors preserve deliberate artifact selection. The
|
|
214
|
+
// 1.001 offset sorts exact names above capped lexical matches (display: 1.0).
|
|
209
215
|
if (entry.name) {
|
|
210
216
|
const queryNorm = normalizeName(text);
|
|
211
217
|
const nameNorm = normalizeName(entry.name);
|
|
@@ -261,7 +267,7 @@ export function scoreEntryDetailed(entry, text, opts = {}) {
|
|
|
261
267
|
// phrase wins big; substring or token-overlap is still strong.
|
|
262
268
|
if (triggersLower.length > 0) {
|
|
263
269
|
for (const trigger of triggersLower) {
|
|
264
|
-
const triggerTokens =
|
|
270
|
+
const triggerTokens = fieldTokens(trigger);
|
|
265
271
|
const matchedTokens = tokens.filter((token) => triggerTokens.includes(token));
|
|
266
272
|
const queryCoverage = tokens.length > 0 ? matchedTokens.length / tokens.length : 0;
|
|
267
273
|
if (trigger === lower || trigger === rawLower) {
|
|
@@ -295,8 +301,8 @@ export function scoreEntryDetailed(entry, text, opts = {}) {
|
|
|
295
301
|
const contribution = suppressedGenericPersona
|
|
296
302
|
? 0.24 * queryCoverage
|
|
297
303
|
: triggerTokens.length > 1
|
|
298
|
-
?
|
|
299
|
-
:
|
|
304
|
+
? (0.75 + 0.25 * containedCoverage) * queryCoverage
|
|
305
|
+
: queryCoverage;
|
|
300
306
|
addMatch(contribution, {
|
|
301
307
|
field: 'trigger',
|
|
302
308
|
match: 'contained-phrase',
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
// Render show metadata cards, sections, and companion resources.
|
|
2
2
|
import * as fs from 'node:fs';
|
|
3
3
|
import * as path from 'node:path';
|
|
4
|
-
import {
|
|
4
|
+
import { isArtifactInstalled } from './query-engine-installation.js';
|
|
5
5
|
import { extractMarkdownLinks, parseFlowDoc, parseFrontmatter } from './index-builder.js';
|
|
6
6
|
import { buildRunHint, discoveryIdForEntry, normalizeIndexedPath } from './query-engine-entries.js';
|
|
7
7
|
import { RULE_CHECK_OBLIGATION, statsText } from './query-engine-rules.js';
|
|
8
8
|
import { emptyRuleStats } from './relations.js';
|
|
9
|
+
import { templateRelationLines } from './query-engine-templates.js';
|
|
9
10
|
/** Sections include their nested headings, stopping at the next peer/ancestor. */
|
|
10
11
|
export function showSections(content) {
|
|
11
12
|
const body = parseFrontmatter(content).body;
|
|
@@ -116,7 +117,7 @@ export async function emitShowCard(cwd, aiwgRoot, entry, filePath, source, param
|
|
|
116
117
|
const owner = normalizeIndexedPath(entry.path).match(/(?:^|\/)(?:agentic\/code|\.aiwg)\/(frameworks|addons|extensions)\/([^/]+)\//);
|
|
117
118
|
const kind = owner ? { frameworks: 'framework', addons: 'addon', extensions: 'extension' }[owner[1]] : null;
|
|
118
119
|
const installed = local && (owner && aiwgRoot
|
|
119
|
-
? await
|
|
120
|
+
? await isArtifactInstalled(cwd, aiwgRoot, entry, kind, owner[2]) : true);
|
|
120
121
|
const resources = local || release ? showResources(filePath, source, release) : [];
|
|
121
122
|
const resource = params.resource ? resources.find(resource => resource.path === params.resource) : undefined;
|
|
122
123
|
if (params.resource && !resource)
|
|
@@ -158,6 +159,8 @@ export async function emitShowCard(cwd, aiwgRoot, entry, filePath, source, param
|
|
|
158
159
|
resources: `${command} --resources`, resource: resources.map(resource => `${command} --resource ${quote(resource.path)}`),
|
|
159
160
|
body: `${command} --body`,
|
|
160
161
|
},
|
|
162
|
+
...(!installed ? { load_hint: `Read the component with \`${command} --body\`.`
|
|
163
|
+
+ (owner ? ` Deploy it with \`aiwg use ${owner[2]}\`.` : '') } : {}),
|
|
161
164
|
...extra,
|
|
162
165
|
...(params.body || selected.length ? { content: params.body ? source : selected.join('\n') } : {}),
|
|
163
166
|
...(resource ? { resource: { ...resource, body: resourceBody } } : {}),
|
|
@@ -182,10 +185,13 @@ export async function emitShowCard(cwd, aiwgRoot, entry, filePath, source, param
|
|
|
182
185
|
}
|
|
183
186
|
const lines = [`# ${card.type}: ${card.name}`, `ID: ${card.id}`, card.description,
|
|
184
187
|
`Owner: ${card.capability ? `${card.capability.kind}:${card.capability.name}` : 'project/unowned'} | installed: ${card.installed}`, statsText(card.rule_stats)];
|
|
188
|
+
if (card.load_hint)
|
|
189
|
+
lines.push(card.load_hint);
|
|
185
190
|
if (pinNote)
|
|
186
191
|
lines.push(pinNote);
|
|
187
192
|
if ('activation' in card)
|
|
188
193
|
lines.push(`Activation: ${card.activation} | enforcement: ${card.enforcement}`, `Bound targets: ${JSON.stringify(card.bound_to)}`);
|
|
194
|
+
lines.push(...templateRelationLines(extra));
|
|
189
195
|
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
196
|
if (card.resource)
|
|
191
197
|
lines.push(`\n## Resource: ${card.resource.path}`, card.resource.body);
|
|
@@ -46,7 +46,7 @@ export async function loadShowEntries(cwd, params, compact = false) {
|
|
|
46
46
|
const localEntries = params.graph ? [] : defaultCapabilityGraphs(cwd).filter(graph => graph !== 'framework')
|
|
47
47
|
.flatMap(graph => loadLocalCapabilityEntries(cwd, graph, undefined, true));
|
|
48
48
|
const compactEntries = [...localEntries, ...frameworkEntries];
|
|
49
|
-
if ((params.typeFilter?.every(type => ['skill', 'agent', 'flow', 'command', 'rule', 'behavior'].includes(type)))
|
|
49
|
+
if ((params.typeFilter?.every(type => ['skill', 'agent', 'flow', 'command', 'rule', 'behavior', 'template'].includes(type)))
|
|
50
50
|
|| findShowMatches(compactEntries, params.typeFilter ?? [...OPERATIONAL_SHOW_TYPES], params.name.trim()).length) {
|
|
51
51
|
return { entries: compactEntries, aiwgRoot, resourceSource: 'local', relations };
|
|
52
52
|
}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
// Serve artifact bodies and metadata through the show surface.
|
|
2
2
|
import * as path from 'node:path';
|
|
3
3
|
import { loadProviderModelMetadata } from '../models/provider-models.js';
|
|
4
|
-
import {
|
|
4
|
+
import { isArtifactInstalled } from './query-engine-installation.js';
|
|
5
5
|
import { findCorpusArtifact } from './query-engine-corpus.js';
|
|
6
6
|
import { buildRunHint, DEFAULT_ARTIFACT_SEARCH_BACKEND, discoveryIdForEntry, normalizeIndexedPath, } from './query-engine-entries.js';
|
|
7
7
|
import { findShowMatches } from './query-engine-matching.js';
|
|
8
8
|
import { showBindings } from './query-engine-rules.js';
|
|
9
9
|
import { emitShowCard } from './query-engine-show-card.js';
|
|
10
|
+
import { templateRelationFields } from './query-engine-templates.js';
|
|
10
11
|
import { fortemiRecordForEntry, loadShowEntries, resolveMetadataPath } from './query-engine-show-load.js';
|
|
11
12
|
import { loadGlobalGraphConfigs, OPERATIONAL_SHOW_TYPES } from './types.js';
|
|
12
13
|
/**
|
|
@@ -59,7 +60,7 @@ export async function showArtifact(cwd, params) {
|
|
|
59
60
|
process.exit(1);
|
|
60
61
|
}
|
|
61
62
|
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
|
|
63
|
+
const installed = await isArtifactInstalled(cwd, aiwgRoot, { path: corpusMatch.path, type: corpusMatch.type }, corpusMatch.bundleKind, corpusMatch.bundleId);
|
|
63
64
|
const installHint = installed
|
|
64
65
|
? 'The installed bundle is missing from this index. Run `aiwg index build --graph framework` to refresh it.'
|
|
65
66
|
: corpusMatch.bundleKind && corpusMatch.bundleId
|
|
@@ -68,7 +69,7 @@ export async function showArtifact(cwd, params) {
|
|
|
68
69
|
const fallbackEntry = { path: path.relative(aiwgRoot, corpusMatch.path), type: corpusMatch.type, name: needle, title: needle };
|
|
69
70
|
const bindings = await showBindings(entries, fallbackEntry, content, params, rule => fs.readFile(resolveMetadataPath(cwd, aiwgRoot, rule), 'utf8'), relations);
|
|
70
71
|
await emitShowCard(cwd, aiwgRoot, fallbackEntry, corpusMatch.path, content, params, bindings, { uninstalled: !installed, installed, hint: installHint,
|
|
71
|
-
...(localPin ? { local_pin: localPin } : {}) }, true);
|
|
72
|
+
...(localPin ? { local_pin: localPin } : {}), ...templateRelationFields(fallbackEntry, relations) }, true);
|
|
72
73
|
return;
|
|
73
74
|
}
|
|
74
75
|
}
|
|
@@ -171,6 +172,7 @@ export async function showArtifact(cwd, params) {
|
|
|
171
172
|
}, relations);
|
|
172
173
|
const providerModels = resourceSource === 'local' ? await loadProviderModelMetadata(cwd, aiwgRoot) : null;
|
|
173
174
|
await emitShowCard(cwd, aiwgRoot, entry, filePath, content, params, bindings, {
|
|
175
|
+
...templateRelationFields(entry, relations),
|
|
174
176
|
provenance: {
|
|
175
177
|
graph: entry.indexGraph ?? null,
|
|
176
178
|
scope: entry.indexScope ?? null,
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// Shape template relationships consistently for show, discover, and prompt lookup.
|
|
2
|
+
import { discoveryIdForEntry } from './query-engine-entries.js';
|
|
3
|
+
export function templateRelationFields(entry, reader, limit = Infinity, includePaths = true) {
|
|
4
|
+
if (!reader)
|
|
5
|
+
return {};
|
|
6
|
+
const describe = (type, id, item) => {
|
|
7
|
+
const aliases = type === 'template' ? reader.index.aliases.templates?.[item.name]
|
|
8
|
+
: reader.index.aliases.targets[`${type}:${item.name}`];
|
|
9
|
+
const selector = aliases?.length === 1 && /^[a-zA-Z0-9][a-zA-Z0-9_.:-]*$/.test(item.name) ? item.name : id;
|
|
10
|
+
return { id, type, name: item.name, ...(includePaths ? { path: item.path } : {}), title: item.title ?? item.name,
|
|
11
|
+
show_command: `aiwg show ${type} ${selector}` };
|
|
12
|
+
};
|
|
13
|
+
const id = discoveryIdForEntry(entry);
|
|
14
|
+
if (entry.type === 'template') {
|
|
15
|
+
return { used_by: reader.targetsForTemplate(id).flatMap(target => {
|
|
16
|
+
const item = reader.index.targets[`${target.type}:${target.id}`];
|
|
17
|
+
return item ? [describe(target.type, target.id, { ...item, title: reader.index.artifacts?.[target.id]?.title })] : [];
|
|
18
|
+
}) };
|
|
19
|
+
}
|
|
20
|
+
if (!['skill', 'agent', 'flow', 'command'].includes(entry.type))
|
|
21
|
+
return {};
|
|
22
|
+
return { templates: reader.templatesForTarget(entry.type, id).slice(0, limit).flatMap(templateId => {
|
|
23
|
+
const template = reader.index.templates?.[templateId];
|
|
24
|
+
return template ? [describe('template', templateId, template)] : [];
|
|
25
|
+
}) };
|
|
26
|
+
}
|
|
27
|
+
export function templateRelationLines(fields) {
|
|
28
|
+
return Object.entries(fields).filter(([, items]) => items?.length).flatMap(([key, items]) => [
|
|
29
|
+
`\n## ${key === 'templates' ? 'Templates' : 'Used by'}`,
|
|
30
|
+
...items.map(item => `- ${item.name} (${item.type}): ${item.title} — \`${item.show_command}\``),
|
|
31
|
+
]);
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=query-engine-templates.js.map
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// Calibrate verbose-query evidence around the leading intent and weighted token coverage.
|
|
2
|
+
export function verboseQueryProfile(text, tokens, tokenize) {
|
|
3
|
+
// Short capability phrases retain their established lexical scores.
|
|
4
|
+
if (tokens.length <= 8)
|
|
5
|
+
return undefined;
|
|
6
|
+
const prose = text.replace(/(`+)[\s\S]*?\1/g, ' ');
|
|
7
|
+
const proseTokens = new Set(tokenize(prose));
|
|
8
|
+
const leading = new Set(tokenize(prose.split(/[.!?;:\n]/, 1)[0]).slice(0, 8));
|
|
9
|
+
const contextCount = tokens.filter(token => proseTokens.has(token) && !leading.has(token)).length;
|
|
10
|
+
// Context gets at most a quarter of the leading clause's total weight.
|
|
11
|
+
// Code-only words carry still less signal, but remain discoverable.
|
|
12
|
+
const contextWeight = Math.min(0.25, Math.max(1, leading.size) / (4 * Math.max(1, contextCount)));
|
|
13
|
+
const weights = new Map(tokens.map(token => [token,
|
|
14
|
+
leading.has(token) ? 1 : proseTokens.has(token) ? contextWeight : contextWeight * 0.2]));
|
|
15
|
+
const mass = (hits) => hits.reduce((sum, token) => sum + (weights.get(token) ?? 0), 0);
|
|
16
|
+
const total = mass(tokens);
|
|
17
|
+
return {
|
|
18
|
+
weight: (hits) => mass(hits) / Math.max(1, hits.length),
|
|
19
|
+
coverage: (matches) => {
|
|
20
|
+
const hits = [...new Set(matches.flatMap(match => match.matched_tokens ?? tokens))];
|
|
21
|
+
return total > 0 ? mass(hits) / total : 0;
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=query-engine-verbose.js.map
|
|
@@ -8,6 +8,7 @@ import { resolveRuleBindingTarget } from './query-engine.js';
|
|
|
8
8
|
import { Minimatch } from 'minimatch';
|
|
9
9
|
import { FRAMEWORK_RELATIONS_REVISION } from './framework-source-digest.js';
|
|
10
10
|
import { writeIndexFile } from './index-reader.js';
|
|
11
|
+
import { createDependencyResolver } from './index-dependencies.js';
|
|
11
12
|
import { RELATIONS_SCHEMA, RELATIONS_VERSION, RULE_TIERS, emptyRuleStats, } from './relations.js';
|
|
12
13
|
const TARGET_TYPES = new Set(['skill', 'agent', 'flow', 'command']);
|
|
13
14
|
const BINDING_TYPES = { skills: 'skill', agents: 'agent', flows: 'flow' };
|
|
@@ -28,9 +29,9 @@ function owner(entry) {
|
|
|
28
29
|
const kind = { frameworks: 'framework', addons: 'addon', extensions: 'extension' }[match[1]];
|
|
29
30
|
return { id: `${kind}:${match[2]}`, kind };
|
|
30
31
|
}
|
|
31
|
-
/** Only rule/action sources affect this projection; no
|
|
32
|
+
/** Only rule/action/template sources affect this projection; no file rereads. */
|
|
32
33
|
export function relationsFingerprint(entries) {
|
|
33
|
-
const sources = entries.filter(entry => TARGET_TYPES.has(entry.type) || ['rule', 'behavior'].includes(entry.type))
|
|
34
|
+
const sources = entries.filter(entry => TARGET_TYPES.has(entry.type) || ['rule', 'behavior', 'template'].includes(entry.type))
|
|
34
35
|
.map(entry => [entry.path, entry.checksum]).sort((a, b) => a[0].localeCompare(b[0]));
|
|
35
36
|
return { version: RELATIONS_VERSION, sources: `sha256:${createHash('sha256').update(JSON.stringify({ projectionVersion: FRAMEWORK_RELATIONS_REVISION, extractorVersion: INDEX_EXTRACTOR_VERSION, sources })).digest('hex')}` };
|
|
36
37
|
}
|
|
@@ -50,10 +51,10 @@ function statsFor(ids, index) {
|
|
|
50
51
|
export function buildRelations(entries) {
|
|
51
52
|
const index = {
|
|
52
53
|
$schema: RELATIONS_SCHEMA, version: RELATIONS_VERSION, generatedAt: '1970-01-01T00:00:00.000Z',
|
|
53
|
-
fingerprint: relationsFingerprint(entries), artifacts: {}, rules: {}, targets: {}, capabilities: {}, aliases: { targets: {}, rules: {} },
|
|
54
|
+
fingerprint: relationsFingerprint(entries), artifacts: {}, rules: {}, templates: {}, targets: {}, capabilities: {}, aliases: { targets: {}, rules: {}, templates: {} },
|
|
54
55
|
};
|
|
55
56
|
for (const entry of [...entries].sort((a, b) => a.path.localeCompare(b.path))) {
|
|
56
|
-
if (!TARGET_TYPES.has(entry.type) && !['rule', 'behavior'].includes(entry.type))
|
|
57
|
+
if (!TARGET_TYPES.has(entry.type) && !['rule', 'behavior', 'template'].includes(entry.type))
|
|
57
58
|
continue;
|
|
58
59
|
const { path: sourcePath, type, name, title, kernel, script, governedPaths } = entry;
|
|
59
60
|
index.artifacts[relationId(entry)] = { path: sourcePath, type, title, ...(name ? { name } : {}), ...(kernel ? { kernel } : {}), ...(script ? { script } : {}), ...(governedPaths ? { governedPaths } : {}) };
|
|
@@ -150,8 +151,52 @@ export function buildRelations(entries) {
|
|
|
150
151
|
index.aliases.targets[`skill:projected:${target.name}`] = [key];
|
|
151
152
|
target.rule_stats = statsFor(target.rules, index);
|
|
152
153
|
}
|
|
154
|
+
addTemplateRelations(entries, index);
|
|
153
155
|
return index;
|
|
154
156
|
}
|
|
157
|
+
/** Project resolved index dependencies, including Markdown-link reverse edges. */
|
|
158
|
+
function addTemplateRelations(entries, index) {
|
|
159
|
+
const byPath = Object.fromEntries(entries.map(entry => [entry.path, entry]));
|
|
160
|
+
const resolve = createDependencyResolver(byPath);
|
|
161
|
+
const templates = entries.filter(entry => entry.type === 'template').sort((a, b) => a.path.localeCompare(b.path));
|
|
162
|
+
const link = (component, template) => {
|
|
163
|
+
if (!TARGET_TYPES.has(component.type))
|
|
164
|
+
return;
|
|
165
|
+
const target = index.targets[`${component.type}:${relationId(component)}`];
|
|
166
|
+
const id = relationId(template);
|
|
167
|
+
const edges = target.templates ??= [];
|
|
168
|
+
if (edges.includes(id))
|
|
169
|
+
return;
|
|
170
|
+
edges.push(id);
|
|
171
|
+
index.templates[id].used_by.push({ type: component.type, id: relationId(component) });
|
|
172
|
+
};
|
|
173
|
+
for (const template of templates) {
|
|
174
|
+
const id = relationId(template);
|
|
175
|
+
index.templates[id] = { name: template.name ?? slug(template), path: template.path, title: template.title, used_by: [] };
|
|
176
|
+
for (const alias of new Set([template.name, slug(template), template.path].filter((value) => !!value))) {
|
|
177
|
+
(index.aliases.templates[alias] ??= []).push(id);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
for (const component of entries.filter(entry => TARGET_TYPES.has(entry.type))) {
|
|
181
|
+
for (const dependency of component.dependencies ?? []) {
|
|
182
|
+
const template = byPath[resolve(component.path, dependency) ?? ''];
|
|
183
|
+
if (template?.type === 'template')
|
|
184
|
+
link(component, template);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
for (const template of templates)
|
|
188
|
+
for (const dependent of template.dependents ?? []) {
|
|
189
|
+
if (byPath[dependent])
|
|
190
|
+
link(byPath[dependent], template);
|
|
191
|
+
}
|
|
192
|
+
for (const target of Object.values(index.targets)) {
|
|
193
|
+
if (target.projected_from)
|
|
194
|
+
target.templates = [...(index.targets[`${target.projected_from.type}:${target.projected_from.id}`].templates ?? [])];
|
|
195
|
+
target.templates?.sort();
|
|
196
|
+
}
|
|
197
|
+
for (const template of Object.values(index.templates))
|
|
198
|
+
template.used_by.sort((a, b) => `${a.type}:${a.id}`.localeCompare(`${b.type}:${b.id}`));
|
|
199
|
+
}
|
|
155
200
|
export async function writeRelations(entries, cwd, indexDir, force = false, existingDir = indexDir) {
|
|
156
201
|
const values = Object.values(entries);
|
|
157
202
|
const fingerprint = relationsFingerprint(values);
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import fs from 'node:fs';
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import { getGraphIndexDir } from './types.js';
|
|
5
|
-
import { resolveFrameworkIndexRoot } from './framework-index-paths.js';
|
|
5
|
+
import { resolveFrameworkCorpusRoot, resolveFrameworkIndexRoot } from './framework-index-paths.js';
|
|
6
6
|
import { frameworkSourceDigest } from './framework-source-digest.js';
|
|
7
7
|
import { createHash } from 'node:crypto';
|
|
8
8
|
import { loadRulePinConfigs, resolveRulePins } from '../rules/pins.mjs';
|
|
@@ -25,6 +25,15 @@ export class RelationsReader {
|
|
|
25
25
|
this.index = index;
|
|
26
26
|
this.pinnedRuleIds = pinnedRuleIds;
|
|
27
27
|
}
|
|
28
|
+
templatesForTarget(type, id) {
|
|
29
|
+
const key = `${type}:${id}`;
|
|
30
|
+
const resolved = Object.hasOwn(this.index.targets, key) ? key : lookupAlias(this.index.aliases.targets, key);
|
|
31
|
+
return [...(resolved ? this.index.targets[resolved]?.templates ?? [] : [])];
|
|
32
|
+
}
|
|
33
|
+
targetsForTemplate(id) {
|
|
34
|
+
const resolved = Object.hasOwn(this.index.templates ?? {}, id) ? id : lookupAlias(this.index.aliases.templates ?? {}, id);
|
|
35
|
+
return resolved ? (this.index.templates?.[resolved]?.used_by ?? []).map(target => ({ ...target })) : [];
|
|
36
|
+
}
|
|
28
37
|
rulesForTarget(type, id) {
|
|
29
38
|
const key = `${type}:${id}`;
|
|
30
39
|
const resolved = Object.hasOwn(this.index.targets, key) ? key : lookupAlias(this.index.aliases.targets, key);
|
|
@@ -91,8 +100,9 @@ function selectPrebuiltRelationsSource(cwd, cacheSourceDigest = true) {
|
|
|
91
100
|
return { reader: null, reason: 'unsupported prebuilt relationship schema' };
|
|
92
101
|
if (stamp.package_version !== pkg.version)
|
|
93
102
|
return { reader: null, reason: 'prebuilt relationship package version differs' };
|
|
94
|
-
|
|
95
|
-
|
|
103
|
+
const sourceDigest = frameworkSourceDigest(root, cacheSourceDigest);
|
|
104
|
+
if (stamp.source_digest !== sourceDigest)
|
|
105
|
+
return { reader: null, sourceDigest, reason: 'prebuilt relationship source digest differs (modified, added or removed corpus source)' };
|
|
96
106
|
const text = fs.readFileSync(path.join(dir, 'relations.json'), 'utf8');
|
|
97
107
|
if (createHash('sha256').update(text).digest('hex') !== stamp.checksums['relations.json'])
|
|
98
108
|
return { reader: null, reason: 'prebuilt relationship checksum differs' };
|
|
@@ -104,7 +114,7 @@ function selectPrebuiltRelationsSource(cwd, cacheSourceDigest = true) {
|
|
|
104
114
|
|| index.fingerprint?.version !== RELATIONS_VERSION || !/^sha256:[a-f0-9]{64}$/.test(index.fingerprint.sources)
|
|
105
115
|
|| !index.rules || !index.targets || !index.capabilities || !index.aliases?.targets || !index.aliases.rules)
|
|
106
116
|
return { reader: null, reason: 'unsupported prebuilt relationship table' };
|
|
107
|
-
return { reader: new RelationsReader(index) };
|
|
117
|
+
return { reader: new RelationsReader(index), sourceDigest };
|
|
108
118
|
}
|
|
109
119
|
catch {
|
|
110
120
|
return { reader: null, reason: 'prebuilt relationship tables unavailable or corrupt' };
|
|
@@ -113,24 +123,30 @@ function selectPrebuiltRelationsSource(cwd, cacheSourceDigest = true) {
|
|
|
113
123
|
/** Apply local pins only after cache validation so policy errors cannot masquerade as cache misses. */
|
|
114
124
|
export function selectPrebuiltRelations(cwd, pinCwd = cwd, cacheSourceDigest = true) {
|
|
115
125
|
const selected = selectPrebuiltRelationsSource(cwd, cacheSourceDigest);
|
|
116
|
-
return selected.reader ? { reader: readerWithPins(selected.reader.index, pinCwd) } : selected;
|
|
126
|
+
return selected.reader ? { ...selected, reader: readerWithPins(selected.reader.index, pinCwd) } : selected;
|
|
117
127
|
}
|
|
118
128
|
/** Synchronous read API: prebuilt first, then this root's built sidecar. */
|
|
119
129
|
export function loadRelations(cwd, pinCwd = cwd, cacheSourceDigest = true) {
|
|
120
130
|
return selectPrebuiltRelations(cwd, pinCwd, cacheSourceDigest).reader ?? loadBuiltRelations(cwd, pinCwd);
|
|
121
131
|
}
|
|
122
132
|
/** Read paths reconcile through the existing lock/receipt when prebuilt is stale. */
|
|
123
|
-
export async function ensureRelations(cwd, pinCwd = cwd) {
|
|
124
|
-
const selected = selectPrebuiltRelations(cwd, pinCwd);
|
|
133
|
+
export async function ensureRelations(cwd, pinCwd = cwd, options = {}) {
|
|
134
|
+
const selected = options.selection ?? selectPrebuiltRelations(cwd, pinCwd);
|
|
125
135
|
if (selected.reader)
|
|
126
136
|
return selected.reader;
|
|
127
137
|
const root = resolveFrameworkIndexRoot(cwd);
|
|
128
|
-
if (
|
|
138
|
+
if ((options.verbose || process.argv.includes('--verbose') || process.argv.includes('--debug')
|
|
139
|
+
|| ['debug', 'info'].includes(process.env.AIWG_LOG_LEVEL ?? ''))
|
|
140
|
+
&& fs.existsSync(path.join(root, PREBUILT_RELATIONS_DIR, 'manifest.json'))) {
|
|
129
141
|
console.error(`Relationship tables: ${selected.reason}; using the per-root index (rebuilding if stale).`);
|
|
130
142
|
}
|
|
131
143
|
const { refreshFrameworkCapabilities } = await import('./framework-capabilities.js');
|
|
132
|
-
|
|
133
|
-
|
|
144
|
+
if (!options.reconciled)
|
|
145
|
+
await refreshFrameworkCapabilities(root, false);
|
|
146
|
+
const reader = loadBuiltRelations(cwd, pinCwd);
|
|
147
|
+
if (!reader && (resolveFrameworkCorpusRoot(root) || fs.existsSync(path.join(root, PREBUILT_RELATIONS_DIR, 'manifest.json'))))
|
|
148
|
+
throw new Error('Relationship tables unavailable: no usable prebuilt or per-root index. Run `aiwg index build --graph framework`.');
|
|
149
|
+
return reader;
|
|
134
150
|
}
|
|
135
151
|
// Convenience entry points; use one loaded reader for a batch of lookups.
|
|
136
152
|
export function rulesForTarget(type, id, cwd = process.cwd()) {
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// Extract concrete template paths and resolve them within their owning bundle.
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
export function isTemplateReference(value) {
|
|
4
|
+
return /(?:^|\/)templates\//.test(value) && /\.[\w-]+$/.test(value);
|
|
5
|
+
}
|
|
6
|
+
export function extractTemplateReferences(content) {
|
|
7
|
+
const references = new Set();
|
|
8
|
+
// Scan whole tokens once: do not restart an unanchored path regex at every
|
|
9
|
+
// character of a long non-matching path. Code samples also contain references.
|
|
10
|
+
for (const match of content.matchAll(/[^\s`"'()[\]{},;:<>|\\]+/g)) {
|
|
11
|
+
const token = match[0].replace(/^@/, '').replace(/[.!?]+$/, '').split('#')[0];
|
|
12
|
+
if (!/^(?:\$AIWG_ROOT\/|\.{1,2}\/|[\w-])/.test(token))
|
|
13
|
+
continue;
|
|
14
|
+
if (!/^[\w$./-]+$/.test(token) || !isTemplateReference(token))
|
|
15
|
+
continue;
|
|
16
|
+
references.add(token);
|
|
17
|
+
}
|
|
18
|
+
return [...references];
|
|
19
|
+
}
|
|
20
|
+
export function sourceBundleRoot(sourcePath) {
|
|
21
|
+
return sourcePath.replace(/\\/g, '/').match(/^(.*?(?:agentic\/code|\.aiwg)\/(?:addons|frameworks|extensions)\/[^/]+)\//)?.[1];
|
|
22
|
+
}
|
|
23
|
+
/** Ordered repo-relative candidates, shared by graph resolution and linting. */
|
|
24
|
+
export function templateReferenceCandidates(sourcePath, reference) {
|
|
25
|
+
const target = reference.replace(/^@/, '');
|
|
26
|
+
if (target.startsWith('$AIWG_ROOT/'))
|
|
27
|
+
return [path.posix.normalize(target.slice(11))];
|
|
28
|
+
if (target.startsWith('agentic/'))
|
|
29
|
+
return [path.posix.normalize(target)];
|
|
30
|
+
if (target.startsWith('./') || target.startsWith('../')) {
|
|
31
|
+
return [path.posix.normalize(path.posix.join(path.posix.dirname(sourcePath), target))];
|
|
32
|
+
}
|
|
33
|
+
const bundle = sourceBundleRoot(sourcePath);
|
|
34
|
+
if (target.startsWith('templates/'))
|
|
35
|
+
return bundle ? [`${bundle}/${target}`] : [target];
|
|
36
|
+
// Explicit <bundle>/templates/... shorthand may name a sibling bundle.
|
|
37
|
+
if (/^[\w-]+\/(?:[\w-]+\/)*templates\//.test(target)) {
|
|
38
|
+
return ['frameworks', 'addons', 'extensions'].map(group => `agentic/code/${group}/${target}`);
|
|
39
|
+
}
|
|
40
|
+
return [path.posix.normalize(path.posix.join(path.posix.dirname(sourcePath), target))];
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=template-references.js.map
|
|
@@ -110,7 +110,7 @@ export const INDEX_VERSION = '1.0.0';
|
|
|
110
110
|
* making the serialized index schema incompatible; a mismatch simply forces a
|
|
111
111
|
* one-time content re-extraction during the next incremental build.
|
|
112
112
|
*/
|
|
113
|
-
export const INDEX_EXTRACTOR_VERSION = '2026.
|
|
113
|
+
export const INDEX_EXTRACTOR_VERSION = '2026.11.06.1';
|
|
114
114
|
/**
|
|
115
115
|
* Built-in graph definitions
|
|
116
116
|
*/
|
|
@@ -16,6 +16,10 @@ export function bundleProviders(installed, id, requested) {
|
|
|
16
16
|
const entry = Object.entries(installed).find(([key]) => frameworkRegistryId(key) === frameworkRegistryId(id))?.[1];
|
|
17
17
|
return Object.keys(entry?.deployedTo ?? {}).filter(provider => !requested || requested.split(',').includes(provider));
|
|
18
18
|
}
|
|
19
|
+
function hasLegacyAllSelection(config, provider) {
|
|
20
|
+
const flags = config.installed.all?.deployedTo[provider];
|
|
21
|
+
return provider !== 'flue' && flags !== undefined && flags.skipUtils === undefined && flags.kernelOnly === undefined;
|
|
22
|
+
}
|
|
19
23
|
export async function expectedBundleOwners(config, provider, frameworkRoot) {
|
|
20
24
|
const selected = Object.keys(config.installed).filter(id => bundleProviders(config.installed, id, provider).length);
|
|
21
25
|
const expected = new Set(selected.map(frameworkRegistryId));
|
|
@@ -25,7 +29,7 @@ export async function expectedBundleOwners(config, provider, frameworkRoot) {
|
|
|
25
29
|
continue;
|
|
26
30
|
const flags = config.installed[id].deployedTo[provider];
|
|
27
31
|
if (id === 'all' && provider !== 'flue' && (flags.skipUtils !== undefined || flags.kernelOnly !== undefined)) {
|
|
28
|
-
|
|
32
|
+
// The composed pass owns outputs as `all`; expanding its scope must retain that owner.
|
|
29
33
|
for (const name of fs.readdirSync(path.join(frameworkRoot, 'agentic/code/frameworks'))) {
|
|
30
34
|
if (fs.existsSync(path.join(frameworkRoot, 'agentic/code/frameworks', name, 'manifest.json')))
|
|
31
35
|
expected.add(frameworkRegistryId(name));
|
|
@@ -104,7 +108,7 @@ export async function pruneUndeclaredBundles(project, config, requested, dryRun
|
|
|
104
108
|
continue;
|
|
105
109
|
const selected = expected.get(provider);
|
|
106
110
|
for (const owner of receiptOwners(project, provider)) {
|
|
107
|
-
if (hashPruned.has(`${provider}:${owner}`) || (
|
|
111
|
+
if (hashPruned.has(`${provider}:${owner}`) || hasLegacyAllSelection(config, provider) || selected.has(frameworkRegistryId(owner)))
|
|
108
112
|
continue;
|
|
109
113
|
const implicit = !history[provider]?.[frameworkRegistryId(owner)] && Object.values(history[provider] ?? {}).some(entry => entry.produces?.includes(frameworkRegistryId(owner)) || entry.produces?.includes('*'));
|
|
110
114
|
if (implicit)
|
|
@@ -114,7 +118,7 @@ export async function pruneUndeclaredBundles(project, config, requested, dryRun
|
|
|
114
118
|
continue;
|
|
115
119
|
}
|
|
116
120
|
const otherProviders = [...expected].filter(([other, owners]) => other !== provider
|
|
117
|
-
&& (history[other]?.[frameworkRegistryId(owner)]?.copy || history[other]?.[frameworkRegistryId(owner)]?.package || owners.has(frameworkRegistryId(owner)) || other
|
|
121
|
+
&& (history[other]?.[frameworkRegistryId(owner)]?.copy || history[other]?.[frameworkRegistryId(owner)]?.package || owners.has(frameworkRegistryId(owner)) || hasLegacyAllSelection(config, other))).map(([other]) => other);
|
|
118
122
|
const sharedRoots = deployedSkillRoots(project, provider).filter(root => otherProviders.some(other => deployedSkillRoots(project, other).includes(root)));
|
|
119
123
|
console.log(`${dryRun ? 'Would remove' : 'Removing'} ${bundleUseName(owner)} for ${provider}`);
|
|
120
124
|
// A temporary historical record supplies context for the public per-bundle
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// Render shipped session handoff documents and persist them beside their checkpoint record.
|
|
2
|
+
import { mkdir, readFile, rm, writeFile } from 'node:fs/promises';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { assertCheckpointRecord } from './checkpoint-record.js';
|
|
5
|
+
export async function writeCheckpointHandoff(frameworkRoot, checkpointsDir, record, input) {
|
|
6
|
+
const template = await readFile(join(frameworkRoot, 'agentic/code/addons/aiwg-utils/templates/checkpoint-handoff.md'), 'utf8');
|
|
7
|
+
const dir = join(checkpointsDir, record.id);
|
|
8
|
+
record.handoffPath = join(dir, 'handoff.md');
|
|
9
|
+
record.nextSessionPromptPath = join(dir, 'next-session-prompt.md');
|
|
10
|
+
assertCheckpointRecord(record, join(record.id, 'checkpoint.json'));
|
|
11
|
+
const fields = {
|
|
12
|
+
scope: input.scope ?? '[TODO: Define scope and ownership.]',
|
|
13
|
+
state: [
|
|
14
|
+
`Checkpoint: ${record.id}${record.name ? ` (${record.name})` : ''}`,
|
|
15
|
+
`Created: ${record.createdAt}`,
|
|
16
|
+
`Working directory: ${record.cwd}`,
|
|
17
|
+
`Phase: ${record.phase ?? '[TODO: Record current phase.]'}`,
|
|
18
|
+
`Step: ${record.step ?? '[TODO: Record current step.]'}`,
|
|
19
|
+
...(record.gitHead ? [`Git HEAD: ${record.gitHead}`] : []),
|
|
20
|
+
record.note ?? '[TODO: Describe completed work, verification, and outstanding state.]',
|
|
21
|
+
].join('\n\n'),
|
|
22
|
+
todos: input.todos.length ? input.todos.map((todo, i) => `${i + 1}. ${todo}`).join('\n')
|
|
23
|
+
: '1. [TODO: List remaining work in execution order.]',
|
|
24
|
+
constraints: input.constraints.length ? input.constraints.map(item => `- ${item}`).join('\n')
|
|
25
|
+
: '- [TODO: Record binding constraints.]',
|
|
26
|
+
links: record.artifacts.length ? record.artifacts.map(path => `- ${path}`).join('\n')
|
|
27
|
+
: '- [TODO: Link relevant artifacts and references.]',
|
|
28
|
+
};
|
|
29
|
+
const handoff = template.replace(/\{\{(\w+)\}\}/g, (match, key) => fields[key] ?? match);
|
|
30
|
+
const prompt = [
|
|
31
|
+
`Continue checkpoint ${record.id}${record.name ? ` (${record.name})` : ''} in ${record.cwd}.`,
|
|
32
|
+
'Read WORKSPACE.md and AIWG.md if present, then read the handoff:',
|
|
33
|
+
record.handoffPath,
|
|
34
|
+
'Follow its binding constraints and ordered to-do list. Verify current state before continuing.',
|
|
35
|
+
'',
|
|
36
|
+
].join('\n');
|
|
37
|
+
await mkdir(dir);
|
|
38
|
+
try {
|
|
39
|
+
await writeFile(record.handoffPath, handoff, { flag: 'wx' });
|
|
40
|
+
await writeFile(record.nextSessionPromptPath, prompt, { flag: 'wx' });
|
|
41
|
+
await writeFile(join(dir, 'checkpoint.json'), `${JSON.stringify(record, null, 2)}\n`, { flag: 'wx' });
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
await rm(dir, { recursive: true, force: true });
|
|
45
|
+
throw error;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=checkpoint-handoff.js.map
|