opencastle 1.4.3 → 1.6.0
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/dist/cli/adapters/claude-code.d.ts.map +1 -1
- package/dist/cli/adapters/claude-code.js +1 -0
- package/dist/cli/adapters/claude-code.js.map +1 -1
- package/dist/cli/adapters/single-file-base.d.ts +8 -0
- package/dist/cli/adapters/single-file-base.d.ts.map +1 -1
- package/dist/cli/adapters/single-file-base.js +48 -22
- package/dist/cli/adapters/single-file-base.js.map +1 -1
- package/dist/cli/bootstrap-on-init.test.js +16 -5
- package/dist/cli/bootstrap-on-init.test.js.map +1 -1
- package/dist/cli/bootstrap.d.ts +17 -0
- package/dist/cli/bootstrap.d.ts.map +1 -1
- package/dist/cli/bootstrap.js +284 -312
- package/dist/cli/bootstrap.js.map +1 -1
- package/dist/cli/bootstrap.test.js +22 -16
- package/dist/cli/bootstrap.test.js.map +1 -1
- package/dist/cli/command-namespace.test.js +17 -0
- package/dist/cli/command-namespace.test.js.map +1 -1
- package/dist/cli/convoy/engine.d.ts +12 -0
- package/dist/cli/convoy/engine.d.ts.map +1 -1
- package/dist/cli/convoy/engine.git.test.js +55 -0
- package/dist/cli/convoy/engine.git.test.js.map +1 -1
- package/dist/cli/convoy/engine.js +47 -3
- package/dist/cli/convoy/engine.js.map +1 -1
- package/dist/cli/convoy/findings.d.ts +35 -0
- package/dist/cli/convoy/findings.d.ts.map +1 -0
- package/dist/cli/convoy/findings.js +100 -0
- package/dist/cli/convoy/findings.js.map +1 -0
- package/dist/cli/convoy/findings.test.d.ts +2 -0
- package/dist/cli/convoy/findings.test.d.ts.map +1 -0
- package/dist/cli/convoy/findings.test.js +75 -0
- package/dist/cli/convoy/findings.test.js.map +1 -0
- package/dist/cli/convoy/isolation.d.ts.map +1 -1
- package/dist/cli/convoy/isolation.js +2 -1
- package/dist/cli/convoy/isolation.js.map +1 -1
- package/dist/cli/convoy/worktree.d.ts +5 -0
- package/dist/cli/convoy/worktree.d.ts.map +1 -1
- package/dist/cli/convoy/worktree.js +12 -0
- package/dist/cli/convoy/worktree.js.map +1 -1
- package/dist/cli/detect.d.ts +4 -0
- package/dist/cli/detect.d.ts.map +1 -1
- package/dist/cli/detect.js +1 -1
- package/dist/cli/detect.js.map +1 -1
- package/dist/cli/docs-accuracy.test.js +34 -0
- package/dist/cli/docs-accuracy.test.js.map +1 -1
- package/dist/cli/doctor.d.ts +11 -0
- package/dist/cli/doctor.d.ts.map +1 -1
- package/dist/cli/doctor.js +74 -10
- package/dist/cli/doctor.js.map +1 -1
- package/dist/cli/doctor.test.js +82 -1
- package/dist/cli/doctor.test.js.map +1 -1
- package/dist/cli/init.d.ts.map +1 -1
- package/dist/cli/init.js +58 -53
- package/dist/cli/init.js.map +1 -1
- package/dist/cli/init.test.js +32 -28
- package/dist/cli/init.test.js.map +1 -1
- package/dist/cli/layers.d.ts +20 -0
- package/dist/cli/layers.d.ts.map +1 -1
- package/dist/cli/layers.js +53 -1
- package/dist/cli/layers.js.map +1 -1
- package/dist/cli/layers.test.js +67 -1
- package/dist/cli/layers.test.js.map +1 -1
- package/dist/cli/lessons.d.ts +10 -0
- package/dist/cli/lessons.d.ts.map +1 -1
- package/dist/cli/lessons.js +26 -1
- package/dist/cli/lessons.js.map +1 -1
- package/dist/cli/lessons.test.js +38 -1
- package/dist/cli/lessons.test.js.map +1 -1
- package/dist/cli/log.d.ts +2 -2
- package/dist/cli/log.d.ts.map +1 -1
- package/dist/cli/log.js +1 -1
- package/dist/cli/log.js.map +1 -1
- package/dist/cli/log.test.js +1 -1
- package/dist/cli/log.test.js.map +1 -1
- package/dist/cli/managed-paths.d.ts +1 -1
- package/dist/cli/managed-paths.d.ts.map +1 -1
- package/dist/cli/managed-paths.js +0 -1
- package/dist/cli/managed-paths.js.map +1 -1
- package/dist/cli/plan.test.js +10 -8
- package/dist/cli/plan.test.js.map +1 -1
- package/dist/cli/project-facts.d.ts +103 -0
- package/dist/cli/project-facts.d.ts.map +1 -0
- package/dist/cli/project-facts.js +577 -0
- package/dist/cli/project-facts.js.map +1 -0
- package/dist/cli/project-facts.test.d.ts +2 -0
- package/dist/cli/project-facts.test.d.ts.map +1 -0
- package/dist/cli/project-facts.test.js +209 -0
- package/dist/cli/project-facts.test.js.map +1 -0
- package/dist/cli/stack-config.js +1 -1
- package/dist/cli/stack-config.js.map +1 -1
- package/dist/cli/sync-check.test.js +14 -2
- package/dist/cli/sync-check.test.js.map +1 -1
- package/dist/orchestrator/plugins/notion/config.d.ts.map +1 -1
- package/dist/orchestrator/plugins/notion/config.js +21 -17
- package/dist/orchestrator/plugins/notion/config.js.map +1 -1
- package/package.json +1 -1
- package/src/cli/adapters/claude-code.ts +1 -0
- package/src/cli/adapters/single-file-base.ts +63 -31
- package/src/cli/bootstrap-on-init.test.ts +17 -5
- package/src/cli/bootstrap.test.ts +22 -16
- package/src/cli/bootstrap.ts +361 -373
- package/src/cli/command-namespace.test.ts +17 -0
- package/src/cli/convoy/engine.git.test.ts +59 -0
- package/src/cli/convoy/engine.ts +53 -2
- package/src/cli/convoy/findings.test.ts +86 -0
- package/src/cli/convoy/findings.ts +129 -0
- package/src/cli/convoy/isolation.ts +2 -1
- package/src/cli/convoy/worktree.ts +12 -0
- package/src/cli/detect.ts +1 -1
- package/src/cli/docs-accuracy.test.ts +42 -0
- package/src/cli/doctor.test.ts +101 -1
- package/src/cli/doctor.ts +77 -11
- package/src/cli/init.test.ts +31 -27
- package/src/cli/init.ts +62 -57
- package/src/cli/layers.test.ts +72 -1
- package/src/cli/layers.ts +52 -1
- package/src/cli/lessons.test.ts +48 -0
- package/src/cli/lessons.ts +27 -1
- package/src/cli/log.test.ts +1 -1
- package/src/cli/log.ts +2 -2
- package/src/cli/managed-paths.ts +0 -1
- package/src/cli/plan.test.ts +10 -8
- package/src/cli/project-facts.test.ts +228 -0
- package/src/cli/project-facts.ts +647 -0
- package/src/cli/stack-config.ts +1 -1
- package/src/cli/sync-check.test.ts +16 -2
- package/src/orchestrator/agent-workflows/data-pipeline.md +2 -2
- package/src/orchestrator/agent-workflows/feature-implementation.md +2 -2
- package/src/orchestrator/agent-workflows/schema-changes.md +1 -1
- package/src/orchestrator/agents/team-lead.agent.md +6 -6
- package/src/orchestrator/agents/testing-expert.agent.md +2 -2
- package/src/orchestrator/customizations/LESSONS-LEARNED.md +1 -1
- package/src/orchestrator/customizations/README.md +27 -84
- package/src/orchestrator/instructions/ai-optimization.instructions.md +6 -23
- package/src/orchestrator/instructions/general.instructions.md +22 -95
- package/src/orchestrator/plugins/astro/skills/astro-framework/SKILL.md +1 -3
- package/src/orchestrator/plugins/chrome-devtools/skills/browser-testing/SKILL.md +3 -5
- package/src/orchestrator/plugins/cloudflare/skills/cloudflare-platform/SKILL.md +2 -2
- package/src/orchestrator/plugins/contentful/skills/contentful-cms/SKILL.md +1 -1
- package/src/orchestrator/plugins/convex/skills/convex-database/SKILL.md +1 -3
- package/src/orchestrator/plugins/coolify/skills/coolify-deployment/SKILL.md +1 -1
- package/src/orchestrator/plugins/cypress/skills/cypress-testing/SKILL.md +1 -1
- package/src/orchestrator/plugins/drizzle/skills/drizzle-orm/SKILL.md +1 -1
- package/src/orchestrator/plugins/expo/skills/expo-development/SKILL.md +2 -2
- package/src/orchestrator/plugins/figma/skills/figma-design/SKILL.md +1 -3
- package/src/orchestrator/plugins/hetzner/skills/hetzner-cloud/SKILL.md +1 -1
- package/src/orchestrator/plugins/jira/skills/jira-management/SKILL.md +1 -3
- package/src/orchestrator/plugins/linear/skills/linear-task-management/SKILL.md +1 -3
- package/src/orchestrator/plugins/netlify/skills/netlify-deployment/SKILL.md +2 -2
- package/src/orchestrator/plugins/nextjs/skills/nextjs-framework/SKILL.md +13 -6
- package/src/orchestrator/plugins/notion/config.ts +21 -17
- package/src/orchestrator/plugins/notion/skills/notion-knowledge-management/SKILL.md +8 -16
- package/src/orchestrator/plugins/nx/skills/nx-workspace/SKILL.md +2 -4
- package/src/orchestrator/plugins/playwright/skills/playwright-testing/SKILL.md +1 -3
- package/src/orchestrator/plugins/prisma/skills/prisma-database/SKILL.md +1 -3
- package/src/orchestrator/plugins/resend/skills/resend-email/SKILL.md +2 -2
- package/src/orchestrator/plugins/sanity/skills/sanity-cms/SKILL.md +1 -3
- package/src/orchestrator/plugins/sentry/skills/sentry-monitoring/SKILL.md +1 -1
- package/src/orchestrator/plugins/slack/skills/slack-notifications/SKILL.md +1 -3
- package/src/orchestrator/plugins/strapi/skills/strapi-cms/SKILL.md +1 -3
- package/src/orchestrator/plugins/stripe/skills/stripe-payments/SKILL.md +4 -4
- package/src/orchestrator/plugins/supabase/skills/supabase-database/SKILL.md +3 -5
- package/src/orchestrator/plugins/teams/skills/teams-notifications/SKILL.md +1 -3
- package/src/orchestrator/plugins/trello/skills/trello-task-management/SKILL.md +1 -1
- package/src/orchestrator/plugins/turborepo/skills/turborepo-monorepo/SKILL.md +15 -88
- package/src/orchestrator/plugins/vercel/skills/vercel-deployment/SKILL.md +2 -2
- package/src/orchestrator/plugins/vitest/skills/vitest-testing/SKILL.md +17 -150
- package/src/orchestrator/prompts/assess-complexity.prompt.md +1 -0
- package/src/orchestrator/prompts/bootstrap-customizations.prompt.md +38 -238
- package/src/orchestrator/prompts/brainstorm.prompt.md +1 -1
- package/src/orchestrator/prompts/create-skill.prompt.md +13 -67
- package/src/orchestrator/prompts/fix-convoy.prompt.md +1 -0
- package/src/orchestrator/prompts/fix-prd.prompt.md +1 -0
- package/src/orchestrator/prompts/generate-prd.prompt.md +1 -0
- package/src/orchestrator/prompts/implement-feature.prompt.md +6 -6
- package/src/orchestrator/prompts/resolve-pr-comments.prompt.md +2 -2
- package/src/orchestrator/prompts/validate-convoy.prompt.md +1 -0
- package/src/orchestrator/prompts/validate-prd.prompt.md +1 -0
- package/src/orchestrator/skills/accessibility-standards/REFERENCE.md +17 -12
- package/src/orchestrator/skills/accessibility-standards/SKILL.md +1 -1
- package/src/orchestrator/skills/agent-hooks/HOOKS-REFERENCE.md +3 -5
- package/src/orchestrator/skills/agent-hooks/SKILL.md +8 -6
- package/src/orchestrator/skills/agent-memory/KNOWLEDGE-GRAPH.md +1 -1
- package/src/orchestrator/skills/agent-memory/SKILL.md +7 -16
- package/src/orchestrator/skills/api-patterns/SKILL.md +1 -1
- package/src/orchestrator/skills/code-commenting/SKILL.md +1 -1
- package/src/orchestrator/skills/context-map/REFERENCE.md +0 -2
- package/src/orchestrator/skills/context-map/SKILL.md +2 -2
- package/src/orchestrator/skills/data-engineering/REFERENCE.md +3 -9
- package/src/orchestrator/skills/data-engineering/SKILL.md +9 -16
- package/src/orchestrator/skills/decomposition/SKILL.md +1 -1
- package/src/orchestrator/skills/deployment-infrastructure/SKILL.md +4 -4
- package/src/orchestrator/skills/documentation-standards/SKILL.md +5 -3
- package/src/orchestrator/skills/fast-review/REFERENCE.md +0 -2
- package/src/orchestrator/skills/fast-review/SKILL.md +5 -5
- package/src/orchestrator/skills/frontend-design/REFERENCE.md +6 -28
- package/src/orchestrator/skills/frontend-design/SKILL.md +19 -9
- package/src/orchestrator/skills/git-workflow/SKILL.md +1 -1
- package/src/orchestrator/skills/memory-merger/SKILL.md +13 -15
- package/src/orchestrator/skills/observability-logging/SKILL.md +2 -2
- package/src/orchestrator/skills/orchestration-protocols/REFERENCE.md +5 -9
- package/src/orchestrator/skills/orchestration-protocols/SKILL.md +6 -6
- package/src/orchestrator/skills/panel-majority-vote/REFERENCE.md +1 -5
- package/src/orchestrator/skills/panel-majority-vote/SKILL.md +1 -1
- package/src/orchestrator/skills/panel-majority-vote/panel-report.template.md +0 -2
- package/src/orchestrator/skills/performance-optimization/SKILL.md +2 -2
- package/src/orchestrator/skills/project-consistency/SKILL.md +2 -2
- package/src/orchestrator/skills/project-consistency/TEMPLATES.md +0 -4
- package/src/orchestrator/skills/react-development/SKILL.md +3 -3
- package/src/orchestrator/skills/security-hardening/SKILL.md +5 -5
- package/src/orchestrator/skills/self-improvement/LESSON-CATEGORIES.md +0 -2
- package/src/orchestrator/skills/self-improvement/SKILL.md +1 -1
- package/src/orchestrator/skills/seo-patterns/SKILL.md +1 -1
- package/src/orchestrator/skills/session-checkpoints/CHECKPOINT-TEMPLATE.md +0 -2
- package/src/orchestrator/skills/session-checkpoints/SKILL.md +1 -1
- package/src/orchestrator/skills/team-lead-reference/SKILL.md +3 -3
- package/src/orchestrator/skills/technical-writing/SKILL.md +8 -13
- package/src/orchestrator/skills/testing-workflow/SKILL.md +6 -6
- package/src/orchestrator/skills/typescript-best-practices/SKILL.md +1 -1
- package/src/orchestrator/skills/unslop/SKILL.md +1 -1
- package/src/orchestrator/skills/validation-gates/REFERENCE.md +6 -31
- package/src/orchestrator/skills/validation-gates/SKILL.md +12 -26
- package/src/orchestrator/skills/writing-for-agents/SKILL.md +2 -2
- package/src/orchestrator/customizations/AGENT-EXPERTISE.md +0 -325
- package/src/orchestrator/customizations/AGENT-FAILURES.md +0 -69
- package/src/orchestrator/customizations/AGENT-PERFORMANCE.md +0 -55
- package/src/orchestrator/customizations/DISPUTES.md +0 -162
- package/src/orchestrator/customizations/KNOWLEDGE-GRAPH.md +0 -10
- package/src/orchestrator/customizations/agents/skill-matrix.md +0 -111
- package/src/orchestrator/customizations/logs/events.ndjson +0 -0
- package/src/orchestrator/customizations/project/decisions.md +0 -31
- package/src/orchestrator/customizations/project/docs-structure.md +0 -34
- package/src/orchestrator/customizations/project/roadmap.md +0 -24
- package/src/orchestrator/skills/documentation-standards/WRITING-GUIDE.md +0 -39
- package/src/orchestrator/skills/frontend-design/COMPONENTS.md +0 -113
- /package/src/orchestrator/{customizations/logs/README.md → skills/observability-logging/LOG-SCHEMA.md} +0 -0
package/src/cli/doctor.ts
CHANGED
|
@@ -31,6 +31,7 @@ import { cliVersionOf, requiredEnvVars } from './layers.js';
|
|
|
31
31
|
import type { CliContext, DoctorCheck, IdeChoice, Manifest } from './types.js';
|
|
32
32
|
import { IDE_LABELS } from './types.js';
|
|
33
33
|
import { c } from './prompt.js';
|
|
34
|
+
import { readLock } from './lock.js';
|
|
34
35
|
|
|
35
36
|
// ── Styled output helpers ─────────────────────────────────────
|
|
36
37
|
|
|
@@ -158,7 +159,51 @@ async function checkCustomizations(projectRoot: string): Promise<CheckResult> {
|
|
|
158
159
|
return { ok: true, label: 'Customizations directory', detail: `${files.length} entries` };
|
|
159
160
|
}
|
|
160
161
|
|
|
161
|
-
|
|
162
|
+
/**
|
|
163
|
+
* Whether the project's facts say anything yet.
|
|
164
|
+
*
|
|
165
|
+
* Every skill that needs this project's commands, routes or models reads them
|
|
166
|
+
* from `.opencastle/`. A file that is still a template — empty table rows,
|
|
167
|
+
* `TODO: verify` markers, as installs before 1.5 left them — gives them
|
|
168
|
+
* nothing, and nothing said so. One written from the code may still list what
|
|
169
|
+
* it could not read under "Still to describe"; that is normal, and counted.
|
|
170
|
+
*/
|
|
171
|
+
export async function checkProjectContext(projectRoot: string): Promise<CheckResult> {
|
|
172
|
+
const dir = resolve(projectRoot, '.opencastle');
|
|
173
|
+
const facts = resolve(dir, 'project.instructions.md');
|
|
174
|
+
const bootstrap = 'have an agent fill it in from the code: /oc:bootstrap-customizations, or the bootstrap-customizations prompt';
|
|
175
|
+
if (!existsSync(facts)) {
|
|
176
|
+
return { ok: true, warning: true, label: 'Project context', detail: '.opencastle/project.instructions.md not found', fix: bootstrap };
|
|
177
|
+
}
|
|
178
|
+
const stack = resolve(dir, 'stack');
|
|
179
|
+
const stackFiles = existsSync(stack) ? (await readdir(stack).catch(() => [])).filter((f) => f.endsWith('.md')) : [];
|
|
180
|
+
const files = [facts, ...stackFiles.map((f) => resolve(stack, f))];
|
|
181
|
+
let placeholders = 0;
|
|
182
|
+
let toDescribe = 0;
|
|
183
|
+
for (const file of files) {
|
|
184
|
+
const text = await readFile(file, 'utf8').catch(() => '');
|
|
185
|
+
placeholders += (text.match(/^\|(?:\s*\|)+\s*$/gm) ?? []).length + (text.match(/TODO: verify/g) ?? []).length;
|
|
186
|
+
// `(?![\s\S])`, not `$`: under the `m` flag `$` ends the first line.
|
|
187
|
+
const list = /^## Still to describe\s*\n([\s\S]*?)(?=\n## |(?![\s\S]))/m.exec(text)?.[1] ?? '';
|
|
188
|
+
toDescribe += (list.match(/^- /gm) ?? []).length;
|
|
189
|
+
}
|
|
190
|
+
if (placeholders >= 3) {
|
|
191
|
+
return {
|
|
192
|
+
ok: true,
|
|
193
|
+
warning: true,
|
|
194
|
+
label: 'Project context',
|
|
195
|
+
detail: `still the template: ${placeholders} empty rows or "TODO: verify" markers in .opencastle/`,
|
|
196
|
+
fix: bootstrap,
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
return {
|
|
200
|
+
ok: true,
|
|
201
|
+
label: 'Project context',
|
|
202
|
+
detail: toDescribe > 0 ? `written; ${toDescribe} still to describe — ${bootstrap}` : 'written',
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
export async function checkSkillMatrix(projectRoot: string): Promise<CheckResult> {
|
|
162
207
|
const path = resolve(projectRoot, '.opencastle', 'agents', 'skill-matrix.json');
|
|
163
208
|
if (!existsSync(path)) {
|
|
164
209
|
// "Not found" only if the directory holding it can actually be looked in.
|
|
@@ -202,14 +247,34 @@ async function checkSkillMatrix(projectRoot: string): Promise<CheckResult> {
|
|
|
202
247
|
}
|
|
203
248
|
try {
|
|
204
249
|
const data = JSON.parse(content);
|
|
205
|
-
const bindings = data.bindings ?? {}
|
|
206
|
-
const
|
|
207
|
-
|
|
250
|
+
const bindings = (data.bindings ?? {}) as Record<string, { entries?: Array<{ skill?: string }> }>;
|
|
251
|
+
const slots = Object.entries(bindings);
|
|
252
|
+
const bound = slots.filter(([, slot]) => Array.isArray(slot.entries) && slot.entries.length > 0);
|
|
253
|
+
// A slot with nothing bound is a domain this stack has nothing special in —
|
|
254
|
+
// no CMS, no payments. That is the normal state of most slots, and warning
|
|
255
|
+
// about it on every fresh install taught people to ignore the warnings. A
|
|
256
|
+
// slot bound to a skill that was not compiled is the real fault.
|
|
257
|
+
const compiled = new Set(
|
|
258
|
+
Object.keys(readLock(projectRoot)?.content ?? {})
|
|
259
|
+
.filter((ref) => ref.startsWith('skills/'))
|
|
260
|
+
.map((ref) => ref.slice('skills/'.length)),
|
|
208
261
|
);
|
|
209
|
-
|
|
210
|
-
|
|
262
|
+
// No lock, nothing to compare against: say nothing rather than call every
|
|
263
|
+
// binding missing.
|
|
264
|
+
const missing = compiled.size === 0 ? [] : bound.flatMap(([name, slot]) =>
|
|
265
|
+
(slot.entries ?? []).filter((e) => e.skill && !compiled.has(e.skill)).map((e) => `${name} → ${e.skill}`));
|
|
266
|
+
if (missing.length > 0) {
|
|
267
|
+
return {
|
|
268
|
+
ok: true,
|
|
269
|
+
warning: true,
|
|
270
|
+
label: 'Skill matrix',
|
|
271
|
+
detail: `bound to skills that are not compiled: ${missing.join(', ')}`,
|
|
272
|
+
// No command named here: the claims check runs the last one doctor
|
|
273
|
+
// prints, and a warning must not stand in for a failure's remedy.
|
|
274
|
+
fix: 'remove those entries from .opencastle/agents/skill-matrix.json, or put back the integration that provided them',
|
|
275
|
+
};
|
|
211
276
|
}
|
|
212
|
-
return { ok: true, label: 'Skill matrix', detail:
|
|
277
|
+
return { ok: true, label: 'Skill matrix', detail: `${bound.length} of ${slots.length} capability slots bound; the rest have nothing in this stack` };
|
|
213
278
|
} catch {
|
|
214
279
|
return {
|
|
215
280
|
ok: false,
|
|
@@ -226,13 +291,13 @@ async function checkLogs(projectRoot: string): Promise<CheckResult> {
|
|
|
226
291
|
const dir = resolve(projectRoot, '.opencastle', 'logs');
|
|
227
292
|
if (!existsSync(dir)) {
|
|
228
293
|
// A local run artefact, not part of the project, so a fresh clone has none —
|
|
229
|
-
// and calling that a failure made `doctor` exit 1 on every clone.
|
|
230
|
-
// creates it; until then "
|
|
294
|
+
// and calling that a failure made `doctor` exit 1 on every clone. The first
|
|
295
|
+
// `opencastle log` creates it; until then "none yet" is the honest reading,
|
|
296
|
+
// and not something to warn about on every new install.
|
|
231
297
|
return {
|
|
232
298
|
ok: true,
|
|
233
|
-
warning: true,
|
|
234
299
|
label: 'Observability logs',
|
|
235
|
-
detail: '
|
|
300
|
+
detail: 'none yet — created when an agent first logs a session',
|
|
236
301
|
};
|
|
237
302
|
}
|
|
238
303
|
// A diagnostic does not write. This used to create five empty `.ndjson` files
|
|
@@ -946,6 +1011,7 @@ export async function runSharedChecks(
|
|
|
946
1011
|
const results = [
|
|
947
1012
|
checkManifest(manifest),
|
|
948
1013
|
await checkCustomizations(projectRoot),
|
|
1014
|
+
await checkProjectContext(projectRoot),
|
|
949
1015
|
await checkSkillMatrix(projectRoot),
|
|
950
1016
|
await checkLogs(projectRoot),
|
|
951
1017
|
await checkMcpEnvVars(projectRoot, manifest, state),
|
package/src/cli/init.test.ts
CHANGED
|
@@ -267,13 +267,13 @@ describe('stack-config: getAgentToolInjections', () => {
|
|
|
267
267
|
|
|
268
268
|
const teamLeadTools = injections.get('team-lead')
|
|
269
269
|
expect(teamLeadTools).toBeDefined()
|
|
270
|
-
expect(teamLeadTools).toContain('Notion/search')
|
|
271
|
-
expect(teamLeadTools).toContain('Notion/
|
|
270
|
+
expect(teamLeadTools).toContain('Notion/notion-search')
|
|
271
|
+
expect(teamLeadTools).toContain('Notion/notion-query-data-sources')
|
|
272
272
|
|
|
273
273
|
const architectTools = injections.get('architect')
|
|
274
274
|
expect(architectTools).toBeDefined()
|
|
275
|
-
expect(architectTools).toContain('Notion/
|
|
276
|
-
expect(architectTools).toContain('Notion/
|
|
275
|
+
expect(architectTools).toContain('Notion/notion-create-pages')
|
|
276
|
+
expect(architectTools).toContain('Notion/notion-update-page')
|
|
277
277
|
})
|
|
278
278
|
})
|
|
279
279
|
|
|
@@ -396,15 +396,14 @@ describe('VS Code adapter install', () => {
|
|
|
396
396
|
expect(existsSync(join(tempDir, '.vscode', 'mcp.json'))).toBe(true)
|
|
397
397
|
})
|
|
398
398
|
|
|
399
|
-
it('
|
|
399
|
+
it('installs no empty logs or ledgers: the first record creates them', async () => {
|
|
400
400
|
const adapter = await IDE_ADAPTERS['vscode']()
|
|
401
401
|
await adapter.install(PKG_ROOT, tempDir, STACK_EMPTY, EMPTY_REPO_INFO)
|
|
402
402
|
await scaffoldCustomizations(PKG_ROOT, tempDir, STACK_EMPTY)
|
|
403
403
|
|
|
404
|
-
const
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
expect(existsSync(join(logsDir, file))).toBe(true)
|
|
404
|
+
const dir = join(tempDir, '.opencastle')
|
|
405
|
+
for (const file of ['logs', 'AGENT-FAILURES.md', 'DISPUTES.md', 'AGENT-EXPERTISE.md', 'AGENT-PERFORMANCE.md', 'KNOWLEDGE-GRAPH.md']) {
|
|
406
|
+
expect(existsSync(join(dir, file)), file).toBe(false)
|
|
408
407
|
}
|
|
409
408
|
})
|
|
410
409
|
|
|
@@ -766,39 +765,44 @@ describe('Claude Code adapter install', () => {
|
|
|
766
765
|
expect(content).toContain('.claude/agents/')
|
|
767
766
|
})
|
|
768
767
|
|
|
769
|
-
|
|
768
|
+
// Claude Code lists its subagents and skills itself, from `.claude/agents/`
|
|
769
|
+
// and `.claude/skills/`. CLAUDE.md repeated both — about 3k tokens loaded
|
|
770
|
+
// twice in every session — so what is compiled is checked where it is read.
|
|
771
|
+
it('compiles the agents the stack keeps as subagents, and does not list them again in CLAUDE.md', async () => {
|
|
770
772
|
const adapter = await IDE_ADAPTERS['claude-code']()
|
|
771
773
|
await adapter.install(PKG_ROOT, tempDir, STACK_EMPTY, EMPTY_REPO_INFO)
|
|
772
774
|
|
|
775
|
+
const agents = await readdir(join(tempDir, '.claude', 'agents'))
|
|
776
|
+
expect(agents).toContain('developer.agent.md')
|
|
777
|
+
expect(agents).toContain('team-lead.agent.md')
|
|
778
|
+
expect(agents).not.toContain('content-engineer.agent.md')
|
|
779
|
+
expect(agents).not.toContain('data-engineer.agent.md')
|
|
773
780
|
const content = await readFile(join(tempDir, 'CLAUDE.md'), 'utf8')
|
|
774
|
-
expect(content).toContain('## Agent Definitions')
|
|
775
|
-
expect(content).toContain('**Developer**')
|
|
776
|
-
expect(content).toContain('**Team Lead (OpenCastle)**')
|
|
777
|
-
// Should NOT list excluded agents
|
|
778
|
-
expect(content).not.toContain('**Content Engineer**')
|
|
779
|
-
expect(content).not.toContain('**Data Engineer**')
|
|
781
|
+
expect(content).not.toContain('## Agent Definitions')
|
|
782
|
+
expect(content).not.toContain('**Developer**')
|
|
780
783
|
})
|
|
781
784
|
|
|
782
|
-
it('
|
|
785
|
+
it('compiles the content engineer when a CMS is selected', async () => {
|
|
783
786
|
const adapter = await IDE_ADAPTERS['claude-code']()
|
|
784
787
|
await adapter.install(PKG_ROOT, tempDir, STACK_SANITY_LINEAR, EMPTY_REPO_INFO)
|
|
785
788
|
|
|
786
|
-
const
|
|
787
|
-
expect(
|
|
788
|
-
expect(
|
|
789
|
+
const agents = await readdir(join(tempDir, '.claude', 'agents'))
|
|
790
|
+
expect(agents).toContain('content-engineer.agent.md')
|
|
791
|
+
expect(agents).not.toContain('data-engineer.agent.md')
|
|
789
792
|
})
|
|
790
793
|
|
|
791
|
-
it('
|
|
794
|
+
it('compiles the selected skills, and does not list them again in CLAUDE.md', async () => {
|
|
792
795
|
const adapter = await IDE_ADAPTERS['claude-code']()
|
|
793
796
|
await adapter.install(PKG_ROOT, tempDir, STACK_SANITY_LINEAR, EMPTY_REPO_INFO)
|
|
794
797
|
|
|
798
|
+
const skills = await readdir(join(tempDir, '.claude', 'skills'))
|
|
799
|
+
expect(skills).toContain('self-improvement')
|
|
800
|
+
expect(skills).toContain('sanity-cms')
|
|
801
|
+
expect(skills).toContain('linear-task-management')
|
|
802
|
+
expect(skills).not.toContain('supabase-database')
|
|
795
803
|
const content = await readFile(join(tempDir, 'CLAUDE.md'), 'utf8')
|
|
796
|
-
expect(content).toContain('## Available Skills')
|
|
797
|
-
expect(content).toContain('
|
|
798
|
-
expect(content).toContain('**sanity-cms**')
|
|
799
|
-
expect(content).toContain('**linear-task-management**')
|
|
800
|
-
// Unselected plugin skills should NOT appear in skill index
|
|
801
|
-
expect(content).not.toContain('**supabase-database**')
|
|
804
|
+
expect(content).not.toContain('## Available Skills')
|
|
805
|
+
expect(content).toContain('listed by the assistant itself')
|
|
802
806
|
})
|
|
803
807
|
|
|
804
808
|
it('writes agent files in .claude/agents/ with only the frontmatter Claude Code reads', async () => {
|
package/src/cli/init.ts
CHANGED
|
@@ -468,7 +468,68 @@ export default async function init({ pkgRoot, args }: CliContext): Promise<void>
|
|
|
468
468
|
const unreadable: string[] = []
|
|
469
469
|
const failedTargets: Array<{ ide: string; message: string }> = []
|
|
470
470
|
|
|
471
|
-
|
|
471
|
+
// ── Scaffold customizations to .opencastle/ ──────────────────────────────
|
|
472
|
+
// Sampled before the copy below, which creates `.opencastle/agents` itself.
|
|
473
|
+
// Read after it, this was true on every run including the first, so the
|
|
474
|
+
// bootstrap guard downstream never let the project scan execute at all: no
|
|
475
|
+
// tech-stack table, no key commands, not even the project name. Every skill
|
|
476
|
+
// that wanted the package manager hardcoded one instead, because the file
|
|
477
|
+
// that was supposed to record it was never filled in.
|
|
478
|
+
const alreadyScaffolded = existsSync(resolve(projectRoot, '.opencastle', 'agents'))
|
|
479
|
+
|
|
480
|
+
const custSrcDir = resolve(getOrchestratorRoot(pkgRoot), 'customizations')
|
|
481
|
+
if (existsSync(custSrcDir)) {
|
|
482
|
+
const custDestDir = resolve(projectRoot, '.opencastle')
|
|
483
|
+
const custTransform = getCustomizationsTransform(stack)
|
|
484
|
+
// Over an existing `.opencastle/`, the templates bootstrap prunes or renames
|
|
485
|
+
// on the first run — `stack/`, the tracker config — stay as that run left
|
|
486
|
+
// them. Copying them again put back every one it had removed: a project
|
|
487
|
+
// with no CMS got `cms-config.md` and `sanity-config.md` on its second init.
|
|
488
|
+
const prunedOnce = (rel: string) => rel === 'stack' || rel.startsWith('stack/') || rel === 'project/tracker-config.md'
|
|
489
|
+
const sub = await copyDir(custSrcDir, custDestDir, {
|
|
490
|
+
transform: custTransform,
|
|
491
|
+
filter: (_name, srcPath) => !(alreadyScaffolded && prunedOnce(relative(custSrcDir, srcPath).split('\\').join('/'))),
|
|
492
|
+
})
|
|
493
|
+
totalCreated += sub.created.length
|
|
494
|
+
totalSkipped += sub.skipped.length
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
// ── Project scan ────────────────────────────────────────────────
|
|
498
|
+
// Bootstrap only on a first install. Its rename steps write over the target
|
|
499
|
+
// unconditionally, so on a re-run they replaced the user's own
|
|
500
|
+
// `stack/<provider>-config.md` with a blank template — the same hazard removed
|
|
501
|
+
// from `sync` in an earlier round and left standing here, and newly reachable
|
|
502
|
+
// without a prompt because `--yes` is new on this branch.
|
|
503
|
+
console.log(`\n ${c.dim('Configuring project...')}`)
|
|
504
|
+
// Keyed off the directory, not the manifest. `isReinit` alone missed two
|
|
505
|
+
// routes onto the destructive path — `remove --keep-files` (which drops only
|
|
506
|
+
// the manifest, by design) and a manifest with merge-conflict markers, which
|
|
507
|
+
// `readManifest` reports as "no install". Both then ran bootstrap's
|
|
508
|
+
// unconditional renames over a populated `.opencastle/` and replaced the
|
|
509
|
+
// user's own stack notes with a blank template. `alreadyScaffolded` is
|
|
510
|
+
// sampled above, before the scaffold step supplies its own answer.
|
|
511
|
+
const bootstrapResult = isReinit || alreadyScaffolded
|
|
512
|
+
? { populated: [], removed: [], renamed: [] }
|
|
513
|
+
: await bootstrapCustomizations(projectRoot, combinedRepoInfo, stack)
|
|
514
|
+
|
|
515
|
+
if (bootstrapResult.populated.length > 0) {
|
|
516
|
+
console.log(` ${c.green('✓')} Populated ${c.bold(String(bootstrapResult.populated.length))} config files`)
|
|
517
|
+
}
|
|
518
|
+
if (bootstrapResult.renamed.length > 0) {
|
|
519
|
+
for (const r of bootstrapResult.renamed) {
|
|
520
|
+
console.log(` ${c.dim('→')} Renamed ${r}`)
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
if (bootstrapResult.removed.length > 0) {
|
|
524
|
+
console.log(` ${c.dim('→')} Removed ${bootstrapResult.removed.length} unused template(s)`)
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
// Compiled after `.opencastle/` is written, not before: on a first install the
|
|
528
|
+
// project's facts — `project.instructions.md`, which every assistant loads —
|
|
529
|
+
// did not exist yet when the assistants' files were compiled, so the first
|
|
530
|
+
// `sync --check` reported every root file as drifted.
|
|
531
|
+
const scaffolded = resolveSources({ pkgRoot, projectRoot, stack, repoInfo: combinedRepoInfo })
|
|
532
|
+
const source = materialize(hasErrors(scaffolded) ? resolved : scaffolded, pkgRoot, ...priorTeam(projectRoot))
|
|
472
533
|
try {
|
|
473
534
|
for (const ide of ides) {
|
|
474
535
|
const adapter = await IDE_ADAPTERS[ide]()
|
|
@@ -612,62 +673,6 @@ export default async function init({ pkgRoot, args }: CliContext): Promise<void>
|
|
|
612
673
|
source.dispose()
|
|
613
674
|
}
|
|
614
675
|
|
|
615
|
-
// ── Scaffold customizations to .opencastle/ ──────────────────────────────
|
|
616
|
-
// Sampled before the copy below, which creates `.opencastle/agents` itself.
|
|
617
|
-
// Read after it, this was true on every run including the first, so the
|
|
618
|
-
// bootstrap guard downstream never let the project scan execute at all: no
|
|
619
|
-
// tech-stack table, no key commands, not even the project name. Every skill
|
|
620
|
-
// that wanted the package manager hardcoded one instead, because the file
|
|
621
|
-
// that was supposed to record it was never filled in.
|
|
622
|
-
const alreadyScaffolded = existsSync(resolve(projectRoot, '.opencastle', 'agents'))
|
|
623
|
-
|
|
624
|
-
const custSrcDir = resolve(getOrchestratorRoot(pkgRoot), 'customizations')
|
|
625
|
-
if (existsSync(custSrcDir)) {
|
|
626
|
-
const custDestDir = resolve(projectRoot, '.opencastle')
|
|
627
|
-
const custTransform = getCustomizationsTransform(stack)
|
|
628
|
-
// Over an existing `.opencastle/`, the templates bootstrap prunes or renames
|
|
629
|
-
// on the first run — `stack/`, the tracker config — stay as that run left
|
|
630
|
-
// them. Copying them again put back every one it had removed: a project
|
|
631
|
-
// with no CMS got `cms-config.md` and `sanity-config.md` on its second init.
|
|
632
|
-
const prunedOnce = (rel: string) => rel === 'stack' || rel.startsWith('stack/') || rel === 'project/tracker-config.md'
|
|
633
|
-
const sub = await copyDir(custSrcDir, custDestDir, {
|
|
634
|
-
transform: custTransform,
|
|
635
|
-
filter: (_name, srcPath) => !(alreadyScaffolded && prunedOnce(relative(custSrcDir, srcPath).split('\\').join('/'))),
|
|
636
|
-
})
|
|
637
|
-
totalCreated += sub.created.length
|
|
638
|
-
totalSkipped += sub.skipped.length
|
|
639
|
-
}
|
|
640
|
-
|
|
641
|
-
// ── Project scan ────────────────────────────────────────────────
|
|
642
|
-
// Bootstrap only on a first install. Its rename steps write over the target
|
|
643
|
-
// unconditionally, so on a re-run they replaced the user's own
|
|
644
|
-
// `stack/<provider>-config.md` with a blank template — the same hazard removed
|
|
645
|
-
// from `sync` in an earlier round and left standing here, and newly reachable
|
|
646
|
-
// without a prompt because `--yes` is new on this branch.
|
|
647
|
-
console.log(`\n ${c.dim('Configuring project...')}`)
|
|
648
|
-
// Keyed off the directory, not the manifest. `isReinit` alone missed two
|
|
649
|
-
// routes onto the destructive path — `remove --keep-files` (which drops only
|
|
650
|
-
// the manifest, by design) and a manifest with merge-conflict markers, which
|
|
651
|
-
// `readManifest` reports as "no install". Both then ran bootstrap's
|
|
652
|
-
// unconditional renames over a populated `.opencastle/` and replaced the
|
|
653
|
-
// user's own stack notes with a blank template. `alreadyScaffolded` is
|
|
654
|
-
// sampled above, before the scaffold step supplies its own answer.
|
|
655
|
-
const bootstrapResult = isReinit || alreadyScaffolded
|
|
656
|
-
? { populated: [], removed: [], renamed: [] }
|
|
657
|
-
: await bootstrapCustomizations(projectRoot, combinedRepoInfo, stack)
|
|
658
|
-
|
|
659
|
-
if (bootstrapResult.populated.length > 0) {
|
|
660
|
-
console.log(` ${c.green('✓')} Populated ${c.bold(String(bootstrapResult.populated.length))} config files`)
|
|
661
|
-
}
|
|
662
|
-
if (bootstrapResult.renamed.length > 0) {
|
|
663
|
-
for (const r of bootstrapResult.renamed) {
|
|
664
|
-
console.log(` ${c.dim('→')} Renamed ${r}`)
|
|
665
|
-
}
|
|
666
|
-
}
|
|
667
|
-
if (bootstrapResult.removed.length > 0) {
|
|
668
|
-
console.log(` ${c.dim('→')} Removed ${bootstrapResult.removed.length} unused template(s)`)
|
|
669
|
-
}
|
|
670
|
-
|
|
671
676
|
// ── Write manifest ──────────────────────────────────────────────
|
|
672
677
|
const manifest = createManifest(pkg.version, ides[0], ides)
|
|
673
678
|
manifest.managedPaths = allManagedPaths
|
package/src/cli/layers.test.ts
CHANGED
|
@@ -11,7 +11,7 @@ import { mkdtempSync, mkdirSync, writeFileSync, readFileSync, rmSync, existsSync
|
|
|
11
11
|
import { tmpdir } from 'node:os'
|
|
12
12
|
import { join, resolve, dirname } from 'node:path'
|
|
13
13
|
import { describe, it, expect, beforeEach, afterEach } from 'vitest'
|
|
14
|
-
import { resolveSources, materialize, usesTeamSources, requiredEnvVars, hasErrors } from './layers.js'
|
|
14
|
+
import { resolveSources, materialize, usesTeamSources, requiredEnvVars, hasErrors, projectContextText, PROJECT_CONTEXT } from './layers.js'
|
|
15
15
|
import { parseTeamConfig, stripJsonc, TeamConfigSchema } from './team-config.js'
|
|
16
16
|
import { satisfies } from './version-range.js'
|
|
17
17
|
import { findInlineSecret } from './policy.js'
|
|
@@ -523,3 +523,74 @@ describe('credential detection, tuned', () => {
|
|
|
523
523
|
expect(findInlineSecret({ env: { DB_PASSWORD: 'x9$Kq2mZ7vLp4wN8' } })).toBe('env.DB_PASSWORD')
|
|
524
524
|
})
|
|
525
525
|
})
|
|
526
|
+
|
|
527
|
+
describe("the project's facts, always loaded", () => {
|
|
528
|
+
let project: string
|
|
529
|
+
beforeEach(() => {
|
|
530
|
+
project = mkdtempSync(join(tmpdir(), 'layers-facts-'))
|
|
531
|
+
mkdirSync(join(project, '.opencastle'), { recursive: true })
|
|
532
|
+
})
|
|
533
|
+
afterEach(() => {
|
|
534
|
+
rmSync(project, { recursive: true, force: true })
|
|
535
|
+
})
|
|
536
|
+
|
|
537
|
+
const write = (text: string) => writeFileSync(join(project, '.opencastle', 'project.instructions.md'), text)
|
|
538
|
+
const resolveHere = () => resolveSources({ pkgRoot, projectRoot: project, stack: noTools })
|
|
539
|
+
|
|
540
|
+
it('compiles .opencastle/project.instructions.md as an instruction every assistant loads', () => {
|
|
541
|
+
write('# Project Context\n\n**demo** — a demo app\n\n## Key Commands\n\n```bash\npnpm test\n```\n')
|
|
542
|
+
const r = resolveHere()
|
|
543
|
+
expect(r.items.get(`instructions/${PROJECT_CONTEXT}`)?.layer).toBe('project')
|
|
544
|
+
const src = materialize(r, pkgRoot)
|
|
545
|
+
try {
|
|
546
|
+
const compiled = readFileSync(join(src.root, 'instructions', `${PROJECT_CONTEXT}.instructions.md`), 'utf8')
|
|
547
|
+
expect(compiled).toContain('**demo** — a demo app')
|
|
548
|
+
expect(compiled).toContain("applyTo: '**'")
|
|
549
|
+
} finally {
|
|
550
|
+
src.dispose()
|
|
551
|
+
}
|
|
552
|
+
})
|
|
553
|
+
|
|
554
|
+
it('leaves out a file that is still the template: there is nothing to load', () => {
|
|
555
|
+
write('```instructions\n# Project Context\n\n<!-- populated by init -->\n\n## Tech Stack\n\n| Layer | Technology |\n|---|---|\n| | |\n\n## Routes\n\n<!-- routes -->\n```\n')
|
|
556
|
+
expect(resolveHere().items.has(`instructions/${PROJECT_CONTEXT}`)).toBe(false)
|
|
557
|
+
})
|
|
558
|
+
|
|
559
|
+
it('keeps what is filled in and drops comments, empty rows and sections, and the to-do list', () => {
|
|
560
|
+
const text = projectContextText([
|
|
561
|
+
'# Project Context',
|
|
562
|
+
'',
|
|
563
|
+
'<!-- Written by init. -->',
|
|
564
|
+
'',
|
|
565
|
+
'## Tech Stack',
|
|
566
|
+
'',
|
|
567
|
+
'| Layer | Technology |',
|
|
568
|
+
'|---|---|',
|
|
569
|
+
'| Framework | Next.js |',
|
|
570
|
+
'| | |',
|
|
571
|
+
'',
|
|
572
|
+
'## Apps',
|
|
573
|
+
'',
|
|
574
|
+
'| App | URL |',
|
|
575
|
+
'|---|---|',
|
|
576
|
+
'| | |',
|
|
577
|
+
'',
|
|
578
|
+
'## Routes',
|
|
579
|
+
'',
|
|
580
|
+
'<!-- none yet -->',
|
|
581
|
+
'',
|
|
582
|
+
'## Still to describe',
|
|
583
|
+
'',
|
|
584
|
+
'- Architecture',
|
|
585
|
+
].join('\n'))
|
|
586
|
+
expect(text).toBe('# Project Context\n\n## Tech Stack\n\n| Layer | Technology |\n|---|---|\n| Framework | Next.js |\n')
|
|
587
|
+
})
|
|
588
|
+
|
|
589
|
+
it('takes the team\'s own instruction of that name over the file', () => {
|
|
590
|
+
write('# Project Context\n\nFROM THE FILE\n')
|
|
591
|
+
mkdirSync(join(project, '.opencastle', 'instructions'), { recursive: true })
|
|
592
|
+
writeFileSync(join(project, '.opencastle', 'instructions', `${PROJECT_CONTEXT}.md`), 'FROM THE TEAM\n')
|
|
593
|
+
const item = resolveHere().items.get(`instructions/${PROJECT_CONTEXT}`)!
|
|
594
|
+
expect(item.path.endsWith(join('instructions', `${PROJECT_CONTEXT}.md`))).toBe(true)
|
|
595
|
+
})
|
|
596
|
+
})
|
package/src/cli/layers.ts
CHANGED
|
@@ -119,6 +119,48 @@ const LAYER_DIR: Record<ContentKind, string> = {
|
|
|
119
119
|
}
|
|
120
120
|
const CORE_DIR: Record<ContentKind, string> = { ...LAYER_DIR, workflows: 'agent-workflows' }
|
|
121
121
|
|
|
122
|
+
/**
|
|
123
|
+
* The project's facts — what `init` read from the code into
|
|
124
|
+
* `.opencastle/project.instructions.md` — compiled as an always-loaded
|
|
125
|
+
* instruction of this name.
|
|
126
|
+
*
|
|
127
|
+
* The general instructions used to say "read `.opencastle/project.instructions.md`
|
|
128
|
+
* before planning", and an agent read it when it decided to: Claude Code's own
|
|
129
|
+
* docs say a file named in words is seen only if the model opens it, and
|
|
130
|
+
* OpenSpec dropped its `project.md` for the same reason. The commands, the
|
|
131
|
+
* stack and the structure are the first thing every assistant's guidance says
|
|
132
|
+
* belongs in the always-loaded file.
|
|
133
|
+
*/
|
|
134
|
+
export const PROJECT_CONTEXT = 'project-context'
|
|
135
|
+
const PROJECT_FACTS_FILE = 'project.instructions.md'
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* What of the project's facts is worth loading every session: no HTML
|
|
139
|
+
* comments, no empty table rows or sections — what an install from before
|
|
140
|
+
* 1.5 left as a template — and not the "Still to describe" list, which is a
|
|
141
|
+
* note for people. Empty when nothing is left.
|
|
142
|
+
*/
|
|
143
|
+
export function projectContextText(raw: string): string {
|
|
144
|
+
let text = raw.replace(/^\uFEFF/, '').replace(/\r\n/g, '\n')
|
|
145
|
+
// Templates before 1.5 wrapped the whole file in a code fence.
|
|
146
|
+
const fenced = /^\s*(`{3,})(?:instructions|markdown|md)?\n([\s\S]*?)\n\1\s*$/.exec(text)
|
|
147
|
+
if (fenced) text = fenced[2]
|
|
148
|
+
text = text.replace(/<!--[\s\S]*?-->/g, '')
|
|
149
|
+
// Rows whose every cell is empty, then tables with no rows left.
|
|
150
|
+
text = text.replace(/^\|(?:\s*\|)+\s*$\n?/gm, '')
|
|
151
|
+
text = text.replace(/^\|[^\n]*\|\n\|(?:[ \t]*:?-{3,}:?[ \t]*\|)+[ \t]*(?:\n(?!\|)|(?![\s\S]))/gm, '')
|
|
152
|
+
const sections = text.split(/\n(?=#{2,3} )/)
|
|
153
|
+
const kept = sections.filter((section, i) => {
|
|
154
|
+
if (i === 0) return true
|
|
155
|
+
const [heading, ...body] = section.split('\n')
|
|
156
|
+
if (/^#{2,3} Still to describe\s*$/.test(heading)) return false
|
|
157
|
+
return body.join('\n').trim().length > 0
|
|
158
|
+
})
|
|
159
|
+
text = kept.join('\n').replace(/\n{3,}/g, '\n\n').trim()
|
|
160
|
+
// A title and nothing under it is not worth a line of context.
|
|
161
|
+
return /^#[^\n]*$/.test(text) || text === '' ? '' : text + '\n'
|
|
162
|
+
}
|
|
163
|
+
|
|
122
164
|
const NAME = /^[A-Za-z0-9][A-Za-z0-9._-]*$/
|
|
123
165
|
const PACKAGE_NAME = /^(@[a-z0-9-~][a-z0-9-._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/
|
|
124
166
|
|
|
@@ -299,6 +341,13 @@ function scanLayer(layer: Layer, projectRoot: string | null): { items: ContentIt
|
|
|
299
341
|
items.push({ kind, name, layer: layer.id, path: join(dir, entry.name), ...(within && { within }) })
|
|
300
342
|
}
|
|
301
343
|
}
|
|
344
|
+
if (layer.kind === 'project') {
|
|
345
|
+
const facts = join(layer.root, PROJECT_FACTS_FILE)
|
|
346
|
+
const taken = items.some((i) => i.kind === 'instructions' && i.name === PROJECT_CONTEXT)
|
|
347
|
+
if (!taken && existsSync(facts) && projectContextText(readFileSync(facts, 'utf8')) !== '') {
|
|
348
|
+
items.push({ kind: 'instructions', name: PROJECT_CONTEXT, layer: layer.id, path: facts })
|
|
349
|
+
}
|
|
350
|
+
}
|
|
302
351
|
return { items, issues }
|
|
303
352
|
}
|
|
304
353
|
|
|
@@ -1113,7 +1162,9 @@ export function materialize(
|
|
|
1113
1162
|
continue
|
|
1114
1163
|
}
|
|
1115
1164
|
const buf = readFileSync(item.path)
|
|
1116
|
-
|
|
1165
|
+
const facts = item.layer === 'project' && item.kind === 'instructions' && item.name === PROJECT_CONTEXT
|
|
1166
|
+
const text = facts ? projectContextText(buf.toString('utf8')) : buf.toString('utf8')
|
|
1167
|
+
writeFileSync(dest, team ? normaliseTeamText(item.kind, item.name, text) : buf)
|
|
1117
1168
|
}
|
|
1118
1169
|
} catch (err) {
|
|
1119
1170
|
rmSync(root, { recursive: true, force: true })
|
package/src/cli/lessons.test.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { tmpdir } from 'node:os'
|
|
|
3
3
|
import { join, resolve } from 'node:path'
|
|
4
4
|
import { describe, it, expect, beforeEach, afterEach } from 'vitest'
|
|
5
5
|
import {
|
|
6
|
+
INDEX_BUDGET_TOKENS,
|
|
6
7
|
INDEX_MARKER,
|
|
7
8
|
checkLessons,
|
|
8
9
|
citedPath,
|
|
@@ -252,3 +253,50 @@ describe('citations against the code', () => {
|
|
|
252
253
|
expect(readLessons(dir).lessons).toHaveLength(1)
|
|
253
254
|
})
|
|
254
255
|
})
|
|
256
|
+
|
|
257
|
+
describe('the size of the index', () => {
|
|
258
|
+
let project: string
|
|
259
|
+
|
|
260
|
+
beforeEach(() => {
|
|
261
|
+
project = mkdtempSync(join(tmpdir(), 'oc-lessons-size-'))
|
|
262
|
+
mkdirSync(join(project, '.opencastle', 'lessons'), { recursive: true })
|
|
263
|
+
})
|
|
264
|
+
|
|
265
|
+
afterEach(() => rmSync(project, { recursive: true, force: true }))
|
|
266
|
+
|
|
267
|
+
function record(count: number, status: Lesson['status'] = 'active'): void {
|
|
268
|
+
const dir = join(project, '.opencastle')
|
|
269
|
+
for (let i = 0; i < count; i++) {
|
|
270
|
+
const id = `2026-10-02-${status}-lesson-${String(i).padStart(3, '0')}`
|
|
271
|
+
writeFileSync(
|
|
272
|
+
join(dir, 'lessons', `${id}.md`),
|
|
273
|
+
renderLesson(lesson({ id, title: `A lesson about one more quirk of the build, number ${i}`, status })),
|
|
274
|
+
)
|
|
275
|
+
}
|
|
276
|
+
syncLessons(dir)
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
it('says nothing about a few dozen lessons', () => {
|
|
280
|
+
record(20)
|
|
281
|
+
const result = checkLessons(project)
|
|
282
|
+
expect(result.warning).toBeUndefined()
|
|
283
|
+
expect(result.detail).toBe('20 lesson(s)')
|
|
284
|
+
})
|
|
285
|
+
|
|
286
|
+
it('suggests merging when the index outgrows its budget', () => {
|
|
287
|
+
record(80)
|
|
288
|
+
const result = checkLessons(project)
|
|
289
|
+
expect(result.warning).toBe(true)
|
|
290
|
+
expect(result.detail).toMatch(/^80 active lessons, ~\d+ tokens in the index agents read before every task$/)
|
|
291
|
+
expect(Number(/~(\d+)/.exec(result.detail ?? '')?.[1])).toBeGreaterThan(INDEX_BUDGET_TOKENS)
|
|
292
|
+
expect(result.fix).toContain('opencastle lesson archive')
|
|
293
|
+
})
|
|
294
|
+
|
|
295
|
+
it('does not count archived lessons against it — archiving cannot shrink them', () => {
|
|
296
|
+
record(80, 'archived')
|
|
297
|
+
record(1)
|
|
298
|
+
const result = checkLessons(project)
|
|
299
|
+
expect(result.warning).toBeUndefined()
|
|
300
|
+
expect(result.detail).toBe('1 lesson(s)')
|
|
301
|
+
})
|
|
302
|
+
})
|
package/src/cli/lessons.ts
CHANGED
|
@@ -235,7 +235,9 @@ export function renderIndex(lessons: Lesson[]): string {
|
|
|
235
235
|
'tool quirk, a convention written down nowhere else. **Read this before you',
|
|
236
236
|
'start work**, then open the lessons that match your task.',
|
|
237
237
|
'',
|
|
238
|
-
|
|
238
|
+
// A path, not a link: the folder is created with the first lesson, and a
|
|
239
|
+
// link to it led nowhere until then.
|
|
240
|
+
'Each lesson is a file in `.opencastle/lessons/`. Add one with',
|
|
239
241
|
'`opencastle lesson --title ... --category ... --severity ... --problem ...`',
|
|
240
242
|
'(and `--cite <path>` for the code it is about). Do not edit this index:',
|
|
241
243
|
'it is rewritten from those files by every `opencastle sync`.',
|
|
@@ -488,6 +490,17 @@ export function staleCitations(projectRoot: string, lessons: Lesson[]): StaleCit
|
|
|
488
490
|
}
|
|
489
491
|
|
|
490
492
|
/** The check `doctor` runs on a project's lessons. */
|
|
493
|
+
/**
|
|
494
|
+
* What the index may cost before doctor suggests pruning it, in tokens.
|
|
495
|
+
*
|
|
496
|
+
* Agents read the index before every task, so each active lesson is paid for
|
|
497
|
+
* on every task, by every agent, whatever the task is. Around forty one-line
|
|
498
|
+
* entries reach this. Past it, the lessons that recur belong in the skill or
|
|
499
|
+
* instruction file they are about — read only by the agents that need them —
|
|
500
|
+
* which is what `archive --into` records.
|
|
501
|
+
*/
|
|
502
|
+
export const INDEX_BUDGET_TOKENS = 2000
|
|
503
|
+
|
|
491
504
|
export function checkLessons(projectRoot: string): {
|
|
492
505
|
ok: boolean
|
|
493
506
|
label: string
|
|
@@ -531,6 +544,19 @@ export function checkLessons(projectRoot: string): {
|
|
|
531
544
|
'with --cite <path> for a file that moved — or retire it with opencastle lesson archive <id> --into <file>',
|
|
532
545
|
}
|
|
533
546
|
}
|
|
547
|
+
// Active lessons only: archiving is the remedy, and it does not shrink the
|
|
548
|
+
// archived list. The lock's chars/4 estimate, inline, so this module stays
|
|
549
|
+
// free of the compiler.
|
|
550
|
+
const indexTokens = Math.ceil(renderIndex(active).length / 4)
|
|
551
|
+
if (indexTokens > INDEX_BUDGET_TOKENS) {
|
|
552
|
+
return {
|
|
553
|
+
ok: true,
|
|
554
|
+
warning: true,
|
|
555
|
+
label,
|
|
556
|
+
detail: `${active.length} active lessons, ~${indexTokens} tokens in the index agents read before every task`,
|
|
557
|
+
fix: 'merge the lessons that recur into the skill or instruction file they are about, then opencastle lesson archive <id> --into <file>',
|
|
558
|
+
}
|
|
559
|
+
}
|
|
534
560
|
const cited = active.filter((l) => l.citations.length > 0).length
|
|
535
561
|
return {
|
|
536
562
|
ok: true,
|
package/src/cli/log.test.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { afterEach, describe, expect, it, vi } from 'vitest'
|
|
|
5
5
|
import log, { LOG_RECORDS, parseLogArgs } from './log.js'
|
|
6
6
|
|
|
7
7
|
const repoRoot = resolve(import.meta.dirname, '..', '..')
|
|
8
|
-
const README = join(repoRoot, 'src', 'orchestrator', '
|
|
8
|
+
const README = join(repoRoot, 'src', 'orchestrator', 'skills', 'observability-logging', 'LOG-SCHEMA.md')
|
|
9
9
|
const SKILL = join(repoRoot, 'src', 'orchestrator', 'skills', 'observability-logging', 'SKILL.md')
|
|
10
10
|
|
|
11
11
|
/** The `opencastle log …` command lines in a document's sh blocks, continuation lines joined. */
|