@aiwg/cli 2026.11.0 → 2026.11.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/agentic/code/addons/aiwg-hooks/canonical/aiwg-prompt-discovery.yaml +9 -0
- package/agentic/code/addons/aiwg-hooks/hooks/aiwg-prompt-discovery.cjs +136 -0
- package/agentic/code/providers/flue/README.md +2 -1
- package/agentic/code/providers/model-capabilities.v1.json +27 -23
- package/agentic/code/providers/model-catalog.v1.json +3 -3
- package/dist/src/artifacts/cli.js +13 -13
- package/dist/src/artifacts/discover-cli-help.js +25 -0
- package/dist/src/artifacts/discover-facets.js +2 -0
- package/dist/src/artifacts/discover-session-facets.js +15 -0
- package/dist/src/artifacts/fortemi-core-prebuilt-freshness.js +28 -0
- package/dist/src/artifacts/fortemi-core-query-adapter.js +4 -4
- package/dist/src/artifacts/fortemi-core-sync.js +3 -0
- package/dist/src/artifacts/framework-capabilities.js +11 -3
- package/dist/src/artifacts/framework-source-digest.js +1 -1
- package/dist/src/artifacts/index-builder.js +12 -13
- package/dist/src/artifacts/index-dependencies.js +72 -0
- package/dist/src/artifacts/query-engine-discover-output.js +13 -5
- package/dist/src/artifacts/query-engine-discover.js +103 -28
- package/dist/src/artifacts/query-engine-entries.js +107 -10
- package/dist/src/artifacts/query-engine-installation.js +27 -0
- package/dist/src/artifacts/query-engine-options.js +14 -1
- package/dist/src/artifacts/query-engine-rules.js +1 -2
- package/dist/src/artifacts/query-engine-scoring.js +38 -32
- package/dist/src/artifacts/query-engine-show-card.js +8 -2
- package/dist/src/artifacts/query-engine-show-load.js +1 -1
- package/dist/src/artifacts/query-engine-show.js +5 -3
- package/dist/src/artifacts/query-engine-templates.js +33 -0
- package/dist/src/artifacts/query-engine-verbose.js +25 -0
- package/dist/src/artifacts/relations-builder.js +49 -4
- package/dist/src/artifacts/relations.js +26 -10
- package/dist/src/artifacts/template-references.js +42 -0
- package/dist/src/artifacts/types.js +1 -1
- package/dist/src/cli/handlers/bundle-reconciliation.js +7 -3
- package/dist/src/cli/handlers/checkpoint-handoff.js +48 -0
- package/dist/src/cli/handlers/checkpoint-record.js +20 -0
- package/dist/src/cli/handlers/checkpoint.js +176 -0
- package/dist/src/cli/handlers/decision.js +1 -1
- package/dist/src/cli/handlers/doctor-args.js +3 -1
- package/dist/src/cli/handlers/doctor-help.js +2 -1
- package/dist/src/cli/handlers/help.js +1 -0
- package/dist/src/cli/handlers/index.js +4 -2
- package/dist/src/cli/handlers/models-resource-sample.js +7 -3
- package/dist/src/cli/handlers/ralph-launcher.js +1 -1
- package/dist/src/cli/handlers/refresh-bundles.js +2 -1
- package/dist/src/cli/handlers/refresh-managed-deployment.js +196 -0
- package/dist/src/cli/handlers/refresh.js +10 -2
- package/dist/src/cli/handlers/script-runner.js +2 -1
- package/dist/src/cli/handlers/steward-signing.js +44 -0
- package/dist/src/cli/handlers/steward.js +5 -0
- package/dist/src/cli/handlers/subcommands-discovery.js +8 -1
- package/dist/src/cli/handlers/use-provider-results.js +17 -0
- package/dist/src/cli/handlers/use.js +19 -18
- package/dist/src/cli/router.js +12 -2
- package/dist/src/cli/services/deployment-verification.js +11 -7
- package/dist/src/cli/user-scope-mirror.js +3 -1
- package/dist/src/config/aiwg-config.js +5 -1
- package/dist/src/config/cli.js +1 -0
- package/dist/src/config/delivery-validation.js +21 -0
- package/dist/src/config/host-resource-report.d.mts +1 -1
- package/dist/src/config/host-resource-report.mjs +23 -4
- package/dist/src/config/host-resource-runtime.d.mts +8 -0
- package/dist/src/config/host-resource-runtime.mjs +67 -24
- package/dist/src/config/index-graph-overrides.js +4 -0
- package/dist/src/config/worker-attribution.d.mts +7 -0
- package/dist/src/config/worker-attribution.mjs +44 -0
- package/dist/src/config/worker-write.js +4 -10
- package/dist/src/decision/ledger.js +15 -15
- package/dist/src/decision/offload.js +6 -7
- package/dist/src/delivery/git.js +62 -0
- package/dist/src/delivery/pr.js +151 -0
- package/dist/src/delivery/template-sections.js +56 -0
- package/dist/src/delivery/tracker.js +33 -0
- package/dist/src/discovery/interview.js +1 -1
- package/dist/src/extensions/claude-hooks-installer.js +62 -53
- package/dist/src/extensions/loader.js +2 -1
- package/dist/src/extensions/managed-hook-script-state.js +48 -0
- package/dist/src/extensions/muse-managed-hooks.js +49 -0
- package/dist/src/issues/cli.js +15 -3
- package/dist/src/issues/external-cli.js +79 -0
- package/dist/src/issues/live.js +26 -2
- package/dist/src/issues/local.js +5 -1
- package/dist/src/issues/tracker-policy.js +27 -0
- package/dist/src/mcp/json-document.d.mts +2 -0
- package/dist/src/mcp/tools/worker-invoke.mjs +2 -1
- package/dist/src/mcp/tools/worker-stdin-runtime.mjs +12 -0
- package/dist/src/models/conductor-data-policy.d.mts +3 -2
- package/dist/src/models/conductor-data-policy.mjs +94 -5
- package/dist/src/models/model-capabilities.v1.json +27 -23
- package/dist/src/models/model-catalog.v1.json +3 -3
- package/dist/src/models/provider-policy.js +8 -0
- package/dist/src/models/worker-health-readiness.js +20 -4
- package/dist/src/models/worker-health-snapshot.js +29 -0
- package/dist/src/models/worker-installation.d.mts +5 -1
- package/dist/src/models/worker-installation.mjs +11 -5
- package/dist/src/models/worker-plan.js +3 -3
- package/dist/src/models/worker-qualification-policy.js +54 -0
- package/dist/src/models/worker-selection-policy.js +2 -1
- package/dist/src/providers/deployment-lock.js +77 -0
- package/dist/src/providers/deployment-ownership.d.mts +12 -2
- package/dist/src/providers/deployment-ownership.mjs +115 -21
- package/dist/src/providers/deployment-preservation.d.mts +2 -1
- package/dist/src/providers/deployment-preservation.mjs +3 -0
- package/dist/src/providers/provider-definitions.js +4 -0
- package/dist/src/providers/skill-ownership.d.mts +1 -0
- package/dist/src/providers/transformation-receipt-integration.js +4 -2
- package/dist/src/providers/transformation-receipt.js +4 -2
- package/dist/src/serve/worker-invocation-preparation.js +3 -1
- package/dist/src/serve/worker-invocation.js +6 -2
- package/dist/src/skills/run.js +5 -0
- package/dist/src/smiths/context-pipeline/workspace-audit.js +34 -17
- package/dist/src/smiths/context-pipeline/workspace-context-shared.js +12 -6
- package/dist/src/smiths/context-pipeline/workspace-doctor.js +44 -4
- package/dist/src/smiths/context-pipeline/workspace-document.js +5 -2
- package/dist/src/smiths/context-pipeline/workspace-migration.js +2 -1
- package/dist/src/smiths/hook-bridge/codex-translator.js +150 -92
- package/dist/src/smiths/hook-bridge/codex-trust.js +50 -0
- package/dist/src/smiths/hook-bridge/factory-hook-config.js +132 -0
- package/dist/src/smiths/hook-bridge/factory-translator.js +88 -33
- package/dist/src/smiths/hook-bridge/hermes-translator.js +3 -1
- package/dist/src/smiths/hook-bridge/index.js +3 -3
- package/dist/src/smiths/hook-bridge/loader.js +10 -2
- package/dist/src/smiths/hook-bridge/prompt-discovery-gaps.js +5 -0
- package/dist/src/storage/workspace-permissions-health.js +64 -0
- package/dist/src/storage/workspace-permissions.js +51 -0
- package/package.json +9 -2
- package/schemas/models/model-config-compatibility.v1.schema.json +4 -0
- package/tools/agents/deploy-agents.mjs +15 -0
- package/tools/agents/providers/base-contract.mjs +7 -1
- package/tools/agents/providers/base-files.mjs +2 -1
- package/tools/agents/providers/base-flat-artifacts.mjs +6 -3
- package/tools/agents/providers/base-inventory.mjs +35 -13
- package/tools/agents/providers/base-models-platforms.mjs +3 -3
- package/tools/agents/providers/base-skill-copy.mjs +2 -0
- package/tools/agents/providers/base.mjs +1 -1
- package/tools/agents/providers/bound-rules-pointer.mjs +21 -0
- package/tools/agents/providers/claude-post-deploy.mjs +9 -5
- package/tools/agents/providers/codex-post-deploy.mjs +10 -0
- package/tools/agents/providers/conductor-data-guard.mjs +35 -11
- package/tools/agents/providers/factory-hooks.mjs +43 -0
- package/tools/agents/providers/factory.mjs +4 -91
- package/tools/agents/providers/muse-hooks.mjs +6 -41
- package/tools/agents/providers/muse-prompt-discovery.mjs +18 -0
- package/tools/agents/providers/packaged-codex-agents.mjs +48 -0
- package/tools/agents/providers/provider-prepare-coordinator.mjs +15 -10
- package/tools/agents/providers/rule-delivery-surface.mjs +10 -7
- package/tools/agents/providers/rule-deployment-commit.mjs +10 -0
- package/tools/agents/providers/rule-presentation.mjs +6 -5
- package/tools/agents/providers/rule-projection.mjs +10 -2
- package/tools/agents/providers/rule-startup.mjs +8 -1
- package/tools/agents/providers/stale-artifact-prune.mjs +9 -8
- package/tools/cli/decision-offload-report.mjs +7 -2
- package/tools/plugin/issue-template-copies.mjs +24 -0
- package/tools/plugin/package-plugins.mjs +11 -3
- package/tools/ralph-external/lib/factory-adapter.mjs +7 -8
- package/tools/ralph-external/lib/worker-artifacts.mjs +4 -2
- package/tools/ralph-external/lib/worker-capture.mjs +157 -0
- package/tools/ralph-external/lib/worker-final.mjs +43 -8
- package/tools/ralph-external/lib/worker-health.mjs +3 -0
- package/tools/ralph-external/lib/worker-invocation-processes.mjs +9 -6
- package/tools/ralph-external/lib/worker-launch-cli.mjs +20 -2
- package/tools/ralph-external/lib/worker-process-identity.mjs +30 -0
- package/tools/ralph-external/lib/worker-prompt.mjs +35 -0
- package/tools/ralph-external/lib/worker-retry-evidence.mjs +87 -6
- package/tools/ralph-external/lib/worker-run-directory-refusal.mjs +8 -0
- package/tools/ralph-external/lib/worker-termination.mjs +56 -6
- package/tools/ralph-external/process-monitor.mjs +12 -18
- package/tools/ralph-external/session-launcher.mjs +53 -36
- package/vscode-extension/schemas/aiwg.config.v1.json +15 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// Install Factory user preflight and project discovery through the existing hook bridge.
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
import { importImpl } from '../../_resolve-impl.mjs';
|
|
6
|
+
|
|
7
|
+
export async function deployFactoryHooks(dryRun, projectPath) {
|
|
8
|
+
const config = await importImpl(import.meta.url, 'smiths/hook-bridge/factory-hook-config.js');
|
|
9
|
+
const { managedFactoryHooks, installFactoryPromptDiscovery } = await importImpl(import.meta.url, 'smiths/hook-bridge/factory-translator.js');
|
|
10
|
+
const { captureDeploymentOutputs, recordDeploymentOutputs } = await importImpl(import.meta.url, 'providers/deployment-ownership.mjs');
|
|
11
|
+
const home = process.env.HOME || process.env.USERPROFILE;
|
|
12
|
+
if (home) {
|
|
13
|
+
const directory = path.join(home, '.factory');
|
|
14
|
+
for (const file of [directory, path.join(directory, 'hooks'), ...['hooks.json', 'settings.json', 'hooks/hooks.json'].map(name => path.join(directory, name))]) {
|
|
15
|
+
if (fs.existsSync(file) && fs.lstatSync(file).isSymbolicLink()) throw new Error(`Refusing symlinked Factory hook target: ${file}`);
|
|
16
|
+
}
|
|
17
|
+
const state = config.factoryHookDocuments(directory);
|
|
18
|
+
const roots = [state.file, state.settingsFile, state.legacyFile, path.join(directory, '.aiwg-manifest.json')];
|
|
19
|
+
const before = dryRun ? undefined : captureDeploymentOutputs(roots);
|
|
20
|
+
const removed = config.removeFactoryManaged(state.doc, 'aiwg-session');
|
|
21
|
+
// A project deploy carries the preflight in the project hooks.json; user scope only
|
|
22
|
+
// migrates AIWG's old copy away, so the session hook never runs twice.
|
|
23
|
+
if (!projectPath) {
|
|
24
|
+
const hook = managedFactoryHooks()[0];
|
|
25
|
+
((state.doc.hooks ??= {})[hook.event] ??= []).push({ matcher: '*', hooks: [{
|
|
26
|
+
type: 'command', command: hook.command, _aiwg_managed: true, _aiwg_id: hook.id,
|
|
27
|
+
}] });
|
|
28
|
+
}
|
|
29
|
+
// Only touch user files when there is something to migrate or install: creating
|
|
30
|
+
// ~/.factory/hooks.json would shadow the user's settings.json hooks fallback.
|
|
31
|
+
const changed = removed || state.migratedSettings || fs.existsSync(state.legacyFile) || !projectPath;
|
|
32
|
+
if (dryRun) { if (changed) console.log(`[dry-run] Would update Factory user hooks in ${state.file}`); }
|
|
33
|
+
else if (changed) {
|
|
34
|
+
config.saveFactoryHooks(state);
|
|
35
|
+
recordDeploymentOutputs(before, roots, { frameworkSlug: 'aiwg-hooks', claimUnchangedSettings: false, writtenFiles: [state.file] });
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
if (projectPath) {
|
|
39
|
+
const frameworkRoot = fileURLToPath(new URL('../../../', import.meta.url));
|
|
40
|
+
const result = await installFactoryPromptDiscovery({ projectPath, frameworkRoot, dryRun });
|
|
41
|
+
for (const warning of result.warnings) console.warn(warning);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -710,95 +710,8 @@ export function enableFactoryCustomDroids(dryRun) {
|
|
|
710
710
|
// Factory Hooks
|
|
711
711
|
// ============================================================================
|
|
712
712
|
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
*
|
|
716
|
-
* Writes a SessionStart hook to ~/.factory/settings.json that runs
|
|
717
|
-
* `aiwg sync --dry-run --quiet` on every new session. Preserves
|
|
718
|
-
* existing hooks and settings.
|
|
719
|
-
*/
|
|
720
|
-
export function deployFactoryHooks(dryRun) {
|
|
721
|
-
const homeDir = process.env.HOME || process.env.USERPROFILE;
|
|
722
|
-
if (!homeDir) {
|
|
723
|
-
console.warn('Could not determine home directory, skipping Factory hooks configuration');
|
|
724
|
-
return;
|
|
725
|
-
}
|
|
726
|
-
|
|
727
|
-
const settingsDir = path.join(homeDir, '.factory');
|
|
728
|
-
const settingsPath = path.join(settingsDir, 'settings.json');
|
|
729
|
-
|
|
730
|
-
let settings = {};
|
|
731
|
-
let originalContent = '';
|
|
732
|
-
let hasExistingFile = false;
|
|
733
|
-
|
|
734
|
-
// Read existing settings if present
|
|
735
|
-
if (fs.existsSync(settingsPath)) {
|
|
736
|
-
hasExistingFile = true;
|
|
737
|
-
try {
|
|
738
|
-
originalContent = fs.readFileSync(settingsPath, 'utf8');
|
|
739
|
-
const jsonContent = stripJsonComments(originalContent);
|
|
740
|
-
settings = JSON.parse(jsonContent);
|
|
741
|
-
} catch (err) {
|
|
742
|
-
console.warn(`Warning: Could not parse Factory settings.json for hooks: ${err.message}`);
|
|
743
|
-
console.warn('Skipping hook deployment to avoid corrupting settings file.');
|
|
744
|
-
return;
|
|
745
|
-
}
|
|
746
|
-
}
|
|
747
|
-
|
|
748
|
-
// Define the AIWG pre-flight hook
|
|
749
|
-
const aiwgHook = {
|
|
750
|
-
type: 'command',
|
|
751
|
-
command: 'aiwg sync --dry-run --quiet'
|
|
752
|
-
};
|
|
753
|
-
|
|
754
|
-
const aiwgMatcher = {
|
|
755
|
-
matcher: '*',
|
|
756
|
-
hooks: [aiwgHook]
|
|
757
|
-
};
|
|
758
|
-
|
|
759
|
-
// Initialize hooks structure if missing
|
|
760
|
-
if (!settings.hooks) {
|
|
761
|
-
settings.hooks = {};
|
|
762
|
-
}
|
|
763
|
-
if (!settings.hooks.SessionStart) {
|
|
764
|
-
settings.hooks.SessionStart = [];
|
|
765
|
-
}
|
|
766
|
-
|
|
767
|
-
// Check if AIWG hook already exists (by command string)
|
|
768
|
-
const alreadyInstalled = settings.hooks.SessionStart.some(entry =>
|
|
769
|
-
entry.hooks?.some(h => h.command && h.command.includes('aiwg sync'))
|
|
770
|
-
);
|
|
771
|
-
|
|
772
|
-
if (alreadyInstalled) {
|
|
773
|
-
console.log('Factory SessionStart hook already installed for AIWG pre-flight');
|
|
774
|
-
return;
|
|
775
|
-
}
|
|
776
|
-
|
|
777
|
-
// Add the hook
|
|
778
|
-
settings.hooks.SessionStart.push(aiwgMatcher);
|
|
779
|
-
|
|
780
|
-
if (dryRun) {
|
|
781
|
-
console.log(`[dry-run] Would add SessionStart hook to ${settingsPath}`);
|
|
782
|
-
console.log(`[dry-run] Hook: aiwg sync --dry-run --quiet`);
|
|
783
|
-
} else {
|
|
784
|
-
if (!fs.existsSync(settingsDir)) {
|
|
785
|
-
fs.mkdirSync(settingsDir, { recursive: true });
|
|
786
|
-
}
|
|
787
|
-
|
|
788
|
-
// Parsed successfully, so the merge is safe to write back. It is written
|
|
789
|
-
// as canonical JSON, which drops operator comments and formatting, so
|
|
790
|
-
// keep a timestamped copy of a hand-edited user-global file first.
|
|
791
|
-
const updatedContent = JSON.stringify(settings, null, 2) + '\n';
|
|
792
|
-
if (hasExistingFile && originalContent !== JSON.stringify(JSON.parse(stripJsonComments(originalContent)), null, 2) + '\n') {
|
|
793
|
-
const backupPath = `${settingsPath}.aiwg-backup-${new Date().toISOString().replace(/[:.]/g, '-')}`;
|
|
794
|
-
fs.copyFileSync(settingsPath, backupPath);
|
|
795
|
-
console.log(`Backed up ${settingsPath} to ${backupPath} (comments and formatting are not preserved)`);
|
|
796
|
-
}
|
|
797
|
-
fs.writeFileSync(settingsPath, updatedContent, 'utf8');
|
|
798
|
-
console.log(`Deployed SessionStart hook to ${settingsPath}`);
|
|
799
|
-
console.log('Hook: aiwg sync --dry-run --quiet (runs on every new Factory session)');
|
|
800
|
-
}
|
|
801
|
-
}
|
|
713
|
+
export { deployFactoryHooks } from './factory-hooks.mjs';
|
|
714
|
+
import { deployFactoryHooks } from './factory-hooks.mjs';
|
|
802
715
|
|
|
803
716
|
// ============================================================================
|
|
804
717
|
// Post-Deployment
|
|
@@ -812,7 +725,7 @@ export async function postDeploy(targetDir, opts) {
|
|
|
812
725
|
enableFactoryCustomDroids(opts.dryRun);
|
|
813
726
|
|
|
814
727
|
// Deploy SessionStart hook for AIWG pre-flight checks
|
|
815
|
-
deployFactoryHooks(opts.dryRun);
|
|
728
|
+
if (opts.hooks !== false) await deployFactoryHooks(opts.dryRun, opts.scope === 'user' ? undefined : targetDir);
|
|
816
729
|
|
|
817
730
|
// Create/update AGENTS.md if requested
|
|
818
731
|
if (opts.createAgentsMd) {
|
|
@@ -901,7 +814,7 @@ export function generatePluginBundle(targetDir, opts) {
|
|
|
901
814
|
hooks: [
|
|
902
815
|
{
|
|
903
816
|
type: 'command',
|
|
904
|
-
command: 'aiwg
|
|
817
|
+
command: 'aiwg refresh --dry-run --quiet'
|
|
905
818
|
}
|
|
906
819
|
]
|
|
907
820
|
}
|
|
@@ -54,8 +54,11 @@ import path from 'node:path';
|
|
|
54
54
|
import { randomUUID } from 'node:crypto';
|
|
55
55
|
import { importImpl } from '../../_resolve-impl.mjs';
|
|
56
56
|
import { stripJsonComments } from './base.mjs';
|
|
57
|
+
import { deployPromptDiscovery } from './muse-prompt-discovery.mjs';
|
|
57
58
|
import { resolveMuseXdgSkillsDir, museXdgSkillsDirRemediation } from './muse-paths.mjs';
|
|
58
59
|
|
|
60
|
+
const { AIWG_MANAGED_HOOKS } = await importImpl(import.meta.url, 'extensions/muse-managed-hooks.js');
|
|
61
|
+
|
|
59
62
|
const { assertConfigDestination, writeConfigAtomic, writeConfigTransaction } = await importImpl(import.meta.url, 'mcp/config-file.mjs');
|
|
60
63
|
|
|
61
64
|
// ---------------------------------------------------------------------------
|
|
@@ -179,47 +182,7 @@ export const MUSE_HOOK_EVENTS = [
|
|
|
179
182
|
'SessionEnd',
|
|
180
183
|
];
|
|
181
184
|
|
|
182
|
-
|
|
183
|
-
* The AIWG-managed hook set. Each entry carries a stated reason (why this
|
|
184
|
-
* hook runs on the operator's machine, outside the agent sandbox) and a
|
|
185
|
-
* removal path (how the operator takes it back out).
|
|
186
|
-
*
|
|
187
|
-
* SessionEnd is intentionally *not* installed yet: Muse documents SessionEnd
|
|
188
|
-
* as observational-only (its output cannot block termination or inject
|
|
189
|
-
* context), and AIWG has no session-catalog note command to invoke — wiring
|
|
190
|
-
* a hook to a command that does not exist would fail every session end.
|
|
191
|
-
* When a real catalog-note command lands, it slots in here with its own
|
|
192
|
-
* reason + removal path.
|
|
193
|
-
*/
|
|
194
|
-
export const AIWG_MANAGED_HOOKS = [
|
|
195
|
-
{
|
|
196
|
-
id: 'aiwg-session-start',
|
|
197
|
-
event: 'SessionStart',
|
|
198
|
-
// Muse matcher groups take ONLY `hooks` + optional `matcher`; no
|
|
199
|
-
// in-band AIWG tags (they would break the group).
|
|
200
|
-
//
|
|
201
|
-
// Muse Code 1.4.0 parses hook stdout as hook output: empty output, plain
|
|
202
|
-
// text, and `{"hookSpecificOutput": ...}` are accepted, but any other
|
|
203
|
-
// JSON key fails the hook ("unsupported `deploymentFailures` in output of
|
|
204
|
-
// SessionStart hook output"). `aiwg refresh --quiet` prints its JSON
|
|
205
|
-
// report, so stdout is discarded; the exit status still records a failed
|
|
206
|
-
// drift check in Muse's hook log. `--provider muse` is required because
|
|
207
|
-
// provider detection is fail-closed for muse and would resolve `claude`.
|
|
208
|
-
// Hook commands run through a shell, so the redirect is honored.
|
|
209
|
-
group: {
|
|
210
|
-
matcher: '*',
|
|
211
|
-
hooks: [{ type: 'command', command: 'aiwg refresh --dry-run --quiet --provider muse > /dev/null', timeout: 60 }],
|
|
212
|
-
},
|
|
213
|
-
reason:
|
|
214
|
-
'Session-start drift check. Runs a read-only `aiwg refresh --dry-run --provider muse` ' +
|
|
215
|
-
'and records its exit status in the Muse hook log. Dry-run by construction: it ' +
|
|
216
|
-
'never mutates the repo, and its report is not injected into the session.',
|
|
217
|
-
removal:
|
|
218
|
-
'Delete this matcher group from `.muse/hooks.json` (the one whose command is ' +
|
|
219
|
-
'`aiwg refresh --dry-run --quiet --provider muse > /dev/null`), or run `aiwg use --provider muse --no-hooks` ' +
|
|
220
|
-
'to stop AIWG managing hooks for this project.',
|
|
221
|
-
},
|
|
222
|
-
];
|
|
185
|
+
export { AIWG_MANAGED_HOOKS };
|
|
223
186
|
|
|
224
187
|
/** Canonical group payloads keyed by hook id, for merge/prune identity. */
|
|
225
188
|
function managedGroupsById() {
|
|
@@ -444,6 +407,8 @@ export function deployMuseHooks(targetDir, opts = {}) {
|
|
|
444
407
|
return { hooksPath, changed, plan, wrote: false };
|
|
445
408
|
}
|
|
446
409
|
|
|
410
|
+
assertMuseDirNotSymlink(path.dirname(hooksPath));
|
|
411
|
+
deployPromptDiscovery(targetDir);
|
|
447
412
|
if (!changed) {
|
|
448
413
|
log(`Muse hooks: ${hooksPath} already current; nothing to do.`);
|
|
449
414
|
return { hooksPath, changed: false, plan: [], wrote: false };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// Deploy the shared prompt discovery hook for Muse's additionalContext contract.
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
|
|
6
|
+
import { importImpl } from '../../_resolve-impl.mjs';
|
|
7
|
+
|
|
8
|
+
export const { promptDiscoveryHook } = await importImpl(import.meta.url, 'extensions/muse-managed-hooks.js');
|
|
9
|
+
|
|
10
|
+
export function deployPromptDiscovery(targetDir) {
|
|
11
|
+
const directory = path.join(targetDir, '.muse', 'hooks');
|
|
12
|
+
if (fs.existsSync(directory) && fs.lstatSync(directory).isSymbolicLink()) {
|
|
13
|
+
throw new Error('Refusing to deploy prompt discovery through a symlinked .muse/hooks directory.');
|
|
14
|
+
}
|
|
15
|
+
fs.mkdirSync(directory, { recursive: true });
|
|
16
|
+
fs.copyFileSync(fileURLToPath(new URL('../../../agentic/code/addons/aiwg-hooks/hooks/aiwg-prompt-discovery.cjs', import.meta.url)),
|
|
17
|
+
path.join(directory, 'aiwg-prompt-discovery.cjs'));
|
|
18
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// Render packaged Codex agents with the same final bindings and marker as deploy.
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { importImpl } from '../../_resolve-impl.mjs';
|
|
5
|
+
import { addManagedMarker, injectBoundRules, listMdFiles } from './base.mjs';
|
|
6
|
+
import { transformAgent } from './codex.mjs';
|
|
7
|
+
import { projectCodexAgentBindings } from './bound-rules-pointer.mjs';
|
|
8
|
+
import { resolveDeliveryRuleBindings } from './rule-binding-targets.mjs';
|
|
9
|
+
const { parseRuleFrontmatter } = await importImpl(import.meta.url, 'rules/activation.mjs');
|
|
10
|
+
const { collectRuleBindingEntries } = await importImpl(import.meta.url, 'artifacts/index-builder.js');
|
|
11
|
+
const { resolveDeployVersion } = await importImpl(import.meta.url, 'providers/deploy-version.mjs');
|
|
12
|
+
|
|
13
|
+
export function packagedRuleSources(root) {
|
|
14
|
+
const code = path.join(root, 'agentic/code');
|
|
15
|
+
const roots = [code];
|
|
16
|
+
for (const kind of ['frameworks', 'addons', 'extensions', 'plugins']) {
|
|
17
|
+
const dir = path.join(code, kind);
|
|
18
|
+
if (fs.existsSync(dir)) roots.push(...fs.readdirSync(dir, { withFileTypes: true })
|
|
19
|
+
.filter(entry => entry.isDirectory()).map(entry => path.join(dir, entry.name)));
|
|
20
|
+
}
|
|
21
|
+
return roots.flatMap(dir => {
|
|
22
|
+
const behaviors = path.join(dir, 'behaviors');
|
|
23
|
+
return [...listMdFiles(path.join(dir, 'rules')).filter(file => !/^RULES-(INDEX|ONDEMAND)\.md$/.test(path.basename(file))), ...(fs.existsSync(behaviors)
|
|
24
|
+
? fs.readdirSync(behaviors, { recursive: true, withFileTypes: true }).filter(entry => entry.isFile() && entry.name === 'BEHAVIOR.md')
|
|
25
|
+
.map(entry => path.join(entry.parentPath, entry.name)) : [])];
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export async function createPackagedCodexRenderer(root, { target = root, ruleSources = packagedRuleSources(root) } = {}) {
|
|
30
|
+
const rules = ruleSources.flatMap(file => {
|
|
31
|
+
const content = fs.readFileSync(file, 'utf8');
|
|
32
|
+
const parsed = parseRuleFrontmatter(content);
|
|
33
|
+
if (!parsed.valid) throw new Error(`Invalid rule frontmatter: ${file}`);
|
|
34
|
+
if (!parsed.rule?.tagged || !parsed.rule.bound_to.agents.length) return [];
|
|
35
|
+
return [{ ...parsed.rule, file, content, body: parsed.body,
|
|
36
|
+
name: path.basename(file) === 'BEHAVIOR.md' ? `behavior/${path.basename(path.dirname(file))}` : parsed.data.name || path.basename(file, '.md'),
|
|
37
|
+
bound_to: { agents: parsed.rule.bound_to.agents, skills: [], flows: [] } }];
|
|
38
|
+
});
|
|
39
|
+
const bindingEntries = rules.length ? await collectRuleBindingEntries(root, 'agentic/code') : [];
|
|
40
|
+
const delivery = await resolveDeliveryRuleBindings({ srcRoot: root, target, bindingEntries }, rules,
|
|
41
|
+
{ project: {}, user: {} }, root, null);
|
|
42
|
+
const deployVersion = resolveDeployVersion(root, undefined, () => {});
|
|
43
|
+
return (source, content = fs.readFileSync(source, 'utf8'), opts = {}) => {
|
|
44
|
+
const transformed = transformAgent(source, injectBoundRules(content, source, { ruleDelivery: delivery }), opts);
|
|
45
|
+
const targets = delivery.targets.filter(entry => entry.source === path.resolve(source));
|
|
46
|
+
return projectCodexAgentBindings(addManagedMarker(transformed, deployVersion, 'bundled', 'line-comment'), targets);
|
|
47
|
+
};
|
|
48
|
+
}
|
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
} from './rule-delivery.mjs';
|
|
16
16
|
|
|
17
17
|
const { trackTemporaryDirectory } = await importImpl(import.meta.url, 'utils/temporary-directory.js');
|
|
18
|
+
const { acquireProviderDeploymentLock } = await importImpl(import.meta.url, 'providers/deployment-lock.js');
|
|
18
19
|
const { signalChild } = await importImpl(import.meta.url, 'process/signal-child.mjs');
|
|
19
20
|
const DEFAULT_WORKER = fileURLToPath(new URL('./provider-prepare-worker.mjs', import.meta.url));
|
|
20
21
|
const CHECKOUT_NEEDS_TS_TRANSFORM = !fs.existsSync(fileURLToPath(new URL('../../../dist/src', import.meta.url)));
|
|
@@ -183,12 +184,16 @@ export async function prepareProviderDeployments({
|
|
|
183
184
|
const activeChildren = new Set();
|
|
184
185
|
let pool;
|
|
185
186
|
let poolDescriptor;
|
|
187
|
+
let releaseLock;
|
|
186
188
|
try {
|
|
189
|
+
// Workers stage only; retain the shared lease through ordered promotion
|
|
190
|
+
// and finalization so another project cannot invalidate their snapshots.
|
|
191
|
+
releaseLock = await acquireProviderDeploymentLock();
|
|
187
192
|
pool = transaction.createPool(srcRoot);
|
|
188
193
|
poolDescriptor = transaction.describePool(pool);
|
|
189
194
|
} catch (error) {
|
|
190
|
-
if (pool) transaction.disposePool(pool);
|
|
191
|
-
|
|
195
|
+
try { if (pool) transaction.disposePool(pool); removeSession(); }
|
|
196
|
+
finally { await releaseLock?.(); }
|
|
192
197
|
throw error;
|
|
193
198
|
}
|
|
194
199
|
const prepared = new Array(jobs.length);
|
|
@@ -209,10 +214,12 @@ export async function prepareProviderDeployments({
|
|
|
209
214
|
const cleanup = async () => {
|
|
210
215
|
if (closed) return;
|
|
211
216
|
closed = true;
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
217
|
+
try {
|
|
218
|
+
await stopChildren();
|
|
219
|
+
for (const item of prepared) if (item?.plan && !item.committed) transaction.disposePlan(item.plan);
|
|
220
|
+
transaction.disposePool(pool);
|
|
221
|
+
removeSession();
|
|
222
|
+
} finally { await releaseLock(); }
|
|
216
223
|
};
|
|
217
224
|
const prepareOne = async (index, attempt = 0) => {
|
|
218
225
|
// Never start a worker once the session is closed: it would outlive
|
|
@@ -243,6 +250,7 @@ export async function prepareProviderDeployments({
|
|
|
243
250
|
}
|
|
244
251
|
return {
|
|
245
252
|
get providers() { return jobs.map(job => job.provider); },
|
|
253
|
+
run(work) { return releaseLock.run(work); },
|
|
246
254
|
async commit(index) {
|
|
247
255
|
if (closed) throw new Error('Provider preparation session is closed');
|
|
248
256
|
if (index !== nextCommit) throw new Error(`Provider plans must commit in order: expected ${nextCommit}, received ${index}`);
|
|
@@ -256,11 +264,8 @@ export async function prepareProviderDeployments({
|
|
|
256
264
|
report = transaction.commit(item.plan);
|
|
257
265
|
}
|
|
258
266
|
item.committed = true;
|
|
259
|
-
nextCommit++;
|
|
260
267
|
return report;
|
|
261
|
-
}
|
|
262
|
-
throw error;
|
|
263
|
-
}
|
|
268
|
+
} finally { nextCommit++; }
|
|
264
269
|
},
|
|
265
270
|
async dispose() { await cleanup(); },
|
|
266
271
|
};
|
|
@@ -14,11 +14,13 @@ import {
|
|
|
14
14
|
ruleEnforcementLevel,
|
|
15
15
|
} from './base.mjs';
|
|
16
16
|
import { resolveDeliveryRuleBindings } from './rule-binding-targets.mjs';
|
|
17
|
+
import { boundRuleAnchor, renderBoundRulesPointer } from './bound-rules-pointer.mjs';
|
|
17
18
|
import { inlineStartup, nativePathLoader, ruleDirectory } from './rule-projection.mjs';
|
|
18
19
|
|
|
19
20
|
export const { parseRuleFrontmatter, inferRuleActivation, readCoreBody, validateCoreSet, formatRuleFrontmatterError } = await importImpl(import.meta.url, 'rules/activation.mjs');
|
|
20
21
|
export const { resolveDeployVersion } = await importImpl(import.meta.url, 'providers/deploy-version.mjs');
|
|
21
22
|
export const { trackTemporaryDirectory } = await importImpl(import.meta.url, 'utils/temporary-directory.js');
|
|
23
|
+
const { outputDigest } = await importImpl(import.meta.url, 'providers/deployment-ownership.mjs');
|
|
22
24
|
export const { loadRulePinConfigs, installedRuleCapabilities, resolveRulePins } = await importImpl(import.meta.url, 'rules/pins.mjs');
|
|
23
25
|
export const { guardRulesInlineBudget } = await importImpl(import.meta.url, 'rules/inline-budget.mjs');
|
|
24
26
|
export const { userConfigFile } = await importImpl(import.meta.url, 'config/user-config-dir.mjs');
|
|
@@ -201,7 +203,7 @@ export function finishBindings(opts, provider) {
|
|
|
201
203
|
const files = [...new Set(roots.flatMap(walk))];
|
|
202
204
|
const indexRel = provider.name === 'copilot' ? '.github/RULES-BOUND.md' : provider.name === 'flue' ? '.agents/.aiwg/RULES-BOUND.md' : `.${provider.name}/RULES-BOUND.md`;
|
|
203
205
|
const indexFile = path.join(opts.target, indexRel);
|
|
204
|
-
const anchor =
|
|
206
|
+
const anchor = boundRuleAnchor;
|
|
205
207
|
const sections = new Map();
|
|
206
208
|
const targetsBySource = new Map();
|
|
207
209
|
for (const target of opts.ruleDelivery.targets) {
|
|
@@ -222,9 +224,11 @@ export function finishBindings(opts, provider) {
|
|
|
222
224
|
const prior = priorSidecar && JSON.parse(priorSidecar.toString()).managed?.[path.basename(file)];
|
|
223
225
|
// Check the pre-deploy claim too: a helper may have rewritten its sidecar
|
|
224
226
|
// or overwritten an edit that preservation will restore after binding.
|
|
225
|
-
|
|
226
|
-
const
|
|
227
|
-
const
|
|
227
|
+
// Snapshot entries may be digests rather than bytes (#3846).
|
|
228
|
+
const contentDigest = `sha256:${contentHash(content)}`;
|
|
229
|
+
const editedBefore = prior && priorBytes && prior.hash !== outputDigest(priorBytes);
|
|
230
|
+
const emitted = opts.ownershipBefore && (!priorBytes || outputDigest(priorBytes) !== contentDigest);
|
|
231
|
+
const editedNow = (record || provider.name === 'flue') && record?.hash !== contentDigest;
|
|
228
232
|
if (editedBefore || !emitted && editedNow) {
|
|
229
233
|
console.warn(`${provider.name}: keeping operator-edited binding target ${opts.logicalOutputPath?.(file) || file}`);
|
|
230
234
|
continue;
|
|
@@ -253,15 +257,14 @@ export function finishBindings(opts, provider) {
|
|
|
253
257
|
const bound = opts.ruleDelivery.bindings.get(target.source) || [];
|
|
254
258
|
const unique = [...new Map(bound.map(rule => [rule.name, rule])).values()].sort((a, b) => a.name.localeCompare(b.name));
|
|
255
259
|
if (unique.length) sections.set(anchor(target), `## ${anchor(target)}\n\n` + unique.map(rule =>
|
|
256
|
-
`- ${rule.name} — ${rule.summary} Fetch
|
|
260
|
+
`- ${rule.name} — ${rule.summary} Fetch when a task or discovered component needs it: \`aiwg show rule ${rule.name} --body\`.`).join('\n'));
|
|
257
261
|
}
|
|
258
262
|
// Skills must carry exact fetch commands themselves: a section pointer
|
|
259
263
|
// alone loses the invocation contract in clean installs (#3473).
|
|
260
264
|
const fetch = skill ? [...new Map(rules.map(rule => [rule.name, rule])).values()]
|
|
261
265
|
.sort((a, b) => a.name.localeCompare(b.name))
|
|
262
266
|
.map(rule => `${rule.summary}\nFetch and follow before governed work: \`aiwg show rule ${rule.name} --body\`.`).join('\n') : '';
|
|
263
|
-
return
|
|
264
|
-
`\`${indexRel}#${anchor(target)}\``).join('; ')}.\n${fetch ? fetch + '\n' : ''}<!-- AIWG:bound-rules:end -->\n`;
|
|
267
|
+
return renderBoundRulesPointer(body, identities, indexRel, { fetch, compact: provider.name === 'codex' && !skill });
|
|
265
268
|
};
|
|
266
269
|
if (file.endsWith('.toml')) content = content.replace(/^developer_instructions = (".*")$/m, (_, value) => `developer_instructions = ${JSON.stringify(pointer(JSON.parse(value)))}`);
|
|
267
270
|
else content = pointer(content);
|
|
@@ -3,6 +3,7 @@ import fs from 'node:fs';
|
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import { importImpl } from '../../_resolve-impl.mjs';
|
|
5
5
|
const { refreshSettingsDigests } = await importImpl(import.meta.url, 'providers/deployment-ownership.mjs');
|
|
6
|
+
const { withProviderDeploymentLock } = await importImpl(import.meta.url, 'providers/deployment-lock.js');
|
|
6
7
|
import {
|
|
7
8
|
contentHash,
|
|
8
9
|
deploySkillsWithKernelRouting,
|
|
@@ -130,6 +131,15 @@ export function commitRuleDeploymentPlan(plan) {
|
|
|
130
131
|
|
|
131
132
|
/** Stage and commit serially for existing provider callers. */
|
|
132
133
|
export async function deployWithRuleDelivery(original, provider, deploy) {
|
|
134
|
+
const shared = [...Object.values(provider.paths), provider.kernelSkillsPath].some(dir => dir && path.isAbsolute(dir))
|
|
135
|
+
|| (provider.name === 'codex' && (original.deployCommands || original.commandsOnly || original.deploySkills || original.skillsOnly));
|
|
136
|
+
if (shared && !original.ruleDelivery && !globalThis[PREPARATION_HOOK] && !original.dryRun && !original.previewReport) {
|
|
137
|
+
return withProviderDeploymentLock(() => deployWithRuleDeliveryUnlocked(original, provider, deploy));
|
|
138
|
+
}
|
|
139
|
+
return deployWithRuleDeliveryUnlocked(original, provider, deploy);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
async function deployWithRuleDeliveryUnlocked(original, provider, deploy) {
|
|
133
143
|
// Kernel source passes share the same selected rule set. Deploy their
|
|
134
144
|
// skills directly; the final source projects rules and bindings across the
|
|
135
145
|
// complete destination. Full passes retain staging for bound flow skills
|
|
@@ -27,15 +27,16 @@ export function renderRuleKernelIndex(rules, nativePaths = false, perRuleFetch =
|
|
|
27
27
|
if (!summary.length && !paths.length && !kernels.length) return '';
|
|
28
28
|
const lines = ['# Rule kernel index', ''];
|
|
29
29
|
// RULES-INDEX receipts are parsed by deployment accounting; retain their command format.
|
|
30
|
-
|
|
31
|
-
if (
|
|
30
|
+
// #3900: "fetch before governed work" made Muse read every rule before discovery; fetch on need.
|
|
31
|
+
if (!perRuleFetch) lines.push("Fetch a rule's full body when a task or discovered component needs it: `aiwg show rule <name> --body`.", '');
|
|
32
|
+
if (kernelFile && kernels.length) lines.push("Kernel rules bind every task and subagent task. On a new task, first run discovery for the request (`aiwg discover --stdin <<'AIWG_REQUEST'`, the request, then `AIWG_REQUEST`) before reading any file below; then read a kernel file before work its subject covers.", '');
|
|
32
33
|
for (const rule of kernels) lines.push(kernelFile
|
|
33
|
-
? `- ${rule.name} — ${rule.summary || '
|
|
34
|
+
? `- ${rule.name} — ${rule.summary || 'Binding kernel rule.'} Full rule: [${kernelFile(rule)}](./${kernelFile(rule)}).`
|
|
34
35
|
: perRuleFetch
|
|
35
|
-
? `- ${rule.name} — ${rule.summary || '
|
|
36
|
+
? `- ${rule.name} — ${rule.summary || 'Binding kernel rule.'} Full rule: \`aiwg show rule ${rule.name} --body\`.`
|
|
36
37
|
: `- ${rule.name}${rule.summary ? ` — ${rule.summary}` : ''}`, '');
|
|
37
38
|
for (const rule of summary) lines.push(perRuleFetch
|
|
38
|
-
? `- ${rule.name} — ${rule.summary} Fetch
|
|
39
|
+
? `- ${rule.name} — ${rule.summary} Fetch when a task or discovered component needs it: \`aiwg show rule ${rule.name} --body\`.`
|
|
39
40
|
: `- ${rule.name}${rule.summary ? ` — ${rule.summary}` : ''}`, '');
|
|
40
41
|
if (paths.length) {
|
|
41
42
|
lines.push(nativePaths ? '## Path rules (native)' : '## Path rules (prompt emulation)', '',
|
|
@@ -56,7 +56,13 @@ export function projectRules(opts, provider) {
|
|
|
56
56
|
const tagged = rules.filter(rule => rule.tagged);
|
|
57
57
|
const extension = provider.name === 'cursor' ? '.mdc' : '.md';
|
|
58
58
|
const managed = content => addManagedMarker(content, opts.deployVersion, opts.deploySource || 'bundled');
|
|
59
|
-
const
|
|
59
|
+
const deployedSources = new Map();
|
|
60
|
+
const writeRule = (rule, content) => {
|
|
61
|
+
const name = `${ruleName(rule, provider)}${extension}`;
|
|
62
|
+
put(path.join(rulesDir, name), managed(content));
|
|
63
|
+
// Keep the source before reference rewriting, pinning, and native transforms.
|
|
64
|
+
deployedSources.set(name, opts.ruleDelivery.rules.find(original => original.file === rule.file));
|
|
65
|
+
};
|
|
60
66
|
for (const file of walk(rulesDir)) {
|
|
61
67
|
if (/\.(md|mdc)$/.test(file) && /aiwg:managed/.test(read(file))) fs.rmSync(file);
|
|
62
68
|
}
|
|
@@ -115,7 +121,9 @@ export function projectRules(opts, provider) {
|
|
|
115
121
|
manifest.managed ||= {};
|
|
116
122
|
for (const file of walk(rulesDir).filter(file => /\.(md|mdc)$/.test(file) && /aiwg:managed/.test(read(file)))) {
|
|
117
123
|
const name = path.relative(rulesDir, file);
|
|
118
|
-
|
|
124
|
+
const source = deployedSources.get(name);
|
|
125
|
+
manifest.managed[name] = { ...manifest.managed[name], hash: `sha256:${contentHash(read(file))}`,
|
|
126
|
+
...(source ? { sourceHash: `sha256:${contentHash(source.content)}` } : {}) };
|
|
119
127
|
}
|
|
120
128
|
for (const name of Object.keys(manifest.managed)) if (!fs.existsSync(path.join(rulesDir, name))) delete manifest.managed[name];
|
|
121
129
|
put(manifestPath, `${JSON.stringify(manifest, null, 2)}\n`);
|
|
@@ -61,7 +61,14 @@ export function projectStartup(opts, provider, coreSection, indexFile) {
|
|
|
61
61
|
if (provider.name !== 'flue' || coreSection) content = section(content, 'rule-core', coreSection.replace(/<!-- AIWG:(?:core-rules|rule-core):(?:start|end) -->\n?/g, '').trimEnd());
|
|
62
62
|
const logical = opts.logicalOutputPath || (file => file);
|
|
63
63
|
const location = path.relative(logical(opts.target), logical(indexFile)).replaceAll('\\', '/');
|
|
64
|
-
|
|
64
|
+
let hook = `${provider.name}: Before every task and subagent task, read and follow \`${location}\`; read every listed kernel file and fetch matching full rules before governed work.`;
|
|
65
|
+
// droid exec runs no prompt hooks, so the Factory line carries discovery itself (#3942).
|
|
66
|
+
// The request goes through a quoted heredoc so the shell never expands it (#3946).
|
|
67
|
+
if (provider.name === 'factory') hook += " On every new request, your first tool call must be the shell command \`aiwg discover --stdin <<'AIWG_REQUEST'\` "
|
|
68
|
+
+ "with the request text on the next lines and \`AIWG_REQUEST\` on the last line; never put request text in quotes on a command line. Answer from its result. "
|
|
69
|
+
+ "Answering or declining without running it violates the skill-discovery rule. Use the \`aiwg\` CLI, not droid's built-in Skill tool. "
|
|
70
|
+
+ "Before writing an issue, comment, PR, report or SDLC artifact, run the same heredoc command with \`--type template\` and \`<output> template\` as the text, "
|
|
71
|
+
+ "read the chosen template with \`aiwg show template <name> --body\`, and fill every required section.";
|
|
65
72
|
content = section(content, `rule-hook-${provider.name}`, hook);
|
|
66
73
|
fs.mkdirSync(path.dirname(startup), { recursive: true });
|
|
67
74
|
writeContextFileSync(startup, content);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/** Preserve projector-owned rules while pruning stale legacy flat artifacts. */
|
|
2
2
|
import fs from 'node:fs';
|
|
3
3
|
import path from 'node:path';
|
|
4
|
-
import {
|
|
4
|
+
import { computeArtifactInventory, computeAllSkillNames, pruneStaleAiwgFiles, resolveAiwgRoot } from './base.mjs';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* After a deploy, prune AIWG-managed flat artifacts (agents/commands/rules)
|
|
@@ -12,10 +12,10 @@ import { computeAllArtifactBasenames, computeAllSkillNames, pruneStaleAiwgFiles,
|
|
|
12
12
|
* or `--source` under `<aiwgRoot>/agentic/code`). Project-local bundle
|
|
13
13
|
* deploys (`--source <bundle>`) are skipped so a bundle's just-deployed
|
|
14
14
|
* artifacts are never mistaken for stale framework files.
|
|
15
|
-
* - `pruneStaleAiwgFiles` itself only removes files
|
|
16
|
-
*
|
|
17
|
-
* stem
|
|
18
|
-
*
|
|
15
|
+
* - `pruneStaleAiwgFiles` itself only removes files whose AIWG
|
|
16
|
+
* receipt hash matches their bytes AND whose recorded owners no longer
|
|
17
|
+
* ship the stem. Without bundle identity, it uses the global source set.
|
|
18
|
+
* Any still-shipping recorded owner protects a shared path.
|
|
19
19
|
* - Aggregate-file paths (e.g. `AGENTS.md`) and unset paths are skipped.
|
|
20
20
|
*
|
|
21
21
|
* @param {object} provider loaded provider module
|
|
@@ -103,8 +103,8 @@ export function pruneStaleAiwgArtifacts(provider, target, srcRoot, opts, explici
|
|
|
103
103
|
if (!relPath) continue; // type not file-deployed by provider
|
|
104
104
|
if (relPath.endsWith('.md')) continue; // aggregate file (e.g. AGENTS.md)
|
|
105
105
|
|
|
106
|
-
const
|
|
107
|
-
if (!
|
|
106
|
+
const inventory = computeArtifactInventory(srcRoot, type);
|
|
107
|
+
if (!inventory) continue; // no global desired set → skip
|
|
108
108
|
|
|
109
109
|
const destDir = path.isAbsolute(relPath) ? relPath : path.join(target, relPath);
|
|
110
110
|
// Activation projection owns its complete selected rule set, including extensions.
|
|
@@ -113,7 +113,8 @@ export function pruneStaleAiwgArtifacts(provider, target, srcRoot, opts, explici
|
|
|
113
113
|
const receipt = path.join(destDir, '.aiwg-manifest.json');
|
|
114
114
|
if (fs.existsSync(receipt) && JSON.parse(fs.readFileSync(receipt, 'utf8')).delivery) continue;
|
|
115
115
|
}
|
|
116
|
-
const removed = pruneStaleAiwgFiles(destDir,
|
|
116
|
+
const removed = pruneStaleAiwgFiles(destDir, inventory.stems, {
|
|
117
|
+
ownerStems: inventory.ownerStems,
|
|
117
118
|
dryRun: opts.dryRun,
|
|
118
119
|
verbose: opts.verbose,
|
|
119
120
|
// Retire wrappers whose source skill no longer ships (#2511). Only the
|
|
@@ -2,10 +2,13 @@ import { fileURLToPath } from 'node:url';
|
|
|
2
2
|
import { importImpl } from '../_resolve-impl.mjs';
|
|
3
3
|
|
|
4
4
|
/** Offline inspection only: never probes a service or records an opportunity. */
|
|
5
|
-
export async function collectDecisionOffloadReport(projectRoot) {
|
|
5
|
+
export async function collectDecisionOffloadReport(projectRoot, { fix = false } = {}) {
|
|
6
6
|
try {
|
|
7
7
|
const { buildDecisionOffloadSnapshot } = await importImpl(import.meta.url, 'decision/offload.js');
|
|
8
|
-
|
|
8
|
+
const { inspectWorkspacePermissions } = await importImpl(import.meta.url, 'storage/workspace-permissions-health.js');
|
|
9
|
+
const permissions = await inspectWorkspacePermissions(projectRoot, fix);
|
|
10
|
+
const snapshot = await buildDecisionOffloadSnapshot({ projectRoot, frameworkRoot: fileURLToPath(new URL('../../', import.meta.url)) });
|
|
11
|
+
return { ...snapshot, permissions };
|
|
9
12
|
} catch {
|
|
10
13
|
// An unavailable reader must not be interpreted as healthy adoption, nor
|
|
11
14
|
// leak exception details that can include private paths or stored values.
|
|
@@ -19,6 +22,8 @@ export function formatDecisionOffloadReport(snapshot) {
|
|
|
19
22
|
lines.push(' Observation: unknown (report unavailable).');
|
|
20
23
|
return lines;
|
|
21
24
|
}
|
|
25
|
+
for (const journal of snapshot.permissions?.journals ?? []) lines.push(` Journal permissions: ${journal.state} (${journal.path})`);
|
|
26
|
+
for (const finding of snapshot.permissions?.findings ?? []) lines.push(` Permissions: ${finding.reason} (${finding.path}); ${finding.repaired ? 'repaired' : finding.repair}`);
|
|
22
27
|
const calls = snapshot.calls?.organic;
|
|
23
28
|
const opportunities = snapshot.opportunities?.organic;
|
|
24
29
|
lines.push(` Scope: ${snapshot.scope?.mode ?? 'unknown'}${snapshot.scope?.sessionId ? ` (${snapshot.scope.sessionId})` : ''}`);
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// Synchronize tracker issue forms from the owning aiwg-utils bundle.
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
|
|
5
|
+
const templates = ['bug-report', 'feature-request', 'tester-report', 'imported-report'];
|
|
6
|
+
|
|
7
|
+
export function syncIssueTemplateCopies(root, { check = false, dryRun = false } = {}) {
|
|
8
|
+
const differences = [];
|
|
9
|
+
for (const name of templates) {
|
|
10
|
+
const source = path.join(root, 'agentic/code/addons/aiwg-utils/templates/issues', `${name}.md`);
|
|
11
|
+
const canonical = fs.readFileSync(source);
|
|
12
|
+
for (const tracker of ['.gitea', '.github']) {
|
|
13
|
+
const relative = `${tracker}/ISSUE_TEMPLATE/${name}.md`;
|
|
14
|
+
const target = path.join(root, relative);
|
|
15
|
+
if (!fs.existsSync(target)) differences.push(`Missing: ${relative}`);
|
|
16
|
+
else if (!fs.readFileSync(target).equals(canonical)) differences.push(`Changed: ${relative}`);
|
|
17
|
+
if (!check && !dryRun) {
|
|
18
|
+
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
19
|
+
fs.writeFileSync(target, canonical);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return differences;
|
|
24
|
+
}
|