@jeiemgi/cckit 0.8.0 → 0.10.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/.claude-plugin/plugin.json +1 -1
- package/AGENTS.md +169 -21
- package/README.md +505 -35
- package/SECURITY.md +5 -0
- package/bin/cckit +189 -20
- package/cckit.config.json +1 -1
- package/commands/kit-doctor.md +13 -5
- package/commands/kit-export-project.md +0 -2
- package/commands/kit-export-training.md +6 -9
- package/commands/kit-init.md +43 -13
- package/commands/kit-routines.md +1 -1
- package/commands/kit-update.md +11 -6
- package/databases/supabase/guide.html +106 -0
- package/databases/supabase/nextjs/lib/supabase/client.ts +9 -0
- package/databases/supabase/nextjs/lib/supabase/server.ts +29 -0
- package/databases/supabase.json +70 -0
- package/integrations/emil-design-eng.json +41 -0
- package/integrations/graft.json +81 -0
- package/integrations/impeccable.json +42 -0
- package/integrations/integration.schema.json +215 -0
- package/integrations/lavish.json +43 -0
- package/integrations/mempalace.json +28 -0
- package/integrations/mlx-lm.json +32 -0
- package/integrations/web-design-guidelines.json +42 -0
- package/kit.config.schema.json +183 -5
- package/package.json +4 -1
- package/profiles/automation.json +7 -1
- package/profiles/content.json +10 -2
- package/profiles/marketing.json +57 -0
- package/profiles/minimal.json +7 -1
- package/profiles/research.json +7 -1
- package/profiles/software.json +7 -1
- package/recipes/nextjs-shadcn.json +49 -0
- package/scripts/agent-skills-external.txt +45 -0
- package/scripts/agent-skills-lint-test.sh +131 -0
- package/scripts/agent-skills-lint.sh +115 -0
- package/scripts/agent-template-lint-test.sh +42 -0
- package/scripts/agent-template-lint.sh +58 -0
- package/scripts/annotate-setup.sh +1 -1
- package/scripts/autopilot-run-test.sh +338 -0
- package/scripts/autopilot-run.sh +448 -0
- package/scripts/autopilot-test.sh +8 -0
- package/scripts/autopilot.sh +10 -1
- package/scripts/benchmark/benchmark-test.sh +85 -0
- package/scripts/benchmark/checkpoint-test.sh +314 -0
- package/scripts/benchmark/checkpoint.sh +408 -0
- package/scripts/benchmark/lib/model.sh +31 -6
- package/scripts/benchmark/report.sh +17 -2
- package/scripts/benchmark/run-quality.sh +36 -10
- package/scripts/benchmark/verb-timings-test.sh +124 -0
- package/scripts/benchmark/verb-timings.sh +149 -0
- package/scripts/check.sh +29 -19
- package/scripts/content-skills-test.sh +144 -0
- package/scripts/copilot-loop-test.sh +25 -0
- package/scripts/database-supabase-test.sh +121 -0
- package/scripts/docs-marketing-words-test.sh +73 -0
- package/scripts/docs-record-tables-test.sh +72 -0
- package/scripts/guard-raw-git-ops-test.sh +8 -0
- package/scripts/hook-adapter-test.sh +193 -0
- package/scripts/init-content-test.sh +225 -0
- package/scripts/init-guided-test.sh +474 -0
- package/scripts/init-recipes-test.sh +104 -0
- package/scripts/init-upgrade-test.sh +341 -2
- package/scripts/init.sh +746 -95
- package/scripts/instruction-budget-baseline.txt +8 -0
- package/scripts/instruction-budget-lint-test.sh +166 -0
- package/scripts/instruction-budget-lint.sh +219 -0
- package/scripts/integrations-check-test.sh +200 -0
- package/scripts/integrations-check.sh +157 -0
- package/scripts/kit-add-test.sh +214 -0
- package/scripts/kit-add.sh +305 -5
- package/scripts/kit-adopt-test.sh +16 -0
- package/scripts/kit-adopt.sh +3 -2
- package/scripts/kit-digest.sh +2 -2
- package/scripts/kit-doctor-test.sh +293 -0
- package/scripts/kit-doctor.sh +272 -140
- package/scripts/kit-export-project-test.sh +3 -3
- package/scripts/kit-remove-test.sh +19 -0
- package/scripts/kit-routines.sh +2 -2
- package/scripts/kit-self-update.sh +1 -1
- package/scripts/kit-version-check-test.sh +4 -0
- package/scripts/kit-version-check.sh +4 -2
- package/scripts/knowledge-lint.sh +4 -4
- package/scripts/leak-fence-test.sh +89 -0
- package/scripts/lib/adapter-select-test.sh +136 -0
- package/scripts/lib/adapter-select.sh +158 -0
- package/scripts/lib/agent-def-test.sh +69 -0
- package/scripts/lib/agent-def.sh +106 -0
- package/scripts/lib/agent-launch-test.sh +212 -0
- package/scripts/lib/agent-launch.sh +335 -0
- package/scripts/lib/board-view-test.sh +11 -0
- package/scripts/lib/board-view.sh +42 -26
- package/scripts/lib/branch-owner-test.sh +26 -0
- package/scripts/lib/branch-owner.sh +16 -9
- package/scripts/lib/captain-test.sh +105 -0
- package/scripts/lib/captain.sh +87 -8
- package/scripts/lib/codex-hooks-test.sh +100 -0
- package/scripts/lib/codex-hooks.sh +69 -0
- package/scripts/lib/commitlint.sh +1 -1
- package/scripts/lib/content-kinds-gc-test.sh +88 -0
- package/scripts/lib/copilot-test.sh +70 -4
- package/scripts/lib/copilot.sh +66 -14
- package/scripts/lib/effort-dispatch-test.sh +3 -3
- package/scripts/lib/effort-metrics-test.sh +178 -1
- package/scripts/lib/effort-metrics.sh +188 -35
- package/scripts/lib/effort-ops-test.sh +217 -7
- package/scripts/lib/effort-ops.sh +281 -49
- package/scripts/lib/effort-parity-test.sh +49 -13
- package/scripts/lib/effort-plan-test.sh +337 -0
- package/scripts/lib/effort-plan.sh +200 -23
- package/scripts/lib/effort-slug.sh +16 -2
- package/scripts/lib/effort.sh +67 -12
- package/scripts/lib/errors-header-test.sh +1 -1
- package/scripts/lib/gh-project-test.sh +35 -1
- package/scripts/lib/gh-project.sh +37 -16
- package/scripts/lib/gh-rest-test.sh +330 -0
- package/scripts/lib/gh-rest.sh +304 -0
- package/scripts/lib/hook-refresh.sh +1 -1
- package/scripts/lib/init-github.sh +412 -0
- package/scripts/lib/init-guide.sh +630 -0
- package/scripts/lib/integration-install-test.sh +343 -0
- package/scripts/lib/integration-install.sh +257 -0
- package/scripts/lib/integrations-test.sh +366 -0
- package/scripts/lib/integrations.sh +244 -0
- package/scripts/lib/kinds-test.sh +125 -0
- package/scripts/lib/kinds.sh +66 -0
- package/scripts/lib/kit-brief-test.sh +22 -3
- package/scripts/lib/kit-brief.sh +45 -5
- package/scripts/lib/kit-config-resolve.sh +2 -2
- package/scripts/lib/kit-config-test.sh +64 -1
- package/scripts/lib/kit-config.sh +37 -1
- package/scripts/lib/kit-events.sh +7 -0
- package/scripts/lib/kit-gc-test.sh +173 -1
- package/scripts/lib/kit-gc.sh +244 -37
- package/scripts/lib/kit-hotfix.sh +216 -0
- package/scripts/lib/kit-interview-test.sh +93 -0
- package/scripts/lib/kit-interview.sh +117 -8
- package/scripts/lib/kit-lib-test.sh +1 -1
- package/scripts/lib/kit-lib.sh +3 -3
- package/scripts/lib/kit-local.sh +2 -2
- package/scripts/lib/kit-manifest.sh +33 -1
- package/scripts/lib/kit-profile-test.sh +3 -3
- package/scripts/lib/kit-status-test.sh +112 -4
- package/scripts/lib/kit-status.sh +246 -16
- package/scripts/lib/kit-task-ops-test.sh +37 -0
- package/scripts/lib/kit-task-ops.sh +362 -89
- package/scripts/lib/kto-hotfix-test.sh +232 -0
- package/scripts/lib/kto-task-close-test.sh +83 -0
- package/scripts/lib/kto-task-new-test.sh +95 -0
- package/scripts/lib/kto-task-pr-merge-test.sh +97 -6
- package/scripts/lib/kto-task-pr-test.sh +70 -0
- package/scripts/lib/leak-fence.sh +89 -0
- package/scripts/lib/light-task-run-test.sh +255 -0
- package/scripts/lib/light-task-test.sh +309 -0
- package/scripts/lib/light-task.sh +706 -0
- package/scripts/lib/next-test.sh +99 -0
- package/scripts/lib/next.sh +9 -3
- package/scripts/lib/orchestration-runtime-test.sh +72 -0
- package/scripts/lib/orchestration-runtime.sh +57 -5
- package/scripts/lib/plan-machine-test.sh +15 -2
- package/scripts/lib/plan-machine.sh +20 -7
- package/scripts/lib/plan-next-test.sh +1 -1
- package/scripts/lib/plan-next.sh +4 -4
- package/scripts/lib/pr-evidence-test.sh +3 -3
- package/scripts/lib/pr-evidence.sh +1 -1
- package/scripts/lib/qa-lane-test.sh +626 -0
- package/scripts/lib/qa-lane.sh +1357 -0
- package/scripts/lib/qa-lanes-test.sh +175 -0
- package/scripts/lib/react-detect.sh +1 -1
- package/scripts/lib/render-test.sh +1 -1
- package/scripts/lib/review-page-test.sh +318 -0
- package/scripts/lib/review-page.sh +369 -0
- package/scripts/lib/review-stage-test.sh +62 -11
- package/scripts/lib/review-stage.sh +42 -60
- package/scripts/lib/role-identity-test.sh +65 -0
- package/scripts/lib/role-identity.sh +25 -2
- package/scripts/lib/secret-guard.sh +3 -3
- package/scripts/lib/session-registry-test.sh +111 -0
- package/scripts/lib/session-registry.sh +233 -0
- package/scripts/lib/stage-receipt-test.sh +14 -1
- package/scripts/lib/stage-receipt.sh +13 -8
- package/scripts/lib/task-source-file.sh +309 -0
- package/scripts/lib/task-source.sh +130 -0
- package/scripts/lib/test-env-test.sh +3 -3
- package/scripts/lib/test-env.sh +7 -4
- package/scripts/lib/upgrade-report-test.sh +120 -0
- package/scripts/lib/upgrade-report.sh +138 -0
- package/scripts/lib/version-bump.sh +3 -3
- package/scripts/lib/wave-result-test.sh +80 -0
- package/scripts/lib/wave-result.sh +127 -0
- package/scripts/lib/worker-brief-test.sh +5 -0
- package/scripts/lib/worker-brief.sh +2 -2
- package/scripts/lib/worktree-issue-test.sh +30 -1
- package/scripts/lib/worktree-issue.sh +93 -9
- package/scripts/lib/worktree-ports-test.sh +57 -4
- package/scripts/lib/worktree-start-test.sh +197 -0
- package/scripts/lib/worktree-start.sh +169 -32
- package/scripts/lib/zsh-safety-test.sh +19 -3
- package/scripts/marketing-walkthrough-test.sh +152 -0
- package/scripts/night-grant-test.sh +37 -0
- package/scripts/night-grant.sh +448 -0
- package/scripts/night-run-test.sh +8 -0
- package/scripts/night-run.mjs +275 -0
- package/scripts/night-run.test.mjs +324 -0
- package/scripts/orchestrate-test.sh +190 -0
- package/scripts/orchestrate.sh +79 -8
- package/scripts/portable-test.sh +11 -2
- package/scripts/publish.sh +28 -3
- package/scripts/review-lint-test.sh +7 -7
- package/scripts/review-lint.sh +2 -2
- package/scripts/review-rules.conf +8 -0
- package/scripts/rule-recipes-test.sh +96 -0
- package/scripts/self-install-test.sh +39 -9
- package/scripts/setup-labels.sh +18 -1
- package/scripts/setup-milestones.sh +1 -1
- package/scripts/showcase.sh +1 -1
- package/scripts/skill-frontmatter-lint-test.sh +4 -4
- package/scripts/skill-frontmatter-lint.sh +1 -1
- package/scripts/status-test.sh +113 -2
- package/scripts/status.sh +16 -3
- package/scripts/task-sync-test.sh +154 -0
- package/scripts/task-sync.sh +243 -32
- package/scripts/test-runner-test.sh +158 -0
- package/scripts/test.sh +131 -23
- package/scripts/update-path-test.sh +279 -0
- package/scripts/ux-ds-audit.sh +1 -1
- package/scripts/ux-graph-scan.sh +6 -6
- package/scripts/wave-worker.sh +54 -0
- package/skills/kit-add/SKILL.md +77 -0
- package/skills/kit-autopilot/SKILL.md +123 -12
- package/skills/kit-cleanup/SKILL.md +5 -2
- package/skills/kit-contribute/SKILL.md +4 -4
- package/skills/kit-docs-writer/SKILL.md +16 -6
- package/skills/kit-effort-close/SKILL.md +17 -8
- package/skills/kit-effort-new/SKILL.md +15 -9
- package/skills/kit-effort-pr/SKILL.md +15 -7
- package/skills/kit-effort-start/SKILL.md +5 -2
- package/skills/kit-gc/SKILL.md +5 -2
- package/skills/kit-next/SKILL.md +5 -1
- package/skills/kit-onboard/SKILL.md +3 -3
- package/skills/kit-page/SKILL.md +93 -0
- package/skills/kit-plan-next/SKILL.md +8 -4
- package/skills/kit-security-sweep/SKILL.md +1 -3
- package/skills/kit-ship/SKILL.md +2 -3
- package/skills/kit-status/SKILL.md +35 -4
- package/skills/kit-task-new/SKILL.md +3 -3
- package/skills/kit-task-pr/SKILL.md +7 -2
- package/skills/kit-task-pr-merge/SKILL.md +7 -2
- package/skills/kit-task-start/SKILL.md +7 -7
- package/skills/kit-task-sync/SKILL.md +19 -3
- package/skills/kit-ux-audit/SKILL.md +3 -2
- package/templates/agents/auto-dev.md +5 -4
- package/templates/agents/backend.md +1 -1
- package/templates/agents/designer.md +2 -0
- package/templates/agents/devops.md +1 -1
- package/templates/agents/editor.md +9 -1
- package/templates/agents/frontend.md +1 -1
- package/templates/agents/local-delegate.md +1 -1
- package/templates/agents/pm.md +5 -5
- package/templates/agents/tech-lead.md +1 -1
- package/templates/benchmarks/SCHEMA.md +9 -3
- package/templates/codex/hooks.json.tmpl +89 -0
- package/templates/hooks/guard-base-branch-commit.sh.tmpl +13 -7
- package/templates/hooks/guard-raw-git-ops.sh.tmpl +27 -14
- package/templates/hooks/mempal_followup.sh.tmpl +2 -2
- package/templates/hooks/mempal_session_start.sh.tmpl +1 -1
- package/templates/hooks/prepush_gate.sh.tmpl +4 -2
- package/templates/hooks/repo-hygiene.sh.tmpl +3 -2
- package/templates/instructions.md.tmpl +174 -0
- package/templates/kit.config.json.tmpl +3 -3
- package/templates/knowledge-INDEX.md.tmpl +1 -1
- package/templates/lib/kit-sigil.sh.tmpl +1 -1
- package/templates/rules/authoring.md +106 -0
- package/templates/rules/branch-naming.md +40 -4
- package/templates/rules/code-retrieval.md +63 -0
- package/templates/rules/delegation-brief.md +0 -3
- package/templates/rules/design-routing.md +3 -3
- package/templates/rules/effort-model.md +14 -10
- package/templates/rules/gate-and-review.md +94 -0
- package/templates/rules/issue-lifecycle.md +88 -0
- package/templates/rules/knowledge-base.md +1 -1
- package/templates/rules/mempalace.md +1 -1
- package/templates/rules/merge-safety.md +108 -0
- package/templates/rules/naming-and-ids.md +23 -17
- package/templates/rules/plain-language.md +59 -0
- package/templates/rules/plan-next.md +9 -11
- package/templates/rules/react-annotate.md +6 -0
- package/templates/rules/review-pages.md +49 -0
- package/templates/rules/risk-tiered-review.md +13 -4
- package/templates/rules/shared-checkout.md +106 -0
- package/templates/rules/skill-gaps.md +2 -7
- package/templates/rules/task-management.md +13 -1
- package/templates/skills/brand-voice/SKILL.md +91 -0
- package/templates/skills/brand-voice/references/voice-template.md +61 -0
- package/templates/skills/campaign/SKILL.md +123 -0
- package/templates/skills/campaign/references/plan-template.md +55 -0
- package/templates/skills/concrete/SKILL.md +2 -2
- package/templates/skills/copywriting/SKILL.md +8 -1
- package/templates/skills/feature-build-refine/SKILL.md +2 -4
- package/templates/skills/morning-briefing/SKILL.md +2 -2
- package/templates/skills/page-design/SKILL.md +145 -0
- package/templates/skills/page-design/add.json +5 -0
- package/templates/skills/page-design/references/design-file-template.md +40 -0
- package/templates/skills/page-design/references/generic-page-patterns.md +43 -0
- package/templates/skills/page-design/references/minimum-rules.md +42 -0
- package/templates/skills/speckit/SKILL.md +4 -5
- package/templates/skills/supabase-patterns/SKILL.md +1 -1
- package/commands/kit-add.md +0 -42
- package/templates/CLAUDE.md.tmpl +0 -106
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
export const meta = {
|
|
2
|
+
name: 'night-run',
|
|
3
|
+
description: 'Run an approved effort plan unattended, wave by wave, under a runtime-enforced token budget',
|
|
4
|
+
whenToUse: 'Unattended execution of approved waves, launched by the kit-autopilot captain with a +N budget',
|
|
5
|
+
phases: [
|
|
6
|
+
{ title: 'Preflight', detail: 'refuse a closed issue, a non-effort, or a held effort' },
|
|
7
|
+
{ title: 'Execute', detail: 'one implementer per effort, no wider than the effort WIP limit (max 4)' },
|
|
8
|
+
{ title: 'Verify', detail: 'independent gate + always-human floor read' },
|
|
9
|
+
{ title: 'Merge', detail: 'close each verified effort' },
|
|
10
|
+
{ title: 'Stop check', detail: 'the grant command after a wave; the gate on the base branch at the end' },
|
|
11
|
+
],
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/* global agent, pipeline, log, budget, args -- the Workflow runtime injects these */
|
|
15
|
+
|
|
16
|
+
// The night engine. A Workflow script is the runtime that enforces the caps a prompt cannot: the
|
|
17
|
+
// token budget is `budget.total` (a +N directive), and concurrency, wave order and stop are code here.
|
|
18
|
+
// args: { waves: number[][], gate?: string, wipLimit?: number,
|
|
19
|
+
// grant?: { waivers?: string[], stopCommand?: string,
|
|
20
|
+
// extraFloors?: {[name]: description}, neverWaivable?: string[] },
|
|
21
|
+
// maxConcurrent?: number, waveReserve?: number, refuseLabels?: string[] }
|
|
22
|
+
// `scripts/night-grant.sh read <issue>` builds these args from the owner's night grant + the kit
|
|
23
|
+
// config. APPROVAL is that grant: the owner names each effort in `waves`, in a comment only the
|
|
24
|
+
// owner can write. There is no second approval marker on the effort itself.
|
|
25
|
+
//
|
|
26
|
+
// WAVE ORDER. Waves are dependency-ordered, so a wave that did not fully merge ends the run: the
|
|
27
|
+
// next wave would build on a base that lacks a parked or refused predecessor.
|
|
28
|
+
//
|
|
29
|
+
// WIP. Every executor runs `cckit effort start`, which refuses a NEW effort once `effort.wipLimit`
|
|
30
|
+
// (default 2) effort branches exist. The engine therefore runs no wider than `wipLimit`, and an
|
|
31
|
+
// effort that parked keeps its branch, so it takes a slot from the rest of its wave.
|
|
32
|
+
// Returns the wake report data; the captain (kit-autopilot) renders it and decides what follows.
|
|
33
|
+
|
|
34
|
+
const HARD_CONCURRENCY = 4 // one usage pool per account: a wide fan-out can spend a window in minutes
|
|
35
|
+
const BASE_NEVER_WAIVABLE = ['workflows', 'cost', 'secret']
|
|
36
|
+
const STANDING_WAIVERS = ['security-prose'] // a security/* diff that changes prose only
|
|
37
|
+
const BASE_FLOORS = {
|
|
38
|
+
lockfile: 'the lockfile or a package manifest',
|
|
39
|
+
auth: 'authentication or authorization code',
|
|
40
|
+
'security-code': 'a security/* branch that changes any non-prose file',
|
|
41
|
+
'security-prose': 'a security/* branch that changes prose only',
|
|
42
|
+
workflows: 'CI workflow files (.github/workflows/** or equivalent)',
|
|
43
|
+
cost: 'scaling, a paid resource, or a plan change',
|
|
44
|
+
secret: 'a value only the owner can provide',
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const waves = Array.isArray(args?.waves) ? args.waves.filter((w) => Array.isArray(w) && w.length) : []
|
|
48
|
+
const grant = args?.grant ?? {}
|
|
49
|
+
const floors = { ...BASE_FLOORS, ...(grant.extraFloors ?? {}) }
|
|
50
|
+
const neverWaivable = [...BASE_NEVER_WAIVABLE, ...(grant.neverWaivable ?? [])]
|
|
51
|
+
const waivers = new Set([...(grant.waivers ?? []), ...STANDING_WAIVERS])
|
|
52
|
+
const DEFAULT_WIP_LIMIT = 2 // effort.wipLimit's default (scripts/lib/effort-ops.sh, _eff_wip_limit)
|
|
53
|
+
const wipLimit = Number.isInteger(args?.wipLimit) && args.wipLimit >= 1 ? args.wipLimit : DEFAULT_WIP_LIMIT
|
|
54
|
+
const concurrency = Math.max(1, Math.min(args?.maxConcurrent ?? HARD_CONCURRENCY, HARD_CONCURRENCY, wipLimit))
|
|
55
|
+
const waveReserve = args?.waveReserve ?? 150_000
|
|
56
|
+
const refuseLabels = Array.isArray(args?.refuseLabels) ? args.refuseLabels : [] // night.refuseLabels
|
|
57
|
+
const gate = args?.gate ?? "the gate commands in the project's delegation brief"
|
|
58
|
+
|
|
59
|
+
const efforts = []
|
|
60
|
+
const report = (stop, reason = '') => ({
|
|
61
|
+
stop,
|
|
62
|
+
reason,
|
|
63
|
+
efforts,
|
|
64
|
+
spent: budget.spent(),
|
|
65
|
+
total: budget.total,
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
if (budget.total === null) {
|
|
69
|
+
return report('refused', 'no token budget: launch with a +N directive (the grant budget)')
|
|
70
|
+
}
|
|
71
|
+
if (!waves.length) return report('refused', 'no approved waves in args.waves')
|
|
72
|
+
|
|
73
|
+
const PREFLIGHT = {
|
|
74
|
+
type: 'object',
|
|
75
|
+
properties: {
|
|
76
|
+
ok: { type: 'boolean' },
|
|
77
|
+
labels: { type: 'array', items: { type: 'string' } },
|
|
78
|
+
reason: { type: 'string' },
|
|
79
|
+
},
|
|
80
|
+
required: ['ok', 'labels', 'reason'],
|
|
81
|
+
}
|
|
82
|
+
const EXECUTE = {
|
|
83
|
+
type: 'object',
|
|
84
|
+
properties: {
|
|
85
|
+
prUrl: { type: 'string' },
|
|
86
|
+
branch: { type: 'string' },
|
|
87
|
+
blocker: { type: 'string' },
|
|
88
|
+
},
|
|
89
|
+
required: ['prUrl', 'branch', 'blocker'],
|
|
90
|
+
}
|
|
91
|
+
const VERIFY = {
|
|
92
|
+
type: 'object',
|
|
93
|
+
properties: {
|
|
94
|
+
gate: { type: 'string', enum: ['PASS', 'FAIL'] },
|
|
95
|
+
floors: { type: 'array', items: { type: 'string', enum: Object.keys(floors) } },
|
|
96
|
+
},
|
|
97
|
+
required: ['gate', 'floors'],
|
|
98
|
+
}
|
|
99
|
+
const MERGE = {
|
|
100
|
+
type: 'object',
|
|
101
|
+
properties: { merged: { type: 'boolean' }, detail: { type: 'string' } },
|
|
102
|
+
required: ['merged', 'detail'],
|
|
103
|
+
}
|
|
104
|
+
const STOP = {
|
|
105
|
+
type: 'object',
|
|
106
|
+
properties: { passed: { type: 'boolean' }, detail: { type: 'string' } },
|
|
107
|
+
required: ['passed', 'detail'],
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const BRIEF =
|
|
111
|
+
"Read the project's delegation brief first if it has one. You run unattended inside a night " +
|
|
112
|
+
'run: never ask a question, never confirm a destructive prompt, never take a cost action, and ' +
|
|
113
|
+
'never open a review page (run every `cckit page` command with `CCKIT_HEADLESS=1`, so it ' +
|
|
114
|
+
'prints to the terminal). Return only the schema.'
|
|
115
|
+
|
|
116
|
+
const preflightPrompt = (n) =>
|
|
117
|
+
`${BRIEF}\nRead effort #${n}: \`gh issue view ${n} --json labels,state\`. ok=false when it ` +
|
|
118
|
+
'is closed or lacks the `effort` label. Return every label name verbatim; reason names what ' +
|
|
119
|
+
'is missing.'
|
|
120
|
+
|
|
121
|
+
const executePrompt = (n) =>
|
|
122
|
+
`${BRIEF}\nYou implement effort #${n}, an approved plan, under the kit-autopilot plan-mode ` +
|
|
123
|
+
`contract. Start or reuse its worktree (\`cckit effort start ${n}\`). Build each open sub-issue ` +
|
|
124
|
+
`in order, one commit per sub. Run ${gate}, open the ONE effort PR with /kit-effort-pr ${n}, ` +
|
|
125
|
+
'and never merge. Never pass `--force` and never set `KIT_FORCE` or `EFFORT_WIP_LIMIT`: when ' +
|
|
126
|
+
'`cckit effort start` refuses on the WIP limit, stop and report that refusal as the blocker. ' +
|
|
127
|
+
'blocker is empty unless you stopped on a genuine blocker: an unresolvable ' +
|
|
128
|
+
'conflict, an ambiguity the plan is silent on, a secret only the owner has, a cost, or that ' +
|
|
129
|
+
'WIP refusal.'
|
|
130
|
+
|
|
131
|
+
const floorList = Object.entries(floors)
|
|
132
|
+
.map(([name, what]) => `${name} (${what})`)
|
|
133
|
+
.join(', ')
|
|
134
|
+
|
|
135
|
+
const verifyPrompt = (n, branch) =>
|
|
136
|
+
`${BRIEF}\nIndependently verify effort #${n} on branch \`${branch}\`; do not trust the ` +
|
|
137
|
+
`implementer. In a fresh worktree at its head run ${gate} and report PASS or FAIL. Then read ` +
|
|
138
|
+
'the diff against the base branch and list every always-human floor it trips: ' +
|
|
139
|
+
`${floorList}.`
|
|
140
|
+
|
|
141
|
+
const mergePrompt = (n) =>
|
|
142
|
+
`${BRIEF}\nEffort #${n} is verified and approved. Run /kit-effort-close ${n}: it merges the ` +
|
|
143
|
+
'effort PR, closes the parent and its subs, and garbage-collects. merged=true only when the PR ' +
|
|
144
|
+
'state reads MERGED afterwards.'
|
|
145
|
+
|
|
146
|
+
// Two separate checks, never one standing in for the other: the grant's stop command ends the
|
|
147
|
+
// night early, the gate is what "the base branch is green" means.
|
|
148
|
+
const stopPrompt = () =>
|
|
149
|
+
`${BRIEF}\nFrom a worktree at the base branch head run: ${grant.stopCommand}\npassed = exit code 0.`
|
|
150
|
+
const gatePrompt = () =>
|
|
151
|
+
`${BRIEF}\nIn a fresh worktree at the base branch head run ${gate}. passed = all green.`
|
|
152
|
+
|
|
153
|
+
function decide(verdict) {
|
|
154
|
+
if (verdict.gate !== 'PASS') return { status: 'parked', reason: 'gate FAIL on the effort branch' }
|
|
155
|
+
const never = verdict.floors.filter((f) => neverWaivable.includes(f))
|
|
156
|
+
if (never.length) return { status: 'parked', reason: `never-waivable floor: ${never.join(', ')}` }
|
|
157
|
+
const open = verdict.floors.filter((f) => !waivers.has(f))
|
|
158
|
+
if (open.length) return { status: 'parked', reason: `floor not waived by the grant: ${open.join(', ')}` }
|
|
159
|
+
return null
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
async function runEffort(n) {
|
|
163
|
+
const entry = { effort: n, status: 'pending', reason: '', prUrl: '' }
|
|
164
|
+
efforts.push(entry)
|
|
165
|
+
const lost = () => {
|
|
166
|
+
entry.status = 'unavailable'
|
|
167
|
+
entry.reason = 'agent returned nothing (usage limit or API error)'
|
|
168
|
+
return entry
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
const pre = await agent(preflightPrompt(n), {
|
|
172
|
+
label: `preflight:${n}`,
|
|
173
|
+
phase: 'Preflight',
|
|
174
|
+
schema: PREFLIGHT,
|
|
175
|
+
effort: 'low',
|
|
176
|
+
})
|
|
177
|
+
if (!pre) return lost()
|
|
178
|
+
const refusedBy = pre.labels.filter((l) => refuseLabels.includes(l))
|
|
179
|
+
if (!pre.ok || refusedBy.length) {
|
|
180
|
+
entry.status = 'refused'
|
|
181
|
+
entry.reason = refusedBy.length ? `carries ${refusedBy.join(', ')}` : pre.reason
|
|
182
|
+
return entry
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
const exec = await agent(executePrompt(n), { label: `execute:${n}`, phase: 'Execute', schema: EXECUTE })
|
|
186
|
+
if (!exec) return lost()
|
|
187
|
+
entry.prUrl = exec.prUrl
|
|
188
|
+
if (exec.blocker) {
|
|
189
|
+
entry.status = 'parked'
|
|
190
|
+
entry.reason = exec.blocker
|
|
191
|
+
return entry
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
const verdict = await agent(verifyPrompt(n, exec.branch), {
|
|
195
|
+
label: `verify:${n}`,
|
|
196
|
+
phase: 'Verify',
|
|
197
|
+
schema: VERIFY,
|
|
198
|
+
})
|
|
199
|
+
if (!verdict) return lost()
|
|
200
|
+
const parked = decide(verdict)
|
|
201
|
+
if (parked) return Object.assign(entry, parked)
|
|
202
|
+
|
|
203
|
+
const merged = await agent(mergePrompt(n), { label: `merge:${n}`, phase: 'Merge', schema: MERGE })
|
|
204
|
+
if (!merged) return lost()
|
|
205
|
+
entry.status = merged.merged ? 'merged' : 'parked'
|
|
206
|
+
entry.reason = merged.merged ? '' : merged.detail
|
|
207
|
+
return entry
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
async function stopCheck() {
|
|
211
|
+
const verdict = await agent(stopPrompt(), { label: 'stop', phase: 'Stop check', schema: STOP })
|
|
212
|
+
return verdict?.passed === true
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
async function gateCheck() {
|
|
216
|
+
const verdict = await agent(gatePrompt(), { label: 'gate', phase: 'Stop check', schema: STOP })
|
|
217
|
+
return verdict?.passed === true
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
const tag = (e) => `#${e.effort} ${e.status}`
|
|
221
|
+
let stopCommandFailed = false
|
|
222
|
+
|
|
223
|
+
for (let w = 0; w < waves.length; w++) {
|
|
224
|
+
if (budget.remaining() < waveReserve) {
|
|
225
|
+
return report('budget', `${budget.remaining()} tokens left, a wave reserves ${waveReserve}`)
|
|
226
|
+
}
|
|
227
|
+
const wave = waves[w]
|
|
228
|
+
log(`wave ${w + 1}/${waves.length}: ${wave.map((n) => `#${n}`).join(' ')}`)
|
|
229
|
+
|
|
230
|
+
// Groups of at most `concurrency`, each a pipeline. An effort of this wave that started and did
|
|
231
|
+
// not merge still holds its effort branch, so it takes a WIP slot from the groups after it.
|
|
232
|
+
const first = efforts.length
|
|
233
|
+
for (let i = 0; i < wave.length; ) {
|
|
234
|
+
const held = efforts.slice(first).filter((e) => e.status !== 'merged' && e.status !== 'refused').length
|
|
235
|
+
const slots = concurrency - held
|
|
236
|
+
if (slots <= 0) {
|
|
237
|
+
for (const n of wave.slice(i)) {
|
|
238
|
+
efforts.push({
|
|
239
|
+
effort: n,
|
|
240
|
+
status: 'skipped',
|
|
241
|
+
reason: `no WIP slot: ${held} unmerged effort(s) of this wave hold the limit of ${concurrency}`,
|
|
242
|
+
prUrl: '',
|
|
243
|
+
})
|
|
244
|
+
}
|
|
245
|
+
break
|
|
246
|
+
}
|
|
247
|
+
const group = wave.slice(i, i + slots)
|
|
248
|
+
i += group.length
|
|
249
|
+
await pipeline(group, (n) => runEffort(n))
|
|
250
|
+
if (efforts.some((e) => e.status === 'unavailable' || e.status === 'pending')) {
|
|
251
|
+
return report('usage-limit', `wave ${w + 1} lost an agent; resume this run after the reset`)
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
const unmerged = efforts.slice(first).filter((e) => e.status !== 'merged')
|
|
256
|
+
if (unmerged.length) {
|
|
257
|
+
const later = waves.length - (w + 1)
|
|
258
|
+
return report(
|
|
259
|
+
'blocked',
|
|
260
|
+
`wave ${w + 1} did not fully merge (${unmerged.map(tag).join(', ')})` +
|
|
261
|
+
(later ? `; ${later} later wave(s) were not started because they build on it` : ''),
|
|
262
|
+
)
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
if (grant.stopCommand) {
|
|
266
|
+
if (await stopCheck()) return report('done', `stop command passed after wave ${w + 1}`)
|
|
267
|
+
stopCommandFailed = true
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
// Every wave merged. "Green" here is the gate, whatever the grant's stop command said.
|
|
272
|
+
const note = stopCommandFailed ? '; the stop command did not pass' : ''
|
|
273
|
+
return (await gateCheck())
|
|
274
|
+
? report('done', `every approved wave merged and the base branch gate is green${note}`)
|
|
275
|
+
: report('blocked', `every wave merged but the base branch gate is red${note}`)
|
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
import assert from 'node:assert/strict'
|
|
2
|
+
import { readFileSync } from 'node:fs'
|
|
3
|
+
import test from 'node:test'
|
|
4
|
+
|
|
5
|
+
// The engine is a Workflow script: plain JS that the Workflow runtime evaluates with agent(),
|
|
6
|
+
// pipeline(), parallel(), phase(), log(), budget and args as globals. This harness evaluates the
|
|
7
|
+
// same text with those globals stubbed, so every unattended decision is exercised without a model.
|
|
8
|
+
const SOURCE = readFileSync(new URL('./night-run.mjs', import.meta.url), 'utf8').replace(
|
|
9
|
+
/^export const meta =/m,
|
|
10
|
+
'const meta =',
|
|
11
|
+
)
|
|
12
|
+
const AsyncFunction = Object.getPrototypeOf(async () => {}).constructor
|
|
13
|
+
|
|
14
|
+
function run({ args, total = 1_000_000, agents = {} }) {
|
|
15
|
+
let spent = 0
|
|
16
|
+
let inFlight = 0
|
|
17
|
+
const calls = []
|
|
18
|
+
const prompts = {}
|
|
19
|
+
const stats = { maxInFlight: 0 }
|
|
20
|
+
const budget = {
|
|
21
|
+
total,
|
|
22
|
+
spent: () => spent,
|
|
23
|
+
remaining: () => (total === null ? Infinity : Math.max(0, total - spent)),
|
|
24
|
+
}
|
|
25
|
+
const agent = async (prompt, opts = {}) => {
|
|
26
|
+
const [kind, id] = (opts.label ?? '').split(':')
|
|
27
|
+
calls.push(opts.label)
|
|
28
|
+
prompts[opts.label] = prompt
|
|
29
|
+
inFlight++
|
|
30
|
+
stats.maxInFlight = Math.max(stats.maxInFlight, inFlight)
|
|
31
|
+
await new Promise((resolve) => setTimeout(resolve, 1))
|
|
32
|
+
inFlight--
|
|
33
|
+
spent += 10_000
|
|
34
|
+
const handler = agents[kind]
|
|
35
|
+
return handler ? handler(Number(id), prompt) : null
|
|
36
|
+
}
|
|
37
|
+
const parallel = async (thunks) =>
|
|
38
|
+
Promise.all(thunks.map((t) => Promise.resolve().then(t).catch(() => null)))
|
|
39
|
+
const pipeline = async (items, ...stages) =>
|
|
40
|
+
Promise.all(
|
|
41
|
+
items.map(async (item, index) => {
|
|
42
|
+
let value = item
|
|
43
|
+
for (const stage of stages) {
|
|
44
|
+
try {
|
|
45
|
+
value = await stage(value, item, index)
|
|
46
|
+
} catch {
|
|
47
|
+
return null
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return value
|
|
51
|
+
}),
|
|
52
|
+
)
|
|
53
|
+
const body = new AsyncFunction(
|
|
54
|
+
'agent',
|
|
55
|
+
'parallel',
|
|
56
|
+
'pipeline',
|
|
57
|
+
'phase',
|
|
58
|
+
'log',
|
|
59
|
+
'budget',
|
|
60
|
+
'args',
|
|
61
|
+
SOURCE,
|
|
62
|
+
)
|
|
63
|
+
return body(agent, parallel, pipeline, () => {}, () => {}, budget, args).then((result) => ({
|
|
64
|
+
result,
|
|
65
|
+
calls,
|
|
66
|
+
prompts,
|
|
67
|
+
stats,
|
|
68
|
+
}))
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const green = {
|
|
72
|
+
preflight: () => ({ ok: true, labels: ['effort'], reason: '' }),
|
|
73
|
+
execute: (n) => ({ prUrl: `https://example.test/pull/${n}`, branch: `effort/${n}`, blocker: '' }),
|
|
74
|
+
verify: () => ({ gate: 'PASS', floors: [] }),
|
|
75
|
+
merge: () => ({ merged: true, detail: '' }),
|
|
76
|
+
stop: () => ({ passed: true, detail: 'stop command exit 0' }),
|
|
77
|
+
gate: () => ({ passed: true, detail: 'develop green' }),
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const statusOf = (result, effort) => result.efforts.find((e) => e.effort === effort)?.status
|
|
81
|
+
|
|
82
|
+
test('refuses to start without a token budget', async () => {
|
|
83
|
+
const { result, calls } = await run({ args: { waves: [[1]] }, total: null, agents: green })
|
|
84
|
+
assert.equal(result.stop, 'refused')
|
|
85
|
+
assert.match(result.reason, /budget/)
|
|
86
|
+
assert.deepEqual(calls, [])
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
test('refuses an empty plan', async () => {
|
|
90
|
+
const { result } = await run({ args: { waves: [] }, agents: green })
|
|
91
|
+
assert.equal(result.stop, 'refused')
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
test('merges every approved wave and stops as done when develop is green', async () => {
|
|
95
|
+
const { result } = await run({ args: { waves: [[1, 2], [3]] }, agents: green })
|
|
96
|
+
assert.equal(result.stop, 'done')
|
|
97
|
+
assert.deepEqual(
|
|
98
|
+
result.efforts.map((e) => e.status),
|
|
99
|
+
['merged', 'merged', 'merged'],
|
|
100
|
+
)
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
test('never runs more than four agents at once, whatever the wave size or the WIP limit', async () => {
|
|
104
|
+
const { stats } = await run({
|
|
105
|
+
args: { waves: [[1, 2, 3, 4, 5, 6, 7, 8, 9]], maxConcurrent: 16, wipLimit: 16 },
|
|
106
|
+
agents: green,
|
|
107
|
+
})
|
|
108
|
+
assert.equal(stats.maxInFlight, 4)
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
test('runs no wider than the default effort WIP limit of 2 when args carry none', async () => {
|
|
112
|
+
const { result, stats } = await run({ args: { waves: [[1, 2, 3, 4, 5, 6]] }, agents: green })
|
|
113
|
+
assert.equal(stats.maxInFlight, 2)
|
|
114
|
+
assert.equal(result.stop, 'done')
|
|
115
|
+
})
|
|
116
|
+
|
|
117
|
+
test('runs as wide as effort.wipLimit, and no wider', async () => {
|
|
118
|
+
const { stats } = await run({ args: { waves: [[1, 2, 3, 4, 5, 6]], wipLimit: 3 }, agents: green })
|
|
119
|
+
assert.equal(stats.maxInFlight, 3)
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
test('a parked effort keeps its WIP slot from the rest of its wave', async () => {
|
|
123
|
+
const one = await run({
|
|
124
|
+
args: { waves: [[1, 2, 3, 4]], wipLimit: 2 },
|
|
125
|
+
agents: { ...green, verify: (n) => ({ gate: n === 1 ? 'FAIL' : 'PASS', floors: [] }) },
|
|
126
|
+
})
|
|
127
|
+
// #1 parked and holds a branch, so #3 and #4 run one at a time in the single slot left
|
|
128
|
+
assert.deepEqual(
|
|
129
|
+
one.result.efforts.map((e) => e.status),
|
|
130
|
+
['parked', 'merged', 'merged', 'merged'],
|
|
131
|
+
)
|
|
132
|
+
assert.ok(one.calls.indexOf('merge:3') < one.calls.indexOf('preflight:4'))
|
|
133
|
+
|
|
134
|
+
const both = await run({
|
|
135
|
+
args: { waves: [[1, 2, 3, 4]], wipLimit: 2 },
|
|
136
|
+
agents: { ...green, verify: () => ({ gate: 'FAIL', floors: [] }) },
|
|
137
|
+
})
|
|
138
|
+
assert.equal(statusOf(both.result, 3), 'skipped')
|
|
139
|
+
assert.equal(statusOf(both.result, 4), 'skipped')
|
|
140
|
+
assert.match(both.result.efforts[2].reason, /WIP/)
|
|
141
|
+
assert.ok(!both.calls.includes('preflight:3'))
|
|
142
|
+
})
|
|
143
|
+
|
|
144
|
+
test('the executor is told never to force past the WIP limit', async () => {
|
|
145
|
+
const { prompts } = await run({ args: { waves: [[1]] }, agents: green })
|
|
146
|
+
assert.match(prompts['execute:1'], /Never pass `--force`/)
|
|
147
|
+
assert.match(prompts['execute:1'], /EFFORT_WIP_LIMIT/)
|
|
148
|
+
})
|
|
149
|
+
|
|
150
|
+
test('an effort created by `cckit effort new` passes preflight: no body section is demanded', async () => {
|
|
151
|
+
const { result, prompts } = await run({
|
|
152
|
+
args: { waves: [[1]] },
|
|
153
|
+
// the labels effort_new applies; no grill:* label and no ## Grilling section exists in the kit
|
|
154
|
+
agents: { ...green, preflight: () => ({ ok: true, labels: ['effort', 'ctx:M', 'flow:core'], reason: '' }) },
|
|
155
|
+
})
|
|
156
|
+
assert.equal(statusOf(result, 1), 'merged')
|
|
157
|
+
assert.doesNotMatch(prompts['preflight:1'], /Grilling|Assumed/)
|
|
158
|
+
assert.doesNotMatch(prompts['preflight:1'], /body/)
|
|
159
|
+
})
|
|
160
|
+
|
|
161
|
+
test('refuses an effort carrying a label the project holds out of night runs', async () => {
|
|
162
|
+
const { result, calls } = await run({
|
|
163
|
+
args: { waves: [[1, 2]], refuseLabels: ['hold'] },
|
|
164
|
+
agents: {
|
|
165
|
+
...green,
|
|
166
|
+
preflight: (n) =>
|
|
167
|
+
n === 2
|
|
168
|
+
? { ok: true, labels: ['effort', 'hold'], reason: '' }
|
|
169
|
+
: { ok: true, labels: ['effort'], reason: '' },
|
|
170
|
+
},
|
|
171
|
+
})
|
|
172
|
+
assert.equal(statusOf(result, 1), 'merged')
|
|
173
|
+
assert.equal(statusOf(result, 2), 'refused')
|
|
174
|
+
assert.ok(!calls.includes('execute:2'))
|
|
175
|
+
})
|
|
176
|
+
|
|
177
|
+
test('parks an effort whose diff trips a floor the grant did not waive', async () => {
|
|
178
|
+
const { result, calls } = await run({
|
|
179
|
+
args: { waves: [[1]] },
|
|
180
|
+
agents: { ...green, verify: () => ({ gate: 'PASS', floors: ['lockfile'] }) },
|
|
181
|
+
})
|
|
182
|
+
assert.equal(statusOf(result, 1), 'parked')
|
|
183
|
+
assert.match(result.efforts[0].reason, /lockfile/)
|
|
184
|
+
assert.ok(!calls.includes('merge:1'))
|
|
185
|
+
})
|
|
186
|
+
|
|
187
|
+
test('merges when the grant waives the tripped floor', async () => {
|
|
188
|
+
const { result } = await run({
|
|
189
|
+
args: { waves: [[1]], grant: { waivers: ['lockfile'] } },
|
|
190
|
+
agents: { ...green, verify: () => ({ gate: 'PASS', floors: ['lockfile'] }) },
|
|
191
|
+
})
|
|
192
|
+
assert.equal(statusOf(result, 1), 'merged')
|
|
193
|
+
})
|
|
194
|
+
|
|
195
|
+
test('a never-waivable floor parks even when the grant lists it', async () => {
|
|
196
|
+
for (const floor of ['workflows', 'cost', 'secret']) {
|
|
197
|
+
const { result } = await run({
|
|
198
|
+
args: { waves: [[1]], grant: { waivers: [floor] } },
|
|
199
|
+
agents: { ...green, verify: () => ({ gate: 'PASS', floors: [floor] }) },
|
|
200
|
+
})
|
|
201
|
+
assert.equal(statusOf(result, 1), 'parked', floor)
|
|
202
|
+
}
|
|
203
|
+
})
|
|
204
|
+
|
|
205
|
+
test('a project-declared never-waivable floor parks even when the grant lists it', async () => {
|
|
206
|
+
const { result } = await run({
|
|
207
|
+
args: {
|
|
208
|
+
waves: [[1]],
|
|
209
|
+
grant: { waivers: ['auth-dep'], extraFloors: { 'auth-dep': 'the auth library version' }, neverWaivable: ['auth-dep'] },
|
|
210
|
+
},
|
|
211
|
+
agents: { ...green, verify: () => ({ gate: 'PASS', floors: ['auth-dep'] }) },
|
|
212
|
+
})
|
|
213
|
+
assert.equal(statusOf(result, 1), 'parked')
|
|
214
|
+
})
|
|
215
|
+
|
|
216
|
+
test('a project-declared extra floor merges when the grant waives it', async () => {
|
|
217
|
+
const { result } = await run({
|
|
218
|
+
args: { waves: [[1]], grant: { waivers: ['build-config'], extraFloors: { 'build-config': 'the build pipeline config' } } },
|
|
219
|
+
agents: { ...green, verify: () => ({ gate: 'PASS', floors: ['build-config'] }) },
|
|
220
|
+
})
|
|
221
|
+
assert.equal(statusOf(result, 1), 'merged')
|
|
222
|
+
})
|
|
223
|
+
|
|
224
|
+
test('a security branch with a prose-only diff merges without a waiver', async () => {
|
|
225
|
+
const { result } = await run({
|
|
226
|
+
args: { waves: [[1]] },
|
|
227
|
+
agents: { ...green, verify: () => ({ gate: 'PASS', floors: ['security-prose'] }) },
|
|
228
|
+
})
|
|
229
|
+
assert.equal(statusOf(result, 1), 'merged')
|
|
230
|
+
})
|
|
231
|
+
|
|
232
|
+
test('parks on a red gate', async () => {
|
|
233
|
+
const { result } = await run({
|
|
234
|
+
args: { waves: [[1]] },
|
|
235
|
+
agents: { ...green, verify: () => ({ gate: 'FAIL', floors: [] }) },
|
|
236
|
+
})
|
|
237
|
+
assert.equal(statusOf(result, 1), 'parked')
|
|
238
|
+
})
|
|
239
|
+
|
|
240
|
+
test('an agent lost mid-wave returns usage-limit so the captain can resume', async () => {
|
|
241
|
+
const { result } = await run({
|
|
242
|
+
args: { waves: [[1, 2], [3]] },
|
|
243
|
+
agents: { ...green, execute: (n) => (n === 2 ? null : green.execute(n)) },
|
|
244
|
+
})
|
|
245
|
+
assert.equal(result.stop, 'usage-limit')
|
|
246
|
+
assert.equal(statusOf(result, 2), 'unavailable')
|
|
247
|
+
assert.equal(statusOf(result, 3), undefined)
|
|
248
|
+
})
|
|
249
|
+
|
|
250
|
+
test('a parked wave stops the run before the waves that depend on it', async () => {
|
|
251
|
+
const { result, calls } = await run({
|
|
252
|
+
args: { waves: [[12], [15], [16]] },
|
|
253
|
+
agents: { ...green, verify: () => ({ gate: 'FAIL', floors: [] }) },
|
|
254
|
+
})
|
|
255
|
+
assert.equal(result.stop, 'blocked')
|
|
256
|
+
assert.match(result.reason, /wave 1 did not fully merge \(#12 parked\)/)
|
|
257
|
+
assert.match(result.reason, /2 later wave\(s\) were not started/)
|
|
258
|
+
assert.equal(statusOf(result, 15), undefined)
|
|
259
|
+
assert.ok(!calls.includes('preflight:15'))
|
|
260
|
+
assert.ok(!calls.includes('gate'))
|
|
261
|
+
})
|
|
262
|
+
|
|
263
|
+
test('a partly merged wave stops the run too: one refused effort holds its dependents back', async () => {
|
|
264
|
+
const { result, calls } = await run({
|
|
265
|
+
args: { waves: [[1, 2], [3]] },
|
|
266
|
+
agents: {
|
|
267
|
+
...green,
|
|
268
|
+
preflight: (n) => ({ ok: n !== 2, labels: ['effort'], reason: n === 2 ? 'closed' : '' }),
|
|
269
|
+
},
|
|
270
|
+
})
|
|
271
|
+
assert.equal(result.stop, 'blocked')
|
|
272
|
+
assert.equal(statusOf(result, 1), 'merged')
|
|
273
|
+
assert.equal(statusOf(result, 2), 'refused')
|
|
274
|
+
assert.ok(!calls.includes('execute:3'))
|
|
275
|
+
})
|
|
276
|
+
|
|
277
|
+
test('the final check runs the gate, not the stop command, when every wave merged', async () => {
|
|
278
|
+
const grant = { stopCommand: 'pnpm typecheck' }
|
|
279
|
+
const failing = { ...green, stop: () => ({ passed: false, detail: 'exit 1' }) }
|
|
280
|
+
|
|
281
|
+
const greenGate = await run({ args: { waves: [[1], [2]], gate: 'make check', grant }, agents: failing })
|
|
282
|
+
assert.equal(greenGate.result.stop, 'done')
|
|
283
|
+
assert.match(greenGate.result.reason, /gate is green; the stop command did not pass/)
|
|
284
|
+
assert.equal(greenGate.calls.at(-1), 'gate')
|
|
285
|
+
assert.match(greenGate.prompts.gate, /make check/)
|
|
286
|
+
assert.doesNotMatch(greenGate.prompts.gate, /pnpm typecheck/)
|
|
287
|
+
assert.doesNotMatch(greenGate.prompts.stop, /make check/)
|
|
288
|
+
|
|
289
|
+
const redGate = await run({
|
|
290
|
+
args: { waves: [[1], [2]], gate: 'make check', grant },
|
|
291
|
+
agents: { ...failing, gate: () => ({ passed: false, detail: 'red' }) },
|
|
292
|
+
})
|
|
293
|
+
assert.equal(redGate.result.stop, 'blocked')
|
|
294
|
+
assert.match(redGate.result.reason, /gate is red/)
|
|
295
|
+
})
|
|
296
|
+
|
|
297
|
+
test('without a stop command the stop agent never runs and the gate decides', async () => {
|
|
298
|
+
const { result, calls } = await run({
|
|
299
|
+
args: { waves: [[1]] },
|
|
300
|
+
agents: { ...green, gate: () => ({ passed: false, detail: 'red' }) },
|
|
301
|
+
})
|
|
302
|
+
assert.equal(result.stop, 'blocked')
|
|
303
|
+
assert.ok(!calls.includes('stop'))
|
|
304
|
+
})
|
|
305
|
+
|
|
306
|
+
test('the grant stop command ends the night early when it passes', async () => {
|
|
307
|
+
const { result, calls } = await run({
|
|
308
|
+
args: { waves: [[1], [2]], grant: { stopCommand: 'scripts/lib/ontology-enforce.sh' } },
|
|
309
|
+
agents: green,
|
|
310
|
+
})
|
|
311
|
+
assert.equal(result.stop, 'done')
|
|
312
|
+
assert.ok(!calls.includes('execute:2'))
|
|
313
|
+
})
|
|
314
|
+
|
|
315
|
+
test('stops before a wave the remaining budget cannot cover', async () => {
|
|
316
|
+
const { result, calls } = await run({
|
|
317
|
+
// wave 1 spends 40k of 90k; the 50k left is under the 55k a wave reserves
|
|
318
|
+
args: { waves: [[1], [2]], waveReserve: 55_000 },
|
|
319
|
+
total: 90_000,
|
|
320
|
+
agents: green,
|
|
321
|
+
})
|
|
322
|
+
assert.equal(result.stop, 'budget')
|
|
323
|
+
assert.ok(!calls.includes('execute:2'))
|
|
324
|
+
})
|