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
|
@@ -140,6 +140,23 @@ describe('Claude Code: /oc:<name>', () => {
|
|
|
140
140
|
)
|
|
141
141
|
})
|
|
142
142
|
|
|
143
|
+
it('keeps the convoy pipeline steps out of what the model is told it can run', async () => {
|
|
144
|
+
const src = materialize(resolveSources({ pkgRoot, projectRoot: project, stack }), pkgRoot)
|
|
145
|
+
try {
|
|
146
|
+
await (await IDE_ADAPTERS['claude-code']()).install(pkgRoot, project, stack, undefined, src)
|
|
147
|
+
} finally {
|
|
148
|
+
src.dispose()
|
|
149
|
+
}
|
|
150
|
+
const hidden = readdirSync(join(project, '.claude/commands/oc'))
|
|
151
|
+
.filter((f) => readFileSync(join(project, '.claude/commands/oc', f), 'utf8').includes('\ndisable-model-invocation: true\n'))
|
|
152
|
+
.sort()
|
|
153
|
+
// The CLI runs these with their input filled in; nobody chooses them.
|
|
154
|
+
expect(hidden).toEqual(['assess-complexity.md', 'fix-convoy.md', 'fix-prd.md', 'generate-prd.md', 'validate-convoy.md', 'validate-prd.md'])
|
|
155
|
+
// generate-convoy stays listed: the Team Lead plans in the editor by its rules.
|
|
156
|
+
expect(readFileSync(join(project, '.claude/commands/oc/generate-convoy.md'), 'utf8')).not.toContain('disable-model-invocation')
|
|
157
|
+
expect(readFileSync(join(project, '.claude/commands/oc/fix-prd.md'), 'utf8')).toMatch(/^---\ndescription: ".+"\ndisable-model-invocation: true\n---\n/)
|
|
158
|
+
})
|
|
159
|
+
|
|
143
160
|
it('writes each agent as a subagent Claude Code registers: a name and a description', async () => {
|
|
144
161
|
const src = materialize(resolveSources({ pkgRoot, projectRoot: project, stack }), pkgRoot)
|
|
145
162
|
try {
|
|
@@ -460,3 +460,62 @@ describe('kept branches', () => {
|
|
|
460
460
|
expect(task.output).toContain(kept!.branch)
|
|
461
461
|
})
|
|
462
462
|
})
|
|
463
|
+
|
|
464
|
+
describe('what workers report outside their task', () => {
|
|
465
|
+
const answer = (id: string) => [
|
|
466
|
+
`Done ${id}.`,
|
|
467
|
+
'',
|
|
468
|
+
'- [LESSON terminal] Run prisma generate before tsc — the client types are generated, not committed',
|
|
469
|
+
`[ISSUE] src/api.ts: the handler swallows a 404 (seen by ${id})`,
|
|
470
|
+
].join('\n')
|
|
471
|
+
const reports: Behaviour = (task, options) => {
|
|
472
|
+
writeFileSync(join(options.cwd!, `${task.id}.txt`), 'x\n')
|
|
473
|
+
return { success: true, output: answer(task.id), exitCode: 0 }
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
it('adds the lessons to the branch once, as lesson files, and prints the issues', async () => {
|
|
477
|
+
// A project that commits its .opencastle/, as installs do.
|
|
478
|
+
writeFileSync(join(repo, '.gitignore'), '.opencastle/logs\n.opencastle/worktrees\n.opencastle/artifacts\n.opencastle/*.db\n.opencastle/*.db-*\n')
|
|
479
|
+
mkdirSync(join(repo, '.opencastle'), { recursive: true })
|
|
480
|
+
writeFileSync(join(repo, '.opencastle', 'project.instructions.md'), '# Project\n')
|
|
481
|
+
git('add', '-A')
|
|
482
|
+
git('commit', '-qm', 'opencastle')
|
|
483
|
+
let printed = ''
|
|
484
|
+
const result = await engine({
|
|
485
|
+
spec: spec([{ id: 'a', files: ['a.txt'] }, { id: 'b', files: ['b.txt'] }]),
|
|
486
|
+
adapter: stubAdapter(reports),
|
|
487
|
+
output: { write: (s: string) => { printed += s; return true }, isTTY: false },
|
|
488
|
+
}).run()
|
|
489
|
+
|
|
490
|
+
expect(result.status, whyNotDone(result.convoyId)).toBe('done')
|
|
491
|
+
const lessons = filesOn(result.branch!).filter((f) => f.startsWith('.opencastle/lessons/'))
|
|
492
|
+
expect(lessons).toHaveLength(1)
|
|
493
|
+
const file = git('show', `${result.branch}:${lessons[0]}`)
|
|
494
|
+
expect(file).toContain('title: "Run prisma generate before tsc"')
|
|
495
|
+
expect(file).toContain('category: "terminal"')
|
|
496
|
+
expect(file).toMatch(/source: "convoy .+, task a"/)
|
|
497
|
+
expect(git('show', `${result.branch}:.opencastle/LESSONS-LEARNED.md`)).toContain('Run prisma generate before tsc')
|
|
498
|
+
expect(git('log', '-1', '--format=%s', result.branch!)).toBe('convoy: 1 lesson(s) workers reported')
|
|
499
|
+
// Issues are printed, one per task that reported one.
|
|
500
|
+
expect(result.findings?.issues.map((i) => i.taskId).sort()).toEqual(['a', 'b'])
|
|
501
|
+
expect(printed).toContain('Lessons workers reported, added to the branch (1)')
|
|
502
|
+
expect(printed).toContain('the handler swallows a 404 (seen by a)')
|
|
503
|
+
// The user's checkout is untouched.
|
|
504
|
+
expect(git('status', '--porcelain')).toBe('')
|
|
505
|
+
expect(existsSync(join(repo, '.opencastle', 'lessons'))).toBe(false)
|
|
506
|
+
}, 30_000)
|
|
507
|
+
|
|
508
|
+
it('prints the lessons when the branch has no .opencastle/ to add them to', async () => {
|
|
509
|
+
let printed = ''
|
|
510
|
+
const result = await engine({
|
|
511
|
+
spec: spec([{ id: 'a', files: ['a.txt'] }]),
|
|
512
|
+
adapter: stubAdapter(reports),
|
|
513
|
+
output: { write: (s: string) => { printed += s; return true }, isTTY: false },
|
|
514
|
+
}).run()
|
|
515
|
+
expect(result.status, whyNotDone(result.convoyId)).toBe('done')
|
|
516
|
+
expect(filesOn(result.branch!).some((f) => f.startsWith('.opencastle/'))).toBe(false)
|
|
517
|
+
expect(result.findings?.recorded).toEqual([])
|
|
518
|
+
expect(result.findings?.unrecorded.map((l) => l.title)).toEqual(['Run prisma generate before tsc'])
|
|
519
|
+
expect(printed).toContain('Lessons workers reported (1)')
|
|
520
|
+
}, 30_000)
|
|
521
|
+
})
|
package/src/cli/convoy/engine.ts
CHANGED
|
@@ -16,11 +16,13 @@ import {
|
|
|
16
16
|
worktreesDirFor,
|
|
17
17
|
workerBranchName,
|
|
18
18
|
commitAllIn,
|
|
19
|
+
commitPathsIn,
|
|
19
20
|
git,
|
|
20
21
|
BranchInUseError,
|
|
21
22
|
type WorktreeManager,
|
|
22
23
|
} from './worktree.js'
|
|
23
24
|
import { createMergeQueue, MergeConflictError, type MergeQueue } from './merge.js'
|
|
25
|
+
import { collectFindings, recordLessons, LESSON_PATHS, type ReportedIssue, type ReportedLesson } from './findings.js'
|
|
24
26
|
import type {
|
|
25
27
|
TaskRecord, ConvoyStatus, ConvoyTaskStatus, GuardConfig, CircuitBreakerConfig, TaskStep, Hook,
|
|
26
28
|
TaskOutput, TaskInput, TDDGateConfig,
|
|
@@ -121,6 +123,14 @@ export interface ConvoyResult {
|
|
|
121
123
|
logPath?: string
|
|
122
124
|
/** Worker branches kept because their work could not be merged. */
|
|
123
125
|
keptBranches?: Array<{ taskId: string; branch: string }>
|
|
126
|
+
/** What finished tasks reported outside their work. */
|
|
127
|
+
findings?: {
|
|
128
|
+
/** Lessons written to the branch, as `.opencastle/lessons/<id>.md`. */
|
|
129
|
+
recorded: Array<{ id: string; title: string }>
|
|
130
|
+
/** Lessons there was no `.opencastle/` or no git checkout to write to. */
|
|
131
|
+
unrecorded: ReportedLesson[]
|
|
132
|
+
issues: ReportedIssue[]
|
|
133
|
+
}
|
|
124
134
|
}
|
|
125
135
|
|
|
126
136
|
export interface ConvoyEngine {
|
|
@@ -389,15 +399,22 @@ function buildDlqMarkdownEntry(
|
|
|
389
399
|
return { marker, entry }
|
|
390
400
|
}
|
|
391
401
|
|
|
402
|
+
/** The heading a ledger starts with: `init` no longer installs the files empty, so the first entry creates them. */
|
|
403
|
+
const LEDGER_TITLE: Record<string, string> = {
|
|
404
|
+
'AGENT-FAILURES.md': '# Agent Failures\n\nDelegations that failed for good: the dead-letter queue. Format: the **team-lead-reference** skill.\n',
|
|
405
|
+
'DISPUTES.md': '# Disputes\n\nDisagreements review could not settle, for a person to decide. Format: the **team-lead-reference** skill.\n',
|
|
406
|
+
}
|
|
407
|
+
|
|
392
408
|
function appendLedger(repoRoot: string, file: string, marker: string, entry: string): void {
|
|
393
409
|
const mdPath = join(resolve(repoRoot), '.opencastle', file)
|
|
410
|
+
let exists = true
|
|
394
411
|
try {
|
|
395
412
|
if (readFileSync(mdPath, 'utf8').includes(marker)) return
|
|
396
413
|
} catch {
|
|
397
|
-
|
|
414
|
+
exists = false
|
|
398
415
|
}
|
|
399
416
|
mkdirSync(dirname(mdPath), { recursive: true })
|
|
400
|
-
appendFileSync(mdPath, entry)
|
|
417
|
+
appendFileSync(mdPath, (exists ? '' : LEDGER_TITLE[file] ?? '') + entry)
|
|
401
418
|
}
|
|
402
419
|
|
|
403
420
|
/**
|
|
@@ -2008,6 +2025,24 @@ async function runConvoy(ctx: RunContext): Promise<ConvoyResult> {
|
|
|
2008
2025
|
}
|
|
2009
2026
|
}
|
|
2010
2027
|
|
|
2028
|
+
// ── What workers found outside their tasks ───────────────────────────────
|
|
2029
|
+
// Read back from each finished task's stored answer, so a resumed run has
|
|
2030
|
+
// them all; lessons go on the branch, reviewed and merged with the work.
|
|
2031
|
+
const found = collectFindings(store.getTasksByConvoy(convoyId).filter(t => t.status === 'done'))
|
|
2032
|
+
let recorded: Array<{ id: string; title: string }> = []
|
|
2033
|
+
let unrecorded = found.lessons
|
|
2034
|
+
if (found.lessons.length > 0 && wtManager.commitAll && existsSync(join(workRoot, '.opencastle'))) {
|
|
2035
|
+
try {
|
|
2036
|
+
recorded = recordLessons(join(workRoot, '.opencastle'), found.lessons, convoyId)
|
|
2037
|
+
if (recorded.length > 0) {
|
|
2038
|
+
await commitPathsIn(workRoot, LESSON_PATHS, `convoy: ${recorded.length} lesson(s) workers reported`)
|
|
2039
|
+
}
|
|
2040
|
+
unrecorded = []
|
|
2041
|
+
} catch (err) {
|
|
2042
|
+
progress.line(` ${c.yellow('!')} could not record the lessons workers reported: ${firstLine((err as Error).message)}`)
|
|
2043
|
+
}
|
|
2044
|
+
}
|
|
2045
|
+
|
|
2011
2046
|
// ── Final status ──────────────────────────────────────────────────────────
|
|
2012
2047
|
const allTasksFinal = store.getTasksByConvoy(convoyId)
|
|
2013
2048
|
const summary = summarize(allTasksFinal)
|
|
@@ -2044,6 +2079,9 @@ async function runConvoy(ctx: RunContext): Promise<ConvoyResult> {
|
|
|
2044
2079
|
baseRef: ctx.baseRef,
|
|
2045
2080
|
logPath: ndjsonPath,
|
|
2046
2081
|
keptBranches: allTasksFinal.filter(t => t.branch).map(t => ({ taskId: t.id, branch: t.branch! })),
|
|
2082
|
+
...(recorded.length + unrecorded.length + found.issues.length > 0 && {
|
|
2083
|
+
findings: { recorded, unrecorded, issues: found.issues },
|
|
2084
|
+
}),
|
|
2047
2085
|
}
|
|
2048
2086
|
|
|
2049
2087
|
function summarize(tasks: TaskRecord[]): ConvoyResult['summary'] {
|
|
@@ -2141,6 +2179,19 @@ function printSummary(progress: Progress, result: ConvoyResult, store: ConvoySto
|
|
|
2141
2179
|
const cost = formatCost(result.cost.total_cost_usd, Boolean(result.cost.estimated))
|
|
2142
2180
|
lines.push(` Spent: ${formatTokens(result.cost.total_tokens)} tokens${result.cost.estimated && !cost ? ' (est.)' : ''}${cost ? ` · ${cost}` : ''}`)
|
|
2143
2181
|
}
|
|
2182
|
+
const f = result.findings
|
|
2183
|
+
if (f && f.recorded.length > 0) {
|
|
2184
|
+
lines.push(` Lessons workers reported, added to the branch (${f.recorded.length}):`)
|
|
2185
|
+
for (const l of f.recorded) lines.push(` ${c.dim('•')} ${l.title} ${c.dim(`(.opencastle/lessons/${l.id}.md)`)}`)
|
|
2186
|
+
}
|
|
2187
|
+
if (f && f.unrecorded.length > 0) {
|
|
2188
|
+
lines.push(` Lessons workers reported (${f.unrecorded.length}):`)
|
|
2189
|
+
for (const l of f.unrecorded) lines.push(` ${c.dim('•')} ${l.detail} ${c.dim(`(${l.taskId})`)}`)
|
|
2190
|
+
}
|
|
2191
|
+
if (f && f.issues.length > 0) {
|
|
2192
|
+
lines.push(` Issues workers found outside their tasks (${f.issues.length}):`)
|
|
2193
|
+
for (const i of f.issues) lines.push(` ${c.dim('•')} ${i.text} ${c.dim(`(${i.taskId})`)}`)
|
|
2194
|
+
}
|
|
2144
2195
|
lines.push(` Convoy: ${result.convoyId}`)
|
|
2145
2196
|
if (result.branch) {
|
|
2146
2197
|
lines.push(` Branch: ${c.bold(result.branch)}${result.baseRef ? c.dim(` (from ${result.baseRef})`) : ''}`)
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { mkdirSync, mkdtempSync, readFileSync, readdirSync, rmSync, writeFileSync } from 'node:fs'
|
|
2
|
+
import { tmpdir } from 'node:os'
|
|
3
|
+
import { join } from 'node:path'
|
|
4
|
+
import { afterEach, beforeEach, describe, expect, it } from 'vitest'
|
|
5
|
+
import { collectFindings, extractFindings, recordLessons } from './findings.js'
|
|
6
|
+
import { readLessons, renderLesson, syncLessons } from '../lessons.js'
|
|
7
|
+
|
|
8
|
+
describe('reading a worker’s answer', () => {
|
|
9
|
+
it('reads a lesson in each shape a worker writes one', () => {
|
|
10
|
+
const out = [
|
|
11
|
+
'[LESSON terminal] Quote paths in shell commands — the repo has a folder with a space',
|
|
12
|
+
'- [LESSON git] Rebase onto main before pushing -- CI checks the merge result',
|
|
13
|
+
'* **[LESSON]** Run the seed script before the e2e tests',
|
|
14
|
+
'[LESSON: database] Use the pooled URL in serverless functions – direct connections run out',
|
|
15
|
+
'Not a lesson: [LESSON terminal] in the middle of a line',
|
|
16
|
+
].join('\n')
|
|
17
|
+
expect(extractFindings('t1', out).lessons).toEqual([
|
|
18
|
+
{ taskId: 't1', category: 'terminal', title: 'Quote paths in shell commands', detail: 'Quote paths in shell commands — the repo has a folder with a space' },
|
|
19
|
+
{ taskId: 't1', category: 'git', title: 'Rebase onto main before pushing', detail: 'Rebase onto main before pushing -- CI checks the merge result' },
|
|
20
|
+
{ taskId: 't1', category: 'general', title: 'Run the seed script before the e2e tests', detail: 'Run the seed script before the e2e tests' },
|
|
21
|
+
{ taskId: 't1', category: 'database', title: 'Use the pooled URL in serverless functions', detail: 'Use the pooled URL in serverless functions – direct connections run out' },
|
|
22
|
+
])
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
it('files a lesson under general when its category is not one there is', () => {
|
|
26
|
+
expect(extractFindings('t1', '[LESSON tooling] Use pnpm, not npm').lessons[0].category).toBe('general')
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
it('reads issues', () => {
|
|
30
|
+
expect(extractFindings('t2', 'ok\n- [ISSUE] src/a.ts: off by one in the pager\n[ISSUE]\n').issues).toEqual([
|
|
31
|
+
{ taskId: 't2', text: 'src/a.ts: off by one in the pager' },
|
|
32
|
+
])
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
it('keeps a lesson two workers reported once, and every issue', () => {
|
|
36
|
+
const found = collectFindings([
|
|
37
|
+
{ id: 'a', output: '[LESSON] Run codegen first\n[ISSUE] x' },
|
|
38
|
+
{ id: 'b', output: '[LESSON] run codegen first — again\n[ISSUE] y' },
|
|
39
|
+
{ id: 'c', output: null },
|
|
40
|
+
])
|
|
41
|
+
expect(found.lessons.map((l) => l.taskId)).toEqual(['a'])
|
|
42
|
+
expect(found.issues.map((i) => i.text)).toEqual(['x', 'y'])
|
|
43
|
+
})
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
describe('recording the lessons', () => {
|
|
47
|
+
let dir: string
|
|
48
|
+
|
|
49
|
+
beforeEach(() => {
|
|
50
|
+
dir = join(mkdtempSync(join(tmpdir(), 'oc-findings-')), '.opencastle')
|
|
51
|
+
mkdirSync(dir)
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
afterEach(() => rmSync(join(dir, '..'), { recursive: true, force: true }))
|
|
55
|
+
|
|
56
|
+
const reported = (title: string, detail = title) => ({ taskId: 'a', category: 'terminal', title, detail })
|
|
57
|
+
|
|
58
|
+
it('writes a lesson file with where it came from, and lists it in the index', () => {
|
|
59
|
+
const written = recordLessons(dir, [reported('Run codegen first', 'Run codegen first — types are generated')], 'cv-1')
|
|
60
|
+
expect(written).toHaveLength(1)
|
|
61
|
+
const [lesson] = readLessons(dir).lessons
|
|
62
|
+
expect(lesson).toMatchObject({ title: 'Run codegen first', category: 'terminal', severity: 'medium', source: 'convoy cv-1, task a', status: 'active' })
|
|
63
|
+
expect(lesson.body).toBe('**Problem:** Run codegen first — types are generated')
|
|
64
|
+
expect(readFileSync(join(dir, 'LESSONS-LEARNED.md'), 'utf8')).toContain('Run codegen first')
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
it('skips a lesson the project already has, so a resumed run adds nothing twice', () => {
|
|
68
|
+
mkdirSync(join(dir, 'lessons'))
|
|
69
|
+
writeFileSync(join(dir, 'lessons', 'x.md'), renderLesson({
|
|
70
|
+
id: 'x', title: 'Run codegen first', category: 'terminal', severity: 'high', added: '2026-10-01', citations: [], status: 'active', body: '**Problem:** p',
|
|
71
|
+
}))
|
|
72
|
+
syncLessons(dir)
|
|
73
|
+
expect(recordLessons(dir, [reported('run codegen first')], 'cv-1')).toEqual([])
|
|
74
|
+
expect(readdirSync(join(dir, 'lessons'))).toEqual(['x.md'])
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
it('skips a lesson that looks like it holds a credential', () => {
|
|
78
|
+
const key = ['AKIA', 'IOSFODNN7', 'EXAMPLE'].join('')
|
|
79
|
+
expect(recordLessons(dir, [reported('Use the deploy key', `Use the deploy key ${key}`)], 'cv-1')).toEqual([])
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
it('writes nothing where there is no .opencastle/', () => {
|
|
83
|
+
rmSync(dir, { recursive: true })
|
|
84
|
+
expect(recordLessons(dir, [reported('Run codegen first')], 'cv-1')).toEqual([])
|
|
85
|
+
})
|
|
86
|
+
})
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What workers found outside their task: lessons for the next agent, and bugs.
|
|
3
|
+
*
|
|
4
|
+
* A worker may not write under `.opencastle/` — several run at once, and each
|
|
5
|
+
* such edit is a change outside its task that review sends back — so it was
|
|
6
|
+
* told to put a lesson or an issue "in your answer instead". Nothing read the
|
|
7
|
+
* answer for them, and every one was lost. Workers now mark them on a line of
|
|
8
|
+
* their own; the engine reads them back from each finished task's stored
|
|
9
|
+
* output when the run ends, so a resumed run loses none either.
|
|
10
|
+
*/
|
|
11
|
+
import { existsSync, mkdirSync, writeFileSync } from 'node:fs'
|
|
12
|
+
import { join } from 'node:path'
|
|
13
|
+
import { scanForSecrets } from '../secret-scan.js'
|
|
14
|
+
import {
|
|
15
|
+
LESSONS_DIR,
|
|
16
|
+
LESSONS_INDEX,
|
|
17
|
+
isLessonCategory,
|
|
18
|
+
lessonBody,
|
|
19
|
+
newLessonId,
|
|
20
|
+
readLessons,
|
|
21
|
+
renderLesson,
|
|
22
|
+
syncLessons,
|
|
23
|
+
today,
|
|
24
|
+
} from '../lessons.js'
|
|
25
|
+
|
|
26
|
+
export interface ReportedLesson {
|
|
27
|
+
taskId: string
|
|
28
|
+
category: string
|
|
29
|
+
title: string
|
|
30
|
+
detail: string
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface ReportedIssue {
|
|
34
|
+
taskId: string
|
|
35
|
+
text: string
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface Findings {
|
|
39
|
+
lessons: ReportedLesson[]
|
|
40
|
+
issues: ReportedIssue[]
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** A marker on a line of its own, optionally a list item or in bold. */
|
|
44
|
+
const LESSON = /^[ \t]*(?:[-*][ \t]+)?\**\[LESSON(?:[ \t:]+([a-z-]+))?\]\**[ \t]*(.+)$/gm
|
|
45
|
+
const ISSUE = /^[ \t]*(?:[-*][ \t]+)?\**\[ISSUE\]\**[ \t]*(.+)$/gm
|
|
46
|
+
|
|
47
|
+
/** The lesson and issue lines in one worker's answer. */
|
|
48
|
+
export function extractFindings(taskId: string, output: string): Findings {
|
|
49
|
+
const lessons: ReportedLesson[] = []
|
|
50
|
+
for (const m of output.matchAll(LESSON)) {
|
|
51
|
+
const text = m[2].trim()
|
|
52
|
+
// `<what to do> — <why>`: the first half names the lesson in the index.
|
|
53
|
+
const split = /\s+(?:—|--|–)\s+/.exec(text)
|
|
54
|
+
const title = (split ? text.slice(0, split.index) : text).replace(/[.:]$/, '').trim()
|
|
55
|
+
if (!title) continue
|
|
56
|
+
const category = m[1] && isLessonCategory(m[1]) ? m[1] : 'general'
|
|
57
|
+
lessons.push({ taskId, category, title, detail: text })
|
|
58
|
+
}
|
|
59
|
+
const issues = [...output.matchAll(ISSUE)].map((m) => ({ taskId, text: m[1].trim() })).filter((i) => i.text)
|
|
60
|
+
return { lessons, issues }
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** Every finding across the tasks, a lesson reported twice kept once. */
|
|
64
|
+
export function collectFindings(tasks: Array<{ id: string; output: string | null }>): Findings {
|
|
65
|
+
const lessons: ReportedLesson[] = []
|
|
66
|
+
const issues: ReportedIssue[] = []
|
|
67
|
+
const seen = new Set<string>()
|
|
68
|
+
for (const t of tasks) {
|
|
69
|
+
const found = extractFindings(t.id, t.output ?? '')
|
|
70
|
+
for (const l of found.lessons) {
|
|
71
|
+
const key = l.title.toLowerCase()
|
|
72
|
+
if (seen.has(key)) continue
|
|
73
|
+
seen.add(key)
|
|
74
|
+
lessons.push(l)
|
|
75
|
+
}
|
|
76
|
+
issues.push(...found.issues)
|
|
77
|
+
}
|
|
78
|
+
return { lessons, issues }
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** What `recordLessons` changes, for the commit that adds them: the files and the index. */
|
|
82
|
+
export const LESSON_PATHS = [`.opencastle/${LESSONS_DIR}`, `.opencastle/${LESSONS_INDEX}`]
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Write each lesson as a file under `<customizationsDir>/lessons/` and rewrite
|
|
86
|
+
* the index. Skips one an active lesson already has the title of — a resumed
|
|
87
|
+
* run reads the same answers again — and one that looks like it holds a
|
|
88
|
+
* credential, since lessons are committed. Nothing is written when there is no
|
|
89
|
+
* `.opencastle/` to write to.
|
|
90
|
+
*/
|
|
91
|
+
export function recordLessons(
|
|
92
|
+
customizationsDir: string,
|
|
93
|
+
lessons: ReportedLesson[],
|
|
94
|
+
convoyId: string,
|
|
95
|
+
): Array<{ id: string; title: string }> {
|
|
96
|
+
if (lessons.length === 0 || !existsSync(customizationsDir)) return []
|
|
97
|
+
const existing = readLessons(customizationsDir).lessons
|
|
98
|
+
const titles = new Set(existing.filter((l) => l.status === 'active').map((l) => l.title.toLowerCase()))
|
|
99
|
+
const taken = new Set(existing.map((l) => l.id))
|
|
100
|
+
const date = today()
|
|
101
|
+
const written: Array<{ id: string; title: string }> = []
|
|
102
|
+
for (const r of lessons) {
|
|
103
|
+
if (titles.has(r.title.toLowerCase())) continue
|
|
104
|
+
const id = newLessonId(r.title, date, taken)
|
|
105
|
+
const text = renderLesson({
|
|
106
|
+
id,
|
|
107
|
+
title: r.title,
|
|
108
|
+
category: r.category,
|
|
109
|
+
// Nobody has checked a worker's lesson yet: `medium` until the person
|
|
110
|
+
// reviewing the branch says otherwise.
|
|
111
|
+
severity: 'medium',
|
|
112
|
+
added: date,
|
|
113
|
+
citations: [],
|
|
114
|
+
status: 'active',
|
|
115
|
+
source: `convoy ${convoyId}, task ${r.taskId}`,
|
|
116
|
+
body: lessonBody({ problem: r.detail }),
|
|
117
|
+
})
|
|
118
|
+
if (!scanForSecrets(text, `${LESSONS_DIR}/${id}.md`).clean) continue
|
|
119
|
+
mkdirSync(join(customizationsDir, LESSONS_DIR), { recursive: true })
|
|
120
|
+
writeFileSync(join(customizationsDir, LESSONS_DIR, `${id}.md`), text)
|
|
121
|
+
taken.add(id)
|
|
122
|
+
titles.add(r.title.toLowerCase())
|
|
123
|
+
written.push({ id, title: r.title })
|
|
124
|
+
}
|
|
125
|
+
// Also moves an old single-file log into lesson files, which is why the
|
|
126
|
+
// commit takes the whole folder and not only the files written here.
|
|
127
|
+
if (written.length > 0) syncLessons(customizationsDir)
|
|
128
|
+
return written
|
|
129
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { normalizePath, pathsOverlap } from './partition.js'
|
|
2
2
|
import type { ConvoyStore } from './store.js'
|
|
3
3
|
import { listArtifacts, type ArtifactRef } from './artifacts.js'
|
|
4
|
+
import { LESSON_CATEGORIES } from '../lessons.js'
|
|
4
5
|
|
|
5
6
|
// ── Interfaces ────────────────────────────────────────────────────────────────
|
|
6
7
|
|
|
@@ -72,7 +73,7 @@ export function buildSharedContext(opts: {
|
|
|
72
73
|
'## Rules',
|
|
73
74
|
'- Do your task and nothing else. Change only the files your task lists; if it needs a change elsewhere, say so in your answer instead of making it.',
|
|
74
75
|
'- Leave committing to the convoy. It commits your work when you finish.',
|
|
75
|
-
|
|
76
|
+
`- Follow the project's own conventions and instruction files, with one exception: do not edit anything under \`.opencastle/\` (KNOWN-ISSUES.md, LESSONS-LEARNED.md, logs) even where those instructions ask you to. Several agents run at once, and each such edit is a change outside your task that review sends back. Report what you found in your answer instead, each on a line of its own: \`[LESSON <category>] <what to do> — <why>\` for what the next agent on this project should know before starting (a command that failed and the one that worked, a tool quirk, a convention written down nowhere else), with <category> one of ${LESSON_CATEGORIES.join(', ')}; and \`[ISSUE] <file or area>: <what is wrong>\` for a bug outside your task. The convoy records them.`,
|
|
76
77
|
`- For long output (a report, a data dump), write it to a file under ${opts.artifactsDir}<your task id>/ and mention it in your answer as \`[ARTIFACT: <file name>] <one-line summary>\`.`,
|
|
77
78
|
].join('\n')
|
|
78
79
|
}
|
|
@@ -160,6 +160,18 @@ export async function commitAllIn(cwd: string, message: string): Promise<boolean
|
|
|
160
160
|
return true
|
|
161
161
|
}
|
|
162
162
|
|
|
163
|
+
/**
|
|
164
|
+
* `commitAllIn`, for the named paths only: what the convoy wrote itself, not
|
|
165
|
+
* whatever a gate left in the checkout.
|
|
166
|
+
*/
|
|
167
|
+
export async function commitPathsIn(cwd: string, paths: string[], message: string): Promise<boolean> {
|
|
168
|
+
await git(['add', '--', ...paths], cwd)
|
|
169
|
+
const staged = await git(['diff', '--cached', '--name-only', '--', ...paths], cwd)
|
|
170
|
+
if (!staged.trim()) return false
|
|
171
|
+
await gitWithIdentity(['commit', '-q', '--no-verify', '-m', message, '--', ...paths], cwd)
|
|
172
|
+
return true
|
|
173
|
+
}
|
|
174
|
+
|
|
163
175
|
/** `git merge` with the convoy's fallback identity. */
|
|
164
176
|
export async function mergeIn(cwd: string, args: string[]): Promise<string> {
|
|
165
177
|
return gitWithIdentity(['merge', ...args], cwd)
|
package/src/cli/detect.ts
CHANGED
|
@@ -196,7 +196,7 @@ const AUTH: DetectionRule[] = [
|
|
|
196
196
|
];
|
|
197
197
|
|
|
198
198
|
// Mapping of npm package names to detection labels
|
|
199
|
-
const PACKAGE_DETECTIONS: Record<string, { category: string; label: string }> = {
|
|
199
|
+
export const PACKAGE_DETECTIONS: Record<string, { category: string; label: string }> = {
|
|
200
200
|
'next': { category: 'frameworks', label: 'next' },
|
|
201
201
|
'nuxt': { category: 'frameworks', label: 'nuxt' },
|
|
202
202
|
'astro': { category: 'frameworks', label: 'astro' },
|
|
@@ -236,6 +236,48 @@ describe('shipped content instructs only commands that exist', () => {
|
|
|
236
236
|
.map((x) => `${x.rel}: ${x.hit}`)
|
|
237
237
|
expect(offenders).toEqual([])
|
|
238
238
|
})
|
|
239
|
+
|
|
240
|
+
// Other people's tools, held to a positive list the way our own commands are.
|
|
241
|
+
// `npx npm-dedupe` (no such package), `rg --type tsx` (ripgrep has no such
|
|
242
|
+
// type; `ts` covers .tsx) and `npx email dev` (the `email` binary is in
|
|
243
|
+
// `react-email`, which the skill never installed) each shipped to every user
|
|
244
|
+
// because nothing asked whether they run. A package joins this list once
|
|
245
|
+
// `npm view <name> bin` shows the binary the content calls, or once the skill
|
|
246
|
+
// that calls it says to install it.
|
|
247
|
+
const NPX_PACKAGES = new Set([
|
|
248
|
+
'opencastle', 'nx', 'playwright', 'cypress', 'jest', 'eslint', 'prisma', 'convex', 'expo',
|
|
249
|
+
'create-expo-module', 'react-email', 'source-map-explorer', 'markdown-link-check',
|
|
250
|
+
'license-checker', '@arethetypeswrong/cli', '@sentry/wizard', '@delorenj/mcp-server-trello',
|
|
251
|
+
])
|
|
252
|
+
/** ripgrep's own names, from `rg --type-list` — the ones a skill could want. */
|
|
253
|
+
const RG_TYPES = new Set([
|
|
254
|
+
'ts', 'typescript', 'js', 'json', 'css', 'html', 'md', 'markdown', 'py', 'python', 'go', 'rust',
|
|
255
|
+
'java', 'kotlin', 'swift', 'ruby', 'php', 'sh', 'sql', 'yaml', 'toml', 'svelte', 'vue', 'graphql',
|
|
256
|
+
'docker', 'c', 'cpp', 'csharp',
|
|
257
|
+
])
|
|
258
|
+
const npxPackages = (text: string): string[] =>
|
|
259
|
+
[...text.matchAll(/\bnpx (?:-y |--yes )?((?:@[a-z0-9-]+\/)?[a-z0-9][a-z0-9._-]*)/g)].map((m) => m[1])
|
|
260
|
+
const rgTypes = (text: string): string[] =>
|
|
261
|
+
[...text.matchAll(/\brg\b[^`\n|]*?\s(?:--type(?:-not)?[ =]|-[tT] ?)([a-z]+)/g)].map((m) => m[1])
|
|
262
|
+
|
|
263
|
+
it('reads the package and the ripgrep type from the lines that shipped broken', () => {
|
|
264
|
+
expect(npxPackages('Preview locally with `npx email dev`.')).toEqual(['email'])
|
|
265
|
+
expect(npxPackages('`npx -y @sentry/wizard@latest -i nextjs`')).toEqual(['@sentry/wizard'])
|
|
266
|
+
expect(rgTypes('`rg -n "useEffect" --type tsx src/`')).toEqual(['tsx'])
|
|
267
|
+
expect(rgTypes('`rg -tts "x" src-tests/`')).toEqual(['ts'])
|
|
268
|
+
})
|
|
269
|
+
|
|
270
|
+
it('runs through npx only packages someone has checked', () => {
|
|
271
|
+
const offenders = instructionFiles.flatMap((f) =>
|
|
272
|
+
npxPackages(f.text).filter((p) => !NPX_PACKAGES.has(p)).map((p) => `${f.rel}: npx ${p}`))
|
|
273
|
+
expect(offenders).toEqual([])
|
|
274
|
+
})
|
|
275
|
+
|
|
276
|
+
it('filters ripgrep only by types ripgrep has', () => {
|
|
277
|
+
const offenders = instructionFiles.flatMap((f) =>
|
|
278
|
+
rgTypes(f.text).filter((t) => !RG_TYPES.has(t)).map((t) => `${f.rel}: rg --type ${t}`))
|
|
279
|
+
expect(offenders).toEqual([])
|
|
280
|
+
})
|
|
239
281
|
})
|
|
240
282
|
|
|
241
283
|
/**
|
package/src/cli/doctor.test.ts
CHANGED
|
@@ -3,7 +3,8 @@ import { mkdtempSync, realpathSync } from 'node:fs'
|
|
|
3
3
|
import { mkdirSync, writeFileSync, rmSync } from 'node:fs'
|
|
4
4
|
import { join } from 'node:path'
|
|
5
5
|
import { tmpdir } from 'node:os'
|
|
6
|
-
import { runDoctorCheck, checkMcpFromPaths } from './doctor.js'
|
|
6
|
+
import { runDoctorCheck, checkMcpFromPaths, checkProjectContext, checkSkillMatrix } from './doctor.js'
|
|
7
|
+
import { LOCKFILE_VERSION } from './lock.js'
|
|
7
8
|
import { IDE_ADAPTERS } from './adapters/index.js'
|
|
8
9
|
import type { DoctorCheck } from './types.js'
|
|
9
10
|
|
|
@@ -172,6 +173,105 @@ describe('checkMcpFromPaths', () => {
|
|
|
172
173
|
})
|
|
173
174
|
})
|
|
174
175
|
|
|
176
|
+
// ── checkProjectContext ───────────────────────────────────────
|
|
177
|
+
|
|
178
|
+
describe('checkProjectContext', () => {
|
|
179
|
+
let tmpDir: string
|
|
180
|
+
|
|
181
|
+
beforeEach(() => {
|
|
182
|
+
tmpDir = makeTempDir()
|
|
183
|
+
mkdirSync(join(tmpDir, '.opencastle', 'stack'), { recursive: true })
|
|
184
|
+
})
|
|
185
|
+
|
|
186
|
+
afterEach(() => {
|
|
187
|
+
rmSync(tmpDir, { recursive: true, force: true })
|
|
188
|
+
})
|
|
189
|
+
|
|
190
|
+
const facts = (text: string) => writeFileSync(join(tmpDir, '.opencastle', 'project.instructions.md'), text)
|
|
191
|
+
|
|
192
|
+
it('warns when the file is missing, and says how to write it', async () => {
|
|
193
|
+
const result = await checkProjectContext(tmpDir)
|
|
194
|
+
expect(result.warning).toBe(true)
|
|
195
|
+
expect(result.fix).toContain('bootstrap-customizations')
|
|
196
|
+
})
|
|
197
|
+
|
|
198
|
+
it('warns when the file is still the template', async () => {
|
|
199
|
+
facts('# Project Context\n\n| Layer | Technology |\n|---|---|\n| | |\n\n| Path | Purpose |\n|---|---|\n| | |\n\nTODO: verify the dev port\n')
|
|
200
|
+
const result = await checkProjectContext(tmpDir)
|
|
201
|
+
expect(result.ok).toBe(true)
|
|
202
|
+
expect(result.warning).toBe(true)
|
|
203
|
+
expect(result.detail).toContain('still the template')
|
|
204
|
+
})
|
|
205
|
+
|
|
206
|
+
it('counts what is left to describe across the facts and the stack files, without warning', async () => {
|
|
207
|
+
facts('# Project Context\n\n## Commands\n\n| Task | Command |\n|---|---|\n| Test | `npm test` |\n\n## Still to describe\n\n- Deploy target\n- Dev ports\n')
|
|
208
|
+
writeFileSync(join(tmpDir, '.opencastle', 'stack', 'testing.md'), '# Testing\n\n## Still to describe\n\n- E2E setup\n\n## Notes\n\n- not counted\n')
|
|
209
|
+
const result = await checkProjectContext(tmpDir)
|
|
210
|
+
expect(result.warning).toBeFalsy()
|
|
211
|
+
expect(result.detail).toContain('3 still to describe')
|
|
212
|
+
})
|
|
213
|
+
|
|
214
|
+
it('reports a fully written file as written', async () => {
|
|
215
|
+
facts('# Project Context\n\n## Commands\n\n| Task | Command |\n|---|---|\n| Test | `npm test` |\n')
|
|
216
|
+
const result = await checkProjectContext(tmpDir)
|
|
217
|
+
expect(result).toMatchObject({ ok: true, detail: 'written' })
|
|
218
|
+
expect(result.warning).toBeFalsy()
|
|
219
|
+
})
|
|
220
|
+
})
|
|
221
|
+
|
|
222
|
+
// ── checkSkillMatrix ──────────────────────────────────────────
|
|
223
|
+
|
|
224
|
+
describe('checkSkillMatrix', () => {
|
|
225
|
+
let tmpDir: string
|
|
226
|
+
|
|
227
|
+
beforeEach(() => {
|
|
228
|
+
tmpDir = makeTempDir()
|
|
229
|
+
mkdirSync(join(tmpDir, '.opencastle', 'agents'), { recursive: true })
|
|
230
|
+
})
|
|
231
|
+
|
|
232
|
+
afterEach(() => {
|
|
233
|
+
rmSync(tmpDir, { recursive: true, force: true })
|
|
234
|
+
})
|
|
235
|
+
|
|
236
|
+
const matrix = (bindings: Record<string, { entries: Array<{ skill: string }> }>) =>
|
|
237
|
+
writeFileSync(join(tmpDir, '.opencastle', 'agents', 'skill-matrix.json'), JSON.stringify({ bindings }))
|
|
238
|
+
const lock = (skills: string[]) =>
|
|
239
|
+
writeFileSync(join(tmpDir, '.opencastle', 'lock.json'), JSON.stringify({
|
|
240
|
+
lockfileVersion: LOCKFILE_VERSION,
|
|
241
|
+
opencastle: '0.0.0',
|
|
242
|
+
targets: [],
|
|
243
|
+
integrations: [],
|
|
244
|
+
layers: [],
|
|
245
|
+
content: Object.fromEntries(skills.map((s) => [`skills/${s}`, { sha: '000000000000' }])),
|
|
246
|
+
mcp: {},
|
|
247
|
+
context: { tokens: 0 },
|
|
248
|
+
}))
|
|
249
|
+
|
|
250
|
+
it('does not warn about slots this stack has nothing for', async () => {
|
|
251
|
+
matrix({ cms: { entries: [] }, payments: { entries: [] }, framework: { entries: [{ skill: 'nextjs-patterns' }] } })
|
|
252
|
+
lock(['nextjs-patterns'])
|
|
253
|
+
const result = await checkSkillMatrix(tmpDir)
|
|
254
|
+
expect(result.warning).toBeFalsy()
|
|
255
|
+
expect(result.detail).toContain('1 of 3 capability slots bound')
|
|
256
|
+
})
|
|
257
|
+
|
|
258
|
+
it('warns about a slot bound to a skill that is not compiled', async () => {
|
|
259
|
+
matrix({ framework: { entries: [{ skill: 'nextjs-patterns' }] }, cms: { entries: [{ skill: 'sanity-cms' }] } })
|
|
260
|
+
lock(['nextjs-patterns'])
|
|
261
|
+
const result = await checkSkillMatrix(tmpDir)
|
|
262
|
+
expect(result.ok).toBe(true)
|
|
263
|
+
expect(result.warning).toBe(true)
|
|
264
|
+
expect(result.detail).toContain('cms → sanity-cms')
|
|
265
|
+
expect(result.detail).not.toContain('nextjs-patterns')
|
|
266
|
+
})
|
|
267
|
+
|
|
268
|
+
it('says nothing about bindings when there is no lock to compare against', async () => {
|
|
269
|
+
matrix({ cms: { entries: [{ skill: 'sanity-cms' }] } })
|
|
270
|
+
const result = await checkSkillMatrix(tmpDir)
|
|
271
|
+
expect(result.warning).toBeFalsy()
|
|
272
|
+
})
|
|
273
|
+
})
|
|
274
|
+
|
|
175
275
|
// ── adapter getDoctorChecks ───────────────────────────────────
|
|
176
276
|
|
|
177
277
|
describe('vscode adapter getDoctorChecks', () => {
|