@aiwg/cli 2026.10.14 → 2026.10.15
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-utils/rules/anti-laziness.core.md +13 -0
- package/agentic/code/addons/aiwg-utils/rules/anti-laziness.md +118 -0
- package/dist/src/artifacts/corpus-tools/cli.js +32 -0
- package/dist/src/artifacts/corpus-tools/discovery-log.js +1 -1
- package/dist/src/artifacts/corpus-tools/expand-cli.js +89 -0
- package/dist/src/artifacts/corpus-tools/expand-queue.js +38 -0
- package/dist/src/artifacts/corpus-tools/expand-state.js +40 -0
- package/dist/src/artifacts/corpus-tools/expand.js +125 -0
- package/dist/src/artifacts/corpus-tools/resolve-cli.js +91 -0
- package/dist/src/artifacts/corpus-tools/resolve-corpus.js +41 -0
- package/dist/src/artifacts/corpus-tools/resolve.js +105 -0
- package/dist/src/cli/handlers/doctor-args.js +40 -0
- package/dist/src/cli/handlers/doctor-help.js +4 -2
- package/dist/src/cli/handlers/utilities.js +5 -31
- package/dist/src/config/worker-context.js +33 -4
- package/dist/src/decision/heldout/collector.js +1 -1
- package/dist/src/features/catalog.js +1 -1
- package/dist/src/gates/evaluate.js +2 -2
- package/dist/src/gates/heldout.js +42 -0
- package/dist/src/gates/index.js +2 -1
- package/dist/src/models/worker-installation-store.mjs +228 -0
- package/dist/src/models/worker-installation.mjs +7 -162
- package/dist/src/providers/provider-definitions.js +10 -10
- package/dist/src/research/clients/arxiv.js +10 -4
- package/dist/src/research/clients/base.js +5 -4
- package/dist/src/research/clients/crossref.js +9 -1
- package/dist/src/research/clients/semantic-scholar.js +73 -44
- package/dist/src/research/identity.js +85 -0
- package/dist/src/research/index.js +1 -0
- package/dist/src/research/reference-match.js +89 -0
- package/dist/src/rules/core-startup.d.mts +2 -0
- package/dist/src/rules/core-startup.mjs +31 -0
- package/dist/src/smiths/context-pipeline/agents-md.js +34 -0
- package/dist/src/smiths/context-pipeline/aiwg-md.js +3 -0
- package/dist/src/smiths/context-pipeline/bridge-ownership.js +50 -0
- package/dist/src/smiths/context-pipeline/generator.js +40 -104
- package/dist/src/smiths/context-pipeline/managed-hook.js +10 -0
- package/package.json +4 -2
- package/tools/agents/deploy-agents.mjs +2 -123
- package/tools/agents/providers/antigravity.mjs +1 -1
- package/tools/agents/providers/context-write.mjs +12 -0
- package/tools/agents/providers/grok-build.mjs +8 -5
- package/tools/agents/providers/hermes-skill-lifecycle.mjs +144 -0
- package/tools/agents/providers/hermes-startup.mjs +209 -0
- package/tools/agents/providers/hermes.mjs +9 -359
- package/tools/agents/providers/model-wrapper.mjs +5 -1
- package/tools/agents/providers/muse.mjs +3 -3
- package/tools/agents/providers/pi.mjs +1 -1
- package/tools/agents/providers/rule-delivery.mjs +23 -225
- package/tools/agents/providers/rule-presentation.mjs +13 -4
- package/tools/agents/providers/rule-projection.mjs +119 -0
- package/tools/agents/providers/rule-startup.mjs +70 -0
- package/tools/agents/providers/stale-artifact-prune.mjs +128 -0
- package/tools/agents/providers/warp.mjs +2 -2
- package/tools/agents/providers/windsurf.mjs +11 -57
- package/tools/plugin/plugin-links.mjs +3 -0
|
@@ -85,8 +85,6 @@ import {
|
|
|
85
85
|
addManagedMarker,
|
|
86
86
|
collectBehaviorDirs,
|
|
87
87
|
collectFrameworkArtifacts,
|
|
88
|
-
computeAllArtifactBasenames,
|
|
89
|
-
computeAllSkillNames,
|
|
90
88
|
contentHash,
|
|
91
89
|
deployEmulatedBehaviors,
|
|
92
90
|
getAddonSkillDirs,
|
|
@@ -95,7 +93,6 @@ import {
|
|
|
95
93
|
loadRuntimeModelCatalog,
|
|
96
94
|
migrateCommandsDirectory,
|
|
97
95
|
parseFrontmatter,
|
|
98
|
-
pruneStaleAiwgFiles,
|
|
99
96
|
resolveAiwgRoot,
|
|
100
97
|
updateSidecarManifest,
|
|
101
98
|
} from './providers/base.mjs';
|
|
@@ -345,126 +342,8 @@ function mirrorSkillsAsCommands(provider, target, srcRoot, opts) {
|
|
|
345
342
|
}
|
|
346
343
|
|
|
347
344
|
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
// ============================================================================
|
|
351
|
-
|
|
352
|
-
/**
|
|
353
|
-
* After a deploy, prune AIWG-managed flat artifacts (agents/commands/rules)
|
|
354
|
-
* whose source no longer ships them — mirroring the skills holistic prune.
|
|
355
|
-
*
|
|
356
|
-
* Safety boundaries:
|
|
357
|
-
* - Runs ONLY for AIWG framework/addon deploys (default source = AIWG root,
|
|
358
|
-
* or `--source` under `<aiwgRoot>/agentic/code`). Project-local bundle
|
|
359
|
-
* deploys (`--source <bundle>`) are skipped so a bundle's just-deployed
|
|
360
|
-
* artifacts are never mistaken for stale framework files.
|
|
361
|
-
* - `pruneStaleAiwgFiles` itself only removes files carrying an AIWG
|
|
362
|
-
* ownership signal (sidecar entry or `aiwg:managed` marker) AND whose
|
|
363
|
-
* stem is absent from the global, mode-independent source set, so
|
|
364
|
-
* user-authored files and sibling-framework artifacts always survive.
|
|
365
|
-
* - Aggregate-file paths (e.g. `AGENTS.md`) and unset paths are skipped.
|
|
366
|
-
*
|
|
367
|
-
* @param {object} provider loaded provider module
|
|
368
|
-
* @param {string} target deploy target dir
|
|
369
|
-
* @param {string} srcRoot effective deploy source
|
|
370
|
-
* @param {object} opts deploy opts (dryRun/verbose/quiet + deploy flags)
|
|
371
|
-
* @param {string|null} explicitSource the raw `--source` value (null when unset)
|
|
372
|
-
*/
|
|
373
|
-
/** Bundles whose deploy is itself the kernel-only bulk install. */
|
|
374
|
-
const BULK_INSTALL_BUNDLES = new Set(['all']);
|
|
375
|
-
|
|
376
|
-
/**
|
|
377
|
-
* True when the kernel-only bulk install is the only thing this project has
|
|
378
|
-
* deployed, so clearing leftover flat artifacts is a migration and not a
|
|
379
|
-
* deletion of another bundle's surface (#2508).
|
|
380
|
-
*
|
|
381
|
-
* A project with no readable `.aiwg/aiwg.config` has no recorded owner, so the
|
|
382
|
-
* pre-#152 migration cleanup still applies.
|
|
383
|
-
*/
|
|
384
|
-
export function bulkInstallOwnsFlatArtifacts(target) {
|
|
385
|
-
let installed;
|
|
386
|
-
try {
|
|
387
|
-
const raw = realFs.readFileSync(path.join(target, '.aiwg', 'aiwg.config'), 'utf8');
|
|
388
|
-
installed = JSON.parse(raw)?.installed;
|
|
389
|
-
} catch {
|
|
390
|
-
return true;
|
|
391
|
-
}
|
|
392
|
-
if (!installed || typeof installed !== 'object') return true;
|
|
393
|
-
return !Object.keys(installed).some(name => !BULK_INSTALL_BUNDLES.has(name));
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
function pruneStaleAiwgArtifacts(provider, target, srcRoot, opts, explicitSource) {
|
|
397
|
-
if (opts.skillsOnly && !opts.kernelOnly) return; // skills run their own prune in the provider
|
|
398
|
-
|
|
399
|
-
const aiwgRoot = resolveAiwgRoot(srcRoot);
|
|
400
|
-
if (!aiwgRoot) return; // no AIWG tree → bundle/standalone deploy; never prune
|
|
401
|
-
|
|
402
|
-
// Gate: only framework/addon deploys are eligible. A default deploy (no
|
|
403
|
-
// --source) sources from the AIWG root. An explicit --source is eligible
|
|
404
|
-
// only when it lives under <aiwgRoot>/agentic/code (bundled fw/addon).
|
|
405
|
-
if (explicitSource) {
|
|
406
|
-
const codeRoot = path.join(aiwgRoot, 'agentic', 'code');
|
|
407
|
-
const rel = path.relative(codeRoot, path.resolve(explicitSource));
|
|
408
|
-
const underCode = !!rel && !rel.startsWith('..') && !path.isAbsolute(rel);
|
|
409
|
-
if (!underCode) return; // project-local bundle / external source → skip
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
if (opts.kernelOnly) {
|
|
413
|
-
// Kernel-only delivers skills and rules. The empty desired set below
|
|
414
|
-
// applies only to bulk agents/commands left by
|
|
415
|
-
// the pre-#152 bulk default, when the bulk install is the only thing this
|
|
416
|
-
// project ever deployed.
|
|
417
|
-
//
|
|
418
|
-
// #2508: applying it unconditionally deleted every artifact a sibling
|
|
419
|
-
// bundle owned — `aiwg use sdlc` followed by `aiwg use all` took
|
|
420
|
-
// .claude/agents from 139 to 0. When another bundle is installed, it owns
|
|
421
|
-
// this surface deliberately and the migration assumption does not hold.
|
|
422
|
-
if (!bulkInstallOwnsFlatArtifacts(target)) {
|
|
423
|
-
if (opts.verbose) {
|
|
424
|
-
console.log('skip kernel-only flat prune: another installed bundle owns agents/commands/rules');
|
|
425
|
-
}
|
|
426
|
-
return;
|
|
427
|
-
}
|
|
428
|
-
for (const type of ['agents', 'commands']) {
|
|
429
|
-
const relPath = provider.paths?.[type];
|
|
430
|
-
if (!relPath || relPath.endsWith('.md')) continue;
|
|
431
|
-
const destDir = path.isAbsolute(relPath) ? relPath : path.join(target, relPath);
|
|
432
|
-
pruneStaleAiwgFiles(destDir, new Set(), {
|
|
433
|
-
dryRun: opts.dryRun,
|
|
434
|
-
verbose: opts.verbose,
|
|
435
|
-
artifactExtensions: ['.md', '.mdc', '.toml'],
|
|
436
|
-
});
|
|
437
|
-
}
|
|
438
|
-
return;
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
const typesThisRun = [];
|
|
442
|
-
if (!opts.commandsOnly && !opts.rulesOnly) typesThisRun.push('agents');
|
|
443
|
-
if (opts.deployCommands || opts.commandsOnly) typesThisRun.push('commands');
|
|
444
|
-
if (opts.deployRules || opts.rulesOnly) typesThisRun.push('rules');
|
|
445
|
-
|
|
446
|
-
for (const type of typesThisRun) {
|
|
447
|
-
const relPath = provider.paths?.[type];
|
|
448
|
-
if (!relPath) continue; // type not file-deployed by provider
|
|
449
|
-
if (relPath.endsWith('.md')) continue; // aggregate file (e.g. AGENTS.md)
|
|
450
|
-
|
|
451
|
-
const desired = computeAllArtifactBasenames(srcRoot, type);
|
|
452
|
-
if (!desired) continue; // no global desired set → skip
|
|
453
|
-
|
|
454
|
-
const destDir = path.isAbsolute(relPath) ? relPath : path.join(target, relPath);
|
|
455
|
-
const removed = pruneStaleAiwgFiles(destDir, desired, {
|
|
456
|
-
dryRun: opts.dryRun,
|
|
457
|
-
verbose: opts.verbose,
|
|
458
|
-
// Retire wrappers whose source skill no longer ships (#2511). Only the
|
|
459
|
-
// command directory holds them; the kernel-only branch returns earlier,
|
|
460
|
-
// so a bulk install still cannot touch wrappers it did not write.
|
|
461
|
-
skillCommandStems: type === 'commands' ? computeAllSkillNames(srcRoot) : null,
|
|
462
|
-
});
|
|
463
|
-
if (removed.length > 0 && !opts.quiet) {
|
|
464
|
-
console.log(` Pruned: ${removed.length} stale AIWG ${type} file${removed.length === 1 ? '' : 's'}`);
|
|
465
|
-
}
|
|
466
|
-
}
|
|
467
|
-
}
|
|
345
|
+
export { bulkInstallOwnsFlatArtifacts } from './providers/stale-artifact-prune.mjs';
|
|
346
|
+
import { pruneStaleAiwgArtifacts } from './providers/stale-artifact-prune.mjs';
|
|
468
347
|
|
|
469
348
|
// ============================================================================
|
|
470
349
|
// Argument Parsing
|
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
} from './base.mjs';
|
|
19
19
|
export const name = 'antigravity';
|
|
20
20
|
export const aliases = ['agy'];
|
|
21
|
-
export const paths = { agents: '.agents/agents', commands: '', skills: '.agents/skills', rules: '' };
|
|
21
|
+
export const paths = { agents: '.agents/agents', commands: '', skills: '.agents/skills', rules: '.antigravity/rules' };
|
|
22
22
|
export const kernelSkillsPath = '.agents/skills';
|
|
23
23
|
export const support = { agents: 'degraded', commands: 'indexed', skills: 'native', rules: 'context' };
|
|
24
24
|
export const capabilities = {
|
|
@@ -14,8 +14,10 @@ export const CONTEXT_STAGE_ENV = 'AIWG_CONTEXT_STAGE_LOG';
|
|
|
14
14
|
|
|
15
15
|
let loadError = null;
|
|
16
16
|
let writer = null;
|
|
17
|
+
let ownership = null;
|
|
17
18
|
try {
|
|
18
19
|
writer = await importImpl(import.meta.url, 'smiths/context-pipeline/context-file-safety.js');
|
|
20
|
+
ownership = await importImpl(import.meta.url, 'smiths/context-pipeline/bridge-ownership.js');
|
|
19
21
|
} catch (error) {
|
|
20
22
|
loadError = error;
|
|
21
23
|
}
|
|
@@ -26,3 +28,13 @@ export function writeContextFileSync(file, content, encoding) {
|
|
|
26
28
|
}
|
|
27
29
|
return writer.writeContextFileSync(file, content, encoding);
|
|
28
30
|
}
|
|
31
|
+
|
|
32
|
+
export function normalizeRuleStartup(content, bootstrap, agentsHeader) {
|
|
33
|
+
if (!ownership) throw new Error('Startup ownership layer is unavailable', { cause: loadError });
|
|
34
|
+
return ownership.normalizeRuleStartup(content, bootstrap, agentsHeader);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function retireLegacyBridge(content) {
|
|
38
|
+
if (!ownership) throw new Error('Startup ownership layer is unavailable', { cause: loadError });
|
|
39
|
+
return ownership.retireLegacyBridge(content);
|
|
40
|
+
}
|
|
@@ -6,7 +6,7 @@ import { withModelWrapper } from './model-wrapper.mjs';
|
|
|
6
6
|
*
|
|
7
7
|
* Native agent compilation is deliberately limited to the three AIWG model
|
|
8
8
|
* workers until the wider corpus has a qualified Grok tool mapping (#2577).
|
|
9
|
-
* Rules
|
|
9
|
+
* Rules are written to .grok/rules and loaded by Grok alongside AGENTS.md.
|
|
10
10
|
*
|
|
11
11
|
* @issue #2575
|
|
12
12
|
*/
|
|
@@ -36,7 +36,7 @@ export const aliases = [];
|
|
|
36
36
|
export const paths = {
|
|
37
37
|
agents: '.grok/agents',
|
|
38
38
|
skills: '.grok/skills',
|
|
39
|
-
rules: '',
|
|
39
|
+
rules: '.grok/rules',
|
|
40
40
|
hooks: '.grok/hooks',
|
|
41
41
|
config: '.grok/config.toml',
|
|
42
42
|
};
|
|
@@ -48,12 +48,15 @@ export const support = {
|
|
|
48
48
|
agents: 'native',
|
|
49
49
|
commands: 'indexed', // discoverable through the AIWG index; no native command writer
|
|
50
50
|
skills: 'native',
|
|
51
|
-
|
|
51
|
+
// CONTEXT_CONTRACTS: https://docs.x.ai/build/features/project-rules
|
|
52
|
+
// .grok/rules/*.md loads hierarchically on every task; no frontmatter marker
|
|
53
|
+
// is required for always-on rules (unlike Windsurf's trigger field).
|
|
54
|
+
rules: 'native', // always-on Markdown rules discovered root-to-cwd by Grok Build
|
|
52
55
|
};
|
|
53
56
|
|
|
54
57
|
export const capabilities = {
|
|
55
58
|
skills: true,
|
|
56
|
-
rules:
|
|
59
|
+
rules: true, // Native Markdown; path activation uses the index
|
|
57
60
|
yamlFormat: false,
|
|
58
61
|
aggregatedOutput: false,
|
|
59
62
|
homeDirectoryDeploy: true,
|
|
@@ -347,7 +350,7 @@ export async function postDeploy(target, opts = {}) {
|
|
|
347
350
|
console.log(
|
|
348
351
|
`Grok Build (experimental): kernel skills → ${kernelSkillsPath}; ` +
|
|
349
352
|
`standard skills index-driven (opt-in mirror → ${standardSkillsPath} with --copy-all); ` +
|
|
350
|
-
`model-worker agents → ${paths.agents}; rules
|
|
353
|
+
`model-worker agents → ${paths.agents}; rules → ${paths.rules}; user home → ${home || '(unresolved GROK_HOME)'}. ` +
|
|
351
354
|
'Distinct from grokbot.',
|
|
352
355
|
);
|
|
353
356
|
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/** Preserve Hermes curator registration and migrate the legacy skill directory. */
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
export function createHermesSkillLifecycle({ getHermesHome, paths, kernelSkillsPath }) {
|
|
5
|
+
/**
|
|
6
|
+
* Hermes v0.12.0+ ships an autonomous Curator (`agent/curator.py`) that
|
|
7
|
+
* grades and archives skills on a 7-day cycle. Skills are excluded from
|
|
8
|
+
* archival if either:
|
|
9
|
+
* (a) they appear in `~/.hermes/skills/.bundled_manifest` (one name per
|
|
10
|
+
* line, format `name:tag`), or
|
|
11
|
+
* (b) their path's first component starts with `.` (verified at
|
|
12
|
+
* `tools/skill_usage.py:241-243`).
|
|
13
|
+
*
|
|
14
|
+
* AIWG standard skills under `~/.hermes/skills/.aiwg/...` are protected
|
|
15
|
+
* by (b) automatically. AIWG kernel skills land at the top level
|
|
16
|
+
* (`~/.hermes/skills/<name>/SKILL.md`) and need explicit (a) registration.
|
|
17
|
+
*
|
|
18
|
+
* This function writes/updates the bundled manifest with the kernel-skill
|
|
19
|
+
* names AIWG owns. Idempotent: existing entries (from Hermes's own bundle
|
|
20
|
+
* or other tools) are preserved.
|
|
21
|
+
*/
|
|
22
|
+
function updateBundledManifest(kernelSkillNames, opts) {
|
|
23
|
+
const { dryRun, quiet } = opts;
|
|
24
|
+
const manifestPath = path.join(opts.kernelSkillsPath || kernelSkillsPath, '.bundled_manifest');
|
|
25
|
+
const aiwgTag = 'aiwg-managed';
|
|
26
|
+
|
|
27
|
+
// Read existing manifest (if any) and split into "ours" vs "theirs"
|
|
28
|
+
let existing = '';
|
|
29
|
+
try {
|
|
30
|
+
existing = fs.readFileSync(manifestPath, 'utf-8');
|
|
31
|
+
} catch {
|
|
32
|
+
existing = '';
|
|
33
|
+
}
|
|
34
|
+
const theirs = [];
|
|
35
|
+
for (const rawLine of existing.split('\n')) {
|
|
36
|
+
const line = rawLine.trim();
|
|
37
|
+
if (!line) continue;
|
|
38
|
+
if (line.endsWith(`:${aiwgTag}`)) continue; // ours — drop, will re-add below
|
|
39
|
+
theirs.push(line);
|
|
40
|
+
}
|
|
41
|
+
const ours = kernelSkillNames.map((n) => `${n}:${aiwgTag}`);
|
|
42
|
+
|
|
43
|
+
// Stable order: theirs first (preserve operator/Hermes-bundled order), then ours
|
|
44
|
+
const merged = [...theirs, ...ours].join('\n') + '\n';
|
|
45
|
+
|
|
46
|
+
if (dryRun) {
|
|
47
|
+
if (!quiet) {
|
|
48
|
+
console.log(` [curator] [dry-run] Would write ${manifestPath} with ${ours.length} AIWG kernel + ${theirs.length} preserved entries`);
|
|
49
|
+
}
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
try {
|
|
54
|
+
fs.mkdirSync(path.dirname(manifestPath), { recursive: true });
|
|
55
|
+
fs.writeFileSync(manifestPath, merged, 'utf-8');
|
|
56
|
+
if (!quiet) {
|
|
57
|
+
console.log(` [curator] Bundled manifest updated: ${ours.length} AIWG kernel skills protected (preserved ${theirs.length} pre-existing entries)`);
|
|
58
|
+
}
|
|
59
|
+
} catch (err) {
|
|
60
|
+
if (!quiet) {
|
|
61
|
+
console.log(` [curator] Warning: could not write bundled manifest: ${err.message}`);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// ============================================================================
|
|
67
|
+
// Legacy skill path migration (#1316 / S5)
|
|
68
|
+
// ============================================================================
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Remove the legacy `~/.hermes/.aiwg/skills/` directory if it exists and the
|
|
72
|
+
* new path `~/.hermes/skills/.aiwg/` is populated with AIWG content.
|
|
73
|
+
*
|
|
74
|
+
* Idempotent: re-running after migration is a no-op.
|
|
75
|
+
*
|
|
76
|
+
* Safety:
|
|
77
|
+
* - Only removes when the new path exists and contains files
|
|
78
|
+
* - Skips removal if the new path is empty (avoids losing skills during
|
|
79
|
+
* an in-progress deploy where the new path hasn't been written yet)
|
|
80
|
+
* - Operates only on the documented legacy path — never touches user-managed
|
|
81
|
+
* directories under ~/.hermes/
|
|
82
|
+
*/
|
|
83
|
+
function migrateLegacySkillPath(opts) {
|
|
84
|
+
const { dryRun, quiet } = opts;
|
|
85
|
+
// Resolve through the same HERMES_HOME contract as every other path in
|
|
86
|
+
// this provider (env var first, platform default otherwise): with
|
|
87
|
+
// HERMES_HOME set, the legacy tree lives under that root — never under
|
|
88
|
+
// the process home directory.
|
|
89
|
+
const legacyPath = opts.hermesLegacySkills || path.join(getHermesHome(), '.aiwg', 'skills');
|
|
90
|
+
const newPath = paths.skills;
|
|
91
|
+
|
|
92
|
+
let legacyExists = false;
|
|
93
|
+
try {
|
|
94
|
+
legacyExists = fs.statSync(legacyPath).isDirectory();
|
|
95
|
+
} catch {
|
|
96
|
+
return; // no legacy path — nothing to migrate
|
|
97
|
+
}
|
|
98
|
+
if (!legacyExists) return;
|
|
99
|
+
|
|
100
|
+
// Sanity: new path must exist and be non-empty before we remove the legacy one
|
|
101
|
+
let newPopulated = false;
|
|
102
|
+
try {
|
|
103
|
+
const entries = fs.readdirSync(newPath);
|
|
104
|
+
newPopulated = entries.length > 0;
|
|
105
|
+
} catch {
|
|
106
|
+
newPopulated = false;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (!newPopulated) {
|
|
110
|
+
if (!quiet) {
|
|
111
|
+
console.log(` [migrate] Legacy skills detected at ${legacyPath}; new path not yet populated. Skipping cleanup until next deploy.`);
|
|
112
|
+
}
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (dryRun) {
|
|
117
|
+
console.log(` [migrate] [dry-run] Would remove legacy skill path: ${legacyPath}`);
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
try {
|
|
122
|
+
fs.rmSync(legacyPath, { recursive: true, force: true });
|
|
123
|
+
// Also remove the empty parent if it's now empty
|
|
124
|
+
const parent = path.dirname(legacyPath);
|
|
125
|
+
try {
|
|
126
|
+
const remaining = fs.readdirSync(parent);
|
|
127
|
+
if (remaining.length === 0) {
|
|
128
|
+
fs.rmdirSync(parent);
|
|
129
|
+
}
|
|
130
|
+
} catch {
|
|
131
|
+
// parent removal is best-effort
|
|
132
|
+
}
|
|
133
|
+
if (!quiet) {
|
|
134
|
+
console.log(` [migrate] Removed legacy skill path: ${legacyPath}`);
|
|
135
|
+
}
|
|
136
|
+
} catch (err) {
|
|
137
|
+
if (!quiet) {
|
|
138
|
+
console.log(` [migrate] Warning: could not remove legacy path ${legacyPath}: ${err.message}`);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
return { updateBundledManifest, migrateLegacySkillPath };
|
|
144
|
+
}
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
/** Legacy Hermes startup compatibility; activation delivery owns current startup policy. */
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { listOnDemandRuleFiles, renderOnDemandRuleSection } from './base.mjs';
|
|
5
|
+
import { writeContextFileSync } from './context-write.mjs';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Generate a lean AGENTS.md for Hermes
|
|
9
|
+
*
|
|
10
|
+
* Hermes reaches AGENTS.md through its startup pointer on every task. Reserve
|
|
11
|
+
* the 19,000-character budget for bootstrap, compact core and operator context.
|
|
12
|
+
* See: docs/integrations/hermes-quickstart.md (Part 3)
|
|
13
|
+
*/
|
|
14
|
+
// Hermes context cap is 20K chars (head-tail truncated above). Hard limit
|
|
15
|
+
// to leave headroom for project-specific additions and skill-discovery.
|
|
16
|
+
const HERMES_AGENTS_MD_HARD_CAP = 19_000;
|
|
17
|
+
const HERMES_AGENTS_MD_SOFT_WARN = 15_000;
|
|
18
|
+
|
|
19
|
+
/** Preserve the harness limit for operator context; kernel bodies live in rules files. */
|
|
20
|
+
export function assertContextBudget(content, name = 'AGENTS.md') {
|
|
21
|
+
if (content.length <= HERMES_AGENTS_MD_HARD_CAP) return;
|
|
22
|
+
throw new Error(`Hermes ${name} (${content.length} chars) exceeds hard cap of ${HERMES_AGENTS_MD_HARD_CAP}. Review wrappers and operator additions.`);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Top-7 CRITICAL rule directives, inlined into AGENTS.md for guaranteed
|
|
27
|
+
* priming on every Hermes turn (#1318 / S7; skill-discovery added #1347).
|
|
28
|
+
*
|
|
29
|
+
* The full rule bodies are reachable without MCP via `aiwg discover` and
|
|
30
|
+
* `aiwg show rule <name> --body`; MCP exposes the same path through `rule-list` and
|
|
31
|
+
* `rule-show` when configured (#1320). The bodies exceed Hermes's 20K context
|
|
32
|
+
* cap if inlined verbatim (anti-laziness alone was 32K chars; it now ships as a compact core body, #3450), so we inline
|
|
33
|
+
* compressed directives only and point to CLI/MCP for the full text.
|
|
34
|
+
*
|
|
35
|
+
* Selection criteria: rules tagged CRITICAL/HIGH enforcement level whose
|
|
36
|
+
* violations are silent or destructive (cost of remembering to query
|
|
37
|
+
* rule-show > cost of inlining the directive). skill-discovery is HIGH
|
|
38
|
+
* but is the linchpin of the discover-first architecture across all
|
|
39
|
+
* providers and is therefore inlined alongside the CRITICAL set.
|
|
40
|
+
*/
|
|
41
|
+
const CRITICAL_RULE_DIRECTIVES = `## CRITICAL Rules (always apply)
|
|
42
|
+
|
|
43
|
+
These are the highest-enforcement AIWG rules. Full bodies are reachable without
|
|
44
|
+
MCP:
|
|
45
|
+
- Find rules: \`aiwg discover "rule <topic>" --type rule\`
|
|
46
|
+
- Fetch a rule: \`aiwg show rule <name> --body\`
|
|
47
|
+
|
|
48
|
+
If the optional MCP sidecar is configured, the same surface is available through
|
|
49
|
+
\`mcp_aiwg_rule_list\` and \`mcp_aiwg_rule_show\`.
|
|
50
|
+
|
|
51
|
+
### Rule: skill-discovery (discover-first protocol)
|
|
52
|
+
Before declining a user request as "outside AIWG's scope" or improvising a
|
|
53
|
+
workflow from training data, you MUST run \`aiwg discover "<user need>"\`
|
|
54
|
+
against the user's need. Most AIWG skills are not in your context; they reach
|
|
55
|
+
you through \`aiwg discover\` + \`aiwg show <type> <name>\`. If MCP is available,
|
|
56
|
+
\`mcp_aiwg_discover\` and type-specific show tools are equivalent. Run discover
|
|
57
|
+
whenever the user mentions AIWG, a framework name (sdlc, research, forensics,
|
|
58
|
+
ops, marketing, security-engineering, media-curator, knowledge-base), or
|
|
59
|
+
capability keywords (skill, agent, command, rule, workflow).
|
|
60
|
+
|
|
61
|
+
### Rule: no-attribution
|
|
62
|
+
Never add AI-tool attribution to commits, PRs, code, or docs. No \`Co-Authored-By:\`,
|
|
63
|
+
no "Generated with", no "Written by [AI tool]". The AI is a tool; tools don't sign
|
|
64
|
+
their output. Applies to ALL platforms (Claude, Codex, Copilot, Cursor, etc.).
|
|
65
|
+
|
|
66
|
+
### Rule: citation-policy
|
|
67
|
+
Never fabricate citations, DOIs, URLs, or page numbers. Only cite sources that
|
|
68
|
+
exist in the research corpus (.aiwg/research/sources/). Match claim strength
|
|
69
|
+
to evidence quality (GRADE): HIGH = "demonstrates"; MODERATE = "suggests";
|
|
70
|
+
LOW = "limited evidence"; VERY LOW = "anecdotal". Document research gaps in
|
|
71
|
+
.aiwg/research/TODO.md when no source supports a claim.
|
|
72
|
+
|
|
73
|
+
### Rule: token-security
|
|
74
|
+
Never hard-code tokens, API keys, or secrets in source files or commit messages.
|
|
75
|
+
Never pass tokens as CLI arguments (visible in process list). Never echo or log
|
|
76
|
+
token values. Load from secure files (mode 600) or environment variables. Use
|
|
77
|
+
heredoc scope for multi-step operations so tokens don't persist beyond use.
|
|
78
|
+
Token files must NEVER be tracked in git (.gitignore enforced).
|
|
79
|
+
|
|
80
|
+
### Rule: versioning
|
|
81
|
+
CalVer format: \`YYYY.M.PATCH\` (e.g., \`2026.5.3\`). NEVER use leading zeros
|
|
82
|
+
(\`2026.01.5\` is broken — npm semver rejects it). Tags use \`v\` prefix.
|
|
83
|
+
CHANGELOG must use same format. PATCH resets each month.
|
|
84
|
+
|
|
85
|
+
### Rule: ops-safety
|
|
86
|
+
Detect interactive commands and flag for human execution (passwords, LUKS
|
|
87
|
+
passphrases, MFA — agents cannot type these). Gate destructive operations
|
|
88
|
+
(\`rm -rf\`, \`fdisk\`, \`mkfs\`, partition table changes) behind explicit
|
|
89
|
+
human confirmation. Assess blast radius before execution (CRITICAL = multi-host
|
|
90
|
+
/ data loss; HIGH = single-host outage). Dry-run first when the tool supports it.
|
|
91
|
+
Never cross host boundaries without confirmation.`;
|
|
92
|
+
|
|
93
|
+
const HERMES_AGENTS_MD_FOOTER = `## Optional MCP Server Surface (\`aiwg mcp serve\`)
|
|
94
|
+
|
|
95
|
+
MCP is optional. The baseline path is file deploy + \`aiwg discover\` /
|
|
96
|
+
\`aiwg show\` from the CLI. MCP exposes the same AIWG catalog and execution
|
|
97
|
+
surface as provider-agnostic tools when configured.
|
|
98
|
+
|
|
99
|
+
**Discovery** (read-only, no project required):
|
|
100
|
+
- \`mcp_aiwg_discover\` — semantic search across skills/agents/commands/rules
|
|
101
|
+
- \`mcp_aiwg_skill_list\` / \`mcp_aiwg_skill_show\`
|
|
102
|
+
- \`mcp_aiwg_command_list\` / \`mcp_aiwg_command_show\`
|
|
103
|
+
- \`mcp_aiwg_rule_list\` / \`mcp_aiwg_rule_show\`
|
|
104
|
+
- \`mcp_aiwg_agent_list\` / \`mcp_aiwg_agent_show\`
|
|
105
|
+
- \`mcp_aiwg_template_list\` / \`mcp_aiwg_template_show\` / \`mcp_aiwg_template_render\`
|
|
106
|
+
|
|
107
|
+
**Execution** (allow-listed):
|
|
108
|
+
- \`mcp_aiwg_command_run\` — dispatches to any of 94 AIWG CLI commands. Destructive
|
|
109
|
+
commands require \`confirmed: true\`.
|
|
110
|
+
|
|
111
|
+
**Artifacts** (project-required, .aiwg/ directory):
|
|
112
|
+
- \`mcp_aiwg_artifact_read\` / \`mcp_aiwg_artifact_write\``;
|
|
113
|
+
|
|
114
|
+
function mergeHermesContext(file, generated, kind) {
|
|
115
|
+
let existing = fs.existsSync(file) ? fs.readFileSync(file, 'utf8') : '';
|
|
116
|
+
existing = existing.replace(/\n?<!-- AIWG:rule-startup:start -->[\s\S]*?<!-- AIWG:rule-startup:end -->\n?/g, '');
|
|
117
|
+
const start = `<!-- AIWG:hermes-${kind}:start -->`;
|
|
118
|
+
const end = `<!-- AIWG:hermes-${kind}:end -->`;
|
|
119
|
+
const managed = `${start}\n${generated}\n${end}`;
|
|
120
|
+
if (existing.includes(start)) return existing.slice(0, existing.indexOf(start)) + managed + existing.slice(existing.indexOf(end) + end.length);
|
|
121
|
+
if (kind === 'context' && existing.startsWith('# AIWG Integration') && existing.includes(HERMES_AGENTS_MD_FOOTER)) {
|
|
122
|
+
existing = existing.slice(existing.indexOf(HERMES_AGENTS_MD_FOOTER) + HERMES_AGENTS_MD_FOOTER.length);
|
|
123
|
+
} else if (kind === 'routing' && existing.includes(generated)) {
|
|
124
|
+
existing = existing.replace(generated, '');
|
|
125
|
+
}
|
|
126
|
+
return existing ? `${existing.trimEnd()}\n\n${managed}\n` : `<!-- aiwg-managed -->\n${managed}\n`;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export function generateAgentsMd(agentCount, skillCount, targetDir, opts) {
|
|
130
|
+
if (opts.contextFiles === false || opts.ruleDelivery) return;
|
|
131
|
+
const { dryRun } = opts;
|
|
132
|
+
|
|
133
|
+
// Startup is reserved for rule contracts. Workflow routing, artifact catalogs,
|
|
134
|
+
// and the optional MCP tool inventory duplicate discover/show and consume
|
|
135
|
+
// Hermes's finite per-turn context before the kernel is appended.
|
|
136
|
+
const header = `# AIWG Integration
|
|
137
|
+
|
|
138
|
+
Skills: \`$HERMES_HOME/skills/\` (kernel), \`$HERMES_HOME/skills/.aiwg/\` (standard).
|
|
139
|
+
Find: \`aiwg discover "rule <topic>" --type rule\`. Fetch: \`aiwg show rule <name> --body\`.
|
|
140
|
+
MCP is optional; \`mcp_aiwg_rule_show\` exposes the same rule catalog.
|
|
141
|
+
`;
|
|
142
|
+
|
|
143
|
+
// On-demand tier (#1675): the MEDIUM/LOW rules not inlined above. Hermes has
|
|
144
|
+
// no scanned rule dir, so the bridge file notes the tier with fetch hints.
|
|
145
|
+
const onDemandSection = opts.srcRoot
|
|
146
|
+
? renderOnDemandRuleSection(listOnDemandRuleFiles(opts.srcRoot))
|
|
147
|
+
: '';
|
|
148
|
+
const migrated = new Set((opts.ruleDelivery?.rules || []).filter(rule => rule.tagged).map(rule => rule.name));
|
|
149
|
+
const directives = CRITICAL_RULE_DIRECTIVES.split(/(?=^### Rule: )/m).filter(section => section.startsWith('### Rule: ') && !migrated.has(section.match(/^### Rule: ([^ \n]+)/)?.[1])).join('');
|
|
150
|
+
const sections = [header, directives];
|
|
151
|
+
if (onDemandSection) sections.push(onDemandSection);
|
|
152
|
+
// The optional tool inventory is available on demand through the CLI.
|
|
153
|
+
const destPath = path.join(targetDir, 'AGENTS.md');
|
|
154
|
+
const output = mergeHermesContext(destPath, sections.join('\n\n'), 'context');
|
|
155
|
+
|
|
156
|
+
if (!opts.ruleDelivery && !opts.deferRuleProjection) assertContextBudget(output, 'AGENTS.md');
|
|
157
|
+
|
|
158
|
+
if (dryRun) {
|
|
159
|
+
console.log(`[dry-run] Would write AGENTS.md (${output.length} chars, ${Math.round(output.length / 4)} tokens estimated)`);
|
|
160
|
+
} else {
|
|
161
|
+
writeContextFileSync(destPath, output, 'utf8');
|
|
162
|
+
const charCount = output.length;
|
|
163
|
+
const tokenEstimate = Math.round(charCount / 4);
|
|
164
|
+
let budgetNote;
|
|
165
|
+
if (charCount > HERMES_AGENTS_MD_SOFT_WARN) {
|
|
166
|
+
budgetNote = `⚠ ${charCount} chars — above soft warn (${HERMES_AGENTS_MD_SOFT_WARN}); below hard cap (${HERMES_AGENTS_MD_HARD_CAP})`;
|
|
167
|
+
} else {
|
|
168
|
+
budgetNote = `✓ within budget (cap: ${HERMES_AGENTS_MD_HARD_CAP})`;
|
|
169
|
+
}
|
|
170
|
+
console.log(` Created AGENTS.md (${charCount} chars, ~${tokenEstimate} tokens, ${budgetNote})`);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
return 1;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Generate `.hermes.md` thin pointer at the project root (#1319 / S8).
|
|
178
|
+
*
|
|
179
|
+
* Hermes loads `.hermes.md` with priority over `AGENTS.md` (first-match-wins
|
|
180
|
+
* at `agent/prompt_builder.py:1417-1456`). The pointer is short so the
|
|
181
|
+
* actual context payload remains in AGENTS.md which is shared with other
|
|
182
|
+
* tools (Claude Code, Codex, etc.).
|
|
183
|
+
*/
|
|
184
|
+
export function generateHermesMd(targetDir, opts) {
|
|
185
|
+
if (opts.contextFiles === false || opts.ruleDelivery) return;
|
|
186
|
+
const { dryRun } = opts;
|
|
187
|
+
const body = `# Hermes Routing
|
|
188
|
+
|
|
189
|
+
AIWG project context lives in \`AGENTS.md\` (this file is a thin Hermes pointer).
|
|
190
|
+
|
|
191
|
+
**Routing**: see \`AGENTS.md\` in this directory.
|
|
192
|
+
**MCP**: AIWG is reachable via \`mcp_aiwg_*\` tools.
|
|
193
|
+
**Skills**: kernel skills at \`$HERMES_HOME/skills/\`; standard skills at \`$HERMES_HOME/skills/.aiwg/\`.
|
|
194
|
+
When unset, \`HERMES_HOME\` defaults to the platform-native Hermes home.
|
|
195
|
+
|
|
196
|
+
Hermes loads only \`.hermes.md\` when it is present (first-match-wins). Keep
|
|
197
|
+
this file minimal; its routing instruction tells the agent to read \`AGENTS.md\`
|
|
198
|
+
when the full AIWG project context is needed.
|
|
199
|
+
`;
|
|
200
|
+
const destPath = path.join(targetDir, '.hermes.md');
|
|
201
|
+
if (dryRun) {
|
|
202
|
+
console.log(`[dry-run] Would write .hermes.md (${body.length} chars)`);
|
|
203
|
+
} else {
|
|
204
|
+
writeContextFileSync(destPath, mergeHermesContext(destPath, body, 'routing'), 'utf8');
|
|
205
|
+
console.log(` Created .hermes.md (${body.length} chars)`);
|
|
206
|
+
}
|
|
207
|
+
return 1;
|
|
208
|
+
}
|
|
209
|
+
|