@aiwg/cli 2026.10.15 → 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/agentic/code/providers/pi/aiwg-bridge.ts +45 -7
- package/dist/src/artifacts/citation-parser.js +7 -6
- package/dist/src/artifacts/corpus-tools/citation-densify.js +4 -2
- package/dist/src/artifacts/corpus-tools/cli.js +8 -3
- package/dist/src/artifacts/corpus-tools/discovery-log.js +26 -24
- package/dist/src/artifacts/corpus-tools/expand-cli.js +3 -2
- package/dist/src/artifacts/corpus-tools/expand-dates.js +107 -0
- package/dist/src/artifacts/corpus-tools/expand-queue.js +4 -1
- package/dist/src/artifacts/corpus-tools/expand-review.js +104 -0
- package/dist/src/artifacts/corpus-tools/expand-state.js +17 -1
- package/dist/src/artifacts/corpus-tools/expand.js +16 -17
- package/dist/src/artifacts/corpus-tools/induction-audit.js +7 -6
- package/dist/src/artifacts/corpus-tools/integrity-scan.js +3 -3
- package/dist/src/artifacts/corpus-tools/radar-shared.js +7 -9
- package/dist/src/artifacts/corpus-tools/ref-files.js +11 -0
- package/dist/src/artifacts/corpus-tools/resolve-cli.js +11 -3
- package/dist/src/artifacts/corpus-tools/resolve.js +42 -11
- package/dist/src/artifacts/corpus-tools/retrieval-lab.js +2 -1
- package/dist/src/artifacts/corpus-tools/sidecar-lint.js +4 -4
- package/dist/src/artifacts/corpus-tools/sidecar-repair.js +2 -1
- package/dist/src/artifacts/corpus-views/ref-parser.js +3 -17
- package/dist/src/artifacts/graph-query.js +5 -3
- package/dist/src/artifacts/hybrid-query.js +11 -2
- package/dist/src/artifacts/index-refresh.js +2 -0
- 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/daemon.js +17 -1
- package/dist/src/cli/handlers/doctor-args.js +10 -5
- package/dist/src/cli/handlers/doctor-help.js +4 -1
- package/dist/src/cli/handlers/index.js +2 -2
- 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-resource-sample.js +10 -0
- package/dist/src/cli/handlers/models.js +5 -3
- package/dist/src/cli/handlers/regenerate.js +8 -16
- 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/sessions.js +7 -7
- 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 -1976
- package/dist/src/cli/handlers/update.js +157 -0
- package/dist/src/cli/handlers/use.js +14 -4
- package/dist/src/cli/handlers/utilities.js +3 -560
- package/dist/src/cli/handlers/utility-doctor.js +412 -0
- package/dist/src/cli/scope-resolver.js +1 -142
- package/dist/src/cli/services/deployment-verification.js +0 -1
- package/dist/src/cli/user-scope-mirror.js +173 -0
- package/dist/src/config/aiwg-config.js +2 -1
- package/dist/src/config/authorization-cli.js +7 -3
- package/dist/src/config/dispatch-host-thresholds.js +2 -0
- package/dist/src/config/dispatch-thresholds-runtime.d.mts +3 -2
- package/dist/src/config/dispatch-thresholds-runtime.mjs +21 -7
- package/dist/src/config/framework-aliases.js +12 -0
- package/dist/src/config/host-resource-report.d.mts +24 -0
- package/dist/src/config/host-resource-report.mjs +110 -0
- package/dist/src/config/host-resource-runtime.d.mts +37 -0
- package/dist/src/config/host-resource-runtime.mjs +296 -0
- package/dist/src/config/installed-selection.js +22 -0
- package/dist/src/config/worker-invocation-marker.d.mts +1 -0
- package/dist/src/config/worker-invocation-marker.mjs +2 -0
- 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/heldout/access.js +74 -0
- package/dist/src/decision/heldout/calibration.js +1 -0
- package/dist/src/decision/heldout/collector.js +8 -1
- package/dist/src/decision/sensitivity/comparative-gates.js +135 -0
- package/dist/src/decision/sensitivity/comparative.js +18 -41
- package/dist/src/effects/verifiers/file.js +22 -5
- package/dist/src/extensions/claude-attribution.js +82 -0
- package/dist/src/extensions/claude-hooks-installer.js +133 -69
- package/dist/src/extensions/commands/daemon.js +109 -0
- package/dist/src/extensions/commands/definitions.js +5 -89
- package/dist/src/gates/evaluate.js +2 -358
- package/dist/src/gates/heldout.js +17 -7
- 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/lint/check-patterns.js +163 -0
- package/dist/src/lint/checks.js +268 -0
- package/dist/src/lint/reference-resolution.js +54 -0
- package/dist/src/lint/runner.js +3 -465
- package/dist/src/mcp/helpers.mjs +11 -1
- package/dist/src/mcp/json-document.mjs +29 -0
- package/dist/src/mcp/muse-native-config.mjs +1 -28
- package/dist/src/memory/project-registry.js +44 -4
- package/dist/src/mission-protocol/worker-review-gate.js +7 -0
- package/dist/src/models/worker-plan.js +36 -5
- package/dist/src/models/wrapper-deployment.js +25 -12
- package/dist/src/models/wrapper-enforcement.js +47 -7
- package/dist/src/network-analysis/research.js +2 -1
- 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/policy/hitl-check.js +14 -4
- package/dist/src/policy/hitl-consume.js +54 -0
- package/dist/src/policy/hitl-receipt.js +2 -0
- package/dist/src/policy/hitl.js +11 -3
- 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/provider-context-contracts.js +162 -0
- package/dist/src/providers/provider-definition-schema.js +136 -0
- package/dist/src/providers/provider-definitions.js +8 -1298
- package/dist/src/providers/provider-seeds-1.js +360 -0
- package/dist/src/providers/provider-seeds-2.js +387 -0
- package/dist/src/providers/provider-seeds-3.js +262 -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/clients/arxiv.js +4 -30
- package/dist/src/research/clients/base.js +48 -22
- package/dist/src/research/identity.js +42 -4
- package/dist/src/research/query-cli.js +3 -87
- package/dist/src/research/query-options.js +87 -0
- package/dist/src/research/reference-match.js +105 -24
- package/dist/src/research/services/acquisition.js +9 -7
- package/dist/src/research/services/citation.js +5 -2
- package/dist/src/research/types.js +2 -0
- package/dist/src/rules/activation.mjs +15 -6
- package/dist/src/rules/core-startup.mjs +2 -2
- package/dist/src/serve/mission-conductor.js +52 -4
- package/dist/src/serve/mission-summary.js +56 -0
- package/dist/src/sessions/adapters/grok-build-native.js +23 -0
- package/dist/src/sessions/adapters/grok-build.js +14 -7
- package/dist/src/sessions/workspace-discovery.js +5 -5
- package/dist/src/smiths/context-pipeline/aiwg-md.js +39 -46
- package/dist/src/smiths/context-pipeline/claude-hook.js +1 -1
- package/dist/src/smiths/context-pipeline/code-regions.js +28 -0
- package/dist/src/smiths/context-pipeline/context-file-safety.js +3 -0
- package/dist/src/smiths/context-pipeline/finalization.js +81 -51
- package/dist/src/smiths/context-pipeline/generator.js +10 -11
- package/dist/src/smiths/context-pipeline/managed-hook.js +1 -1
- package/dist/src/smiths/context-pipeline/muse-bridge.js +2 -2
- package/dist/src/smiths/context-pipeline/provider-policy.js +6 -12
- package/dist/src/smiths/context-pipeline/workspace-audit.js +299 -0
- package/dist/src/smiths/context-pipeline/workspace-bootstrap.js +148 -0
- package/dist/src/smiths/context-pipeline/workspace-context-shared.js +111 -0
- package/dist/src/smiths/context-pipeline/workspace-context.js +8 -1373
- package/dist/src/smiths/context-pipeline/workspace-doctor.js +192 -0
- package/dist/src/smiths/context-pipeline/workspace-document.js +201 -0
- package/dist/src/smiths/context-pipeline/workspace-extraction.js +205 -0
- package/dist/src/smiths/context-pipeline/workspace-migration.js +250 -0
- package/dist/src/smiths/hook-bridge/index.js +9 -0
- package/package.json +13 -1
- package/schemas/decision/D17StudyProtocol.v1.schema.json +39 -67
- package/schemas/decision/D29Study.v10.schema.json +65 -0
- package/tools/agents/deploy-agents.mjs +24 -675
- 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 +20 -1
- package/tools/agents/providers/context-write.mjs +4 -0
- package/tools/agents/providers/hermes-startup.mjs +0 -5
- package/tools/agents/providers/muse.mjs +7 -2
- package/tools/agents/providers/pi.mjs +3 -1
- package/tools/agents/providers/rule-delivery-surface.mjs +359 -0
- package/tools/agents/providers/rule-delivery.mjs +20 -1144
- package/tools/agents/providers/rule-deployment-commit.mjs +148 -0
- package/tools/agents/providers/rule-deployment-prepare.mjs +461 -0
- package/tools/agents/providers/rule-deployment-state.mjs +300 -0
- package/tools/agents/providers/rule-projection.mjs +3 -0
- package/tools/daemon/README.md +511 -0
- package/tools/daemon/adapters/base-adapter.mjs +84 -0
- package/tools/daemon/adapters/webhook-adapter.mjs +107 -0
- package/tools/daemon/agent-supervisor.mjs +299 -0
- package/tools/daemon/automation-engine.mjs +310 -0
- package/tools/daemon/autonomous-engine.mjs +346 -0
- package/tools/daemon/behavior-loader.mjs +316 -0
- package/tools/daemon/behavior.mjs +174 -0
- package/tools/daemon/concierge/intent-router.mjs +401 -0
- package/tools/daemon/concierge/orchestrator.mjs +272 -0
- package/tools/daemon/concierge/response-translator.mjs +462 -0
- package/tools/daemon/config.mjs +377 -0
- package/tools/daemon/cron-scheduler.mjs +178 -0
- package/tools/daemon/daemon-main.mjs +1169 -0
- package/tools/daemon/event-router.mjs +84 -0
- package/tools/daemon/file-watcher.mjs +383 -0
- package/tools/daemon/index.mjs +1181 -0
- package/tools/daemon/init-profile.mjs +124 -0
- package/tools/daemon/ipc-client.mjs +197 -0
- package/tools/daemon/ipc-ops-handlers.mjs +236 -0
- package/tools/daemon/ipc-server.mjs +275 -0
- package/tools/daemon/maintenance-owner.mjs +79 -0
- package/tools/daemon/memory-manager.mjs +386 -0
- package/tools/daemon/message-router.mjs +194 -0
- package/tools/daemon/provider-watcher.mjs +585 -0
- package/tools/daemon/pty-adapter.mjs +420 -0
- package/tools/daemon/repl-chat.mjs +359 -0
- package/tools/daemon/resource-bounds.mjs +88 -0
- package/tools/daemon/sandbox-transport.mjs +295 -0
- package/tools/daemon/scheduled-task-runner.mjs +535 -0
- package/tools/daemon/task-store.mjs +450 -0
- package/tools/daemon/tmux-manager.mjs +324 -0
- package/tools/daemon/update-policy.mjs +517 -0
- package/tools/daemon/web-server.mjs +399 -0
- package/tools/daemon/web-ui/index.html +585 -0
- package/tools/daemon/web-ui/styles.css +156 -0
- package/tools/docker/Dockerfile.daemon +35 -0
- package/tools/docker/container-manager.mjs +291 -0
- package/tools/messaging/adapter-registry.mjs +230 -0
- package/tools/messaging/adapters/base.mjs +326 -0
- package/tools/messaging/adapters/discord.mjs +462 -0
- package/tools/messaging/adapters/slack.mjs +402 -0
- package/tools/messaging/adapters/telegram.mjs +552 -0
- package/tools/messaging/chat-handler.mjs +297 -0
- package/tools/messaging/command-router.mjs +269 -0
- package/tools/messaging/event-bus.mjs +199 -0
- package/tools/messaging/index.mjs +456 -0
- package/tools/messaging/message-formatter.mjs +320 -0
- package/tools/messaging/room-manager.mjs +277 -0
- package/tools/messaging/types.mjs +94 -0
- package/tools/providers/pi-bridge-policy.mjs +4 -0
- package/tools/ralph-external/daemon-supervisor.mjs +394 -0
- package/tools/ralph-external/lib/behavior-registry.mjs +270 -0
- package/tools/ralph-external/lib/worker-invocation-processes.mjs +7 -4
- package/tools/ralph-external/lib/worker-isolation-args.mjs +217 -0
- package/tools/ralph-external/lib/worker-isolation-status.mjs +19 -0
- package/tools/ralph-external/lib/worker-isolation.mjs +11 -237
- package/tools/ralph-external/lib/worker-overflow.mjs +10 -2
- package/tools/ralph-external/lib/worker-termination.mjs +15 -8
- package/tools/ralph-external/lib/worker-unit-cleanup.mjs +72 -0
- package/tools/ralph-external/session-launcher.mjs +7 -7
- package/tools/scripts/resource-preflight.mjs +3 -242
- package/vscode-extension/schemas/aiwg.config.v1.json +2 -4
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
// Apply project settings and context after provider file deployment.
|
|
2
2
|
import fs from 'node:fs';
|
|
3
3
|
import path from 'node:path';
|
|
4
|
+
import { importImpl } from '../../_resolve-impl.mjs';
|
|
4
5
|
import { initializeFrameworkWorkspace, ensureDir } from './base.mjs';
|
|
5
6
|
import { deployHookFile } from './claude.mjs';
|
|
6
7
|
import { deployConductorDataGuard } from './conductor-data-guard.mjs';
|
|
7
8
|
|
|
8
9
|
export async function postDeploy(targetDir, opts) {
|
|
9
10
|
initializeFrameworkWorkspace(targetDir, opts.mode, opts.dryRun, opts.srcRoot);
|
|
10
|
-
|
|
11
|
+
// Validate the data policy before publishing any settings; merge before its writes.
|
|
12
|
+
await deployConductorDataGuard(targetDir, 'claude', { ...opts, dryRun: true });
|
|
11
13
|
|
|
12
14
|
// Claude-specific post-deployment (settings.json, etc.)
|
|
13
15
|
const claudeDir = path.join(targetDir, '.claude');
|
|
@@ -15,6 +17,8 @@ export async function postDeploy(targetDir, opts) {
|
|
|
15
17
|
|
|
16
18
|
// If settings.json doesn't exist, create a minimal one
|
|
17
19
|
if (!fs.existsSync(settingsPath) && !opts.dryRun) {
|
|
20
|
+
const { captureDeploymentOutputs, recordDeploymentOutputs } = await importImpl(import.meta.url, 'providers/deployment-ownership.mjs');
|
|
21
|
+
const before = captureDeploymentOutputs([claudeDir]);
|
|
18
22
|
ensureDir(claudeDir);
|
|
19
23
|
const settings = {
|
|
20
24
|
version: '1.0',
|
|
@@ -25,9 +29,24 @@ export async function postDeploy(targetDir, opts) {
|
|
|
25
29
|
}
|
|
26
30
|
};
|
|
27
31
|
fs.writeFileSync(settingsPath, JSON.stringify(settings, null, 2), 'utf8');
|
|
32
|
+
recordDeploymentOutputs(before, [claudeDir], { ...opts, writtenFiles: [settingsPath] });
|
|
33
|
+
opts.writtenFiles?.push(settingsPath);
|
|
28
34
|
console.log('Created .claude/settings.json');
|
|
29
35
|
}
|
|
30
36
|
|
|
37
|
+
const addonPass = /(?:agentic\/code|\.aiwg)\/(?:addons|extensions)\//.test((opts.logicalInputPath?.(opts.srcRoot) || opts.srcRoot)?.replaceAll('\\', '/') || '');
|
|
38
|
+
|
|
39
|
+
// Reuse the settings owner's backup/atomic merge, independently of hooks.
|
|
40
|
+
if (opts.attribution !== false) {
|
|
41
|
+
const { installAiwgHooks } = await importImpl(import.meta.url, 'extensions/claude-hooks-installer.js');
|
|
42
|
+
const { deploymentOwner } = await importImpl(import.meta.url, 'providers/deployment-ownership.mjs');
|
|
43
|
+
const result = await installAiwgHooks({ frameworkSlug: deploymentOwner(opts), claimUnchangedSettings: !addonPass, projectPath: targetDir, frameworkRoot: opts.srcRoot || targetDir,
|
|
44
|
+
attribution: opts.attribution !== false, hooks: false, dryRun: opts.dryRun });
|
|
45
|
+
if (!opts.dryRun && result) opts.writtenFiles?.push(result.settingsPath);
|
|
46
|
+
for (const warning of result?.warnings || []) console.warn(`Claude settings: ${warning}`);
|
|
47
|
+
}
|
|
48
|
+
await deployConductorDataGuard(targetDir, 'claude', opts);
|
|
49
|
+
|
|
31
50
|
// Hook file architecture: write AIWG.md and wire @AIWG.md into CLAUDE.md
|
|
32
51
|
if (opts.srcRoot && opts.contextFiles !== false) {
|
|
33
52
|
deployHookFile(targetDir, opts);
|
|
@@ -38,3 +38,7 @@ export function retireLegacyBridge(content) {
|
|
|
38
38
|
if (!ownership) throw new Error('Startup ownership layer is unavailable', { cause: loadError });
|
|
39
39
|
return ownership.retireLegacyBridge(content);
|
|
40
40
|
}
|
|
41
|
+
|
|
42
|
+
// Generated context outputs and the optional notes input share staging/rollback ownership.
|
|
43
|
+
export const GENERATED_CONTEXT_NAMES = ['AGENTS.md', 'AIWG.md', 'WORKSPACE.md', 'CLAUDE.md', 'WARP.md', '.hermes.md'];
|
|
44
|
+
export const OPERATOR_CONTEXT_NAMES = ['.aiwg/AIWG.md'];
|
|
@@ -58,11 +58,6 @@ whenever the user mentions AIWG, a framework name (sdlc, research, forensics,
|
|
|
58
58
|
ops, marketing, security-engineering, media-curator, knowledge-base), or
|
|
59
59
|
capability keywords (skill, agent, command, rule, workflow).
|
|
60
60
|
|
|
61
|
-
### Rule: no-attribution
|
|
62
|
-
Never add AI-tool attribution to commits, PRs, code, or docs. No \`Co-Authored-By:\`,
|
|
63
|
-
no "Generated with", no "Written by [AI tool]". The AI is a tool; tools don't sign
|
|
64
|
-
their output. Applies to ALL platforms (Claude, Codex, Copilot, Cursor, etc.).
|
|
65
|
-
|
|
66
61
|
### Rule: citation-policy
|
|
67
62
|
Never fabricate citations, DOIs, URLs, or page numbers. Only cite sources that
|
|
68
63
|
exist in the research corpus (.aiwg/research/sources/). Match claim strength
|
|
@@ -49,7 +49,9 @@ import {
|
|
|
49
49
|
resolveMuseXdgSkillsDir,
|
|
50
50
|
museXdgSkillsDirRemediation,
|
|
51
51
|
} from './muse-paths.mjs';
|
|
52
|
-
import {
|
|
52
|
+
import { importImpl } from '../../_resolve-impl.mjs';
|
|
53
|
+
const { captureDeploymentOutputs, recordDeploymentOutputs } = await importImpl(import.meta.url, 'providers/deployment-ownership.mjs');
|
|
54
|
+
import { assertMuseUserSettingsPath, deployMuseHooks, deployMuseMcp } from './muse-hooks.mjs';
|
|
53
55
|
|
|
54
56
|
export const name = 'muse';
|
|
55
57
|
export const aliases = []; // ADR: no aliases (no muse-spark, muse-code, spark, meta)
|
|
@@ -241,7 +243,10 @@ export async function postDeploy(targetDir, opts = {}) {
|
|
|
241
243
|
// #228 — optional MCP settings profile. Explicit opt-in only (--mcp);
|
|
242
244
|
// default `aiwg use --provider muse` never touches user settings.
|
|
243
245
|
if (fullDeploy && opts.mcp === true) {
|
|
244
|
-
|
|
246
|
+
const settingsPath = assertMuseUserSettingsPath(opts.env || process.env, opts.userHome || os.homedir());
|
|
247
|
+
const before = opts.dryRun ? null : captureDeploymentOutputs([settingsPath]);
|
|
248
|
+
const result = await deployMuseMcp(opts);
|
|
249
|
+
if (before && result.wrote) recordDeploymentOutputs(before, [settingsPath], { ...opts, writtenFiles: [settingsPath] });
|
|
245
250
|
}
|
|
246
251
|
|
|
247
252
|
if (!opts.quiet) {
|
|
@@ -118,7 +118,9 @@ export function deployExtensionBridge(targetDir, opts) {
|
|
|
118
118
|
if (!fs.existsSync(source)) return 0;
|
|
119
119
|
const destination = path.join(targetDir, '.pi/extensions');
|
|
120
120
|
ensureDir(destination, opts.dryRun);
|
|
121
|
-
|
|
121
|
+
const loader = new URL('../../providers/pi-bridge-policy.mjs', import.meta.url).href;
|
|
122
|
+
return deployFiles([source], destination, opts, (_file, content) =>
|
|
123
|
+
content.replace("'../../../../tools/providers/pi-bridge-policy.mjs'", JSON.stringify(loader)));
|
|
122
124
|
}
|
|
123
125
|
|
|
124
126
|
export function createAgentsMd(target, srcRoot, dryRun) {
|
|
@@ -0,0 +1,359 @@
|
|
|
1
|
+
// Select and project deployment rules and measure startup context.
|
|
2
|
+
import { createHash } from 'node:crypto';
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { importImpl } from '../../_resolve-impl.mjs';
|
|
6
|
+
import {
|
|
7
|
+
addManagedMarker,
|
|
8
|
+
contentHash,
|
|
9
|
+
extractFrameworkSlug,
|
|
10
|
+
getFrameworksForMode,
|
|
11
|
+
listMdFiles,
|
|
12
|
+
replaceBoundRulesBlock,
|
|
13
|
+
resolveAiwgRoot,
|
|
14
|
+
ruleEnforcementLevel,
|
|
15
|
+
} from './base.mjs';
|
|
16
|
+
import { resolveDeliveryRuleBindings } from './rule-binding-targets.mjs';
|
|
17
|
+
import { inlineStartup, nativePathLoader, ruleDirectory } from './rule-projection.mjs';
|
|
18
|
+
|
|
19
|
+
export const { parseRuleFrontmatter, inferRuleActivation, readCoreBody, validateCoreSet, formatRuleFrontmatterError } = await importImpl(import.meta.url, 'rules/activation.mjs');
|
|
20
|
+
export const { resolveDeployVersion } = await importImpl(import.meta.url, 'providers/deploy-version.mjs');
|
|
21
|
+
export const { trackTemporaryDirectory } = await importImpl(import.meta.url, 'utils/temporary-directory.js');
|
|
22
|
+
export const { loadRulePinConfigs, installedRuleCapabilities, resolveRulePins } = await importImpl(import.meta.url, 'rules/pins.mjs');
|
|
23
|
+
export const { guardRulesInlineBudget } = await importImpl(import.meta.url, 'rules/inline-budget.mjs');
|
|
24
|
+
export const { userConfigFile } = await importImpl(import.meta.url, 'config/user-config-dir.mjs');
|
|
25
|
+
export const { resolveProjectAiwgDir } = await importImpl(import.meta.url, 'config/project-artifacts-runtime.mjs');
|
|
26
|
+
export { renderRuleKernelIndex } from './rule-presentation.mjs';
|
|
27
|
+
export const PREPARATION_HOOK = Symbol.for('aiwg.provider-preparation-hook.v1');
|
|
28
|
+
|
|
29
|
+
export function installRuleDeploymentPreparationHook(hook) {
|
|
30
|
+
if (!hook || typeof hook.scratch !== 'string' || !hook.inputPool || typeof hook.accept !== 'function' || globalThis[PREPARATION_HOOK]) {
|
|
31
|
+
throw new Error('Invalid or already active rule deployment preparation hook');
|
|
32
|
+
}
|
|
33
|
+
globalThis[PREPARATION_HOOK] = hook;
|
|
34
|
+
return () => { if (globalThis[PREPARATION_HOOK] === hook) delete globalThis[PREPARATION_HOOK]; };
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function isRuleDeploymentPreparationActive() {
|
|
38
|
+
return Boolean(globalThis[PREPARATION_HOOK]);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function walk(dir) {
|
|
42
|
+
if (!fs.existsSync(dir)) return [];
|
|
43
|
+
return fs.readdirSync(dir, { withFileTypes: true }).flatMap(entry => {
|
|
44
|
+
const file = path.join(dir, entry.name);
|
|
45
|
+
return entry.isDirectory() ? walk(file) : entry.isFile() ? [file] : [];
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
// Keep only digests in the transaction snapshot. Artifact stores and binary skill
|
|
49
|
+
// resources can be much larger than the provider output being changed.
|
|
50
|
+
export function fileDigest(file) {
|
|
51
|
+
const hash = createHash('sha256');
|
|
52
|
+
const buffer = Buffer.allocUnsafe(64 * 1024);
|
|
53
|
+
const fd = fs.openSync(file, 'r');
|
|
54
|
+
try {
|
|
55
|
+
let count;
|
|
56
|
+
while ((count = fs.readSync(fd, buffer, 0, buffer.length, null))) hash.update(buffer.subarray(0, count));
|
|
57
|
+
return hash.digest('hex');
|
|
58
|
+
} finally {
|
|
59
|
+
fs.closeSync(fd);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
// Empty directories are part of workspace and skill-resource scaffolds too.
|
|
63
|
+
export function promoteDirectories(source, destination, skip = () => false, prefix = '') {
|
|
64
|
+
const entries = fs.readdirSync(source, { withFileTypes: true });
|
|
65
|
+
if (!entries.length && !fs.existsSync(destination)) fs.mkdirSync(destination, { recursive: true });
|
|
66
|
+
for (const entry of entries) {
|
|
67
|
+
const rel = path.join(prefix, entry.name);
|
|
68
|
+
if (entry.isDirectory() && !skip(rel)) {
|
|
69
|
+
promoteDirectories(path.join(source, entry.name), path.join(destination, entry.name), skip, rel);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
export const read = file => fs.existsSync(file) ? fs.readFileSync(file, 'utf8') : '';
|
|
74
|
+
export const structural = file => /^(RULES-INDEX|RULES-ONDEMAND)\.(md|mdc)$/.test(path.basename(file));
|
|
75
|
+
/** Collect selected source contracts, before any tier filter or projection. */
|
|
76
|
+
export function collectDeploymentRuleSources(opts) {
|
|
77
|
+
if (opts.ruleSources) {
|
|
78
|
+
// Pin-only callers enumerate rule files separately from behavior contracts.
|
|
79
|
+
// Retain earlier behaviors only while their owning bundle is still selected.
|
|
80
|
+
const selected = new Set(collectDeploymentRuleSources({ ...opts, ruleSources: undefined }));
|
|
81
|
+
const behaviors = (opts.previousRuleSources || []).filter(file => path.basename(file) === 'BEHAVIOR.md' && selected.has(file));
|
|
82
|
+
return [...new Set([...opts.ruleSources, ...behaviors])];
|
|
83
|
+
}
|
|
84
|
+
const corpus = resolveAiwgRoot(opts.srcRoot) || opts.srcRoot;
|
|
85
|
+
const bundles = [];
|
|
86
|
+
const frameworks = getFrameworksForMode(corpus, 'all');
|
|
87
|
+
for (const kind of ['frameworks', 'addons', 'extensions', 'plugins']) {
|
|
88
|
+
const dir = path.join(corpus, 'agentic', 'code', kind);
|
|
89
|
+
if (!fs.existsSync(dir)) continue;
|
|
90
|
+
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
91
|
+
if (!entry.isDirectory()) continue;
|
|
92
|
+
const root = path.join(dir, entry.name);
|
|
93
|
+
const manifest = JSON.parse(read(path.join(root, 'manifest.json')) || '{}');
|
|
94
|
+
bundles.push({ root, manifest, id: manifest.id || manifest.framework || entry.name,
|
|
95
|
+
aliases: [entry.name, ...(manifest.modeAliases || []), ...(manifest.aliases || []),
|
|
96
|
+
...(kind === 'frameworks' ? frameworks.find(framework => framework.path === root)?.aliases || [] : [])] });
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
const configs = opts.pinConfigs || loadRulePinConfigs(opts.target, opts.config);
|
|
100
|
+
// Project installation is authoritative. User-wide discoverability is not a
|
|
101
|
+
// project install, and a previous projection must never reselect retired rules.
|
|
102
|
+
const installed = configs.project.installed || {};
|
|
103
|
+
const names = Array.isArray(installed) ? installed : Object.keys(installed);
|
|
104
|
+
const selected = new Set();
|
|
105
|
+
const select = name => {
|
|
106
|
+
const id = name.replace(/^(framework|addon|extension|plugin):/, '');
|
|
107
|
+
const bundle = bundles.find(b => b.id === id || b.aliases.includes(id));
|
|
108
|
+
if (!bundle || selected.has(bundle)) return;
|
|
109
|
+
selected.add(bundle);
|
|
110
|
+
const required = Array.isArray(bundle.manifest.dependencies) ? bundle.manifest.dependencies : bundle.manifest.dependencies?.required || [];
|
|
111
|
+
for (const dep of Array.isArray(required) ? required : Object.keys(required)) select(dep);
|
|
112
|
+
};
|
|
113
|
+
for (const bundle of bundles.filter(b => b.manifest.core && b.manifest.autoInstall)) select(bundle.id);
|
|
114
|
+
for (const name of names.filter(name => name !== 'all')) select(name);
|
|
115
|
+
const invoked = bundles.find(bundle => path.resolve(bundle.root) === path.resolve(opts.srcRoot));
|
|
116
|
+
if (invoked && !opts.kernelOnly) select(invoked.id);
|
|
117
|
+
// Include the invocation being installed before its config entry is saved.
|
|
118
|
+
if (!opts.kernelOnly) for (const framework of getFrameworksForMode(opts.srcRoot, opts.mode === 'all' && names.length ? 'general' : opts.mode)) select(framework.id);
|
|
119
|
+
const roots = [...(!invoked || !opts.kernelOnly ? [opts.srcRoot] : []), ...(opts.additionalSources || []), ...[...selected].map(bundle => bundle.root)];
|
|
120
|
+
for (const entry of Object.values(installed)) if (entry?.localPath) roots.push(path.resolve(opts.target, entry.localPath));
|
|
121
|
+
const files = roots.flatMap(root => listMdFiles(path.join(root, 'rules'))).filter(file => !structural(file));
|
|
122
|
+
const behaviors = roots.flatMap(root => walk(path.join(root, 'behaviors')).filter(file => path.basename(file) === 'BEHAVIOR.md'));
|
|
123
|
+
return [...new Set([...files, ...behaviors])];
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export async function prepareRuleDelivery(opts) {
|
|
127
|
+
const rules = collectDeploymentRuleSources(opts).map(file => {
|
|
128
|
+
const content = fs.readFileSync(file, 'utf8');
|
|
129
|
+
const parsed = parseRuleFrontmatter(content);
|
|
130
|
+
if (!parsed.valid) throw new Error(formatRuleFrontmatterError(opts.logicalInputPath ? opts.logicalInputPath(file) : file, parsed.data, parsed.diagnostics));
|
|
131
|
+
const behavior = path.basename(file) === 'BEHAVIOR.md';
|
|
132
|
+
const rule = { ...parsed.rule, file, content, body: parsed.body, behavior,
|
|
133
|
+
name: behavior ? `behavior/${path.basename(path.dirname(file))}` : parsed.data.name || path.basename(file, '.md') };
|
|
134
|
+
if (!rule.tagged) rule.activation = inferRuleActivation();
|
|
135
|
+
// Core rules (#3450) carry a compact body beside the full rule; the full text is never inlined.
|
|
136
|
+
if (rule.activation === 'core') rule.coreBody = readCoreBody(file);
|
|
137
|
+
for (const diagnostic of parsed.diagnostics) {
|
|
138
|
+
console.warn(`${opts.logicalInputPath ? opts.logicalInputPath(file) : file}: ${diagnostic.code}: ${diagnostic.code === 'missing-activation' ? `Missing activation; inferred ${rule.activation} delivery (migration fallback); add explicit activation frontmatter.` : diagnostic.message}`);
|
|
139
|
+
}
|
|
140
|
+
return rule;
|
|
141
|
+
});
|
|
142
|
+
const coreErrors = validateCoreSet([...new Map(rules.filter(rule => rule.coreBody !== undefined).map(rule => [rule.name, { name: rule.name, text: rule.coreBody }])).values()]);
|
|
143
|
+
if (coreErrors.length) throw new Error(coreErrors.join('; '));
|
|
144
|
+
const configs = opts.pinConfigs || loadRulePinConfigs(opts.target, opts.config);
|
|
145
|
+
const installed = installedRuleCapabilities(configs);
|
|
146
|
+
const root = resolveAiwgRoot(opts.srcRoot) || opts.srcRoot;
|
|
147
|
+
const { loadRelations, selectPrebuiltRelations } = await importImpl(import.meta.url, 'artifacts/relations.js');
|
|
148
|
+
const packageRelations = selectPrebuiltRelations(root, opts.target).reader;
|
|
149
|
+
const relations = packageRelations || loadRelations(opts.target) || loadRelations(root, opts.target);
|
|
150
|
+
const ruleIdsByPath = new Map(Object.entries(relations?.index.rules || {}).map(([id, rule]) => [rule.path, id]));
|
|
151
|
+
const pinRules = rules.map(rule => {
|
|
152
|
+
const owner = rule.file.replaceAll('\\', '/').match(/(?:frameworks|addons|extensions|plugins)\/([^/]+)\//)?.[1];
|
|
153
|
+
const local = Object.entries(configs.project.installed || {}).find(([, entry]) => entry.localPath && rule.file.startsWith(path.resolve(opts.target, entry.localPath) + path.sep))?.[0];
|
|
154
|
+
const indexedPath = path.relative(root, rule.file);
|
|
155
|
+
return { ...rule, id: ruleIdsByPath.get(indexedPath) || rule.file, path: rule.file, indexedPath,
|
|
156
|
+
capability: local || owner || opts.capability, enforcement: ruleEnforcementLevel(rule.content) };
|
|
157
|
+
});
|
|
158
|
+
const pinned = resolveRulePins({ rules: pinRules, configs, installed, relations });
|
|
159
|
+
for (const warning of pinned.warnings) console.warn(warning);
|
|
160
|
+
const pinsByFile = new Map(pinned.rules.map(rule => [rule.file, rule]));
|
|
161
|
+
for (const rule of rules) {
|
|
162
|
+
const pin = pinsByFile.get(rule.file);
|
|
163
|
+
// A core rule is already delivered in full; a pin must not re-promote it to a kernel body.
|
|
164
|
+
if (!pin || rule.activation === 'core') continue;
|
|
165
|
+
rule.canonicalActivation = rule.activation;
|
|
166
|
+
rule.pinMatches = pin.matches;
|
|
167
|
+
rule.pinned = true;
|
|
168
|
+
rule.activation = 'kernel';
|
|
169
|
+
// All pins use native kernel projection, including legacy untagged rules.
|
|
170
|
+
rule.tagged = true;
|
|
171
|
+
}
|
|
172
|
+
const { bindings, targets } = await resolveDeliveryRuleBindings(opts, rules, configs, root, packageRelations);
|
|
173
|
+
return { rules, bindings, targets, pins: pinned.rules, pinWarnings: pinned.warnings };
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export const managed = (content, opts) => addManagedMarker(content, opts.deployVersion, opts.deploySource || 'bundled');
|
|
177
|
+
export function put(file, content) { fs.mkdirSync(path.dirname(file), { recursive: true }); fs.writeFileSync(file, content); }
|
|
178
|
+
|
|
179
|
+
/** External helpers also project skills/flows. Inject into their body, never descriptions. */
|
|
180
|
+
export function finishBindings(opts, provider) {
|
|
181
|
+
const putOwned = (file, content) => { put(file, content); opts.writtenFiles?.push(file); };
|
|
182
|
+
const corpus = opts.srcRoot && (resolveAiwgRoot(opts.srcRoot) || opts.srcRoot);
|
|
183
|
+
const frameworks = corpus ? getFrameworksForMode(corpus, 'all') : [];
|
|
184
|
+
const knownFrameworks = new Set(frameworks.map(framework => framework.id));
|
|
185
|
+
const installed = Object.keys(opts.config?.installed || opts.pinConfigs?.project?.installed || {});
|
|
186
|
+
const invoked = opts.srcRoot ? getFrameworksForMode(opts.srcRoot,
|
|
187
|
+
opts.mode === 'all' && installed.length ? 'general' : opts.mode) : [];
|
|
188
|
+
const selectedFrameworks = new Set([
|
|
189
|
+
...invoked,
|
|
190
|
+
...installed.filter(name => name !== 'all').flatMap(name => corpus ? getFrameworksForMode(corpus, name) : []),
|
|
191
|
+
...frameworks.filter(framework => [opts.srcRoot, ...(opts.additionalSources || [])].filter(Boolean)
|
|
192
|
+
.some(source => path.resolve(framework.path) === path.resolve(source)) || (framework.manifest.core && framework.manifest.autoInstall)),
|
|
193
|
+
].map(framework => framework.id));
|
|
194
|
+
// Selected dependency rules also identify frameworks reached through addons.
|
|
195
|
+
for (const rule of opts.ruleDelivery.rules || []) {
|
|
196
|
+
const owner = rule.file && extractFrameworkSlug(rule.file);
|
|
197
|
+
if (knownFrameworks.has(owner)) selectedFrameworks.add(owner);
|
|
198
|
+
}
|
|
199
|
+
const roots = [opts.target, opts.deploymentHome,
|
|
200
|
+
...[opts.kernelSkillsPath, opts.activeWorkspace, ...Object.values(provider.paths)].filter(p => p && path.isAbsolute(p))];
|
|
201
|
+
const files = [...new Set(roots.flatMap(walk))];
|
|
202
|
+
const indexRel = provider.name === 'copilot' ? '.github/RULES-BOUND.md' : `.${provider.name}/RULES-BOUND.md`;
|
|
203
|
+
const indexFile = path.join(opts.target, indexRel);
|
|
204
|
+
const anchor = target => `${target.type}-${target.name}`.toLowerCase().replace(/[^a-z0-9_-]/g, '-');
|
|
205
|
+
const sections = new Map();
|
|
206
|
+
const targetsBySource = new Map();
|
|
207
|
+
for (const target of opts.ruleDelivery.targets) {
|
|
208
|
+
targetsBySource.set(target.source, [...(targetsBySource.get(target.source) || []), target]);
|
|
209
|
+
}
|
|
210
|
+
for (const file of files.filter(file => /\.(md|toml)$/.test(file))) {
|
|
211
|
+
if (path.basename(file) !== 'SKILL.md' && !/(?:[/\\](?:skills?|agents?|droids|commands?|prompts|modes?)[/\\])/.test(file)) continue;
|
|
212
|
+
if (/[/\\]rules[/\\]/.test(file) || /[/\\]\.aiwg[/\\](?!skills[/\\])/.test(file.replace(opts.target, ''))) continue;
|
|
213
|
+
let content = read(file);
|
|
214
|
+
if (!/aiwg:managed/.test(content) && !fs.existsSync(path.join(path.dirname(file), '.aiwg-managed')) && !fs.existsSync(path.join(path.dirname(file), '.aiwg-manifest.json'))) continue;
|
|
215
|
+
const skill = path.basename(file) === 'SKILL.md';
|
|
216
|
+
const name = skill ? path.basename(path.dirname(file)) : path.basename(file).replace(/\.(md|toml)$/, '');
|
|
217
|
+
const sidecarPath = path.join(skill ? path.dirname(file) : path.dirname(file), '.aiwg-manifest.json');
|
|
218
|
+
const sidecar = fs.existsSync(sidecarPath) ? JSON.parse(read(sidecarPath)) : null;
|
|
219
|
+
// Wrapper source identity is ownership metadata. Preserve the legacy
|
|
220
|
+
// flow-only name lookup instead of selecting new skill binding targets.
|
|
221
|
+
const wrapper = !skill && sidecar?.managed?.[path.basename(file)]?.kind === 'skill-command';
|
|
222
|
+
const wrapperOwner = sidecar?.managed?.[path.basename(file)]?.frameworkSlug
|
|
223
|
+
|| extractFrameworkSlug(sidecar?.managed?.[path.basename(file)]?.sourcePath || '');
|
|
224
|
+
// Shared command surfaces can contain a framework's late wrappers before
|
|
225
|
+
// that framework is selected. Do not activate its bindings on redeploy.
|
|
226
|
+
if (wrapper && knownFrameworks.has(wrapperOwner) && !selectedFrameworks.has(wrapperOwner)) continue;
|
|
227
|
+
const source = wrapper ? undefined : sidecar?.skillSource ? path.join(sidecar.skillSource, 'SKILL.md') : sidecar?.managed?.[path.basename(file)]?.sourcePath;
|
|
228
|
+
const flowSource = opts.flowSkillSources?.get(file);
|
|
229
|
+
const targets = [...(flowSource ? targetsBySource.get(flowSource) || [] : []),
|
|
230
|
+
...(source ? targetsBySource.get(path.resolve(source)) || [] : opts.ruleDelivery.targets.filter(target =>
|
|
231
|
+
(skill ? target.type !== 'agent' : /[/\\](?:agents?|droids|modes?)[/\\]/.test(file) ? target.type === 'agent' : target.type === 'flow') &&
|
|
232
|
+
[target.name, path.basename(target.source, '.md'), path.basename(path.dirname(target.source))].includes(name)))];
|
|
233
|
+
const rules = targets.flatMap(target => opts.ruleDelivery.bindings.get(target.source) || []);
|
|
234
|
+
if (!rules.length && !content.includes('<!-- AIWG:bound-rules:start -->')) continue;
|
|
235
|
+
const pointer = body => {
|
|
236
|
+
const clean = replaceBoundRulesBlock(body, []);
|
|
237
|
+
if (!rules.length) return clean;
|
|
238
|
+
const identities = [...new Map(targets.map(target => [`${target.type} ${target.name}`, target])).values()];
|
|
239
|
+
for (const target of identities) {
|
|
240
|
+
const bound = opts.ruleDelivery.bindings.get(target.source) || [];
|
|
241
|
+
const unique = [...new Map(bound.map(rule => [rule.name, rule])).values()].sort((a, b) => a.name.localeCompare(b.name));
|
|
242
|
+
if (unique.length) sections.set(anchor(target), `## ${anchor(target)}\n\n` + unique.map(rule =>
|
|
243
|
+
`- ${rule.name} — ${rule.summary} Fetch and follow: \`aiwg show rule ${rule.name} --body\`.`).join('\n'));
|
|
244
|
+
}
|
|
245
|
+
// Skills must carry exact fetch commands themselves: a section pointer
|
|
246
|
+
// alone loses the invocation contract in clean installs (#3473).
|
|
247
|
+
const fetch = skill ? [...new Map(rules.map(rule => [rule.name, rule])).values()]
|
|
248
|
+
.sort((a, b) => a.name.localeCompare(b.name))
|
|
249
|
+
.map(rule => `${rule.summary}\nFetch and follow before governed work: \`aiwg show rule ${rule.name} --body\`.`).join('\n') : '';
|
|
250
|
+
return `${clean}${clean.endsWith('\n') ? '' : '\n'}\n<!-- AIWG:bound-rules:start -->\nRead and follow before governed work: ${identities.map(target =>
|
|
251
|
+
`\`${indexRel}#${anchor(target)}\``).join('; ')}.\n${fetch ? fetch + '\n' : ''}<!-- AIWG:bound-rules:end -->\n`;
|
|
252
|
+
};
|
|
253
|
+
if (file.endsWith('.toml')) content = content.replace(/^developer_instructions = (".*")$/m, (_, value) => `developer_instructions = ${JSON.stringify(pointer(JSON.parse(value)))}`);
|
|
254
|
+
else content = pointer(content);
|
|
255
|
+
putOwned(file, content);
|
|
256
|
+
// Keep deployment hashes honest after projection by external helpers.
|
|
257
|
+
if (sidecar?.managed?.[path.basename(file)]) {
|
|
258
|
+
sidecar.managed[path.basename(file)].hash = `sha256:${contentHash(content)}`;
|
|
259
|
+
putOwned(sidecarPath, `${JSON.stringify(sidecar, null, 2)}\n`);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
if (sections.size) putOwned(indexFile, managed('# Bound rules\n\nFetch and follow every full rule in the invoked artifact’s section before governed work.\n\n' +
|
|
263
|
+
[...sections.entries()].sort(([a], [b]) => a.localeCompare(b)).map(([, section]) => section).join('\n\n') + '\n', opts));
|
|
264
|
+
else if (/aiwg:managed/.test(read(indexFile))) fs.rmSync(indexFile);
|
|
265
|
+
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/** Bindings annotate the selected deployment; they do not select standard skills
|
|
269
|
+
* (ADR lines 102–108). Flow projections follow the same opt-in and tier routing. */
|
|
270
|
+
export function projectBoundFlowSkills(opts, provider, selected) {
|
|
271
|
+
opts.flowSkillSources = new Map();
|
|
272
|
+
if (opts.rulesOnly || opts.commandsOnly || !(opts.deploySkills || opts.skillsOnly)) return;
|
|
273
|
+
const kernel = path.isAbsolute(provider.kernelSkillsPath || '') ? opts.kernelSkillsPath
|
|
274
|
+
: path.join(opts.target, provider.kernelSkillsPath || `.${provider.name}/skills`);
|
|
275
|
+
// Codex's opt-in standard tier shares the native skills directory.
|
|
276
|
+
const standard = provider.name === 'codex' ? kernel : path.isAbsolute(provider.paths.skills)
|
|
277
|
+
? provider.paths.skills : path.join(opts.target, provider.paths.skills);
|
|
278
|
+
const flows = opts.ruleDelivery.targets.filter(entry => entry.type === 'flow' && selected(entry));
|
|
279
|
+
const sources = new Set(flows.map(entry => entry.source));
|
|
280
|
+
for (const root of new Set([kernel, standard])) {
|
|
281
|
+
if (!fs.existsSync(root)) continue;
|
|
282
|
+
for (const entry of fs.readdirSync(root, { withFileTypes: true })) {
|
|
283
|
+
if (!entry.isDirectory()) continue;
|
|
284
|
+
const dir = path.join(root, entry.name);
|
|
285
|
+
const file = path.join(dir, 'SKILL.md');
|
|
286
|
+
const content = read(file);
|
|
287
|
+
const receiptFile = path.join(dir, '.aiwg-manifest.json');
|
|
288
|
+
const receipt = fs.existsSync(receiptFile) ? JSON.parse(read(receiptFile)) : null;
|
|
289
|
+
// Recognize the old projector's exact generated wrapper as well as new
|
|
290
|
+
// receipts. Ordinary deployed skills and operator files are preserved.
|
|
291
|
+
const legacy = !receipt?.skillSource && !receipt?.flowSource && /aiwg:managed/.test(content)
|
|
292
|
+
&& content.includes(`description: Invoke ${entry.name}.\n`)
|
|
293
|
+
&& content.includes('```yaml\n') && content.includes('<!-- AIWG:bound-rules:start -->');
|
|
294
|
+
const stale = receipt?.flowSource && (opts.copyStandardSkills !== true
|
|
295
|
+
|| !sources.has(receipt.flowSource) || root !== standard);
|
|
296
|
+
if (!legacy && !stale) continue;
|
|
297
|
+
fs.rmSync(file, { force: true });
|
|
298
|
+
if (receipt?.flowSource) {
|
|
299
|
+
fs.rmSync(receiptFile, { force: true });
|
|
300
|
+
fs.rmSync(path.join(dir, '.aiwg-managed'), { force: true });
|
|
301
|
+
}
|
|
302
|
+
if (!fs.readdirSync(dir).length) fs.rmdirSync(dir);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
if (opts.copyStandardSkills !== true) return;
|
|
306
|
+
for (const entry of flows) {
|
|
307
|
+
const name = entry.name || path.basename(entry.source).replace(/\.(md|ya?ml)$/, '');
|
|
308
|
+
const dir = path.join(standard, name);
|
|
309
|
+
const file = path.join(dir, 'SKILL.md');
|
|
310
|
+
const receiptFile = path.join(dir, '.aiwg-manifest.json');
|
|
311
|
+
const receipt = fs.existsSync(receiptFile) ? JSON.parse(read(receiptFile)) : null;
|
|
312
|
+
// A selected authored skill may already represent this flow. Keep its body;
|
|
313
|
+
// finishBindings adds both artifact identities' contracts after projection.
|
|
314
|
+
if (!fs.existsSync(file) || receipt?.flowSource === entry.source) {
|
|
315
|
+
const body = read(entry.source);
|
|
316
|
+
const markdown = entry.source.endsWith('.md') ? body : `---\nname: ${name}\nnamespace: aiwg\ndescription: Invoke ${name}.\n---\n\n\`\`\`yaml\n${body}\n\`\`\`\n`;
|
|
317
|
+
const projected = provider.transformSkillMd ? provider.transformSkillMd(markdown, opts) : markdown;
|
|
318
|
+
const content = managed(replaceBoundRulesBlock(projected, opts.ruleDelivery.bindings.get(entry.source)), opts);
|
|
319
|
+
put(file, content);
|
|
320
|
+
put(path.join(dir, '.aiwg-managed'), 'true\n');
|
|
321
|
+
put(receiptFile, `${JSON.stringify({ flowSource: entry.source,
|
|
322
|
+
managed: { 'SKILL.md': { sourcePath: entry.source, hash: `sha256:${contentHash(content)}` } } }, null, 2)}\n`);
|
|
323
|
+
}
|
|
324
|
+
opts.flowSkillSources.set(file, entry.source);
|
|
325
|
+
if (['warp', 'hermes'].includes(provider.name)) opts.definitionRoutes.push(`${name}: ${file}`);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
/** Count rule sections, excluding aggregated agent/command definitions and project prose. */
|
|
330
|
+
export function warpRuleContent(content) {
|
|
331
|
+
const blocks = [...content.matchAll(/<!-- AIWG:(rule-(?:startup|core|hook-[\w-]+)):start -->[\s\S]*?<!-- AIWG:\1:end -->/g)].map(match => match[0]);
|
|
332
|
+
// Remove managed blocks first so their internal headings cannot be counted twice.
|
|
333
|
+
const remaining = content.replace(/<!-- AIWG:(rule-(?:startup|core|hook-[\w-]+)):start -->[\s\S]*?<!-- AIWG:\1:end -->/g, '');
|
|
334
|
+
const sections = [...remaining.matchAll(/^## (?:AIWG Rules|On-Demand Rules)\r?\n[\s\S]*?(?=^## |(?![\s\S]))/gm)].map(match => match[0]);
|
|
335
|
+
return [...sections, ...blocks].join('\n');
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
export function startupFiles(opts, provider) {
|
|
339
|
+
const bridgeNames = { claude: ['CLAUDE.md'], cursor: ['AGENTS.md'], codex: ['AGENTS.md'], hermes: ['AGENTS.md', '.hermes.md'], pi: ['AGENTS.md'], warp: ['WARP.md'], openclaw: [] };
|
|
340
|
+
const paths = ['AIWG.md', 'WORKSPACE.md', ...(bridgeNames[provider.name] || ['AGENTS.md']), inlineStartup[provider.name]].filter(Boolean).map(name => path.join(opts.target, name));
|
|
341
|
+
if (opts.activeWorkspace) paths.push(path.join(opts.activeWorkspace, 'AGENTS.md'));
|
|
342
|
+
{
|
|
343
|
+
// Hook-reached files count too: moving a body must not hide its budget cost.
|
|
344
|
+
const dir = ruleDirectory(opts, provider);
|
|
345
|
+
paths.push(...walk(dir).filter(file => /\.(md|mdc)$/.test(file)));
|
|
346
|
+
}
|
|
347
|
+
return [...new Set(paths)].filter(file => fs.existsSync(file)).map(file => {
|
|
348
|
+
let content = read(file);
|
|
349
|
+
if (nativePathLoader(provider.name)) {
|
|
350
|
+
const parsed = parseRuleFrontmatter(content);
|
|
351
|
+
if (parsed.data?.paths || parsed.data?.globs) content = content.slice(0, content.length - parsed.body.length);
|
|
352
|
+
}
|
|
353
|
+
// Count managed rule sections while preserving historical accounting for
|
|
354
|
+
// operator aggregates; discrete hook-reached rule files are counted above.
|
|
355
|
+
if ((provider.name === 'warp' && path.basename(file) === 'WARP.md')
|
|
356
|
+
|| (provider.name === 'windsurf' && file === path.join(opts.target, 'AGENTS.md'))) content = warpRuleContent(content);
|
|
357
|
+
return { path: file, content };
|
|
358
|
+
});
|
|
359
|
+
}
|