@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,1145 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
discoverAddons, getFrameworksForMode, collectBehaviorDirs,
|
|
10
|
-
resolveAiwgRoot, ruleEnforcementLevel, stripTriggersFromContent,
|
|
11
|
-
addManagedMarker, contentHash, replaceBoundRulesBlock, deployEmulatedBehaviors, filterAgentFiles,
|
|
12
|
-
} from './base.mjs';
|
|
13
|
-
|
|
14
|
-
const { parseRuleFrontmatter, inferRuleActivation, readCoreBody, validateCoreSet, formatRuleFrontmatterError } = await importImpl(import.meta.url, 'rules/activation.mjs');
|
|
15
|
-
const { resolveDeployVersion } = await importImpl(import.meta.url, 'providers/deploy-version.mjs');
|
|
16
|
-
const { trackTemporaryDirectory } = await importImpl(import.meta.url, 'utils/temporary-directory.js');
|
|
17
|
-
const { loadRulePinConfigs, installedRuleCapabilities, resolveRulePins } = await importImpl(import.meta.url, 'rules/pins.mjs');
|
|
18
|
-
const { guardRulesInlineBudget } = await importImpl(import.meta.url, 'rules/inline-budget.mjs');
|
|
19
|
-
const { userConfigFile } = await importImpl(import.meta.url, 'config/user-config-dir.mjs');
|
|
20
|
-
const { resolveProjectAiwgDir } = await importImpl(import.meta.url, 'config/project-artifacts-runtime.mjs');
|
|
21
|
-
import { writeContextFileSync, CONTEXT_STAGE_ENV } from './context-write.mjs';
|
|
22
|
-
import { captureProviderPathDescriptors, setStagedProviderPath, restoreProviderPaths, logicalProviderOutputPath } from './provider-paths-staging.mjs';
|
|
23
|
-
import { resolveDeliveryRuleBindings } from './rule-binding-targets.mjs';
|
|
24
|
-
import { renderRuleKernelIndex } from './rule-presentation.mjs';
|
|
1
|
+
// Public facade for the focused context/deployment owners.
|
|
2
|
+
export {
|
|
3
|
+
installRuleDeploymentPreparationHook,
|
|
4
|
+
isRuleDeploymentPreparationActive,
|
|
5
|
+
collectDeploymentRuleSources,
|
|
6
|
+
prepareRuleDelivery,
|
|
7
|
+
warpRuleContent,
|
|
8
|
+
} from './rule-delivery-surface.mjs';
|
|
25
9
|
export { renderRuleKernelIndex } from './rule-presentation.mjs';
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export function isRuleDeploymentPreparationActive() {
|
|
39
|
-
return Boolean(globalThis[PREPARATION_HOOK]);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function walk(dir) {
|
|
43
|
-
if (!fs.existsSync(dir)) return [];
|
|
44
|
-
return fs.readdirSync(dir, { withFileTypes: true }).flatMap(entry => {
|
|
45
|
-
const file = path.join(dir, entry.name);
|
|
46
|
-
return entry.isDirectory() ? walk(file) : entry.isFile() ? [file] : [];
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
// Keep only digests in the transaction snapshot. Artifact stores and binary skill
|
|
50
|
-
// resources can be much larger than the provider output being changed.
|
|
51
|
-
function fileDigest(file) {
|
|
52
|
-
const hash = createHash('sha256');
|
|
53
|
-
const buffer = Buffer.allocUnsafe(64 * 1024);
|
|
54
|
-
const fd = fs.openSync(file, 'r');
|
|
55
|
-
try {
|
|
56
|
-
let count;
|
|
57
|
-
while ((count = fs.readSync(fd, buffer, 0, buffer.length, null))) hash.update(buffer.subarray(0, count));
|
|
58
|
-
return hash.digest('hex');
|
|
59
|
-
} finally {
|
|
60
|
-
fs.closeSync(fd);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
// Empty directories are part of workspace and skill-resource scaffolds too.
|
|
64
|
-
function promoteDirectories(source, destination, skip = () => false, prefix = '') {
|
|
65
|
-
const entries = fs.readdirSync(source, { withFileTypes: true });
|
|
66
|
-
if (!entries.length && !fs.existsSync(destination)) fs.mkdirSync(destination, { recursive: true });
|
|
67
|
-
for (const entry of entries) {
|
|
68
|
-
const rel = path.join(prefix, entry.name);
|
|
69
|
-
if (entry.isDirectory() && !skip(rel)) {
|
|
70
|
-
promoteDirectories(path.join(source, entry.name), path.join(destination, entry.name), skip, rel);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
const read = file => fs.existsSync(file) ? fs.readFileSync(file, 'utf8') : '';
|
|
75
|
-
const structural = file => /^(RULES-INDEX|RULES-ONDEMAND)\.(md|mdc)$/.test(path.basename(file));
|
|
76
|
-
/** Collect selected source contracts, before any tier filter or projection. */
|
|
77
|
-
export function collectDeploymentRuleSources(opts) {
|
|
78
|
-
if (opts.ruleSources) {
|
|
79
|
-
// Pin-only callers enumerate rule files separately from behavior contracts.
|
|
80
|
-
// Retain earlier behaviors only while their owning bundle is still selected.
|
|
81
|
-
const selected = new Set(collectDeploymentRuleSources({ ...opts, ruleSources: undefined }));
|
|
82
|
-
const behaviors = (opts.previousRuleSources || []).filter(file => path.basename(file) === 'BEHAVIOR.md' && selected.has(file));
|
|
83
|
-
return [...new Set([...opts.ruleSources, ...behaviors])];
|
|
84
|
-
}
|
|
85
|
-
const corpus = resolveAiwgRoot(opts.srcRoot) || opts.srcRoot;
|
|
86
|
-
const bundles = [];
|
|
87
|
-
const frameworks = getFrameworksForMode(corpus, 'all');
|
|
88
|
-
for (const kind of ['frameworks', 'addons', 'extensions', 'plugins']) {
|
|
89
|
-
const dir = path.join(corpus, 'agentic', 'code', kind);
|
|
90
|
-
if (!fs.existsSync(dir)) continue;
|
|
91
|
-
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
92
|
-
if (!entry.isDirectory()) continue;
|
|
93
|
-
const root = path.join(dir, entry.name);
|
|
94
|
-
const manifest = JSON.parse(read(path.join(root, 'manifest.json')) || '{}');
|
|
95
|
-
bundles.push({ root, manifest, id: manifest.id || manifest.framework || entry.name,
|
|
96
|
-
aliases: [entry.name, ...(manifest.modeAliases || []), ...(manifest.aliases || []),
|
|
97
|
-
...(kind === 'frameworks' ? frameworks.find(framework => framework.path === root)?.aliases || [] : [])] });
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
const configs = opts.pinConfigs || loadRulePinConfigs(opts.target, opts.config);
|
|
101
|
-
// Project installation is authoritative. User-wide discoverability is not a
|
|
102
|
-
// project install, and a previous projection must never reselect retired rules.
|
|
103
|
-
const installed = configs.project.installed || {};
|
|
104
|
-
const names = Array.isArray(installed) ? installed : Object.keys(installed);
|
|
105
|
-
const selected = new Set();
|
|
106
|
-
const select = name => {
|
|
107
|
-
const id = name.replace(/^(framework|addon|extension|plugin):/, '');
|
|
108
|
-
const bundle = bundles.find(b => b.id === id || b.aliases.includes(id));
|
|
109
|
-
if (!bundle || selected.has(bundle)) return;
|
|
110
|
-
selected.add(bundle);
|
|
111
|
-
const required = Array.isArray(bundle.manifest.dependencies) ? bundle.manifest.dependencies : bundle.manifest.dependencies?.required || [];
|
|
112
|
-
for (const dep of Array.isArray(required) ? required : Object.keys(required)) select(dep);
|
|
113
|
-
};
|
|
114
|
-
for (const bundle of bundles.filter(b => b.manifest.core && b.manifest.autoInstall)) select(bundle.id);
|
|
115
|
-
for (const name of names.filter(name => name !== 'all')) select(name);
|
|
116
|
-
const invoked = bundles.find(bundle => path.resolve(bundle.root) === path.resolve(opts.srcRoot));
|
|
117
|
-
if (invoked && !opts.kernelOnly) select(invoked.id);
|
|
118
|
-
// Include the invocation being installed before its config entry is saved.
|
|
119
|
-
if (!opts.kernelOnly) for (const framework of getFrameworksForMode(opts.srcRoot, opts.mode === 'all' && names.length ? 'general' : opts.mode)) select(framework.id);
|
|
120
|
-
const roots = [...(!invoked || !opts.kernelOnly ? [opts.srcRoot] : []), ...(opts.additionalSources || []), ...[...selected].map(bundle => bundle.root)];
|
|
121
|
-
for (const entry of Object.values(installed)) if (entry?.localPath) roots.push(path.resolve(opts.target, entry.localPath));
|
|
122
|
-
const files = roots.flatMap(root => listMdFiles(path.join(root, 'rules'))).filter(file => !structural(file));
|
|
123
|
-
const behaviors = roots.flatMap(root => walk(path.join(root, 'behaviors')).filter(file => path.basename(file) === 'BEHAVIOR.md'));
|
|
124
|
-
return [...new Set([...files, ...behaviors])];
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
export async function prepareRuleDelivery(opts) {
|
|
128
|
-
const rules = collectDeploymentRuleSources(opts).map(file => {
|
|
129
|
-
const content = fs.readFileSync(file, 'utf8');
|
|
130
|
-
const parsed = parseRuleFrontmatter(content);
|
|
131
|
-
if (!parsed.valid) throw new Error(formatRuleFrontmatterError(opts.logicalInputPath ? opts.logicalInputPath(file) : file, parsed.data, parsed.diagnostics));
|
|
132
|
-
const behavior = path.basename(file) === 'BEHAVIOR.md';
|
|
133
|
-
const rule = { ...parsed.rule, file, content, body: parsed.body, behavior,
|
|
134
|
-
name: behavior ? `behavior/${path.basename(path.dirname(file))}` : parsed.data.name || path.basename(file, '.md') };
|
|
135
|
-
if (!rule.tagged) rule.activation = inferRuleActivation();
|
|
136
|
-
// Core rules (#3450) carry a compact body beside the full rule; the full text is never inlined.
|
|
137
|
-
if (rule.activation === 'core') rule.coreBody = readCoreBody(file);
|
|
138
|
-
for (const diagnostic of parsed.diagnostics) {
|
|
139
|
-
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}`);
|
|
140
|
-
}
|
|
141
|
-
return rule;
|
|
142
|
-
});
|
|
143
|
-
const coreErrors = validateCoreSet([...new Map(rules.filter(rule => rule.coreBody !== undefined).map(rule => [rule.name, { name: rule.name, text: rule.coreBody }])).values()]);
|
|
144
|
-
if (coreErrors.length) throw new Error(coreErrors.join('; '));
|
|
145
|
-
const configs = opts.pinConfigs || loadRulePinConfigs(opts.target, opts.config);
|
|
146
|
-
const installed = installedRuleCapabilities(configs);
|
|
147
|
-
const root = resolveAiwgRoot(opts.srcRoot) || opts.srcRoot;
|
|
148
|
-
const { loadRelations, selectPrebuiltRelations } = await importImpl(import.meta.url, 'artifacts/relations.js');
|
|
149
|
-
const packageRelations = selectPrebuiltRelations(root, opts.target).reader;
|
|
150
|
-
const relations = packageRelations || loadRelations(opts.target) || loadRelations(root, opts.target);
|
|
151
|
-
const ruleIdsByPath = new Map(Object.entries(relations?.index.rules || {}).map(([id, rule]) => [rule.path, id]));
|
|
152
|
-
const pinRules = rules.map(rule => {
|
|
153
|
-
const owner = rule.file.replaceAll('\\', '/').match(/(?:frameworks|addons|extensions|plugins)\/([^/]+)\//)?.[1];
|
|
154
|
-
const local = Object.entries(configs.project.installed || {}).find(([, entry]) => entry.localPath && rule.file.startsWith(path.resolve(opts.target, entry.localPath) + path.sep))?.[0];
|
|
155
|
-
const indexedPath = path.relative(root, rule.file);
|
|
156
|
-
return { ...rule, id: ruleIdsByPath.get(indexedPath) || rule.file, path: rule.file, indexedPath,
|
|
157
|
-
capability: local || owner || opts.capability, enforcement: ruleEnforcementLevel(rule.content) };
|
|
158
|
-
});
|
|
159
|
-
const pinned = resolveRulePins({ rules: pinRules, configs, installed, relations });
|
|
160
|
-
for (const warning of pinned.warnings) console.warn(warning);
|
|
161
|
-
const pinsByFile = new Map(pinned.rules.map(rule => [rule.file, rule]));
|
|
162
|
-
for (const rule of rules) {
|
|
163
|
-
const pin = pinsByFile.get(rule.file);
|
|
164
|
-
// A core rule is already delivered in full; a pin must not re-promote it to a kernel body.
|
|
165
|
-
if (!pin || rule.activation === 'core') continue;
|
|
166
|
-
rule.canonicalActivation = rule.activation;
|
|
167
|
-
rule.pinMatches = pin.matches;
|
|
168
|
-
rule.pinned = true;
|
|
169
|
-
rule.activation = 'kernel';
|
|
170
|
-
// All pins use native kernel projection, including legacy untagged rules.
|
|
171
|
-
rule.tagged = true;
|
|
172
|
-
}
|
|
173
|
-
const { bindings, targets } = await resolveDeliveryRuleBindings(opts, rules, configs, root, packageRelations);
|
|
174
|
-
return { rules, bindings, targets, pins: pinned.rules, pinWarnings: pinned.warnings };
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
const managed = (content, opts) => addManagedMarker(content, opts.deployVersion, opts.deploySource || 'bundled');
|
|
179
|
-
function put(file, content) { fs.mkdirSync(path.dirname(file), { recursive: true }); fs.writeFileSync(file, content); }
|
|
180
|
-
|
|
181
|
-
/** External helpers also project skills/flows. Inject into their body, never descriptions. */
|
|
182
|
-
function finishBindings(opts, provider) {
|
|
183
|
-
const roots = [opts.target, opts.deploymentHome,
|
|
184
|
-
...[opts.kernelSkillsPath, opts.activeWorkspace, ...Object.values(provider.paths)].filter(p => p && path.isAbsolute(p))];
|
|
185
|
-
const files = [...new Set(roots.flatMap(walk))];
|
|
186
|
-
const indexRel = provider.name === 'copilot' ? '.github/RULES-BOUND.md' : `.${provider.name}/RULES-BOUND.md`;
|
|
187
|
-
const indexFile = path.join(opts.target, indexRel);
|
|
188
|
-
const anchor = target => `${target.type}-${target.name}`.toLowerCase().replace(/[^a-z0-9_-]/g, '-');
|
|
189
|
-
const sections = new Map();
|
|
190
|
-
const targetsBySource = new Map();
|
|
191
|
-
for (const target of opts.ruleDelivery.targets) {
|
|
192
|
-
targetsBySource.set(target.source, [...(targetsBySource.get(target.source) || []), target]);
|
|
193
|
-
}
|
|
194
|
-
for (const file of files.filter(file => /\.(md|toml)$/.test(file))) {
|
|
195
|
-
if (path.basename(file) !== 'SKILL.md' && !/(?:[/\\](?:skills?|agents?|droids|commands?|prompts|modes?)[/\\])/.test(file)) continue;
|
|
196
|
-
if (/[/\\]rules[/\\]/.test(file) || /[/\\]\.aiwg[/\\](?!skills[/\\])/.test(file.replace(opts.target, ''))) continue;
|
|
197
|
-
let content = read(file);
|
|
198
|
-
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;
|
|
199
|
-
const skill = path.basename(file) === 'SKILL.md';
|
|
200
|
-
const name = skill ? path.basename(path.dirname(file)) : path.basename(file).replace(/\.(md|toml)$/, '');
|
|
201
|
-
const sidecarPath = path.join(skill ? path.dirname(file) : path.dirname(file), '.aiwg-manifest.json');
|
|
202
|
-
const sidecar = fs.existsSync(sidecarPath) ? JSON.parse(read(sidecarPath)) : null;
|
|
203
|
-
const source = sidecar?.skillSource ? path.join(sidecar.skillSource, 'SKILL.md') : sidecar?.managed?.[path.basename(file)]?.sourcePath;
|
|
204
|
-
const flowSource = opts.flowSkillSources?.get(file);
|
|
205
|
-
const targets = [...(flowSource ? targetsBySource.get(flowSource) || [] : []),
|
|
206
|
-
...(source ? targetsBySource.get(path.resolve(source)) || [] : opts.ruleDelivery.targets.filter(target =>
|
|
207
|
-
(skill ? target.type !== 'agent' : /[/\\](?:agents?|droids|modes?)[/\\]/.test(file) ? target.type === 'agent' : target.type === 'flow') &&
|
|
208
|
-
[target.name, path.basename(target.source, '.md'), path.basename(path.dirname(target.source))].includes(name)))];
|
|
209
|
-
const rules = targets.flatMap(target => opts.ruleDelivery.bindings.get(target.source) || []);
|
|
210
|
-
if (!rules.length && !content.includes('<!-- AIWG:bound-rules:start -->')) continue;
|
|
211
|
-
const pointer = body => {
|
|
212
|
-
const clean = replaceBoundRulesBlock(body, []);
|
|
213
|
-
if (!rules.length) return clean;
|
|
214
|
-
const identities = [...new Map(targets.map(target => [`${target.type} ${target.name}`, target])).values()];
|
|
215
|
-
for (const target of identities) {
|
|
216
|
-
const bound = opts.ruleDelivery.bindings.get(target.source) || [];
|
|
217
|
-
const unique = [...new Map(bound.map(rule => [rule.name, rule])).values()].sort((a, b) => a.name.localeCompare(b.name));
|
|
218
|
-
if (unique.length) sections.set(anchor(target), `## ${anchor(target)}\n\n` + unique.map(rule =>
|
|
219
|
-
`- ${rule.name} — ${rule.summary} Fetch and follow: \`aiwg show rule ${rule.name} --body\`.`).join('\n'));
|
|
220
|
-
}
|
|
221
|
-
// Skills must carry exact fetch commands themselves: a section pointer
|
|
222
|
-
// alone loses the invocation contract in clean installs (#3473).
|
|
223
|
-
const fetch = skill ? [...new Map(rules.map(rule => [rule.name, rule])).values()]
|
|
224
|
-
.sort((a, b) => a.name.localeCompare(b.name))
|
|
225
|
-
.map(rule => `${rule.summary}\nFetch and follow before governed work: \`aiwg show rule ${rule.name} --body\`.`).join('\n') : '';
|
|
226
|
-
return `${clean}${clean.endsWith('\n') ? '' : '\n'}\n<!-- AIWG:bound-rules:start -->\nRead and follow before governed work: ${identities.map(target =>
|
|
227
|
-
`\`${indexRel}#${anchor(target)}\``).join('; ')}.\n${fetch ? fetch + '\n' : ''}<!-- AIWG:bound-rules:end -->\n`;
|
|
228
|
-
};
|
|
229
|
-
if (file.endsWith('.toml')) content = content.replace(/^developer_instructions = (".*")$/m, (_, value) => `developer_instructions = ${JSON.stringify(pointer(JSON.parse(value)))}`);
|
|
230
|
-
else content = pointer(content);
|
|
231
|
-
put(file, content);
|
|
232
|
-
// Keep deployment hashes honest after projection by external helpers.
|
|
233
|
-
if (sidecar?.managed?.[path.basename(file)]) {
|
|
234
|
-
sidecar.managed[path.basename(file)].hash = `sha256:${contentHash(content)}`;
|
|
235
|
-
put(sidecarPath, `${JSON.stringify(sidecar, null, 2)}\n`);
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
if (sections.size) put(indexFile, managed('# Bound rules\n\nFetch and follow every full rule in the invoked artifact’s section before governed work.\n\n' +
|
|
239
|
-
[...sections.entries()].sort(([a], [b]) => a.localeCompare(b)).map(([, section]) => section).join('\n\n') + '\n', opts));
|
|
240
|
-
else if (/aiwg:managed/.test(read(indexFile))) fs.rmSync(indexFile);
|
|
241
|
-
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
/** Bindings annotate the selected deployment; they do not select standard skills
|
|
245
|
-
* (ADR lines 102–108). Flow projections follow the same opt-in and tier routing. */
|
|
246
|
-
function projectBoundFlowSkills(opts, provider, selected) {
|
|
247
|
-
opts.flowSkillSources = new Map();
|
|
248
|
-
if (opts.rulesOnly || opts.commandsOnly || !(opts.deploySkills || opts.skillsOnly)) return;
|
|
249
|
-
const kernel = path.isAbsolute(provider.kernelSkillsPath || '') ? opts.kernelSkillsPath
|
|
250
|
-
: path.join(opts.target, provider.kernelSkillsPath || `.${provider.name}/skills`);
|
|
251
|
-
// Codex's opt-in standard tier shares the native skills directory.
|
|
252
|
-
const standard = provider.name === 'codex' ? kernel : path.isAbsolute(provider.paths.skills)
|
|
253
|
-
? provider.paths.skills : path.join(opts.target, provider.paths.skills);
|
|
254
|
-
const flows = opts.ruleDelivery.targets.filter(entry => entry.type === 'flow' && selected(entry));
|
|
255
|
-
const sources = new Set(flows.map(entry => entry.source));
|
|
256
|
-
for (const root of new Set([kernel, standard])) {
|
|
257
|
-
if (!fs.existsSync(root)) continue;
|
|
258
|
-
for (const entry of fs.readdirSync(root, { withFileTypes: true })) {
|
|
259
|
-
if (!entry.isDirectory()) continue;
|
|
260
|
-
const dir = path.join(root, entry.name);
|
|
261
|
-
const file = path.join(dir, 'SKILL.md');
|
|
262
|
-
const content = read(file);
|
|
263
|
-
const receiptFile = path.join(dir, '.aiwg-manifest.json');
|
|
264
|
-
const receipt = fs.existsSync(receiptFile) ? JSON.parse(read(receiptFile)) : null;
|
|
265
|
-
// Recognize the old projector's exact generated wrapper as well as new
|
|
266
|
-
// receipts. Ordinary deployed skills and operator files are preserved.
|
|
267
|
-
const legacy = !receipt?.skillSource && !receipt?.flowSource && /aiwg:managed/.test(content)
|
|
268
|
-
&& content.includes(`description: Invoke ${entry.name}.\n`)
|
|
269
|
-
&& content.includes('```yaml\n') && content.includes('<!-- AIWG:bound-rules:start -->');
|
|
270
|
-
const stale = receipt?.flowSource && (opts.copyStandardSkills !== true
|
|
271
|
-
|| !sources.has(receipt.flowSource) || root !== standard);
|
|
272
|
-
if (!legacy && !stale) continue;
|
|
273
|
-
fs.rmSync(file, { force: true });
|
|
274
|
-
if (receipt?.flowSource) {
|
|
275
|
-
fs.rmSync(receiptFile, { force: true });
|
|
276
|
-
fs.rmSync(path.join(dir, '.aiwg-managed'), { force: true });
|
|
277
|
-
}
|
|
278
|
-
if (!fs.readdirSync(dir).length) fs.rmdirSync(dir);
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
if (opts.copyStandardSkills !== true) return;
|
|
282
|
-
for (const entry of flows) {
|
|
283
|
-
const name = entry.name || path.basename(entry.source).replace(/\.(md|ya?ml)$/, '');
|
|
284
|
-
const dir = path.join(standard, name);
|
|
285
|
-
const file = path.join(dir, 'SKILL.md');
|
|
286
|
-
const receiptFile = path.join(dir, '.aiwg-manifest.json');
|
|
287
|
-
const receipt = fs.existsSync(receiptFile) ? JSON.parse(read(receiptFile)) : null;
|
|
288
|
-
// A selected authored skill may already represent this flow. Keep its body;
|
|
289
|
-
// finishBindings adds both artifact identities' contracts after projection.
|
|
290
|
-
if (!fs.existsSync(file) || receipt?.flowSource === entry.source) {
|
|
291
|
-
const body = read(entry.source);
|
|
292
|
-
const markdown = entry.source.endsWith('.md') ? body : `---\nname: ${name}\nnamespace: aiwg\ndescription: Invoke ${name}.\n---\n\n\`\`\`yaml\n${body}\n\`\`\`\n`;
|
|
293
|
-
const projected = provider.transformSkillMd ? provider.transformSkillMd(markdown, opts) : markdown;
|
|
294
|
-
const content = managed(replaceBoundRulesBlock(projected, opts.ruleDelivery.bindings.get(entry.source)), opts);
|
|
295
|
-
put(file, content);
|
|
296
|
-
put(path.join(dir, '.aiwg-managed'), 'true\n');
|
|
297
|
-
put(receiptFile, `${JSON.stringify({ flowSource: entry.source,
|
|
298
|
-
managed: { 'SKILL.md': { sourcePath: entry.source, hash: `sha256:${contentHash(content)}` } } }, null, 2)}\n`);
|
|
299
|
-
}
|
|
300
|
-
opts.flowSkillSources.set(file, entry.source);
|
|
301
|
-
if (['warp', 'hermes'].includes(provider.name)) opts.definitionRoutes.push(`${name}: ${file}`);
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
/** Count rule sections, excluding aggregated agent/command definitions and project prose. */
|
|
306
|
-
export function warpRuleContent(content) {
|
|
307
|
-
const blocks = [...content.matchAll(/<!-- AIWG:(rule-(?:startup|core|hook-[\w-]+)):start -->[\s\S]*?<!-- AIWG:\1:end -->/g)].map(match => match[0]);
|
|
308
|
-
// Remove managed blocks first so their internal headings cannot be counted twice.
|
|
309
|
-
const remaining = content.replace(/<!-- AIWG:(rule-(?:startup|core|hook-[\w-]+)):start -->[\s\S]*?<!-- AIWG:\1:end -->/g, '');
|
|
310
|
-
const sections = [...remaining.matchAll(/^## (?:AIWG Rules|On-Demand Rules)\r?\n[\s\S]*?(?=^## |(?![\s\S]))/gm)].map(match => match[0]);
|
|
311
|
-
return [...sections, ...blocks].join('\n');
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
function startupFiles(opts, provider) {
|
|
315
|
-
const bridgeNames = { claude: ['CLAUDE.md'], cursor: ['AGENTS.md'], codex: ['AGENTS.md'], hermes: ['AGENTS.md', '.hermes.md'], pi: ['AGENTS.md'], warp: ['WARP.md'], openclaw: [] };
|
|
316
|
-
const paths = ['AIWG.md', 'WORKSPACE.md', '.aiwg/AIWG.md', ...(bridgeNames[provider.name] || ['AGENTS.md']), inlineStartup[provider.name]].filter(Boolean).map(name => path.join(opts.target, name));
|
|
317
|
-
if (opts.activeWorkspace) paths.push(path.join(opts.activeWorkspace, 'AGENTS.md'));
|
|
318
|
-
{
|
|
319
|
-
// Hook-reached files count too: moving a body must not hide its budget cost.
|
|
320
|
-
const dir = ruleDirectory(opts, provider);
|
|
321
|
-
paths.push(...walk(dir).filter(file => /\.(md|mdc)$/.test(file)));
|
|
322
|
-
}
|
|
323
|
-
return [...new Set(paths)].filter(file => fs.existsSync(file)).map(file => {
|
|
324
|
-
let content = read(file);
|
|
325
|
-
if (nativePathLoader(provider.name)) {
|
|
326
|
-
const parsed = parseRuleFrontmatter(content);
|
|
327
|
-
if (parsed.data?.paths || parsed.data?.globs) content = content.slice(0, content.length - parsed.body.length);
|
|
328
|
-
}
|
|
329
|
-
// Count managed rule sections while preserving historical accounting for
|
|
330
|
-
// operator aggregates; discrete hook-reached rule files are counted above.
|
|
331
|
-
if ((provider.name === 'warp' && path.basename(file) === 'WARP.md')
|
|
332
|
-
|| (provider.name === 'windsurf' && file === path.join(opts.target, 'AGENTS.md'))) content = warpRuleContent(content);
|
|
333
|
-
return { path: file, content };
|
|
334
|
-
});
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
// Plans contain only JSON values and a scratch directory. The preparing process
|
|
338
|
-
// owns that directory until disposal; cross-process transfer needs a separate lease.
|
|
339
|
-
const stagedCleanups = new Map();
|
|
340
|
-
export class RuleDeploymentStaleError extends Error {
|
|
341
|
-
constructor(message, paths = []) {
|
|
342
|
-
super(message);
|
|
343
|
-
this.name = 'RuleDeploymentStaleError';
|
|
344
|
-
this.code = 'AIWG_RULE_DEPLOYMENT_STALE';
|
|
345
|
-
this.paths = paths;
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
function capturePreimage(file, ancestors = new Set()) {
|
|
349
|
-
let stat;
|
|
350
|
-
try { stat = fs.lstatSync(file); } catch (error) {
|
|
351
|
-
if (error.code === 'ENOENT') return { kind: 'missing' };
|
|
352
|
-
throw error;
|
|
353
|
-
}
|
|
354
|
-
const mode = stat.mode & 0o7777;
|
|
355
|
-
if (stat.isSymbolicLink()) {
|
|
356
|
-
const target = fs.readlinkSync(file);
|
|
357
|
-
const resolved = path.resolve(path.dirname(file), target);
|
|
358
|
-
if (ancestors.has(resolved)) throw new Error(`Cyclic deployment preimage: ${file}`);
|
|
359
|
-
return { kind: 'symlink', mode, target, resolved: capturePreimage(resolved, new Set([...ancestors, resolved])) };
|
|
360
|
-
}
|
|
361
|
-
if (stat.isFile()) return { kind: 'file', mode, digest: fileDigest(file) };
|
|
362
|
-
if (stat.isDirectory()) return { kind: 'directory', mode, entries: fs.readdirSync(file).sort().map(name => [name, capturePreimage(path.join(file, name), new Set([...ancestors, path.resolve(file)]))]) };
|
|
363
|
-
throw new Error(`Unsupported deployment preimage: ${file}`);
|
|
364
|
-
}
|
|
365
|
-
// cpSync materializes links; compare its output with the recursively resolved
|
|
366
|
-
// content while retaining the original link-shaped preimage for commit drift.
|
|
367
|
-
function materializeInput(from, to, ancestors = new Set(), parentReady = false) {
|
|
368
|
-
let stat;
|
|
369
|
-
try { stat = fs.statSync(from); } catch (error) {
|
|
370
|
-
if (error.code === 'ENOENT') return;
|
|
371
|
-
throw error;
|
|
372
|
-
}
|
|
373
|
-
if (stat.isDirectory()) {
|
|
374
|
-
// Only directories can lead back to an ancestor. Resolve them once and
|
|
375
|
-
// share the immutable ancestry set with their children, including aliases.
|
|
376
|
-
const real = fs.realpathSync(from);
|
|
377
|
-
if (ancestors.has(real)) throw new Error(`Cyclic deployment input: ${from}`);
|
|
378
|
-
const children = new Set([...ancestors, real]);
|
|
379
|
-
fs.mkdirSync(to, { recursive: true });
|
|
380
|
-
for (const name of fs.readdirSync(from)) materializeInput(path.join(from, name), path.join(to, name), children, true);
|
|
381
|
-
fs.chmodSync(to, stat.mode & 0o7777);
|
|
382
|
-
} else if (stat.isFile()) {
|
|
383
|
-
if (!parentReady) fs.mkdirSync(path.dirname(to), { recursive: true });
|
|
384
|
-
fs.copyFileSync(from, to); fs.chmodSync(to, stat.mode & 0o7777);
|
|
385
|
-
} else throw new Error(`Unsupported deployment input: ${from}`);
|
|
386
|
-
}
|
|
387
|
-
function materializedPreimage(state) {
|
|
388
|
-
if (state.kind === 'symlink') return materializedPreimage(state.resolved);
|
|
389
|
-
if (state.kind === 'directory') return { ...state, entries: state.entries.map(([name, child]) => [name, materializedPreimage(child)]) };
|
|
390
|
-
return state;
|
|
391
|
-
}
|
|
392
|
-
function snapshotPreimages(paths) {
|
|
393
|
-
return [...new Set(paths.map(file => path.resolve(file)))].map(file => ({ path: file, state: capturePreimage(file) }));
|
|
394
|
-
}
|
|
395
|
-
function planSeal(plan) { return createHash('sha256').update(JSON.stringify(plan)).digest('hex'); }
|
|
396
|
-
function planOwner(plan) {
|
|
397
|
-
const owner = stagedCleanups.get(plan?.lease);
|
|
398
|
-
return owner && owner.seal === planSeal(plan) ? owner : null;
|
|
399
|
-
}
|
|
400
|
-
export function disposeRuleDeploymentPlan(plan) {
|
|
401
|
-
const owner = planOwner(plan);
|
|
402
|
-
if (owner) { stagedCleanups.delete(plan.lease); owner.cleanup(); }
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
/** Release process-local ownership while retaining a coordinator-owned stage. */
|
|
406
|
-
export function detachRuleDeploymentPlan(plan) {
|
|
407
|
-
const owner = planOwner(plan);
|
|
408
|
-
if (!owner || !owner.transferable) throw new Error('Rule deployment plan is not transferable');
|
|
409
|
-
stagedCleanups.delete(plan.lease);
|
|
410
|
-
owner.detach();
|
|
411
|
-
return plan;
|
|
412
|
-
}
|
|
413
|
-
function captureAnchors(paths) {
|
|
414
|
-
const names = new Set();
|
|
415
|
-
for (const name of paths) {
|
|
416
|
-
let current = path.resolve(name);
|
|
417
|
-
for (;;) {
|
|
418
|
-
names.add(current);
|
|
419
|
-
const parent = path.dirname(current);
|
|
420
|
-
if (parent === current) break;
|
|
421
|
-
current = parent;
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
return [...names].sort().map(file => {
|
|
425
|
-
try {
|
|
426
|
-
const stat = fs.lstatSync(file, { bigint: true });
|
|
427
|
-
return { path: file, dev: String(stat.dev), ino: String(stat.ino), mode: String(stat.mode),
|
|
428
|
-
link: stat.isSymbolicLink() ? fs.readlinkSync(file) : null, real: fs.realpathSync(file) };
|
|
429
|
-
} catch (error) {
|
|
430
|
-
if (error.code === 'ENOENT') return { path: file, missing: true };
|
|
431
|
-
throw error;
|
|
432
|
-
}
|
|
433
|
-
});
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
// Opaque coordinator-owned input pool. A plan retains a lease until committed or
|
|
437
|
-
// disposed, so disposing the creator's handle cannot invalidate active stages.
|
|
438
|
-
const inputPools = new WeakMap();
|
|
439
|
-
// Executable links are identity-bound but their installed code is trusted host
|
|
440
|
-
// state. Data files, modes, directory membership, and links are sealed in full.
|
|
441
|
-
function poolInventory(file) {
|
|
442
|
-
let stat;
|
|
443
|
-
try { stat = fs.lstatSync(file); } catch (error) {
|
|
444
|
-
if (error.code === 'ENOENT') return { kind: 'missing' };
|
|
445
|
-
throw error;
|
|
446
|
-
}
|
|
447
|
-
const mode = stat.mode & 0o7777;
|
|
448
|
-
if (stat.isSymbolicLink()) return { kind: 'symlink', mode, target: fs.readlinkSync(file) };
|
|
449
|
-
if (stat.isFile()) return { kind: 'file', mode, digest: fileDigest(file) };
|
|
450
|
-
if (stat.isDirectory()) return { kind: 'directory', mode, entries: fs.readdirSync(file).sort().map(name => [name, poolInventory(path.join(file, name))]) };
|
|
451
|
-
throw new Error(`Unsupported shared input pool entry: ${file}`);
|
|
452
|
-
}
|
|
453
|
-
function setPoolWritable(file, writable) {
|
|
454
|
-
let stat;
|
|
455
|
-
try { stat = fs.lstatSync(file); } catch (error) { if (error.code === 'ENOENT') return; throw error; }
|
|
456
|
-
if (stat.isSymbolicLink()) return;
|
|
457
|
-
if (stat.isDirectory() && writable) fs.chmodSync(file, (stat.mode & 0o7777) | 0o700);
|
|
458
|
-
if (stat.isDirectory()) for (const name of fs.readdirSync(file)) setPoolWritable(path.join(file, name), writable);
|
|
459
|
-
if (!writable) fs.chmodSync(file, (stat.mode & 0o7777) & ~0o222);
|
|
460
|
-
}
|
|
461
|
-
function verifyInputPool(pool) {
|
|
462
|
-
try {
|
|
463
|
-
if (planSeal(poolInventory(pool.snapshotRoot)) === pool.inventorySeal &&
|
|
464
|
-
JSON.stringify(captureAnchors(pool.execAnchors.map(anchor => anchor.path))) === JSON.stringify(pool.execAnchors)) return;
|
|
465
|
-
} catch (error) { throw new Error(`Shared input pool changed: ${error.message}`); }
|
|
466
|
-
throw new Error('Shared input pool changed');
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
export function createRuleDeploymentInputPool(srcRoot) {
|
|
470
|
-
const corpusRoot = resolveAiwgRoot(srcRoot) || srcRoot;
|
|
471
|
-
const sourceTree = fs.existsSync(path.join(corpusRoot, 'agentic', 'code')) ? path.join(corpusRoot, 'agentic', 'code') : srcRoot;
|
|
472
|
-
const isCorpusTree = path.relative(corpusRoot, sourceTree) === path.join('agentic', 'code');
|
|
473
|
-
const paths = [sourceTree, path.join(corpusRoot, 'prebuilt', 'framework-relations'), path.join(corpusRoot, 'package.json'), path.join(corpusRoot, 'schemas')];
|
|
474
|
-
const preimages = snapshotPreimages(paths);
|
|
475
|
-
const temp = fs.mkdtempSync(path.join(os.tmpdir(), 'aiwg-rule-input-'));
|
|
476
|
-
const cleanup = trackTemporaryDirectory(temp);
|
|
477
|
-
try {
|
|
478
|
-
const snapshotRoot = path.join(temp, 'input');
|
|
479
|
-
const snapshotTree = isCorpusTree ? path.join(snapshotRoot, 'agentic', 'code') : snapshotRoot;
|
|
480
|
-
materializeInput(sourceTree, snapshotTree);
|
|
481
|
-
if (JSON.stringify(capturePreimage(snapshotTree)) !== JSON.stringify(materializedPreimage(preimages[0].state))) throw new Error('Source changed while preparing immutable snapshot');
|
|
482
|
-
const trustedExec = [];
|
|
483
|
-
if (isCorpusTree) {
|
|
484
|
-
for (const rel of ['package.json', 'prebuilt/framework-relations', 'schemas']) {
|
|
485
|
-
const from = path.join(corpusRoot, rel), to = path.join(snapshotRoot, rel);
|
|
486
|
-
materializeInput(from, to);
|
|
487
|
-
const expected = preimages.find(item => item.path === path.resolve(from));
|
|
488
|
-
if (JSON.stringify(capturePreimage(to)) !== JSON.stringify(materializedPreimage(expected.state))) throw new Error(`Package input changed while preparing snapshot: ${from}`);
|
|
489
|
-
}
|
|
490
|
-
for (const rel of ['tools', 'dist', 'node_modules', 'src']) {
|
|
491
|
-
const from = path.join(corpusRoot, rel), to = path.join(snapshotRoot, rel);
|
|
492
|
-
if (fs.existsSync(from)) { fs.symlinkSync(from, to, 'dir'); trustedExec.push(from); }
|
|
493
|
-
}
|
|
494
|
-
}
|
|
495
|
-
setPoolWritable(snapshotRoot, false);
|
|
496
|
-
const inventorySeal = planSeal(poolInventory(snapshotRoot));
|
|
497
|
-
const execAnchors = captureAnchors(trustedExec);
|
|
498
|
-
const safeCleanup = () => { setPoolWritable(snapshotRoot, true); cleanup(); };
|
|
499
|
-
const token = Object.freeze({});
|
|
500
|
-
inputPools.set(token, { corpusRoot: path.resolve(corpusRoot), sourceTree: path.resolve(sourceTree), snapshotRoot, snapshotTree, isCorpusTree, preimages, inventorySeal, execAnchors, refs: 1, closed: false, cleanup: safeCleanup, transferable: true });
|
|
501
|
-
return token;
|
|
502
|
-
} catch (error) { setPoolWritable(path.join(temp, 'input'), true); cleanup(); throw error; }
|
|
503
|
-
}
|
|
504
|
-
function releaseInputPool(pool) { if (--pool.refs === 0) pool.cleanup(); }
|
|
505
|
-
export function disposeRuleDeploymentInputPool(token) {
|
|
506
|
-
const pool = inputPools.get(token);
|
|
507
|
-
if (pool && !pool.closed) { pool.closed = true; releaseInputPool(pool); }
|
|
508
|
-
}
|
|
509
|
-
|
|
510
|
-
/** A descriptor contains immutable snapshot identity, never its cleanup lease. */
|
|
511
|
-
export function describeRuleDeploymentInputPool(token) {
|
|
512
|
-
const pool = inputPools.get(token);
|
|
513
|
-
if (!pool || pool.closed || !pool.transferable) throw new Error('Invalid or closed rule deployment input pool');
|
|
514
|
-
verifyInputPool(pool);
|
|
515
|
-
return {
|
|
516
|
-
version: 1,
|
|
517
|
-
corpusRoot: pool.corpusRoot,
|
|
518
|
-
sourceTree: pool.sourceTree,
|
|
519
|
-
snapshotRoot: pool.snapshotRoot,
|
|
520
|
-
snapshotTree: pool.snapshotTree,
|
|
521
|
-
isCorpusTree: pool.isCorpusTree,
|
|
522
|
-
inventorySeal: pool.inventorySeal,
|
|
523
|
-
execAnchors: pool.execAnchors,
|
|
524
|
-
};
|
|
525
|
-
}
|
|
526
|
-
|
|
527
|
-
/** Import a read-only pool view in a preparation worker. The coordinator keeps
|
|
528
|
-
* the only cleanup lease and later restores the live-source preimages. */
|
|
529
|
-
export function importRuleDeploymentInputPool(descriptor) {
|
|
530
|
-
if (!descriptor || descriptor.version !== 1 || typeof descriptor.inventorySeal !== 'string' ||
|
|
531
|
-
!Array.isArray(descriptor.execAnchors)) throw new Error('Invalid rule deployment input pool descriptor');
|
|
532
|
-
for (const key of ['corpusRoot', 'sourceTree', 'snapshotRoot', 'snapshotTree']) {
|
|
533
|
-
if (typeof descriptor[key] !== 'string' || !path.isAbsolute(descriptor[key])) throw new Error('Invalid rule deployment input pool descriptor');
|
|
534
|
-
}
|
|
535
|
-
const token = Object.freeze({});
|
|
536
|
-
const pool = { ...descriptor, corpusRoot: path.resolve(descriptor.corpusRoot), sourceTree: path.resolve(descriptor.sourceTree),
|
|
537
|
-
snapshotRoot: path.resolve(descriptor.snapshotRoot), snapshotTree: path.resolve(descriptor.snapshotTree), preimages: [],
|
|
538
|
-
refs: 1, closed: false, cleanup: () => {}, transferable: false };
|
|
539
|
-
verifyInputPool(pool);
|
|
540
|
-
inputPools.set(token, pool);
|
|
541
|
-
return token;
|
|
542
|
-
}
|
|
543
|
-
|
|
544
|
-
function within(root, file) {
|
|
545
|
-
const relative = path.relative(path.resolve(root), path.resolve(file));
|
|
546
|
-
return relative === '' || (!relative.startsWith(`..${path.sep}`) && relative !== '..' && !path.isAbsolute(relative));
|
|
547
|
-
}
|
|
548
|
-
|
|
549
|
-
function safeRelative(root, name) {
|
|
550
|
-
return typeof name === 'string' && name !== '' && name !== '.' && path.normalize(name) === name && !path.isAbsolute(name) && within(root, path.join(root, name));
|
|
551
|
-
}
|
|
552
|
-
|
|
553
|
-
function exactObjectKeys(value, keys) {
|
|
554
|
-
return value && typeof value === 'object' && !Array.isArray(value) &&
|
|
555
|
-
JSON.stringify(Object.keys(value).sort()) === JSON.stringify([...keys].sort());
|
|
556
|
-
}
|
|
557
|
-
|
|
558
|
-
function validPreimageState(state) {
|
|
559
|
-
if (!state || typeof state !== 'object' || Array.isArray(state) || typeof state.kind !== 'string') return false;
|
|
560
|
-
if (state.kind === 'missing') return Object.keys(state).length === 1;
|
|
561
|
-
if (!Number.isSafeInteger(state.mode) || state.mode < 0) return false;
|
|
562
|
-
if (state.kind === 'file') return Object.keys(state).length === 3 && /^[a-f0-9]{64}$/.test(state.digest);
|
|
563
|
-
if (state.kind === 'symlink') return Object.keys(state).length === 4 && typeof state.target === 'string' && validPreimageState(state.resolved);
|
|
564
|
-
return state.kind === 'directory' && Object.keys(state).length === 3 && Array.isArray(state.entries) && state.entries.every(entry =>
|
|
565
|
-
Array.isArray(entry) && entry.length === 2 && typeof entry[0] === 'string' && entry[0] !== '' && !entry[0].includes(path.sep) && validPreimageState(entry[1]));
|
|
566
|
-
}
|
|
567
|
-
|
|
568
|
-
function expectedAnchorPaths(paths) {
|
|
569
|
-
const names = new Set();
|
|
570
|
-
for (const name of paths) {
|
|
571
|
-
let current = path.resolve(name);
|
|
572
|
-
for (;;) {
|
|
573
|
-
names.add(current);
|
|
574
|
-
const parent = path.dirname(current);
|
|
575
|
-
if (parent === current) break;
|
|
576
|
-
current = parent;
|
|
577
|
-
}
|
|
578
|
-
}
|
|
579
|
-
return [...names].sort();
|
|
580
|
-
}
|
|
581
|
-
|
|
582
|
-
/** Adopt a detached worker plan into the coordinator's process-local lease. */
|
|
583
|
-
export function adoptRuleDeploymentPlan(detached, { scratch, target, inputPool, cleanup }) {
|
|
584
|
-
const invalid = () => { throw new Error('Invalid transferred rule deployment plan'); };
|
|
585
|
-
if (!exactObjectKeys(detached, ['version', 'lease', 'temp', 'target', 'stage', 'rootNames', 'workspaceDirs', 'preimages', 'poolSeal', 'anchors', 'snapshotRoot', 'corpusRoot', 'sourceMappings', 'staged', 'report', 'mappings', 'contextWrites']) ||
|
|
586
|
-
detached.version !== 1 || typeof detached.lease !== 'string' || !(detached.poolSeal === null || typeof detached.poolSeal === 'string') ||
|
|
587
|
-
!detached.report || typeof detached.report !== 'object' || Array.isArray(detached.report) || typeof scratch !== 'string' || typeof target !== 'string' || typeof cleanup !== 'function') invalid();
|
|
588
|
-
const root = path.resolve(scratch), expectedTarget = path.resolve(target);
|
|
589
|
-
if (path.resolve(detached.temp || '') !== root || path.resolve(detached.stage || '') !== path.join(root, 'project') || path.resolve(detached.target || '') !== expectedTarget) invalid();
|
|
590
|
-
if (!Array.isArray(detached.contextWrites) || detached.contextWrites.some(file => typeof file !== 'string' || !within(root, file)) || !Array.isArray(detached.staged) || !Array.isArray(detached.mappings) || !Array.isArray(detached.rootNames) || !Array.isArray(detached.preimages) ||
|
|
591
|
-
!Array.isArray(detached.workspaceDirs) || !Array.isArray(detached.anchors) || !Array.isArray(detached.sourceMappings) ||
|
|
592
|
-
typeof detached.snapshotRoot !== 'string' || !path.isAbsolute(detached.snapshotRoot) || typeof detached.corpusRoot !== 'string' || !path.isAbsolute(detached.corpusRoot)) invalid();
|
|
593
|
-
if (detached.rootNames.some(name => !safeRelative(expectedTarget, name))) invalid();
|
|
594
|
-
const pool = inputPool && inputPools.get(inputPool);
|
|
595
|
-
if (inputPool && (!pool || pool.closed || !pool.transferable)) invalid();
|
|
596
|
-
if (pool) {
|
|
597
|
-
verifyInputPool(pool);
|
|
598
|
-
if (detached.poolSeal !== pool.inventorySeal || path.resolve(detached.snapshotRoot || '') !== pool.snapshotRoot) invalid();
|
|
599
|
-
} else if (detached.poolSeal) invalid();
|
|
600
|
-
const expectedArtifactRoot = path.resolve(resolveProjectAiwgDir(expectedTarget));
|
|
601
|
-
const validSourceMapping = item => within(root, item.to) || (pool && within(pool.snapshotRoot, item.to)) ||
|
|
602
|
-
(path.resolve(item.from) === path.join(expectedTarget, '.aiwg') && path.resolve(item.to) === expectedArtifactRoot);
|
|
603
|
-
if (detached.workspaceDirs.some(name => !safeRelative(expectedTarget, name)) ||
|
|
604
|
-
detached.preimages.some(item => !item || Object.keys(item).length !== 2 || typeof item.path !== 'string' || !path.isAbsolute(item.path) || !validPreimageState(item.state)) ||
|
|
605
|
-
detached.staged.some(item => !item || Object.keys(item).length !== 2 || typeof item.path !== 'string' || !within(root, item.path) || !validPreimageState(item.state)) ||
|
|
606
|
-
detached.sourceMappings.some(item => !item || Object.keys(item).length !== 2 || typeof item.from !== 'string' || !path.isAbsolute(item.from) ||
|
|
607
|
-
typeof item.to !== 'string' || !path.isAbsolute(item.to) || !validSourceMapping(item)) ||
|
|
608
|
-
detached.mappings.some(item => !item || Object.keys(item).length !== 3 || typeof item.from !== 'string' || !path.isAbsolute(item.from) ||
|
|
609
|
-
typeof item.to !== 'string' || !within(root, item.to) || within(root, item.from) || !Array.isArray(item.before) || item.before.some(entry =>
|
|
610
|
-
!Array.isArray(entry) || entry.length !== 2 || !safeRelative(item.to, entry[0]) || !/^[a-f0-9]{64}$/.test(entry[1])))) invalid();
|
|
611
|
-
const expectedStaged = [path.join(root, 'project'), ...detached.mappings.map(item => path.resolve(item.to))].sort();
|
|
612
|
-
if (JSON.stringify(detached.staged.map(item => path.resolve(item.path)).sort()) !== JSON.stringify([...new Set(expectedStaged)])) invalid();
|
|
613
|
-
const anchorPaths = expectedAnchorPaths([expectedTarget, ...detached.mappings.map(item => item.from), ...detached.workspaceDirs.map(name => path.join(expectedTarget, name))]);
|
|
614
|
-
if (detached.anchors.some(item => !item || typeof item.path !== 'string' || !path.isAbsolute(item.path) ||
|
|
615
|
-
(item.missing === true ? Object.keys(item).length !== 2 : Object.keys(item).sort().join(',') !== 'dev,ino,link,mode,path,real' ||
|
|
616
|
-
!['dev', 'ino', 'mode', 'real'].every(key => typeof item[key] === 'string') || !(item.link === null || typeof item.link === 'string'))) ||
|
|
617
|
-
JSON.stringify(detached.anchors.map(item => path.resolve(item.path)).sort()) !== JSON.stringify(anchorPaths)) invalid();
|
|
618
|
-
const plan = structuredClone(detached);
|
|
619
|
-
plan.lease = randomUUID();
|
|
620
|
-
if (pool) {
|
|
621
|
-
const existing = new Set(plan.preimages.map(item => path.resolve(item.path)));
|
|
622
|
-
plan.preimages.unshift(...pool.preimages.filter(item => !existing.has(path.resolve(item.path))));
|
|
623
|
-
pool.refs++;
|
|
624
|
-
}
|
|
625
|
-
const ownerCleanup = () => { try { cleanup(); } finally { if (pool) releaseInputPool(pool); } };
|
|
626
|
-
stagedCleanups.set(plan.lease, { temp: root, cleanup: ownerCleanup, pool, seal: planSeal(plan), transferable: false, detach: () => {} });
|
|
627
|
-
return plan;
|
|
628
|
-
}
|
|
629
|
-
|
|
630
|
-
/** Stage only provider/context output, never the user's source tree. On failure
|
|
631
|
-
* no staged output (including skills and behaviors) reaches the prior deployment. */
|
|
632
|
-
export async function prepareRuleDeployment(original, provider, deploy) {
|
|
633
|
-
const budgetEnv = { ...process.env };
|
|
634
|
-
const ruleDir = path.isAbsolute(provider.paths.rules || '') ? provider.paths.rules : path.join(original.target, provider.paths.rules || `.${provider.name}/rules`);
|
|
635
|
-
const manifestFile = path.join(ruleDir, '.aiwg-manifest.json');
|
|
636
|
-
const previousText = fs.existsSync(manifestFile) ? read(manifestFile) : '';
|
|
637
|
-
const previous = previousText ? JSON.parse(previousText) : {};
|
|
638
|
-
const corpusRoot = resolveAiwgRoot(original.srcRoot) || original.srcRoot;
|
|
639
|
-
if (!original.deployVersion || /unknown/i.test(original.deployVersion)) {
|
|
640
|
-
original = { ...original, deployVersion: resolveDeployVersion(corpusRoot, original.deployVersion) };
|
|
641
|
-
}
|
|
642
|
-
const sourceTree = fs.existsSync(path.join(corpusRoot, 'agentic', 'code'))
|
|
643
|
-
? path.join(corpusRoot, 'agentic', 'code') : original.srcRoot;
|
|
644
|
-
const pool = original.inputPool && inputPools.get(original.inputPool);
|
|
645
|
-
if (original.inputPool && (!pool || pool.closed || pool.corpusRoot !== path.resolve(corpusRoot) || pool.sourceTree !== path.resolve(sourceTree))) throw new Error('Invalid or closed rule deployment input pool');
|
|
646
|
-
if (pool) verifyInputPool(pool);
|
|
647
|
-
let projectConfig = original.config;
|
|
648
|
-
if (!projectConfig) {
|
|
649
|
-
try { projectConfig = JSON.parse(read(path.join(original.target, '.aiwg', 'aiwg.config')) || '{}'); } catch { projectConfig = {}; }
|
|
650
|
-
}
|
|
651
|
-
const artifactRoot = resolveProjectAiwgDir(original.target);
|
|
652
|
-
const userIndexRoot = path.join(process.env.XDG_DATA_HOME || path.join(os.homedir(), '.local', 'share'), 'aiwg', 'index');
|
|
653
|
-
const projectGraphFiles = ['.index/metadata.json', '.index/project/metadata.json'].map(name => path.join(artifactRoot, name));
|
|
654
|
-
const userGraphFiles = ['user'].map(name => path.join(userIndexRoot, name, 'metadata.json'));
|
|
655
|
-
const localSources = Object.values(projectConfig.installed || {}).filter(entry => entry?.localPath)
|
|
656
|
-
.map(entry => path.resolve(original.target, entry.localPath));
|
|
657
|
-
const selectedRules = collectDeploymentRuleSources({ ...original, previousRuleSources: previous.ruleSources || [] });
|
|
658
|
-
const initialPreimages = [...(pool ? pool.preimages : snapshotPreimages([sourceTree, path.join(corpusRoot, 'prebuilt', 'framework-relations'), path.join(corpusRoot, 'package.json'), path.join(corpusRoot, 'schemas')])), ...snapshotPreimages([path.join(corpusRoot, '.aiwg', '.index'),
|
|
659
|
-
manifestFile, path.join(original.target, '.aiwg', 'aiwg.config'), path.join(original.target, '.aiwg', 'AIWG.md'), path.join(original.target, '.aiwg', 'skills'), path.join(original.target, '.aiwg-location'), ...projectGraphFiles, ...userGraphFiles, ...localSources,
|
|
660
|
-
...(path.resolve(original.srcRoot) === path.resolve(corpusRoot) ? [] : [original.srcRoot]), ...(original.additionalSources || []), ...selectedRules, ...selectedRules.map(file => path.dirname(file)),
|
|
661
|
-
userConfigFile('aiwg.config'), process.env.AIWG_USER_REGISTRY_PATH || userConfigFile('installed.json'),
|
|
662
|
-
...(original.ruleSources || []), ...(previous.ruleSources || []), ...(original.bindingEntries || []).map(entry => entry.path)])];
|
|
663
|
-
let manifestState = initialPreimages.find(item => item.path === path.resolve(manifestFile)).state;
|
|
664
|
-
if (manifestState.kind === 'symlink') manifestState = manifestState.resolved;
|
|
665
|
-
const manifestDigest = previousText ? createHash('sha256').update(previousText).digest('hex') : null;
|
|
666
|
-
if ((manifestState.kind === 'missing' ? null : manifestState.digest) !== manifestDigest) throw new Error('Rule manifest changed while preparing snapshot');
|
|
667
|
-
const transferable = Boolean(original.ruleDeploymentScratch);
|
|
668
|
-
const temp = transferable ? path.resolve(original.ruleDeploymentScratch) : fs.mkdtempSync(path.join(os.tmpdir(), 'aiwg-rule-deploy-'));
|
|
669
|
-
if (transferable) {
|
|
670
|
-
const stat = fs.lstatSync(temp);
|
|
671
|
-
if (!stat.isDirectory() || stat.isSymbolicLink() || fs.readdirSync(temp).length) throw new Error('Invalid rule deployment scratch directory');
|
|
672
|
-
}
|
|
673
|
-
const removeStage = transferable
|
|
674
|
-
? () => fs.rmSync(temp, { recursive: true, force: true })
|
|
675
|
-
: trackTemporaryDirectory(temp);
|
|
676
|
-
if (pool) pool.refs++;
|
|
677
|
-
const removeTemp = () => { removeStage(); if (pool) releaseInputPool(pool); };
|
|
678
|
-
const lease = randomUUID();
|
|
679
|
-
stagedCleanups.set(lease, { temp, cleanup: removeTemp, detach: () => { if (pool) releaseInputPool(pool); }, pool, seal: null, transferable });
|
|
680
|
-
const priorContextStage = process.env[CONTEXT_STAGE_ENV];
|
|
681
|
-
const contextStageLog = path.join(temp, 'context-writes.jsonl');
|
|
682
|
-
fs.writeFileSync(contextStageLog, '');
|
|
683
|
-
process.env[CONTEXT_STAGE_ENV] = contextStageLog;
|
|
684
|
-
const mappings = [];
|
|
685
|
-
const preimages = [...initialPreimages];
|
|
686
|
-
let retained = false;
|
|
687
|
-
const originals = captureProviderPathDescriptors(provider);
|
|
688
|
-
const logicalTarget = original.target;
|
|
689
|
-
const priorAiwgRoot = process.env.AIWG_ROOT;
|
|
690
|
-
const priorRegistry = process.env.AIWG_USER_REGISTRY_PATH;
|
|
691
|
-
const priorArtifacts = process.env.AIWG_ARTIFACTS_PATH;
|
|
692
|
-
const priorXdgData = process.env.XDG_DATA_HOME;
|
|
693
|
-
try {
|
|
694
|
-
const snapshotRoot = pool ? pool.snapshotRoot : path.join(temp, 'input');
|
|
695
|
-
const treeRelative = path.relative(corpusRoot, sourceTree);
|
|
696
|
-
const isCorpusTree = treeRelative === path.join('agentic', 'code');
|
|
697
|
-
const snapshotTree = isCorpusTree ? path.join(snapshotRoot, 'agentic', 'code') : snapshotRoot;
|
|
698
|
-
if (!pool) { fs.mkdirSync(path.dirname(snapshotTree), { recursive: true }); materializeInput(sourceTree, snapshotTree); }
|
|
699
|
-
const expectedTree = initialPreimages.find(item => item.path === path.resolve(sourceTree));
|
|
700
|
-
if (!pool && JSON.stringify(capturePreimage(snapshotTree)) !== JSON.stringify(materializedPreimage(expectedTree.state))) throw new Error('Source changed while preparing immutable snapshot');
|
|
701
|
-
if (isCorpusTree && !pool) {
|
|
702
|
-
for (const rel of ['package.json', 'prebuilt', 'schemas']) {
|
|
703
|
-
const from = path.join(corpusRoot, rel), to = path.join(snapshotRoot, rel);
|
|
704
|
-
if (fs.existsSync(from)) materializeInput(from, to);
|
|
705
|
-
const expected = initialPreimages.find(item => item.path === path.resolve(from));
|
|
706
|
-
if (expected && JSON.stringify(capturePreimage(to)) !== JSON.stringify(materializedPreimage(expected.state))) throw new Error(`Package input changed while preparing snapshot: ${from}`);
|
|
707
|
-
}
|
|
708
|
-
// The projector helpers execute installed code but receive the snapshot as data.
|
|
709
|
-
for (const rel of ['tools', 'dist', 'node_modules', 'src']) {
|
|
710
|
-
const from = path.join(corpusRoot, rel), to = path.join(snapshotRoot, rel);
|
|
711
|
-
if (fs.existsSync(from)) fs.symlinkSync(from, to, 'dir');
|
|
712
|
-
}
|
|
713
|
-
}
|
|
714
|
-
// Keep standalone fixture/bundle snapshots from inheriting the installed
|
|
715
|
-
// package's unrelated prebuilt relations through module-root fallback.
|
|
716
|
-
process.env.AIWG_ROOT = snapshotRoot;
|
|
717
|
-
const frozenConfigDir = path.join(temp, 'config');
|
|
718
|
-
fs.mkdirSync(frozenConfigDir);
|
|
719
|
-
const frozenFile = (from, name, expected) => {
|
|
720
|
-
const to = path.join(frozenConfigDir, name);
|
|
721
|
-
if (fs.existsSync(from)) { fs.copyFileSync(from, to); fs.chmodSync(to, fs.statSync(from).mode & 0o7777); }
|
|
722
|
-
if (JSON.stringify(capturePreimage(to)) !== JSON.stringify(materializedPreimage(expected || { kind: 'missing' }))) throw new Error(`Configuration changed while preparing snapshot: ${from}`);
|
|
723
|
-
return to;
|
|
724
|
-
};
|
|
725
|
-
const projectFile = path.join(logicalTarget, '.aiwg', 'aiwg.config');
|
|
726
|
-
const projectFileState = initialPreimages.find(item => item.path === path.resolve(projectFile))?.state;
|
|
727
|
-
const userFile = userConfigFile('aiwg.config');
|
|
728
|
-
const registryFile = priorRegistry || userConfigFile('installed.json');
|
|
729
|
-
const projectSnapshot = frozenFile(projectFile, 'project.json', projectFileState);
|
|
730
|
-
const userSnapshot = frozenFile(userFile, 'user.json', initialPreimages.find(item => item.path === path.resolve(userFile))?.state);
|
|
731
|
-
const registrySnapshot = frozenFile(registryFile, 'registry.json', initialPreimages.find(item => item.path === path.resolve(registryFile))?.state);
|
|
732
|
-
const readConfig = file => fs.existsSync(file) ? JSON.parse(read(file)) : {};
|
|
733
|
-
const effectiveConfig = structuredClone(original.config || readConfig(projectSnapshot));
|
|
734
|
-
const pinConfigs = structuredClone(original.pinConfigs || { project: effectiveConfig, user: readConfig(userSnapshot) });
|
|
735
|
-
const frozenLocal = Object.values(pinConfigs.project.installed || {}).filter(entry => entry?.localPath)
|
|
736
|
-
.map(entry => path.resolve(logicalTarget, entry.localPath));
|
|
737
|
-
if (JSON.stringify([...new Set(frozenLocal)].sort()) !== JSON.stringify([...new Set(localSources)].sort())) throw new Error('Project-local configuration changed while preparing snapshot');
|
|
738
|
-
const sourceMappings = [{ from: path.resolve(sourceTree), to: snapshotTree }];
|
|
739
|
-
for (const [index, from] of [...new Set(localSources)].entries()) {
|
|
740
|
-
const to = path.join(temp, 'local-input', String(index));
|
|
741
|
-
const expected = initialPreimages.find(item => item.path === from)?.state;
|
|
742
|
-
if (fs.existsSync(from)) { fs.mkdirSync(path.dirname(to), { recursive: true }); materializeInput(from, to); }
|
|
743
|
-
if (JSON.stringify(capturePreimage(to)) !== JSON.stringify(materializedPreimage(expected || { kind: 'missing' }))) throw new Error(`Project-local input changed while preparing snapshot: ${from}`);
|
|
744
|
-
sourceMappings.push({ from, to });
|
|
745
|
-
}
|
|
746
|
-
const externalInputs = [...new Set([...(path.resolve(original.srcRoot) === path.resolve(corpusRoot) ? [] : [original.srcRoot]), ...(original.additionalSources || []), ...(original.ruleSources || []), ...(previous.ruleSources || []),
|
|
747
|
-
...(original.bindingEntries || []).map(entry => entry.path)].map(file => path.resolve(file)))];
|
|
748
|
-
for (const [index, from] of externalInputs.entries()) {
|
|
749
|
-
if (sourceMappings.some(item => from === item.from || from.startsWith(`${item.from}${path.sep}`))) continue;
|
|
750
|
-
const to = path.join(temp, 'external-input', String(index), path.basename(from));
|
|
751
|
-
const expected = initialPreimages.find(item => item.path === from)?.state;
|
|
752
|
-
if (fs.existsSync(from)) { fs.mkdirSync(path.dirname(to), { recursive: true }); materializeInput(from, to); }
|
|
753
|
-
if (JSON.stringify(capturePreimage(to)) !== JSON.stringify(materializedPreimage(expected || { kind: 'missing' }))) throw new Error(`External input changed while preparing snapshot: ${from}`);
|
|
754
|
-
sourceMappings.push({ from, to });
|
|
755
|
-
}
|
|
756
|
-
for (const entry of Object.values(pinConfigs.project.installed || {})) {
|
|
757
|
-
if (!entry?.localPath) continue;
|
|
758
|
-
const from = path.resolve(logicalTarget, entry.localPath);
|
|
759
|
-
entry.localPath = sourceMappings.find(mapping => mapping.from === from).to;
|
|
760
|
-
}
|
|
761
|
-
process.env.AIWG_USER_REGISTRY_PATH = registrySnapshot;
|
|
762
|
-
let stagedProjectRoot;
|
|
763
|
-
const mapSource = file => {
|
|
764
|
-
let absolute = path.resolve(file);
|
|
765
|
-
if (stagedProjectRoot && absolute.startsWith(`${stagedProjectRoot}${path.sep}`)) {
|
|
766
|
-
const logical = path.join(logicalTarget, path.relative(stagedProjectRoot, absolute));
|
|
767
|
-
if (sourceMappings.some(item => logical === item.from || logical.startsWith(`${item.from}${path.sep}`)) || !fs.existsSync(absolute)) absolute = logical;
|
|
768
|
-
}
|
|
769
|
-
const mapping = [...sourceMappings].sort((a, b) => b.from.length - a.from.length)
|
|
770
|
-
.find(item => absolute === item.from || absolute.startsWith(`${item.from}${path.sep}`));
|
|
771
|
-
if (mapping) return path.join(mapping.to, path.relative(mapping.from, absolute));
|
|
772
|
-
if (isCorpusTree && absolute === path.resolve(corpusRoot)) return snapshotRoot;
|
|
773
|
-
return file;
|
|
774
|
-
};
|
|
775
|
-
const logicalInputPath = file => {
|
|
776
|
-
let result = file;
|
|
777
|
-
for (const mapping of [...sourceMappings].sort((a, b) => b.to.length - a.to.length)) result = result.split(mapping.to).join(mapping.from);
|
|
778
|
-
return result.split(snapshotRoot).join(corpusRoot);
|
|
779
|
-
};
|
|
780
|
-
original = { ...original, config: effectiveConfig, srcRoot: mapSource(original.srcRoot), pinConfigs, mapInputPath: mapSource, logicalInputPath,
|
|
781
|
-
...(original.additionalSources ? { additionalSources: original.additionalSources.map(mapSource) } : {}),
|
|
782
|
-
...(original.ruleSources ? { ruleSources: original.ruleSources.map(mapSource) } : {}),
|
|
783
|
-
...(original.bindingEntries ? { bindingEntries: original.bindingEntries.map(entry => ({ ...entry, path: mapSource(entry.path) })) } : {}) };
|
|
784
|
-
const target = path.resolve(original.target);
|
|
785
|
-
const stage = path.join(temp, 'project');
|
|
786
|
-
stagedProjectRoot = stage;
|
|
787
|
-
fs.mkdirSync(stage);
|
|
788
|
-
const mount = (from, to) => {
|
|
789
|
-
if (mappings.some(mapping => mapping.from === from)) return;
|
|
790
|
-
const mountPreimage = snapshotPreimages([from])[0];
|
|
791
|
-
preimages.push(mountPreimage);
|
|
792
|
-
if (fs.existsSync(from)) materializeInput(from, to);
|
|
793
|
-
const before = new Map(walk(to).map(file => [path.relative(to, file), fileDigest(file)]));
|
|
794
|
-
if (JSON.stringify(capturePreimage(to)) !== JSON.stringify(materializedPreimage(mountPreimage.state))) throw new Error(`Deployment input changed while preparing snapshot: ${from}`);
|
|
795
|
-
mappings.push({ from, to, before });
|
|
796
|
-
};
|
|
797
|
-
// Mount directories independently so only provider-owned surfaces are promoted.
|
|
798
|
-
const relativeRoots = Object.values(provider.paths).filter(dir => dir && !path.isAbsolute(dir))
|
|
799
|
-
.map(dir => dir.split(/[\\/]/)[0]).filter(dir => dir && dir !== '.' && !path.extname(dir));
|
|
800
|
-
for (const dir of new Set([`.${provider.name}`, '.agents', '.aiwg/skills', ...relativeRoots])) mount(path.join(target, dir), path.join(stage, dir));
|
|
801
|
-
fs.mkdirSync(path.join(stage, '.aiwg'), { recursive: true });
|
|
802
|
-
if (fs.existsSync(projectSnapshot)) materializeInput(projectSnapshot, path.join(stage, '.aiwg', 'aiwg.config'));
|
|
803
|
-
const rootNames = ['opencode.json', 'AGENTS.md', 'AIWG.md', 'WORKSPACE.md', 'CLAUDE.md', 'WARP.md', '.hermes.md', '.aiwg/AIWG.md', '.aiwg/frameworks/registry.json'];
|
|
804
|
-
if (provider.name === 'windsurf') rootNames.push('.windsurfrules');
|
|
805
|
-
for (const framework of getFrameworksForMode(original.srcRoot, original.mode)) {
|
|
806
|
-
for (const entry of framework.manifest?.memory?.creates || []) {
|
|
807
|
-
if (typeof entry?.path !== 'string' || !entry.path.startsWith('.aiwg/') || !path.extname(entry.path)) continue;
|
|
808
|
-
const safe = path.normalize(entry.path);
|
|
809
|
-
if (!safe.startsWith(`.aiwg${path.sep}`)) throw new Error(`Invalid framework workspace path: ${entry.path}`);
|
|
810
|
-
if (!rootNames.includes(safe)) rootNames.push(safe);
|
|
811
|
-
}
|
|
812
|
-
}
|
|
813
|
-
preimages.push(...snapshotPreimages(rootNames.map(name => path.join(target, name))));
|
|
814
|
-
for (const name of rootNames) {
|
|
815
|
-
const from = path.join(target, name), to = path.join(stage, name);
|
|
816
|
-
if (fs.existsSync(from)) { fs.mkdirSync(path.dirname(to), { recursive: true }); fs.copyFileSync(from, to); fs.chmodSync(to, fs.statSync(from).mode & 0o7777); }
|
|
817
|
-
const expected = preimages.find(item => item.path === path.resolve(from));
|
|
818
|
-
if (JSON.stringify(capturePreimage(to)) !== JSON.stringify(materializedPreimage(expected.state))) throw new Error(`Deployment input changed while preparing snapshot: ${from}`);
|
|
819
|
-
}
|
|
820
|
-
const home = path.join(temp, 'home');
|
|
821
|
-
for (const [key, dir] of Object.entries(provider.paths)) {
|
|
822
|
-
if (!path.isAbsolute(dir)) continue;
|
|
823
|
-
const to = path.join(temp, 'native', key);
|
|
824
|
-
mount(dir, to);
|
|
825
|
-
setStagedProviderPath(provider, key, to);
|
|
826
|
-
}
|
|
827
|
-
let kernel = provider.kernelSkillsPath;
|
|
828
|
-
if (kernel && path.isAbsolute(kernel)) {
|
|
829
|
-
const to = path.join(temp, 'native', 'kernel-skills');
|
|
830
|
-
mount(kernel, to);
|
|
831
|
-
kernel = to;
|
|
832
|
-
}
|
|
833
|
-
// Codex's legacy prompt helper is home-global. Give it an isolated home and
|
|
834
|
-
// promote only its output after validation.
|
|
835
|
-
if (provider.name === 'codex' && (original.deployCommands || original.commandsOnly)) mount(path.join(os.homedir(), '.codex', 'prompts'), path.join(home, '.codex', 'prompts'));
|
|
836
|
-
let hermesLegacySkills;
|
|
837
|
-
let legacyCodexSkills;
|
|
838
|
-
if (provider.name === 'hermes') {
|
|
839
|
-
const source = path.join(path.dirname(provider.kernelSkillsPath), '.aiwg', 'skills');
|
|
840
|
-
hermesLegacySkills = path.join(temp, 'hermes-legacy-skills');
|
|
841
|
-
mount(source, hermesLegacySkills);
|
|
842
|
-
}
|
|
843
|
-
if (provider.name === 'codex' && (original.deploySkills || original.skillsOnly)) {
|
|
844
|
-
legacyCodexSkills = path.join(temp, 'codex-legacy-skills');
|
|
845
|
-
mount(path.join(os.homedir(), '.codex', 'skills'), legacyCodexSkills);
|
|
846
|
-
}
|
|
847
|
-
// Existing receipts carry logical source paths. Projectors operate against
|
|
848
|
-
// the immutable snapshot, so translate those paths before stale cleanup;
|
|
849
|
-
// promotion normalizes them back to their logical paths.
|
|
850
|
-
for (const { to } of mappings) {
|
|
851
|
-
for (const file of walk(to).filter(name => path.basename(name) === '.aiwg-manifest.json')) {
|
|
852
|
-
let receipt; try { receipt = JSON.parse(read(file)); } catch { continue; }
|
|
853
|
-
let changed = false;
|
|
854
|
-
const remap = value => {
|
|
855
|
-
if (!value || typeof value !== 'object') return;
|
|
856
|
-
for (const [key, child] of Object.entries(value)) {
|
|
857
|
-
if (['skillSource', 'flowSource', 'sourcePath'].includes(key) && typeof child === 'string' && path.isAbsolute(child)) {
|
|
858
|
-
const mapped = mapSource(child); if (mapped !== child) { value[key] = mapped; changed = true; }
|
|
859
|
-
}
|
|
860
|
-
else remap(child);
|
|
861
|
-
}
|
|
862
|
-
};
|
|
863
|
-
remap(receipt); if (changed) fs.writeFileSync(file, `${JSON.stringify(receipt, null, 2)}\n`);
|
|
864
|
-
}
|
|
865
|
-
}
|
|
866
|
-
let activeWorkspace;
|
|
867
|
-
if (provider.resolveOpenClawWorkspace) {
|
|
868
|
-
const from = provider.resolveOpenClawWorkspace();
|
|
869
|
-
activeWorkspace = path.join(temp, 'active-workspace');
|
|
870
|
-
mount(from, activeWorkspace);
|
|
871
|
-
}
|
|
872
|
-
// Graph discovery must read the same immutable inputs as projection, including
|
|
873
|
-
// relocated project indexes and shared user indexes.
|
|
874
|
-
const graphRoot = path.join(temp, 'graph-artifacts');
|
|
875
|
-
const xdgRoot = path.join(temp, 'xdg-data');
|
|
876
|
-
const copyGraph = (from, to) => {
|
|
877
|
-
const expected = initialPreimages.find(item => item.path === path.resolve(from)).state;
|
|
878
|
-
materializeInput(from, to);
|
|
879
|
-
if (JSON.stringify(capturePreimage(to)) !== JSON.stringify(materializedPreimage(expected))) throw new Error(`Graph input changed while preparing snapshot: ${from}`);
|
|
880
|
-
};
|
|
881
|
-
for (const from of projectGraphFiles) copyGraph(from, path.join(graphRoot, path.relative(artifactRoot, from)));
|
|
882
|
-
for (const from of userGraphFiles) copyGraph(from, path.join(xdgRoot, 'aiwg', 'index', path.relative(userIndexRoot, from)));
|
|
883
|
-
// Non-index graph targets remain logical until selected, then are copied
|
|
884
|
-
// individually by the discovered-input loop below.
|
|
885
|
-
if (path.resolve(artifactRoot) !== path.resolve(target, '.aiwg')) sourceMappings.push({ from: path.resolve(target, '.aiwg'), to: artifactRoot });
|
|
886
|
-
process.env.AIWG_ARTIFACTS_PATH = graphRoot;
|
|
887
|
-
process.env.XDG_DATA_HOME = xdgRoot;
|
|
888
|
-
const delivery = await prepareRuleDelivery({ ...original, target: stage, sharedProjectGraph: path.resolve(artifactRoot) !== path.resolve(target, '.aiwg'), previousRuleSources: (previous.ruleSources || []).map(mapSource) });
|
|
889
|
-
// Provider writes belong to the staged project control plane, not the
|
|
890
|
-
// read-only graph snapshot used for binding discovery.
|
|
891
|
-
process.env.AIWG_ARTIFACTS_PATH = path.join(stage, '.aiwg');
|
|
892
|
-
// Discovery can select absolute user/project sources not known at entry.
|
|
893
|
-
// Bind the exact copied bytes before any projector consumes them.
|
|
894
|
-
const remappedBindings = new Map();
|
|
895
|
-
for (const entry of delivery.targets) {
|
|
896
|
-
const source = path.resolve(entry.source);
|
|
897
|
-
const alreadyFrozen = source.startsWith(`${temp}${path.sep}`);
|
|
898
|
-
if (!alreadyFrozen) {
|
|
899
|
-
const state = capturePreimage(source);
|
|
900
|
-
const to = path.join(temp, 'discovered-input', String(sourceMappings.length), path.basename(source));
|
|
901
|
-
materializeInput(source, to);
|
|
902
|
-
if (JSON.stringify(capturePreimage(to)) !== JSON.stringify(materializedPreimage(state))) throw new Error(`Discovered input changed while preparing snapshot: ${source}`);
|
|
903
|
-
preimages.push({ path: source, state });
|
|
904
|
-
sourceMappings.push({ from: source, to });
|
|
905
|
-
entry.source = to;
|
|
906
|
-
}
|
|
907
|
-
const rules = delivery.bindings.get(source);
|
|
908
|
-
if (rules) remappedBindings.set(entry.source, rules);
|
|
909
|
-
}
|
|
910
|
-
delivery.bindings = remappedBindings;
|
|
911
|
-
preimages.push(...snapshotPreimages([...delivery.rules.map(rule => rule.file), ...delivery.targets.map(entry => entry.source), path.join(target, '.aiwg', 'aiwg.config')]));
|
|
912
|
-
const opts = { ...original, target: stage, dryRun: false, ruleDelivery: delivery, logicalOutputPath: file => logicalProviderOutputPath(file, stage, target, mappings),
|
|
913
|
-
kernelSkillsPath: kernel, deploymentHome: home, activeWorkspace, hermesLegacySkills, legacyCodexSkills, staging: true };
|
|
914
|
-
if (!opts.deferRuleProjection && (opts.kernelOnly || opts.deployRules || opts.rulesOnly ||
|
|
915
|
-
(!opts.skillsOnly && !opts.commandsOnly && (inlineStartup[provider.name] || ['hermes', 'warp'].includes(provider.name))))) retireInlineStartup(opts, provider);
|
|
916
|
-
await deploySelectedSurface(opts, provider, deploy);
|
|
917
|
-
if (!opts.commandsOnly && !opts.skillsOnly && !opts.rulesOnly && opts.deployBehaviors !== false) {
|
|
918
|
-
deployEmulatedBehaviors(delivery.rules.filter(rule => rule.behavior).map(rule => path.dirname(rule.file)), provider.name, stage, opts);
|
|
919
|
-
}
|
|
920
|
-
const selectedRoots = [original.srcRoot, ...(original.additionalSources || []), ...getFrameworksForMode(original.srcRoot, original.mode).map(framework => framework.path), ...discoverAddons(original.srcRoot).map(addon => addon.path)];
|
|
921
|
-
const selected = entry => selectedRoots.some(root => /^(agents|skills|commands|flows|workflows)[/\\]/.test(path.relative(root, entry.source)));
|
|
922
|
-
opts.definitionRoutes = [];
|
|
923
|
-
if (provider.name === 'hermes' && !opts.kernelOnly && !opts.skillsOnly && !opts.commandsOnly && !opts.rulesOnly) {
|
|
924
|
-
const agents = delivery.targets.filter(target => target.type === 'agent' && selected(target));
|
|
925
|
-
const selectedAgents = new Set(filterAgentFiles(agents.map(target => target.source), opts));
|
|
926
|
-
for (const target of agents.filter(target => selectedAgents.has(target.source))) {
|
|
927
|
-
const source = target.source;
|
|
928
|
-
put(path.join(stage, '.hermes', 'agents', path.basename(source)), managed(replaceBoundRulesBlock(read(source), delivery.bindings.get(source)), opts));
|
|
929
|
-
opts.definitionRoutes.push(`${target.name}: .hermes/agents/${path.basename(source)}`);
|
|
930
|
-
}
|
|
931
|
-
}
|
|
932
|
-
projectBoundFlowSkills(opts, provider, selected);
|
|
933
|
-
if (['warp', 'windsurf'].includes(provider.name)) {
|
|
934
|
-
for (const file of walk(path.join(stage, `.${provider.name}`, 'commands'))) {
|
|
935
|
-
if (/\.md$/.test(file)) opts.definitionRoutes.push(`${path.basename(file, '.md')}: .${provider.name}/commands/${path.basename(file)}`);
|
|
936
|
-
}
|
|
937
|
-
for (const entry of delivery.targets.filter(entry => entry.type === 'agent' && selected(entry))) {
|
|
938
|
-
const dest = path.join(stage, `.${provider.name}`, 'agents', path.basename(entry.source));
|
|
939
|
-
if (fs.existsSync(dest)) opts.definitionRoutes.push(`${entry.name}: .${provider.name}/agents/${path.basename(entry.source)}`);
|
|
940
|
-
}
|
|
941
|
-
}
|
|
942
|
-
if (!opts.deferRuleProjection) {
|
|
943
|
-
if (opts.kernelOnly || opts.deployRules || opts.rulesOnly || (!opts.skillsOnly && !opts.commandsOnly && (inlineStartup[provider.name] || ['hermes', 'warp'].includes(provider.name)))) projectRules(opts, provider);
|
|
944
|
-
finishBindings(opts, provider);
|
|
945
|
-
}
|
|
946
|
-
// Normalize all generated path wrappers before counting or promoting bytes.
|
|
947
|
-
const normalize = content => {
|
|
948
|
-
for (const mapping of [...mappings].sort((a, b) => b.to.length - a.to.length)) content = content.split(mapping.to).join(mapping.from);
|
|
949
|
-
for (const mapping of [...sourceMappings].sort((a, b) => b.to.length - a.to.length)) content = content.split(mapping.to).join(mapping.from);
|
|
950
|
-
return content.split(snapshotRoot).join(corpusRoot).split(stage).join(target);
|
|
951
|
-
};
|
|
952
|
-
const projected = startupFiles(opts, provider).map(file => ({ path: normalize(file.path), content: normalize(file.content) }));
|
|
953
|
-
const config = effectiveConfig;
|
|
954
|
-
const guarded = guardRulesInlineBudget({ provider: provider.name, files: projected, config, env: budgetEnv,
|
|
955
|
-
reportOnly: delivery.pins.length ? original.allowOverBudget === true : original.reportOnly !== false && !original.strict && !budgetEnv.CI });
|
|
956
|
-
guarded.report.pins = delivery.pins.map(rule => ({ id: rule.id, name: rule.name, matches: rule.matches, canonical_activation: rule.canonical_activation, bytes: Buffer.byteLength(rule.body || '') }));
|
|
957
|
-
const pinDetails = delivery.pins.map(rule => `${rule.name}: ${Buffer.byteLength(rule.body || '')} body bytes via ${JSON.stringify(rule.matches)}`).join('; ');
|
|
958
|
-
const budgetFailure = message => new Error(`${provider.name}: ${message}; ${guarded.report.selected_bytes} startup bytes. Pins: ${pinDetails || '(none)'}.${delivery.pins.length ? ' Use --allow-over-budget to retain every pinned body.' : ''}`);
|
|
959
|
-
for (const diagnostic of guarded.diagnostics) console.warn(diagnostic.message);
|
|
960
|
-
if (!guarded.passed) throw budgetFailure(guarded.diagnostics.map(d => d.message).join('\n'));
|
|
961
|
-
const agents = normalize(read(path.join(stage, 'AGENTS.md')));
|
|
962
|
-
if (provider.name === 'codex' && Buffer.byteLength(agents) >= 32_768 && !(delivery.pins.length && original.allowOverBudget)) throw budgetFailure(`Codex AGENTS.md (${Buffer.byteLength(agents)} bytes) exceeds its 32 KB hard cap`);
|
|
963
|
-
if (provider.name === 'hermes') {
|
|
964
|
-
for (const name of ['AGENTS.md', '.hermes.md']) {
|
|
965
|
-
const content = normalize(read(path.join(stage, name)));
|
|
966
|
-
if (!(delivery.pins.length && original.allowOverBudget)) {
|
|
967
|
-
try { provider.assertContextBudget(content, name, delivery.rules); }
|
|
968
|
-
catch (error) { throw budgetFailure(error.message); }
|
|
969
|
-
}
|
|
970
|
-
if (content.length > 15_000) console.warn(`Hermes ${name} above 15000 character soft limit (${content.length})`);
|
|
971
|
-
}
|
|
972
|
-
}
|
|
973
|
-
// Absolute provider roots can nest (Hermes standard skills live beneath
|
|
974
|
-
// its kernel root). A more specific mount owns that subtree exclusively;
|
|
975
|
-
// the parent's older snapshot must not resurrect pruned files/directories.
|
|
976
|
-
const delegated = (from, rel) => mappings.some(mapping => mapping.from !== from
|
|
977
|
-
&& mapping.from.startsWith(`${from}${path.sep}`)
|
|
978
|
-
&& (path.join(from, rel) === mapping.from || path.join(from, rel).startsWith(`${mapping.from}${path.sep}`)));
|
|
979
|
-
if (original.contextFiles === false) {
|
|
980
|
-
// Keep context inputs in the snapshot for validation, but exclude them
|
|
981
|
-
// from both dry-run output and promotion (including unchanged rewrites).
|
|
982
|
-
for (let i = rootNames.length - 1; i >= 0; i--) {
|
|
983
|
-
if (['AGENTS.md', 'AIWG.md', 'WORKSPACE.md', 'CLAUDE.md', 'WARP.md', '.hermes.md', '.aiwg/AIWG.md'].includes(rootNames[i])) rootNames.splice(i, 1);
|
|
984
|
-
}
|
|
985
|
-
}
|
|
986
|
-
if (pool) verifyInputPool(pool);
|
|
987
|
-
if (original.previewReport) return { report: guarded.report, noop: true };
|
|
988
|
-
if (original.dryRun) {
|
|
989
|
-
// A validated plan must describe the operator's final paths, rather than
|
|
990
|
-
// exposing only the temporary paths used to assemble that plan.
|
|
991
|
-
for (const { from, to, before } of mappings) {
|
|
992
|
-
const after = new Set(walk(to).map(file => path.relative(to, file)).filter(rel => !delegated(from, rel)));
|
|
993
|
-
for (const rel of after) {
|
|
994
|
-
const file = path.join(to, rel);
|
|
995
|
-
if (before.get(rel) !== fileDigest(file)) console.log(`[dry-run] Would write ${normalize(file)}`);
|
|
996
|
-
}
|
|
997
|
-
for (const rel of before.keys()) if (!delegated(from, rel) && !after.has(rel)) console.log(`[dry-run] Would remove ${path.join(from, rel)}`);
|
|
998
|
-
}
|
|
999
|
-
for (const name of rootNames) {
|
|
1000
|
-
const file = path.join(stage, name);
|
|
1001
|
-
if (fs.existsSync(file) && normalize(read(file)) !== read(path.join(target, name))) console.log(`[dry-run] Would write ${path.join(target, name)}`);
|
|
1002
|
-
}
|
|
1003
|
-
console.log(`[dry-run] Planned ${provider.name} deployment: ${guarded.report.selected_bytes} startup bytes; no output promoted.`);
|
|
1004
|
-
return { report: guarded.report, noop: true };
|
|
1005
|
-
}
|
|
1006
|
-
const workspaceDirs = [];
|
|
1007
|
-
const collectDirs = (dir, rel = '') => {
|
|
1008
|
-
if (!fs.existsSync(dir)) return;
|
|
1009
|
-
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
1010
|
-
if (!entry.isDirectory()) continue;
|
|
1011
|
-
const name = path.join(rel, entry.name); workspaceDirs.push(name);
|
|
1012
|
-
collectDirs(path.join(dir, entry.name), name);
|
|
1013
|
-
}
|
|
1014
|
-
};
|
|
1015
|
-
collectDirs(path.join(stage, '.aiwg'), '.aiwg');
|
|
1016
|
-
const contextWrites = [...new Set(fs.readFileSync(contextStageLog, 'utf8').split('\n').filter(Boolean).map(line => JSON.parse(line)))];
|
|
1017
|
-
const plan = { version: 1, lease, temp, target, stage, contextWrites, rootNames, workspaceDirs, preimages, poolSeal: pool?.inventorySeal || null,
|
|
1018
|
-
anchors: captureAnchors([target, ...mappings.map(mapping => mapping.from), ...workspaceDirs.map(dir => path.join(target, dir))]),
|
|
1019
|
-
snapshotRoot, corpusRoot, sourceMappings, staged: snapshotPreimages([stage, ...mappings.map(mapping => mapping.to)]), report: guarded.report,
|
|
1020
|
-
mappings: mappings.map(({ from, to, before }) => ({ from, to, before: [...before] })) };
|
|
1021
|
-
stagedCleanups.get(lease).seal = planSeal(plan);
|
|
1022
|
-
retained = true;
|
|
1023
|
-
return plan;
|
|
1024
|
-
} finally {
|
|
1025
|
-
if (priorContextStage === undefined) delete process.env[CONTEXT_STAGE_ENV]; else process.env[CONTEXT_STAGE_ENV] = priorContextStage;
|
|
1026
|
-
restoreProviderPaths(provider, originals);
|
|
1027
|
-
if (priorAiwgRoot === undefined) delete process.env.AIWG_ROOT; else process.env.AIWG_ROOT = priorAiwgRoot;
|
|
1028
|
-
if (priorRegistry === undefined) delete process.env.AIWG_USER_REGISTRY_PATH; else process.env.AIWG_USER_REGISTRY_PATH = priorRegistry;
|
|
1029
|
-
if (priorArtifacts === undefined) delete process.env.AIWG_ARTIFACTS_PATH; else process.env.AIWG_ARTIFACTS_PATH = priorArtifacts;
|
|
1030
|
-
if (priorXdgData === undefined) delete process.env.XDG_DATA_HOME; else process.env.XDG_DATA_HOME = priorXdgData;
|
|
1031
|
-
if (!retained) { stagedCleanups.delete(lease); removeTemp(); }
|
|
1032
|
-
}
|
|
1033
|
-
}
|
|
1034
|
-
|
|
1035
|
-
/** Validate every captured input before applying a staged provider plan. */
|
|
1036
|
-
export function commitRuleDeploymentPlan(plan) {
|
|
1037
|
-
if (plan.noop) return plan.report;
|
|
1038
|
-
try {
|
|
1039
|
-
if (plan.version !== 1 || !plan.temp || !plan.stage || !Array.isArray(plan.preimages)) throw new Error('Invalid rule deployment plan');
|
|
1040
|
-
const owner = planOwner(plan);
|
|
1041
|
-
if (!owner) throw new Error('Unowned or modified rule deployment plan');
|
|
1042
|
-
if (owner.pool) { if (plan.poolSeal !== owner.pool.inventorySeal) throw new Error('Shared input pool lease changed'); verifyInputPool(owner.pool); }
|
|
1043
|
-
if (JSON.stringify(snapshotPreimages(plan.staged.map(item => item.path))) !== JSON.stringify(plan.staged)) throw new Error('Staged provider output changed');
|
|
1044
|
-
if (JSON.stringify(captureAnchors(plan.anchors.map(item => item.path))) !== JSON.stringify(plan.anchors)) {
|
|
1045
|
-
throw new RuleDeploymentStaleError('Provider deployment root or ancestor changed', plan.anchors.map(item => item.path));
|
|
1046
|
-
}
|
|
1047
|
-
const stale = plan.preimages.filter(item => JSON.stringify(capturePreimage(item.path)) !== JSON.stringify(item.state)).map(item => item.path);
|
|
1048
|
-
if (stale.length) throw new RuleDeploymentStaleError(`Provider deployment preimage changed: ${stale.join(', ')}`, stale);
|
|
1049
|
-
const { target, stage, rootNames } = plan;
|
|
1050
|
-
for (const dir of plan.workspaceDirs || []) fs.mkdirSync(path.join(target, dir), { recursive: true });
|
|
1051
|
-
const mappings = plan.mappings.map(({ from, to, before }) => ({ from, to, before: new Map(before) }));
|
|
1052
|
-
const normalize = content => {
|
|
1053
|
-
for (const mapping of [...mappings].sort((a, b) => b.to.length - a.to.length)) content = content.split(mapping.to).join(mapping.from);
|
|
1054
|
-
for (const mapping of [...plan.sourceMappings].sort((a, b) => b.to.length - a.to.length)) content = content.split(mapping.to).join(mapping.from);
|
|
1055
|
-
return content.split(plan.snapshotRoot).join(plan.corpusRoot).split(stage).join(target);
|
|
1056
|
-
};
|
|
1057
|
-
const delegated = (from, rel) => mappings.some(mapping => mapping.from !== from
|
|
1058
|
-
&& mapping.from.startsWith(`${from}${path.sep}`)
|
|
1059
|
-
&& (path.join(from, rel) === mapping.from || path.join(from, rel).startsWith(`${mapping.from}${path.sep}`)));
|
|
1060
|
-
for (const { from, to, before } of mappings) {
|
|
1061
|
-
if (!fs.existsSync(to)) {
|
|
1062
|
-
if (before.size) fs.rmSync(from, { recursive: true, force: true });
|
|
1063
|
-
continue;
|
|
1064
|
-
}
|
|
1065
|
-
promoteDirectories(to, from, rel => delegated(from, rel));
|
|
1066
|
-
const after = new Set(walk(to).map(file => path.relative(to, file)).filter(rel => !delegated(from, rel)));
|
|
1067
|
-
for (const rel of before.keys()) if (!delegated(from, rel) && !after.has(rel)) {
|
|
1068
|
-
fs.rmSync(path.join(from, rel), { force: true });
|
|
1069
|
-
// A pruned managed skill must disappear as a directory too. Remove
|
|
1070
|
-
// only empty parents absent from the staged result; preserve siblings.
|
|
1071
|
-
let parent = path.dirname(rel);
|
|
1072
|
-
while (parent !== '.' && !fs.existsSync(path.join(to, parent))) {
|
|
1073
|
-
try { fs.rmdirSync(path.join(from, parent)); } catch { break; }
|
|
1074
|
-
parent = path.dirname(parent);
|
|
1075
|
-
}
|
|
1076
|
-
}
|
|
1077
|
-
for (const rel of after) {
|
|
1078
|
-
const file = path.join(to, rel);
|
|
1079
|
-
if (before.get(rel) === fileDigest(file)) continue;
|
|
1080
|
-
const buffer = fs.readFileSync(file);
|
|
1081
|
-
// Provider output includes binary skill resources; normalize text only.
|
|
1082
|
-
let output = buffer.includes(0) ? buffer : Buffer.from(normalize(buffer.toString('utf8')));
|
|
1083
|
-
if (path.basename(file) === '.aiwg-manifest.json') {
|
|
1084
|
-
const receipt = JSON.parse(output.toString('utf8'));
|
|
1085
|
-
for (const [name, record] of Object.entries(receipt.managed || {})) {
|
|
1086
|
-
const recordedFile = path.resolve(path.dirname(file), name);
|
|
1087
|
-
if (!within(path.dirname(file), recordedFile) || !fs.existsSync(recordedFile)) continue;
|
|
1088
|
-
const recorded = fs.readFileSync(recordedFile);
|
|
1089
|
-
// Do not bless operator edits whose bytes already differ from the
|
|
1090
|
-
// ownership receipt. Only normalize hashes of pristine staged files.
|
|
1091
|
-
if (record.hash !== `sha256:${contentHash(recorded)}`) continue;
|
|
1092
|
-
const promoted = recorded.includes(0) ? recorded : Buffer.from(normalize(recorded.toString('utf8')));
|
|
1093
|
-
record.hash = `sha256:${contentHash(promoted)}`;
|
|
1094
|
-
}
|
|
1095
|
-
output = Buffer.from(`${JSON.stringify(receipt, null, 2)}\n`);
|
|
1096
|
-
}
|
|
1097
|
-
fs.mkdirSync(path.dirname(path.join(from, rel)), { recursive: true });
|
|
1098
|
-
if (plan.contextWrites.includes(file)) writeContextFileSync(path.join(from, rel), output);
|
|
1099
|
-
else fs.writeFileSync(path.join(from, rel), output);
|
|
1100
|
-
}
|
|
1101
|
-
}
|
|
1102
|
-
for (const name of rootNames) if (fs.existsSync(path.join(stage, name))) {
|
|
1103
|
-
const output = normalize(read(path.join(stage, name)));
|
|
1104
|
-
if (output === read(path.join(target, name))) continue;
|
|
1105
|
-
const write = plan.contextWrites.includes(path.join(stage, name)) ? writeContextFileSync : put;
|
|
1106
|
-
write(path.join(target, name), output);
|
|
1107
|
-
}
|
|
1108
|
-
return plan.report;
|
|
1109
|
-
} finally {
|
|
1110
|
-
disposeRuleDeploymentPlan(plan);
|
|
1111
|
-
}
|
|
1112
|
-
}
|
|
1113
|
-
|
|
1114
|
-
/** Stage and commit serially for existing provider callers. */
|
|
1115
|
-
export async function deployWithRuleDelivery(original, provider, deploy) {
|
|
1116
|
-
// Kernel source passes share the same selected rule set. Deploy their
|
|
1117
|
-
// skills directly; the final source projects rules and bindings across the
|
|
1118
|
-
// complete destination. Full passes retain staging for bound flow skills
|
|
1119
|
-
// and provider definitions, but defer rule presentation above.
|
|
1120
|
-
if (original.kernelOnly && original.deferRuleProjection && !globalThis[PREPARATION_HOOK]) {
|
|
1121
|
-
return deploySelectedSurface(original, provider, deploy);
|
|
1122
|
-
}
|
|
1123
|
-
if (original.ruleDelivery) return deploy(original);
|
|
1124
|
-
const hook = globalThis[PREPARATION_HOOK];
|
|
1125
|
-
if (hook) {
|
|
1126
|
-
const plan = await prepareRuleDeployment({ ...original, inputPool: hook.inputPool, ruleDeploymentScratch: hook.scratch }, provider, deploy);
|
|
1127
|
-
const report = plan.report;
|
|
1128
|
-
hook.accept(detachRuleDeploymentPlan(plan));
|
|
1129
|
-
return report;
|
|
1130
|
-
}
|
|
1131
|
-
return commitRuleDeploymentPlan(await prepareRuleDeployment(original, provider, deploy));
|
|
1132
|
-
}
|
|
1133
|
-
|
|
1134
|
-
async function deploySelectedSurface(opts, provider, deploy) {
|
|
1135
|
-
if (!opts.kernelOnly || provider.name !== 'warp') return deploy(opts);
|
|
1136
|
-
// Warp's aggregate writer emits bulk definitions even in skills-only mode.
|
|
1137
|
-
// Both staged and deferred kernel passes use only its shared skill router.
|
|
1138
|
-
const skills = [...listSkillDirs(path.join(opts.srcRoot, 'skills')),
|
|
1139
|
-
...getFrameworksForMode(opts.srcRoot, opts.mode).flatMap(bundle => listSkillDirs(path.join(bundle.path, 'skills'))),
|
|
1140
|
-
...getAddonSkillDirs(opts.srcRoot)].filter(isKernelSkill);
|
|
1141
|
-
const standard = path.join(opts.target, provider.paths.skills);
|
|
1142
|
-
for (const dir of new Set([opts.kernelSkillsPath || provider.kernelSkillsPath, provider.paths.crossAgentSkills])) {
|
|
1143
|
-
if (dir) deploySkillsWithKernelRouting(skills, standard, path.isAbsolute(dir) ? dir : path.join(opts.target, dir), opts);
|
|
1144
|
-
}
|
|
1145
|
-
}
|
|
10
|
+
export {
|
|
11
|
+
RuleDeploymentStaleError,
|
|
12
|
+
disposeRuleDeploymentPlan,
|
|
13
|
+
detachRuleDeploymentPlan,
|
|
14
|
+
createRuleDeploymentInputPool,
|
|
15
|
+
disposeRuleDeploymentInputPool,
|
|
16
|
+
describeRuleDeploymentInputPool,
|
|
17
|
+
importRuleDeploymentInputPool,
|
|
18
|
+
adoptRuleDeploymentPlan,
|
|
19
|
+
} from './rule-deployment-state.mjs';
|
|
20
|
+
export { prepareRuleDeployment } from './rule-deployment-prepare.mjs';
|
|
21
|
+
export { commitRuleDeploymentPlan, deployWithRuleDelivery } from './rule-deployment-commit.mjs';
|