@aiwg/cli 2026.10.14 → 2026.10.16
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/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 +37 -0
- package/dist/src/artifacts/corpus-tools/discovery-log.js +27 -25
- package/dist/src/artifacts/corpus-tools/expand-cli.js +90 -0
- package/dist/src/artifacts/corpus-tools/expand-dates.js +107 -0
- package/dist/src/artifacts/corpus-tools/expand-queue.js +41 -0
- package/dist/src/artifacts/corpus-tools/expand-review.js +104 -0
- package/dist/src/artifacts/corpus-tools/expand-state.js +56 -0
- package/dist/src/artifacts/corpus-tools/expand.js +124 -0
- 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 +99 -0
- package/dist/src/artifacts/corpus-tools/resolve-corpus.js +41 -0
- package/dist/src/artifacts/corpus-tools/resolve.js +119 -0
- 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/cli/handlers/daemon.js +17 -1
- package/dist/src/cli/handlers/doctor-args.js +45 -0
- package/dist/src/cli/handlers/doctor-help.js +8 -3
- package/dist/src/cli/handlers/index.js +2 -2
- package/dist/src/cli/handlers/models-resource-sample.js +10 -0
- package/dist/src/cli/handlers/models.js +3 -2
- package/dist/src/cli/handlers/regenerate.js +8 -16
- package/dist/src/cli/handlers/sessions.js +7 -7
- package/dist/src/cli/handlers/subcommands.js +8 -0
- 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 -586
- package/dist/src/cli/handlers/utility-doctor.js +412 -0
- package/dist/src/cli/services/deployment-verification.js +0 -1
- package/dist/src/config/aiwg-config.js +2 -1
- package/dist/src/config/authorization-cli.js +7 -3
- package/dist/src/config/dispatch-thresholds-runtime.d.mts +3 -2
- package/dist/src/config/dispatch-thresholds-runtime.mjs +17 -7
- package/dist/src/config/framework-aliases.js +12 -0
- package/dist/src/config/host-resource-report.d.mts +19 -0
- package/dist/src/config/host-resource-report.mjs +80 -0
- package/dist/src/config/host-resource-runtime.d.mts +34 -0
- package/dist/src/config/host-resource-runtime.mjs +293 -0
- package/dist/src/config/installed-selection.js +22 -0
- package/dist/src/config/worker-context.js +33 -4
- 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/heldout/access.js +74 -0
- package/dist/src/decision/heldout/calibration.js +1 -0
- package/dist/src/decision/heldout/collector.js +9 -2
- 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 +115 -69
- package/dist/src/extensions/commands/daemon.js +109 -0
- package/dist/src/extensions/commands/definitions.js +5 -89
- package/dist/src/features/catalog.js +1 -1
- package/dist/src/gates/evaluate.js +2 -2
- package/dist/src/gates/heldout.js +52 -0
- package/dist/src/gates/index.js +2 -1
- 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/memory/project-registry.js +44 -4
- package/dist/src/models/worker-installation-store.mjs +228 -0
- package/dist/src/models/worker-installation.mjs +7 -162
- 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/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/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/research/clients/arxiv.js +14 -34
- package/dist/src/research/clients/base.js +53 -26
- 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 +117 -0
- package/dist/src/research/index.js +1 -0
- 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 +135 -0
- 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/core-startup.d.mts +2 -0
- package/dist/src/rules/core-startup.mjs +31 -0
- package/dist/src/serve/mission-conductor.js +48 -4
- 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/agents-md.js +34 -0
- package/dist/src/smiths/context-pipeline/aiwg-md.js +19 -46
- package/dist/src/smiths/context-pipeline/bridge-ownership.js +50 -0
- 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/finalization.js +81 -51
- package/dist/src/smiths/context-pipeline/generator.js +49 -114
- package/dist/src/smiths/context-pipeline/managed-hook.js +11 -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/package.json +13 -2
- package/schemas/decision/D29Study.v10.schema.json +65 -0
- package/tools/agents/deploy-agents.mjs +12 -123
- package/tools/agents/providers/antigravity.mjs +1 -1
- package/tools/agents/providers/claude-post-deploy.mjs +12 -1
- package/tools/agents/providers/context-write.mjs +16 -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 +4 -2
- package/tools/agents/providers/rule-delivery-surface.mjs +332 -0
- package/tools/agents/providers/rule-delivery.mjs +20 -1346
- package/tools/agents/providers/rule-deployment-commit.mjs +144 -0
- package/tools/agents/providers/rule-deployment-prepare.mjs +452 -0
- package/tools/agents/providers/rule-deployment-state.mjs +300 -0
- 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/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/plugin/plugin-links.mjs +3 -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 +3 -2
- 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-unit-cleanup.mjs +72 -0
- package/tools/ralph-external/session-launcher.mjs +7 -7
- package/tools/scripts/resource-preflight.mjs +3 -242
|
@@ -1,28 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
* WORKSPACE.md owns provider-neutral project/operator context; AIWG.md owns
|
|
5
|
-
* generated discovery detail; provider startup files are minimal adapters.
|
|
6
|
-
*
|
|
7
|
-
* This file contains the public generator API. Callers are expected to have already
|
|
8
|
-
* deployed artifacts and to pass pre-aggregated `AgentsMdSection[]` describing what
|
|
9
|
-
* was deployed. The generator does not walk the filesystem to discover artifacts;
|
|
10
|
-
* that's the caller's responsibility (per ADR-1 §7 generator-runs-after-deploy
|
|
11
|
-
* invariant — the caller knows what landed).
|
|
12
|
-
*/
|
|
1
|
+
// Generate canonical workspace context and provider adapters after artifact deployment.
|
|
2
|
+
import { ensureCoreStartup } from '../../rules/core-startup.mjs';
|
|
3
|
+
import { preserveBridgeOperatorText } from './bridge-ownership.js';
|
|
13
4
|
import { promises as fs } from 'node:fs';
|
|
14
5
|
import * as path from 'node:path';
|
|
6
|
+
import { readdirSync, readFileSync } from 'node:fs';
|
|
15
7
|
import { sanitizeDescription, sanitizeTags } from './sanitizer.js';
|
|
16
8
|
import { checkPathAllowed } from './allowlist.js';
|
|
17
9
|
import { generateAiwgMd } from './aiwg-md.js';
|
|
18
10
|
import { injectSpilloverBlock } from './overflow.js';
|
|
19
|
-
import {
|
|
20
|
-
import { shouldEmitAgentsMd,
|
|
11
|
+
import { migrateAiwgOperatorNotes } from './finalization.js';
|
|
12
|
+
import { shouldEmitAgentsMd, shouldEmitClaudeMdHook } from './provider-policy.js';
|
|
21
13
|
import { ensureClaudeMdHook } from './claude-hook.js';
|
|
22
14
|
import { ensureManagedHook } from './managed-hook.js';
|
|
23
15
|
import { assertSafeContextFile, writeContextFileSync } from './context-file-safety.js';
|
|
24
|
-
import {
|
|
25
|
-
import {
|
|
16
|
+
import { ensureWorkspaceContext, registerProviderContext, } from './workspace-context.js';
|
|
17
|
+
import { buildAgentsMd } from './agents-md.js';
|
|
18
|
+
/** True when deployed native Claude rules already carry the compact core set. */
|
|
19
|
+
function hasNativeClaudeCore(projectDir) {
|
|
20
|
+
try {
|
|
21
|
+
return readdirSync(path.join(projectDir, '.claude', 'rules'))
|
|
22
|
+
.some(name => /^core-.+\.md$/.test(name) && /aiwg:managed/.test(readFileSync(path.join(projectDir, '.claude', 'rules', name), 'utf8')));
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
export { buildAgentsMd } from './agents-md.js';
|
|
26
29
|
const SECTION_TITLES = {
|
|
27
30
|
agents: 'Agents',
|
|
28
31
|
rules: 'Rules',
|
|
@@ -108,54 +111,6 @@ export function renderSection(section) {
|
|
|
108
111
|
warnings,
|
|
109
112
|
};
|
|
110
113
|
}
|
|
111
|
-
/**
|
|
112
|
-
* Build the full AGENTS.md content (in-memory; does not write).
|
|
113
|
-
*
|
|
114
|
-
* Per operator direction (#1239): AGENTS.md is a thin pointer to AIWG.md at
|
|
115
|
-
* project root. AIWG.md mirrors CLAUDE.md (ADR-1 §0.5) and contains the full
|
|
116
|
-
* framework guidance — including the kernel-skill discovery pattern
|
|
117
|
-
* (`aiwg discover` / `aiwg show`). Inlining a full link-index here pushed the
|
|
118
|
-
* file past Codex's 32KB cap on real deploys, triggered auto-split, and ran
|
|
119
|
-
* every artifact description through the sanitizer (rejecting any with
|
|
120
|
-
* backticks). The thin-pointer body sidesteps all of that: zero warnings on
|
|
121
|
-
* any provider, regardless of how many artifacts are deployed.
|
|
122
|
-
*
|
|
123
|
-
* `opts.sections` is accepted for backwards compatibility with callers that
|
|
124
|
-
* still aggregate a link-index (no internal use). `splitOccurred` is always
|
|
125
|
-
* false; `spilloverContent` is always empty. The `partitionForOverflow` /
|
|
126
|
-
* spillover utilities remain exported for any external consumer.
|
|
127
|
-
*/
|
|
128
|
-
export async function buildAgentsMd(opts) {
|
|
129
|
-
const warnings = [];
|
|
130
|
-
const parts = [];
|
|
131
|
-
parts.push('# AGENTS.md');
|
|
132
|
-
parts.push(`${AIWG_SIGNATURE_COMMENT}`);
|
|
133
|
-
parts.push('<!-- Generated by AIWG. Edit AGENTS.override.md for operator additions. -->');
|
|
134
|
-
parts.push('');
|
|
135
|
-
parts.push(buildProviderBootstrapBlock(opts.provider));
|
|
136
|
-
parts.push('');
|
|
137
|
-
parts.push('## Framework Context');
|
|
138
|
-
parts.push('');
|
|
139
|
-
parts.push('See [AIWG.md](./AIWG.md) for the full AIWG framework context');
|
|
140
|
-
parts.push('(active frameworks, addons, agents, behaviors, rules).');
|
|
141
|
-
const configRelative = path.relative(opts.projectPath, projectControlPath(opts.projectPath, 'aiwg.config')).replace(/\\/g, '/');
|
|
142
|
-
const configLink = configRelative.startsWith('.') ? configRelative : `./${configRelative}`;
|
|
143
|
-
parts.push(`Tracker and delivery source of truth: [${configRelative}](${configLink}).`);
|
|
144
|
-
parts.push('');
|
|
145
|
-
parts.push('Deployed artifacts live under your provider\'s native directory');
|
|
146
|
-
parts.push('(for example `.codex/agents/`, `.warp/agents/`, `.github/agents/`).');
|
|
147
|
-
parts.push('Use `aiwg discover "<intent>"` and `aiwg show <type> <name>` to browse');
|
|
148
|
-
parts.push('skills, agents, rules, and commands across the installation.');
|
|
149
|
-
parts.push('');
|
|
150
|
-
if (opts.projectContext && opts.projectContext.trim().length > 0) {
|
|
151
|
-
warnings.push('projectContext is no longer inlined in provider startup files; place it in the protected WORKSPACE.md operator section.');
|
|
152
|
-
}
|
|
153
|
-
parts.push('---');
|
|
154
|
-
parts.push('');
|
|
155
|
-
parts.push('*See `AGENTS.override.md` for operator-authored additions.*');
|
|
156
|
-
parts.push('');
|
|
157
|
-
return { content: parts.join('\n'), warnings, spilloverContent: '', splitOccurred: false };
|
|
158
|
-
}
|
|
159
114
|
/**
|
|
160
115
|
* Detect whether a pre-existing file at `filePath` carries the AIWG signature.
|
|
161
116
|
*
|
|
@@ -172,6 +127,14 @@ export async function isOverwriteSafe(filePath) {
|
|
|
172
127
|
return true;
|
|
173
128
|
if (/Generated by\s+(AIWG|aiwg)/i.test(head))
|
|
174
129
|
return true;
|
|
130
|
+
// Provider templates use a different ownership marker. Adopt only wholly
|
|
131
|
+
// generated files; text outside managed blocks still belongs to the operator.
|
|
132
|
+
if (content.includes('<!-- BEGIN AIWG-managed (auto-generated;')) {
|
|
133
|
+
const remainder = content
|
|
134
|
+
.replace(/<!-- BEGIN AIWG-managed \(auto-generated;[^\n]*-->[\s\S]*?<!-- END AIWG-managed -->/g, '')
|
|
135
|
+
.replace(/<!-- AIWG:([\w-]+):start -->[\s\S]*?<!-- AIWG:\1:end -->/g, '');
|
|
136
|
+
return remainder.trim().length === 0;
|
|
137
|
+
}
|
|
175
138
|
// Backwards-compatibility scan: pre-ADR-1 emitters wrote AGENTS.md /
|
|
176
139
|
// WARP.md / .hermes.md without the canonical signature. Those files
|
|
177
140
|
// typically include AIWG-specific markers somewhere in the first ~50
|
|
@@ -202,13 +165,21 @@ async function atomicWrite(filePath, content, provider) {
|
|
|
202
165
|
// Rule delivery owns this block. Context regeneration runs after deployment
|
|
203
166
|
// and must retain the selected kernel even when rebuilding the adapter.
|
|
204
167
|
const existing = await fs.readFile(filePath, 'utf8').catch(() => '');
|
|
205
|
-
|
|
168
|
+
content = preserveBridgeOperatorText(existing, content);
|
|
169
|
+
for (const owner of ['rule-startup', 'rule-core', ...[...existing.matchAll(/<!-- AIWG:(rule-hook-[\w-]+):start -->/g)].map(match => match[1]), 'hermes-context', 'hermes-routing', 'warp-context']) {
|
|
206
170
|
if (content.includes(`<!-- AIWG:${owner}:start -->`))
|
|
207
171
|
continue;
|
|
208
172
|
const managed = existing.match(new RegExp(`<!-- AIWG:${owner}:start -->[\\s\\S]*?<!-- AIWG:${owner}:end -->`));
|
|
209
173
|
if (managed)
|
|
210
174
|
content = `${content.trimEnd()}\n\n${managed[0]}\n`;
|
|
211
175
|
}
|
|
176
|
+
// Claude loads core natively from .claude/rules/core-*.md once deployed; inject into CLAUDE.md
|
|
177
|
+
// only when those native files are absent (for example a regenerate before any `aiwg use`).
|
|
178
|
+
const nativeCore = provider === 'claude' && hasNativeClaudeCore(path.dirname(filePath));
|
|
179
|
+
if (provider && !nativeCore)
|
|
180
|
+
content = ensureCoreStartup(content);
|
|
181
|
+
else if (nativeCore)
|
|
182
|
+
content = content.replace(/\n*<!-- AIWG:rule-core:start -->[\s\S]*?<!-- AIWG:rule-core:end -->\n?/, '\n');
|
|
212
183
|
const bytes = Buffer.byteLength(content, 'utf8');
|
|
213
184
|
if (provider === 'codex' && path.basename(filePath) === 'AGENTS.md' && bytes >= 32768) {
|
|
214
185
|
throw new Error('Codex AGENTS.md exceeds its 32 KB hard cap');
|
|
@@ -224,54 +195,16 @@ async function atomicWrite(filePath, content, provider) {
|
|
|
224
195
|
*
|
|
225
196
|
* Hermes scans `.hermes.md` first (priority 1) and falls back to AGENTS.md.
|
|
226
197
|
* Warp prefers AGENTS.md but tooling expects `WARP.md` to exist. Both are
|
|
227
|
-
* written with the same content as AGENTS.md
|
|
228
|
-
* `applyTwinSuffix` below for the Hermes-specific MCP guidance suffix
|
|
229
|
-
* (#1242).
|
|
198
|
+
* written with the same minimal bootstrap content as AGENTS.md.
|
|
230
199
|
*/
|
|
231
200
|
const TWIN_FILES_BY_PROVIDER = {
|
|
232
201
|
copilot: ['.github/copilot-instructions.md'],
|
|
233
202
|
hermes: ['.hermes.md'],
|
|
234
203
|
warp: ['WARP.md'],
|
|
235
204
|
};
|
|
236
|
-
/**
|
|
237
|
-
* Hermes-specific suffix appended to `.hermes.md` (#1242).
|
|
238
|
-
*
|
|
239
|
-
* The cross-platform AGENTS.md thin pointer (#1239) says *"See [AIWG.md] for
|
|
240
|
-
* the full AIWG framework context."* From inside a Hermes turn that link is
|
|
241
|
-
* a dead end — Hermes auto-loads AGENTS.md and CLAUDE.md but not AIWG.md.
|
|
242
|
-
* The twin file gets a Hermes-correct alternative path so a model running
|
|
243
|
-
* inside Hermes knows to call `artifact-read` over MCP rather than chase the
|
|
244
|
-
* AIWG.md link.
|
|
245
|
-
*
|
|
246
|
-
* Suffix is ~390 chars (~95 tokens) — keeps the .hermes.md twin total under
|
|
247
|
-
* Hermes's <1,000-char turn-budget target on top of the 579-byte primary.
|
|
248
|
-
*/
|
|
249
|
-
const HERMES_TWIN_SUFFIX = [
|
|
250
|
-
'',
|
|
251
|
-
'## For Hermes Sessions',
|
|
252
|
-
'',
|
|
253
|
-
'Hermes does not auto-load AIWG.md. Browse AIWG capabilities with:',
|
|
254
|
-
'',
|
|
255
|
-
'- `artifact-read AIWG.md` through AIWG MCP.',
|
|
256
|
-
'- `aiwg discover "<intent>"` and `aiwg show <type> <name>`.',
|
|
257
|
-
'- `delegate_task` through the AIWG-orchestrate skill.',
|
|
258
|
-
'',
|
|
259
|
-
].join('\n');
|
|
260
|
-
/**
|
|
261
|
-
* Apply provider-specific transformations to twin-file content.
|
|
262
|
-
*
|
|
263
|
-
* Currently used only for Hermes (#1242). Extend by adding more
|
|
264
|
-
* provider-keyed branches as new twin formats need divergence.
|
|
265
|
-
*/
|
|
266
|
-
function applyTwinSuffix(provider, baseContent) {
|
|
267
|
-
if (provider === 'hermes') {
|
|
268
|
-
return `${baseContent}${HERMES_TWIN_SUFFIX}`;
|
|
269
|
-
}
|
|
270
|
-
return baseContent;
|
|
271
|
-
}
|
|
272
205
|
/**
|
|
273
206
|
* Write per-provider twin files (.hermes.md, WARP.md). Twin content is the
|
|
274
|
-
* AGENTS.md body
|
|
207
|
+
* same minimal AGENTS.md bootstrap body.
|
|
275
208
|
* Operator-claimed twin files are not overwritten unless --force is set,
|
|
276
209
|
* matching the AGENTS.md guard.
|
|
277
210
|
*/
|
|
@@ -279,7 +212,7 @@ async function writeTwinFiles(provider, projectPath, agentsMdContent, opts, resu
|
|
|
279
212
|
const twinNames = TWIN_FILES_BY_PROVIDER[provider];
|
|
280
213
|
if (!twinNames || twinNames.length === 0)
|
|
281
214
|
return;
|
|
282
|
-
const twinContent =
|
|
215
|
+
const twinContent = agentsMdContent;
|
|
283
216
|
for (const twinName of twinNames) {
|
|
284
217
|
const twinPath = path.join(projectPath, twinName);
|
|
285
218
|
if (opts.detectExistingFiles && !opts.force) {
|
|
@@ -291,6 +224,7 @@ async function writeTwinFiles(provider, projectPath, agentsMdContent, opts, resu
|
|
|
291
224
|
result.warnings.push(hook.action === 'unchanged'
|
|
292
225
|
? `${twinName} is operator-owned and already loads WORKSPACE.md then AIWG.md — left as-is.`
|
|
293
226
|
: `${twinName} is operator-owned; ${hook.action} the WORKSPACE.md → AIWG.md hook additively (existing content preserved). Pass --force to replace the whole file.`);
|
|
227
|
+
await atomicWrite(twinPath, await fs.readFile(twinPath, 'utf8'), provider);
|
|
294
228
|
result.twinPaths.push(twinPath);
|
|
295
229
|
continue;
|
|
296
230
|
}
|
|
@@ -345,10 +279,9 @@ async function writeSpilloverBlock(projectPath, spilloverMarkdown, result) {
|
|
|
345
279
|
/**
|
|
346
280
|
* Generate the canonical graph and provider startup adapters.
|
|
347
281
|
*
|
|
348
|
-
*
|
|
349
|
-
*
|
|
350
|
-
*
|
|
351
|
-
* is present; otherwise it is skipped with a warning.
|
|
282
|
+
* Root AIWG.md is the single generated framework context, including optional
|
|
283
|
+
* operator notes. Provider adapters declare their supported startup loader;
|
|
284
|
+
* home-only providers can still read the root context explicitly.
|
|
352
285
|
*/
|
|
353
286
|
export async function generate(opts) {
|
|
354
287
|
// Check every startup/context output before writing the first one. A linked
|
|
@@ -357,7 +290,7 @@ export async function generate(opts) {
|
|
|
357
290
|
const plannedFiles = [
|
|
358
291
|
...(!opts.skip?.workspaceMd ? ['WORKSPACE.md'] : []),
|
|
359
292
|
...(!opts.skip?.agentsMd && shouldEmitAgentsMd(opts.provider) ? ['AGENTS.md'] : []),
|
|
360
|
-
...(!opts.skip?.aiwgMd
|
|
293
|
+
...(!opts.skip?.aiwgMd ? ['AIWG.md'] : []),
|
|
361
294
|
...(shouldEmitClaudeMdHook(opts.provider) ? ['CLAUDE.md'] : []),
|
|
362
295
|
];
|
|
363
296
|
for (const file of plannedFiles)
|
|
@@ -382,8 +315,6 @@ export async function generate(opts) {
|
|
|
382
315
|
if (workspace.backupPath)
|
|
383
316
|
result.backupPaths.push(workspace.backupPath);
|
|
384
317
|
}
|
|
385
|
-
const normalizedAiwgPath = await writeNormalizedAiwgMd(opts.projectPath);
|
|
386
|
-
result.normalizedAiwgMdPath = normalizedAiwgPath;
|
|
387
318
|
// AGENTS.md emission is gated on the provider's link-mechanism: codex/copilot/
|
|
388
319
|
// cursor/windsurf/hermes/warp/factory/opencode use AGENTS.md as their bridge
|
|
389
320
|
// to AIWG.md. Claude uses CLAUDE.md hook instead (#1437); openclaw is
|
|
@@ -426,6 +357,7 @@ export async function generate(opts) {
|
|
|
426
357
|
// canonical graph hook (preserve operator content; no --force needed) so Codex/
|
|
427
358
|
// fallback consumers load the generated AIWG.md.
|
|
428
359
|
const hook = await ensureManagedHook(agentsMdPath, { provider: opts.provider });
|
|
360
|
+
result.agentsMdBytes = await atomicWrite(agentsMdPath, await fs.readFile(agentsMdPath, 'utf8'), opts.provider);
|
|
429
361
|
result.agentsMdPath = agentsMdPath;
|
|
430
362
|
result.warnings.push(hook.action === 'unchanged'
|
|
431
363
|
? `AGENTS.md is operator-owned and already loads WORKSPACE.md then AIWG.md — left as-is.`
|
|
@@ -436,7 +368,7 @@ export async function generate(opts) {
|
|
|
436
368
|
// additive hook), so this runs whether or not AGENTS.md itself was rewritten.
|
|
437
369
|
await writeTwinFiles(opts.provider, opts.projectPath, built.content, opts, result);
|
|
438
370
|
}
|
|
439
|
-
if (!opts.skip?.aiwgMd
|
|
371
|
+
if (!opts.skip?.aiwgMd) {
|
|
440
372
|
const aiwgMdPath = path.join(opts.projectPath, 'AIWG.md');
|
|
441
373
|
let canWrite = true;
|
|
442
374
|
if (opts.detectExistingFiles && !opts.force) {
|
|
@@ -465,6 +397,8 @@ export async function generate(opts) {
|
|
|
465
397
|
const content = await generateAiwgMd(opts.projectPath);
|
|
466
398
|
await atomicWrite(aiwgMdPath, content);
|
|
467
399
|
result.aiwgMdPath = aiwgMdPath;
|
|
400
|
+
result.normalizedAiwgMdPath = aiwgMdPath; // Compatibility alias: there is only one generated context.
|
|
401
|
+
await migrateAiwgOperatorNotes(opts.projectPath);
|
|
468
402
|
}
|
|
469
403
|
}
|
|
470
404
|
// CLAUDE.md hook emission for the claude provider (#1437). Mirrors how
|
|
@@ -476,6 +410,7 @@ export async function generate(opts) {
|
|
|
476
410
|
force: opts.force,
|
|
477
411
|
detectExistingFiles: opts.detectExistingFiles,
|
|
478
412
|
});
|
|
413
|
+
await atomicWrite(hookResult.claudeMdPath, await fs.readFile(hookResult.claudeMdPath, 'utf8'), opts.provider);
|
|
479
414
|
result.claudeMdHookPath = hookResult.claudeMdPath;
|
|
480
415
|
result.claudeMdHookAction = hookResult.action;
|
|
481
416
|
if (hookResult.backupPath) {
|
|
@@ -16,6 +16,7 @@ import * as path from 'path';
|
|
|
16
16
|
import { buildProviderBootstrapBlock } from './workspace-context.js';
|
|
17
17
|
import { dominantLineEnding, withLineEnding } from './line-endings.js';
|
|
18
18
|
import { assertSafeContextFile, writeContextFileSync } from './context-file-safety.js';
|
|
19
|
+
import { hasRuleStartup, normalizeRuleStartup } from './bridge-ownership.js';
|
|
19
20
|
export const CONTEXT_HOOK_START = '<!-- AIWG:context-hook:start -->';
|
|
20
21
|
export const CONTEXT_HOOK_END = '<!-- AIWG:context-hook:end -->';
|
|
21
22
|
/** The managed block — loads canonical workspace context before framework context. */
|
|
@@ -28,7 +29,7 @@ export function buildContextHookBlock(provider = 'codex') {
|
|
|
28
29
|
'<!--',
|
|
29
30
|
' This block is managed by `aiwg regenerate` and `aiwg use`.',
|
|
30
31
|
' Operator content above and below this block is preserved on regenerate.',
|
|
31
|
-
' Edit .aiwg/AIWG.md
|
|
32
|
+
' Edit WORKSPACE.md Project Context or optional .aiwg/AIWG.md operator notes, then run `aiwg regenerate`.',
|
|
32
33
|
'-->',
|
|
33
34
|
'',
|
|
34
35
|
CONTEXT_HOOK_END,
|
|
@@ -61,6 +62,15 @@ export async function ensureManagedHook(filePath, opts = {}) {
|
|
|
61
62
|
}
|
|
62
63
|
const lineEnding = dominantLineEnding(existing);
|
|
63
64
|
block = withLineEnding(block, lineEnding);
|
|
65
|
+
if (hasRuleStartup(existing)) {
|
|
66
|
+
const bootstrap = existing.match(/<!-- AIWG:provider-bootstrap:start -->[\s\S]*?<!-- AIWG:provider-bootstrap:end -->/)?.[0]
|
|
67
|
+
|| buildProviderBootstrapBlock(opts.provider || 'codex');
|
|
68
|
+
const normalized = normalizeRuleStartup(existing, bootstrap, false, false);
|
|
69
|
+
result.action = normalized === existing ? 'unchanged' : 'updated';
|
|
70
|
+
if (normalized !== existing)
|
|
71
|
+
writeContextFileSync(filePath, normalized, 'utf8');
|
|
72
|
+
return result;
|
|
73
|
+
}
|
|
64
74
|
// Already has both bare includes (operator wired them by hand) — nothing to do.
|
|
65
75
|
if (!existing.includes(CONTEXT_HOOK_START) && /^[ \t]*@WORKSPACE\.md[ \t]*$/m.test(existing) && /^[ \t]*@AIWG\.md[ \t]*$/m.test(existing)) {
|
|
66
76
|
result.action = 'unchanged';
|
|
@@ -31,8 +31,8 @@ export function buildMuseBridgeText() {
|
|
|
31
31
|
'Muse session so the bridge is read.',
|
|
32
32
|
'',
|
|
33
33
|
'Instruction order: this AGENTS.md first, then [WORKSPACE.md](./WORKSPACE.md)',
|
|
34
|
-
'for project/operator context, then [AIWG.md](./AIWG.md)
|
|
35
|
-
'
|
|
34
|
+
'for project/operator context, then [AIWG.md](./AIWG.md), the single generated',
|
|
35
|
+
'context for AIWG discovery, quickrefs, and framework routing.',
|
|
36
36
|
'Plain Markdown links are explicit reading instructions; AIWG does not',
|
|
37
37
|
'claim Muse auto-loads any other AIWG path on its own.',
|
|
38
38
|
'',
|
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
* with the misleading rationale "claude uses CLAUDE.md natively." That
|
|
12
12
|
* conflated two facts: claude DOES read CLAUDE.md without aiwg-side
|
|
13
13
|
* wiring, but regenerate STILL needs to refresh AIWG.md and ensure the
|
|
14
|
-
* `@AIWG.md` link is present in CLAUDE.md. The
|
|
15
|
-
*
|
|
14
|
+
* `@AIWG.md` link is present in CLAUDE.md. The provider hooks remain granular;
|
|
15
|
+
* root AIWG.md is now universal (#3762).
|
|
16
16
|
*
|
|
17
17
|
* @issue #1437
|
|
18
18
|
*/
|
|
@@ -27,19 +27,13 @@ import { getProviderDefinition, listProviderDefinitions } from '../../providers/
|
|
|
27
27
|
export const AGENTS_MD_PROVIDERS = new Set(listProviderDefinitions()
|
|
28
28
|
.filter((definition) => definition.paths.contextFiles.agentsMd)
|
|
29
29
|
.map((definition) => definition.id));
|
|
30
|
-
/**
|
|
31
|
-
* Whether the context-pipeline has ANY work to do for this provider.
|
|
32
|
-
* Returns false only for providers that have no project-local context
|
|
33
|
-
* footprint: OpenClaw/OpenHuman (home-dir-only) and 'generic' (no specific provider).
|
|
34
|
-
*
|
|
35
|
-
* Claude returns TRUE — it needs AIWG.md + a CLAUDE.md hook update.
|
|
36
|
-
*/
|
|
30
|
+
/** Compatibility query: every registered provider receives root AIWG.md (#3762). */
|
|
37
31
|
export function shouldEmitContextFiles(provider) {
|
|
38
|
-
return shouldEmitAiwgMd(provider)
|
|
32
|
+
return shouldEmitAiwgMd(provider);
|
|
39
33
|
}
|
|
40
34
|
/**
|
|
41
|
-
*
|
|
42
|
-
*
|
|
35
|
+
* Compatibility query, no longer an emission gate. Root AIWG.md is always
|
|
36
|
+
* generated; only an explicit caller opt-out can suppress it (#3762).
|
|
43
37
|
*/
|
|
44
38
|
export function shouldEmitAiwgMd(provider) {
|
|
45
39
|
return getProviderDefinition(provider)?.paths.contextFiles.aiwgMd ?? false;
|
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
// Audit workspace instruction sources and directive overlap.
|
|
2
|
+
import { existsSync, promises as fs } from 'node:fs';
|
|
3
|
+
import { homedir } from 'node:os';
|
|
4
|
+
import * as path from 'node:path';
|
|
5
|
+
import { projectAiwgPath, resolveProjectAiwgDir } from '../../config/project-artifacts.js';
|
|
6
|
+
import { listProviderDefinitions } from '../../providers/provider-definitions.js';
|
|
7
|
+
import { isGeneratedRootContext, LEGACY_ROOT_FILES, readOptional, SCOPE_REVIEW_BYTES, sha256, stripGeneratedBlocks, WORKSPACE_OPERATOR_END, WORKSPACE_OPERATOR_START, WORKSPACE_SIGNATURE, } from './workspace-context-shared.js';
|
|
8
|
+
import { providerForPath } from './workspace-document.js';
|
|
9
|
+
import { extractExistingProjectContext } from './workspace-extraction.js';
|
|
10
|
+
import { projectOutputPath } from './workspace-migration.js';
|
|
11
|
+
export function directives(content) {
|
|
12
|
+
return [...new Set(content
|
|
13
|
+
.split('\n')
|
|
14
|
+
.map((line) => line.replace(/^\s*[-*+]\s+/, '').replace(/^#+\s+/, '').trim())
|
|
15
|
+
.filter((line) => line.length >= 8 && !line.startsWith('<!--') && !/^https?:\/\//i.test(line)))];
|
|
16
|
+
}
|
|
17
|
+
export function directiveKey(directive) {
|
|
18
|
+
if (!/^(always|never|must|do not|don't|required|prefer|use|avoid|keep|preserve)\b/i.test(directive))
|
|
19
|
+
return null;
|
|
20
|
+
return directive.toLowerCase()
|
|
21
|
+
.replace(/[^a-z0-9\s]/g, '')
|
|
22
|
+
.replace(/^(?:always|never|must|required|prefer|avoid|keep|preserve|do not|dont)\s+/, '')
|
|
23
|
+
.replace(/^use\s+/, '')
|
|
24
|
+
.split(/\s+/).slice(0, 5).join(' ');
|
|
25
|
+
}
|
|
26
|
+
export function directivePolarity(directive) {
|
|
27
|
+
return /^(?:never|do not|don't|avoid)\b/i.test(directive) ? 'negative' : 'positive';
|
|
28
|
+
}
|
|
29
|
+
export function sensitiveEvidence(content) {
|
|
30
|
+
const findings = [];
|
|
31
|
+
for (const line of content.split('\n')) {
|
|
32
|
+
if (/-----BEGIN (?:RSA |EC |OPENSSH )?PRIVATE KEY-----/.test(line)) {
|
|
33
|
+
findings.push(`private-key material (${sha256(line).slice(0, 12)})`);
|
|
34
|
+
}
|
|
35
|
+
if (/\b(?:api[_-]?key|token|secret|password)\s*[:=]\s*(?!<|\$\{|\*{3}|example|placeholder)["']?[A-Za-z0-9_\-/.+=]{12,}/i.test(line)) {
|
|
36
|
+
findings.push(`credential-like assignment (${sha256(line).slice(0, 12)})`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return findings;
|
|
40
|
+
}
|
|
41
|
+
// Directory names the context-graph walk always skips, regardless of where
|
|
42
|
+
// the walk root is: VCS/build output that is never hand-authored project
|
|
43
|
+
// content (#277, pre-existing) plus two reserved, self-identifying names
|
|
44
|
+
// that are never legitimately a real project directory.
|
|
45
|
+
export const CONTEXT_WALK_ALWAYS_IGNORED_DIR_NAMES = new Set([
|
|
46
|
+
'.git', 'node_modules', 'dist', 'build', 'coverage', '.aiwg',
|
|
47
|
+
]);
|
|
48
|
+
// Cache/registry directory names that are only skipped when the walk root
|
|
49
|
+
// is the home directory itself (#277 fix-round). A project subtree that
|
|
50
|
+
// happens to be named `.cache`, `target`, `.gradle`, etc. is NOT generated
|
|
51
|
+
// data and must still be scanned — these names are only reliably "cache,
|
|
52
|
+
// not project" when they sit directly under $HOME. `Library/Caches` and
|
|
53
|
+
// `.local/share` are two-segment (parent + name) patterns, handled
|
|
54
|
+
// separately below.
|
|
55
|
+
export const HOME_LEVEL_CACHE_DIR_NAMES = new Set([
|
|
56
|
+
'.cache', '.cargo', '.rustup', '.npm', '.nvm', '.pnpm-store',
|
|
57
|
+
'.gradle', '.m2', 'Trash',
|
|
58
|
+
]);
|
|
59
|
+
/** True when `dirPath` contains `markerFile` — a cheap, synchronous, read-only check. */
|
|
60
|
+
export function hasMarkerFile(dirPath, markerFile) {
|
|
61
|
+
return existsSync(path.join(dirPath, markerFile));
|
|
62
|
+
}
|
|
63
|
+
/** A `target` directory is Cargo/build output only when it carries the
|
|
64
|
+
* standard `CACHEDIR.TAG` marker, or sits next to a `Cargo.toml` — not
|
|
65
|
+
* merely because it is named `target` (#277 fix-round). */
|
|
66
|
+
export function isGeneratedTargetDir(dirPath) {
|
|
67
|
+
if (hasMarkerFile(dirPath, 'CACHEDIR.TAG'))
|
|
68
|
+
return true;
|
|
69
|
+
return existsSync(path.join(path.dirname(dirPath), 'Cargo.toml'));
|
|
70
|
+
}
|
|
71
|
+
/** A `venv`/`.venv` directory is a Python virtualenv only when it carries
|
|
72
|
+
* `pyvenv.cfg` — not merely because of its name (#277 fix-round). */
|
|
73
|
+
export function isPythonVenvDir(dirPath) {
|
|
74
|
+
return hasMarkerFile(dirPath, 'pyvenv.cfg');
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Whether the context-graph walk should skip `entryName` (a directory
|
|
78
|
+
* directly under `directory`) without descending into it.
|
|
79
|
+
*
|
|
80
|
+
* `isHomeRoot` gates the home-level cache list and the `Library/Caches` /
|
|
81
|
+
* `.local/share` two-segment patterns — they apply only when the overall
|
|
82
|
+
* walk root is $HOME, never for an arbitrary project subtree that happens
|
|
83
|
+
* to share one of those names (#277 fix-round).
|
|
84
|
+
*/
|
|
85
|
+
export function shouldSkipContextWalkDir(directory, entryName, isHomeRoot) {
|
|
86
|
+
if (CONTEXT_WALK_ALWAYS_IGNORED_DIR_NAMES.has(entryName))
|
|
87
|
+
return true;
|
|
88
|
+
if (entryName.startsWith('.context-migration-'))
|
|
89
|
+
return true;
|
|
90
|
+
const childPath = path.join(directory, entryName);
|
|
91
|
+
if (entryName === 'target' && isGeneratedTargetDir(childPath))
|
|
92
|
+
return true;
|
|
93
|
+
if ((entryName === 'venv' || entryName === '.venv') && isPythonVenvDir(childPath))
|
|
94
|
+
return true;
|
|
95
|
+
// Codex's own plugin/temp scratch — a known, specific noise source named
|
|
96
|
+
// in the original report, not a broad `.tmp` exclusion (#277 fix-round).
|
|
97
|
+
if (entryName === '.tmp' && path.basename(directory) === '.codex')
|
|
98
|
+
return true;
|
|
99
|
+
if (isHomeRoot) {
|
|
100
|
+
if (HOME_LEVEL_CACHE_DIR_NAMES.has(entryName))
|
|
101
|
+
return true;
|
|
102
|
+
if (entryName === 'Caches' && path.basename(directory) === 'Library')
|
|
103
|
+
return true;
|
|
104
|
+
if (entryName === 'share' && path.basename(directory) === '.local')
|
|
105
|
+
return true;
|
|
106
|
+
}
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
109
|
+
/** Walk depth/entry bounds for the context-graph walk (#277). A hit sets
|
|
110
|
+
* `truncated: true` on the result instead of silently stopping. Overridable
|
|
111
|
+
* via environment for tests that need to exercise the bound without
|
|
112
|
+
* building a correspondingly large fixture tree. */
|
|
113
|
+
export function readPositiveIntEnv(name, fallback) {
|
|
114
|
+
const raw = process.env[name];
|
|
115
|
+
if (!raw)
|
|
116
|
+
return fallback;
|
|
117
|
+
const parsed = Number.parseInt(raw, 10);
|
|
118
|
+
return Number.isFinite(parsed) && parsed > 0 ? parsed : fallback;
|
|
119
|
+
}
|
|
120
|
+
export const CONTEXT_WALK_MAX_DEPTH = readPositiveIntEnv('AIWG_CONTEXT_WALK_MAX_DEPTH', 10);
|
|
121
|
+
export const CONTEXT_WALK_MAX_DIRECTORIES = readPositiveIntEnv('AIWG_CONTEXT_WALK_MAX_DIRECTORIES', 20_000);
|
|
122
|
+
export async function nestedInstructionFiles(projectPath) {
|
|
123
|
+
const found = [];
|
|
124
|
+
const artifactRoot = path.resolve(resolveProjectAiwgDir(projectPath));
|
|
125
|
+
// Running from $HOME is the exact shape of #277: bound the walk to the
|
|
126
|
+
// top level and apply the home-level cache exclusions instead of
|
|
127
|
+
// recursing into every cache/registry/venv underneath it. A markerless
|
|
128
|
+
// but otherwise ordinary (non-home) project root keeps the full bounded
|
|
129
|
+
// walk — "no project marker" is not evidence the directory is generated
|
|
130
|
+
// data (#277 fix-round).
|
|
131
|
+
const isHomeDirectory = path.resolve(projectPath) === path.resolve(homedir());
|
|
132
|
+
const maxDepth = isHomeDirectory ? 1 : CONTEXT_WALK_MAX_DEPTH;
|
|
133
|
+
let visitedDirectories = 0;
|
|
134
|
+
let truncated = false;
|
|
135
|
+
async function walk(directory, depth) {
|
|
136
|
+
if (depth > maxDepth || visitedDirectories >= CONTEXT_WALK_MAX_DIRECTORIES) {
|
|
137
|
+
truncated = true;
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
visitedDirectories += 1;
|
|
141
|
+
let entries;
|
|
142
|
+
try {
|
|
143
|
+
entries = await fs.readdir(directory, { withFileTypes: true });
|
|
144
|
+
}
|
|
145
|
+
catch {
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
for (const entry of entries) {
|
|
149
|
+
// Dirent.isDirectory() is false for symlinks (it reflects the entry
|
|
150
|
+
// itself, not its target), so symlinked directories are never
|
|
151
|
+
// followed out of the root by this walk.
|
|
152
|
+
if (entry.isDirectory()) {
|
|
153
|
+
const child = path.join(directory, entry.name);
|
|
154
|
+
if (!shouldSkipContextWalkDir(directory, entry.name, isHomeDirectory)
|
|
155
|
+
&& path.resolve(child) !== artifactRoot)
|
|
156
|
+
await walk(child, depth + 1);
|
|
157
|
+
}
|
|
158
|
+
else if (['AGENTS.md', 'CLAUDE.md', 'WARP.md'].includes(entry.name)) {
|
|
159
|
+
const relative = path.relative(projectPath, path.join(directory, entry.name)).replace(/\\/g, '/');
|
|
160
|
+
const segments = relative.split('/');
|
|
161
|
+
const generatedArtifactPath = segments.includes('templates') || segments.includes('fixtures');
|
|
162
|
+
if (!generatedArtifactPath && !LEGACY_ROOT_FILES.includes(relative))
|
|
163
|
+
found.push(relative);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
await walk(projectPath, 1);
|
|
168
|
+
return { files: found.sort((a, b) => a.localeCompare(b)), truncated };
|
|
169
|
+
}
|
|
170
|
+
export async function migratedProviderFiles(projectPath) {
|
|
171
|
+
const directory = projectAiwgPath(projectPath, 'context', 'providers');
|
|
172
|
+
try {
|
|
173
|
+
return (await fs.readdir(directory, { withFileTypes: true }))
|
|
174
|
+
.filter((entry) => entry.isFile() && entry.name.endsWith('.md'))
|
|
175
|
+
.map((entry) => projectOutputPath(projectPath, path.join(directory, entry.name)))
|
|
176
|
+
.sort();
|
|
177
|
+
}
|
|
178
|
+
catch {
|
|
179
|
+
return [];
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
export async function auditWorkspaceContext(projectPath) {
|
|
183
|
+
const extractedProject = await extractExistingProjectContext(projectPath);
|
|
184
|
+
const nested = await nestedInstructionFiles(projectPath);
|
|
185
|
+
const candidates = new Set([
|
|
186
|
+
'WORKSPACE.md',
|
|
187
|
+
...LEGACY_ROOT_FILES,
|
|
188
|
+
...nested.files,
|
|
189
|
+
...await migratedProviderFiles(projectPath),
|
|
190
|
+
]);
|
|
191
|
+
const sources = [];
|
|
192
|
+
const sensitiveFindings = [...extractedProject.sensitiveFindings];
|
|
193
|
+
for (const relativePath of [...candidates].sort((a, b) => a.localeCompare(b))) {
|
|
194
|
+
const content = await readOptional(path.join(projectPath, relativePath));
|
|
195
|
+
if (content === null)
|
|
196
|
+
continue;
|
|
197
|
+
const operatorContent = relativePath === 'WORKSPACE.md'
|
|
198
|
+
? (() => {
|
|
199
|
+
const start = content.indexOf(WORKSPACE_OPERATOR_START);
|
|
200
|
+
const end = content.indexOf(WORKSPACE_OPERATOR_END);
|
|
201
|
+
return start >= 0 && end > start
|
|
202
|
+
? content.slice(start + WORKSPACE_OPERATOR_START.length, end).trim()
|
|
203
|
+
: stripGeneratedBlocks(content);
|
|
204
|
+
})()
|
|
205
|
+
: isGeneratedRootContext(relativePath, content)
|
|
206
|
+
? ''
|
|
207
|
+
: stripGeneratedBlocks(content);
|
|
208
|
+
for (const evidence of sensitiveEvidence(operatorContent))
|
|
209
|
+
sensitiveFindings.push({ path: relativePath, evidence });
|
|
210
|
+
sources.push({
|
|
211
|
+
path: relativePath,
|
|
212
|
+
provider: providerForPath(relativePath),
|
|
213
|
+
scope: LEGACY_ROOT_FILES.includes(relativePath) || relativePath === 'WORKSPACE.md' ? 'root' : 'nested',
|
|
214
|
+
managed: content.includes(WORKSPACE_SIGNATURE) || content.includes('AIWG:context-hook:start') || content.includes('AIWG:claude-md-hook:start'),
|
|
215
|
+
operatorContent,
|
|
216
|
+
checksum: sha256(content),
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
const byDirective = new Map();
|
|
220
|
+
for (const source of sources) {
|
|
221
|
+
for (const directive of directives(source.operatorContent)) {
|
|
222
|
+
const paths = byDirective.get(directive) ?? [];
|
|
223
|
+
paths.push(source.path);
|
|
224
|
+
byDirective.set(directive, paths);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
const identical = [...byDirective]
|
|
228
|
+
.filter(([, paths]) => paths.length > 1)
|
|
229
|
+
.map(([directive, paths]) => ({ sources: [...paths].sort(), directives: [directive] }));
|
|
230
|
+
const overlaps = [];
|
|
231
|
+
for (let index = 0; index < sources.length; index += 1) {
|
|
232
|
+
const left = new Set(directives(sources[index].operatorContent));
|
|
233
|
+
for (let rightIndex = index + 1; rightIndex < sources.length; rightIndex += 1) {
|
|
234
|
+
const common = directives(sources[rightIndex].operatorContent).filter((item) => left.has(item));
|
|
235
|
+
if (common.length > 0)
|
|
236
|
+
overlaps.push({ sources: [sources[index].path, sources[rightIndex].path], directives: common.sort() });
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
const conflictMap = new Map();
|
|
240
|
+
for (const source of sources) {
|
|
241
|
+
for (const directive of directives(source.operatorContent)) {
|
|
242
|
+
const key = directiveKey(directive);
|
|
243
|
+
if (!key)
|
|
244
|
+
continue;
|
|
245
|
+
const values = conflictMap.get(key) ?? [];
|
|
246
|
+
values.push({ path: source.path, directive, polarity: directivePolarity(directive) });
|
|
247
|
+
conflictMap.set(key, values);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
const conflicts = [...conflictMap]
|
|
251
|
+
.filter(([, values]) => new Set(values.map((value) => value.polarity)).size > 1)
|
|
252
|
+
.map(([key, values]) => ({ key, sources: values.map(({ path: sourcePath, directive }) => ({ path: sourcePath, directive })).sort((a, b) => a.path.localeCompare(b.path)) }));
|
|
253
|
+
const rootOperator = sources.filter((source) => source.scope === 'root' && source.operatorContent.trim());
|
|
254
|
+
// Provider startup files (CLAUDE.md, AGENTS.md, WARP.md, …) are bootstrap
|
|
255
|
+
// surfaces: AIWG rewrites them to a managed bootstrap that `@`-imports
|
|
256
|
+
// WORKSPACE.md. The operator content they carried therefore ports into the
|
|
257
|
+
// WORKSPACE.md operator block, which every provider bootstrap loads and
|
|
258
|
+
// which `aiwg use` and `aiwg regenerate` preserve byte-for-byte. Routing
|
|
259
|
+
// it to `.aiwg/context/providers/` instead left it linked but never
|
|
260
|
+
// loaded, and a later `aiwg use` dropped even the link (#2558).
|
|
261
|
+
const neutralSources = rootOperator.map((source) => source.path);
|
|
262
|
+
const providerSources = [];
|
|
263
|
+
const providerOutputs = [];
|
|
264
|
+
const workspaceExists = sources.some((source) => source.path === 'WORKSPACE.md');
|
|
265
|
+
// Report volume and destination per source. A substantial provider-named
|
|
266
|
+
// body is still surfaced for review (#2537): it now lands where every
|
|
267
|
+
// provider reads it, so anything genuinely provider-only should be moved to
|
|
268
|
+
// `.aiwg/context/providers/` by the operator after migration.
|
|
269
|
+
const routing = rootOperator.map((source) => ({
|
|
270
|
+
source: source.path,
|
|
271
|
+
operatorBytes: Buffer.byteLength(source.operatorContent, 'utf8'),
|
|
272
|
+
destination: 'WORKSPACE.md',
|
|
273
|
+
scope: 'project-neutral',
|
|
274
|
+
provider: source.path === 'WORKSPACE.md' ? null : source.provider,
|
|
275
|
+
})).sort((a, b) => b.operatorBytes - a.operatorBytes);
|
|
276
|
+
const scopeReview = routing.filter((entry) => entry.source !== 'WORKSPACE.md' && entry.operatorBytes >= SCOPE_REVIEW_BYTES);
|
|
277
|
+
return {
|
|
278
|
+
version: 1,
|
|
279
|
+
projectPath,
|
|
280
|
+
workspaceExists,
|
|
281
|
+
legacyCompatible: !workspaceExists && sources.some((source) => LEGACY_ROOT_FILES.includes(source.path)),
|
|
282
|
+
sources,
|
|
283
|
+
identical,
|
|
284
|
+
overlaps,
|
|
285
|
+
conflicts,
|
|
286
|
+
sensitiveFindings,
|
|
287
|
+
contextWalkTruncated: nested.truncated,
|
|
288
|
+
plan: {
|
|
289
|
+
routing,
|
|
290
|
+
scopeReview,
|
|
291
|
+
neutralSources,
|
|
292
|
+
providerSources,
|
|
293
|
+
nestedSources: sources.filter((source) => source.scope === 'nested').map((source) => source.path),
|
|
294
|
+
projectSources: extractedProject.sources,
|
|
295
|
+
outputs: ['WORKSPACE.md', ...providerOutputs, ...listProviderDefinitions().flatMap((definition) => definition.context.bootstrapTargets)].filter((value, index, all) => all.indexOf(value) === index).sort(),
|
|
296
|
+
},
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
//# sourceMappingURL=workspace-audit.js.map
|