@rasensio/aidlc 1.98.0 → 2.0.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.
Files changed (133) hide show
  1. package/README.md +17 -9
  2. package/dist/autopilot/cap.d.ts +39 -0
  3. package/dist/autopilot/cap.d.ts.map +1 -0
  4. package/dist/autopilot/cap.js +55 -0
  5. package/dist/autopilot/cap.js.map +1 -0
  6. package/dist/autopilot/driver.d.ts.map +1 -1
  7. package/dist/autopilot/driver.js +79 -15
  8. package/dist/autopilot/driver.js.map +1 -1
  9. package/dist/autopilot/presets.d.ts +12 -6
  10. package/dist/autopilot/presets.d.ts.map +1 -1
  11. package/dist/autopilot/presets.js +9 -3
  12. package/dist/autopilot/presets.js.map +1 -1
  13. package/dist/autopilot/questions.d.ts +1 -1
  14. package/dist/autopilot/questions.d.ts.map +1 -1
  15. package/dist/autopilot/questions.js +22 -8
  16. package/dist/autopilot/questions.js.map +1 -1
  17. package/dist/autopilot/result.d.ts +2 -0
  18. package/dist/autopilot/result.d.ts.map +1 -1
  19. package/dist/autopilot/result.js +40 -1
  20. package/dist/autopilot/result.js.map +1 -1
  21. package/dist/autopilot/state.d.ts +8 -0
  22. package/dist/autopilot/state.d.ts.map +1 -1
  23. package/dist/autopilot/state.js.map +1 -1
  24. package/dist/autopilot/team.d.ts +2 -0
  25. package/dist/autopilot/team.d.ts.map +1 -1
  26. package/dist/autopilot/team.js +13 -2
  27. package/dist/autopilot/team.js.map +1 -1
  28. package/dist/commands/add-skill.d.ts.map +1 -1
  29. package/dist/commands/add-skill.js +9 -1
  30. package/dist/commands/add-skill.js.map +1 -1
  31. package/dist/commands/autopilot.d.ts +3 -0
  32. package/dist/commands/autopilot.d.ts.map +1 -1
  33. package/dist/commands/autopilot.js +42 -8
  34. package/dist/commands/autopilot.js.map +1 -1
  35. package/dist/commands/cost.d.ts +11 -0
  36. package/dist/commands/cost.d.ts.map +1 -1
  37. package/dist/commands/cost.js +38 -8
  38. package/dist/commands/cost.js.map +1 -1
  39. package/dist/commands/docs.js +1 -1
  40. package/dist/commands/docs.js.map +1 -1
  41. package/dist/commands/init.d.ts +3 -2
  42. package/dist/commands/init.d.ts.map +1 -1
  43. package/dist/commands/init.js +115 -66
  44. package/dist/commands/init.js.map +1 -1
  45. package/dist/commands/metrics.d.ts.map +1 -1
  46. package/dist/commands/metrics.js +9 -2
  47. package/dist/commands/metrics.js.map +1 -1
  48. package/dist/commands/roadmap.d.ts.map +1 -1
  49. package/dist/commands/roadmap.js +10 -0
  50. package/dist/commands/roadmap.js.map +1 -1
  51. package/dist/commands/status.d.ts.map +1 -1
  52. package/dist/commands/status.js +19 -4
  53. package/dist/commands/status.js.map +1 -1
  54. package/dist/commands/update.d.ts.map +1 -1
  55. package/dist/commands/update.js +16 -8
  56. package/dist/commands/update.js.map +1 -1
  57. package/dist/compile/adapters/codex.d.ts +2 -3
  58. package/dist/compile/adapters/codex.d.ts.map +1 -1
  59. package/dist/compile/adapters/codex.js +4 -5
  60. package/dist/compile/adapters/codex.js.map +1 -1
  61. package/dist/compile/adapters/index.d.ts +27 -1
  62. package/dist/compile/adapters/index.d.ts.map +1 -1
  63. package/dist/compile/adapters/index.js +47 -9
  64. package/dist/compile/adapters/index.js.map +1 -1
  65. package/dist/compile/loaders.d.ts.map +1 -1
  66. package/dist/compile/loaders.js +7 -9
  67. package/dist/compile/loaders.js.map +1 -1
  68. package/dist/compile/naming.d.ts +12 -50
  69. package/dist/compile/naming.d.ts.map +1 -1
  70. package/dist/compile/naming.js +12 -54
  71. package/dist/compile/naming.js.map +1 -1
  72. package/dist/compile/skill-format.d.ts +8 -12
  73. package/dist/compile/skill-format.d.ts.map +1 -1
  74. package/dist/compile/skill-format.js +10 -17
  75. package/dist/compile/skill-format.js.map +1 -1
  76. package/dist/core/host.d.ts +39 -0
  77. package/dist/core/host.d.ts.map +1 -0
  78. package/dist/core/host.js +99 -0
  79. package/dist/core/host.js.map +1 -0
  80. package/dist/core/types.d.ts +1 -1
  81. package/dist/core/types.d.ts.map +1 -1
  82. package/dist/cost/report.d.ts +14 -0
  83. package/dist/cost/report.d.ts.map +1 -1
  84. package/dist/cost/report.js +17 -2
  85. package/dist/cost/report.js.map +1 -1
  86. package/dist/doctor/migrations/artifact-source-drift.d.ts.map +1 -1
  87. package/dist/doctor/migrations/artifact-source-drift.js +8 -7
  88. package/dist/doctor/migrations/artifact-source-drift.js.map +1 -1
  89. package/dist/doctor/migrations/roadmap-sync-gh-missing.d.ts.map +1 -1
  90. package/dist/doctor/migrations/roadmap-sync-gh-missing.js +7 -0
  91. package/dist/doctor/migrations/roadmap-sync-gh-missing.js.map +1 -1
  92. package/dist/events/event-bus.d.ts.map +1 -1
  93. package/dist/events/event-bus.js +18 -1
  94. package/dist/events/event-bus.js.map +1 -1
  95. package/dist/metrics/report.d.ts +5 -0
  96. package/dist/metrics/report.d.ts.map +1 -1
  97. package/dist/metrics/report.js +12 -0
  98. package/dist/metrics/report.js.map +1 -1
  99. package/dist/operational/packagers.d.ts +6 -10
  100. package/dist/operational/packagers.d.ts.map +1 -1
  101. package/dist/operational/packagers.js +6 -125
  102. package/dist/operational/packagers.js.map +1 -1
  103. package/dist/roadmap/sync/config.js +4 -4
  104. package/dist/roadmap/sync/config.js.map +1 -1
  105. package/dist/setup/host.d.ts +51 -0
  106. package/dist/setup/host.d.ts.map +1 -0
  107. package/dist/setup/host.js +67 -0
  108. package/dist/setup/host.js.map +1 -0
  109. package/dist/setup/setup-compute.d.ts +6 -0
  110. package/dist/setup/setup-compute.d.ts.map +1 -1
  111. package/dist/setup/setup-compute.js +10 -4
  112. package/dist/setup/setup-compute.js.map +1 -1
  113. package/package.json +2 -2
  114. package/dist/compile/adapters/copilot.d.ts +0 -64
  115. package/dist/compile/adapters/copilot.d.ts.map +0 -1
  116. package/dist/compile/adapters/copilot.js +0 -272
  117. package/dist/compile/adapters/copilot.js.map +0 -1
  118. package/dist/compile/adapters/cursor.d.ts +0 -21
  119. package/dist/compile/adapters/cursor.d.ts.map +0 -1
  120. package/dist/compile/adapters/cursor.js +0 -171
  121. package/dist/compile/adapters/cursor.js.map +0 -1
  122. package/dist/compile/adapters/kiro.d.ts +0 -24
  123. package/dist/compile/adapters/kiro.d.ts.map +0 -1
  124. package/dist/compile/adapters/kiro.js +0 -206
  125. package/dist/compile/adapters/kiro.js.map +0 -1
  126. package/dist/compile/adapters/windsurf.d.ts +0 -25
  127. package/dist/compile/adapters/windsurf.d.ts.map +0 -1
  128. package/dist/compile/adapters/windsurf.js +0 -246
  129. package/dist/compile/adapters/windsurf.js.map +0 -1
  130. package/dist/compile/limits.d.ts +0 -30
  131. package/dist/compile/limits.d.ts.map +0 -1
  132. package/dist/compile/limits.js +0 -30
  133. package/dist/compile/limits.js.map +0 -1
package/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
 
8
8
  ## AI codes fast. AIDLC makes it ship right.
9
9
 
10
- A real software lifecycle for AI coding agents: **phases, gates, state, and traceability** — from idea to maintenance, on any agent platform.
10
+ A real software lifecycle for AI coding agents: **phases, gates, state, and traceability** — from idea to maintenance, in Claude Code and Codex.
11
11
 
12
12
  [![npm](https://img.shields.io/npm/v/%40rasensio%2Faidlc?logo=npm&color=cb3837)](https://www.npmjs.com/package/@rasensio/aidlc)
13
13
  [![downloads](https://img.shields.io/npm/dm/%40rasensio%2Faidlc?color=1f9d55)](https://www.npmjs.com/package/@rasensio/aidlc)
@@ -21,7 +21,7 @@ A real software lifecycle for AI coding agents: **phases, gates, state, and trac
21
21
  npx @rasensio/aidlc init
22
22
  ```
23
23
 
24
- **One command. Any agent.**
24
+ **One command. Claude Code or Codex.**
25
25
 
26
26
  </div>
27
27
 
@@ -36,7 +36,19 @@ Agents outpace the capacity to review what they produce. What's missing isn't th
36
36
  - tests mapped to the criteria they're supposed to prove
37
37
  - a record of why decisions were made
38
38
 
39
- AIDLC adds that missing lifecycle **without slowing the agent down**. It works with **Claude Code**, **Kiro**, **Cursor**, **Windsurf**, **Codex**, **GitHub Copilot** — and any platform that reads skills. State lives as plain YAML in your repo: no server, no lock-in.
39
+ AIDLC adds that missing lifecycle **without slowing the agent down**. It works with **Claude Code** and **Codex**. State lives as plain YAML in your repo: no server, no lock-in.
40
+
41
+ ## Why v2: Claude Code and Codex only
42
+
43
+ AIDLC 2 supports two platforms: Claude Code and Codex. Cursor, Windsurf, Kiro and GitHub Copilot are no longer supported.
44
+
45
+ We are focusing on the top contenders. Two platforms built and tested well beat six built thinly. Every skill, hook and install change used to be shaped six ways, and the four we dropped always got a lesser version. Claude Code and Codex are where the native features exist: plugins, hooks, skill metadata, typed agent results and token cost.
46
+
47
+ If your project is set up for a dropped platform:
48
+
49
+ - Your existing files are left alone. Nothing is deleted.
50
+ - `aidlc update` says so once, and tells you how to silence it.
51
+ - To keep updating those files, stay on 1.x: `npm i -g @rasensio/aidlc@1`.
40
52
 
41
53
  ## The loop
42
54
 
@@ -144,11 +156,7 @@ One canonical skill body is written once and packaged into whatever each tool re
144
156
  | Platform | Config Location | Strategy |
145
157
  |----------|----------------|----------|
146
158
  | Claude Code | `.claude/skills/aidlc-*/SKILL.md` | Thin activation shims |
147
- | Kiro | `.kiro/skills/aidlc-*/SKILL.md` + steering | Shims + steering file |
148
- | Cursor | `.cursor/rules/aidlc-*.mdc` | Description-based rules |
149
- | Windsurf | `.windsurf/rules/aidlc-*.md` | Size-constrained pointer shims |
150
- | Codex | `AGENTS.md` | Managed delimiter block |
151
- | GitHub Copilot | `.github/skills/aidlc-*/SKILL.md` + `.github/copilot-instructions.md` | Full bodies + instructions block |
159
+ | Codex | `.agents/skills/aidlc-*/SKILL.md` + `AGENTS.md` | Skills + managed delimiter block |
152
160
 
153
161
  Switching assistants, or having two people on different ones, doesn't fork your process: the rules are in your repository, the packaging is per-tool.
154
162
 
@@ -333,7 +341,7 @@ The pages ship inside `@rasensio/aidlc-content`, so a project that installed AID
333
341
  | [cost-tracking.md](https://github.com/rasensio/aidlc/blob/main/packages/content/docs/cost-tracking.md) | What a feature cost, and how the number is attributed |
334
342
  | [metrics.md](https://github.com/rasensio/aidlc/blob/main/packages/content/docs/metrics.md) | Change failure rate, lead times, true cost |
335
343
  | [knowledge-graph.md](https://github.com/rasensio/aidlc/blob/main/packages/content/docs/knowledge-graph.md) | Persistent codebase memory for agents |
336
- | [skills-and-platforms.md](https://github.com/rasensio/aidlc/blob/main/packages/content/docs/skills-and-platforms.md) | One canonical skill body, six platform packagings |
344
+ | [skills-and-platforms.md](https://github.com/rasensio/aidlc/blob/main/packages/content/docs/skills-and-platforms.md) | One canonical skill body, two platform packagings |
337
345
  | [hygiene-and-compliance.md](https://github.com/rasensio/aidlc/blob/main/packages/content/docs/hygiene-and-compliance.md) | `aidlc doctor`, compliance packs |
338
346
 
339
347
  ## Development
@@ -0,0 +1,39 @@
1
+ /**
2
+ * The autopilot cost cap in force, in tokens or in dollars (cost-in-tokens/AC-9..AC-19).
3
+ *
4
+ * On a Claude or Codex subscription the dollars are never charged, so a dollar cap
5
+ * stops a run on a figure nobody pays. Setup and init now save the cap in tokens;
6
+ * a dollar cap already saved keeps working until someone sets a new one, because
7
+ * converting it at a guessed rate would change what it stops on without anyone
8
+ * choosing that (design D1).
9
+ *
10
+ * @module
11
+ */
12
+ import type { AutopilotConfig } from './state.js';
13
+ export type Cap = {
14
+ unit: 'tokens';
15
+ tokens: number;
16
+ } | {
17
+ unit: 'usd';
18
+ usd: number;
19
+ };
20
+ /**
21
+ * The cap a config sets, or null for none. Within one config the token cap wins
22
+ * (cost-in-tokens/AC-12); which config the keys came from is settled earlier, by
23
+ * `withTeamDefaults`, which keeps them together.
24
+ */
25
+ export declare function capInForce(c: AutopilotConfig | null | undefined): Cap | null;
26
+ /**
27
+ * `40M`, `500k`, `40000000` → whole tokens; `none` → null; anything else → undefined
28
+ * (cost-in-tokens/AC-10). A fraction is allowed only where a suffix makes it whole
29
+ * (`1.5M`), so a cap is always a whole number of tokens.
30
+ */
31
+ export declare function parseTokenCap(text: string): number | null | undefined;
32
+ /**
33
+ * Tokens left before the cap less a 10% margin — the same margin the dollar cap
34
+ * keeps (autopilot-reads-agent-result/AC-17). Negative once past it.
35
+ */
36
+ export declare function tokensLeft(capTokens: number, usedTokens: number): number;
37
+ /** `40M tokens` or `$15`: the cap in the unit it is set in (cost-in-tokens/AC-19). */
38
+ export declare function capText(cap: Cap): string;
39
+ //# sourceMappingURL=cap.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cap.d.ts","sourceRoot":"","sources":["../../src/autopilot/cap.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElD,MAAM,MAAM,GAAG,GAAG;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,KAAK,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC;AAEpF;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,eAAe,GAAG,IAAI,GAAG,SAAS,GAAG,GAAG,GAAG,IAAI,CAM5E;AAID;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,CAQrE;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAExE;AAED,sFAAsF;AACtF,wBAAgB,OAAO,CAAC,GAAG,EAAE,GAAG,GAAG,MAAM,CAExC"}
@@ -0,0 +1,55 @@
1
+ /**
2
+ * The autopilot cost cap in force, in tokens or in dollars (cost-in-tokens/AC-9..AC-19).
3
+ *
4
+ * On a Claude or Codex subscription the dollars are never charged, so a dollar cap
5
+ * stops a run on a figure nobody pays. Setup and init now save the cap in tokens;
6
+ * a dollar cap already saved keeps working until someone sets a new one, because
7
+ * converting it at a guessed rate would change what it stops on without anyone
8
+ * choosing that (design D1).
9
+ *
10
+ * @module
11
+ */
12
+ import { fmtTokens } from '../commands/cost.js';
13
+ /**
14
+ * The cap a config sets, or null for none. Within one config the token cap wins
15
+ * (cost-in-tokens/AC-12); which config the keys came from is settled earlier, by
16
+ * `withTeamDefaults`, which keeps them together.
17
+ */
18
+ export function capInForce(c) {
19
+ const tokens = c?.cost_cap_tokens;
20
+ if (typeof tokens === 'number')
21
+ return { unit: 'tokens', tokens };
22
+ if (tokens === null)
23
+ return null;
24
+ const usd = c?.cost_cap_usd;
25
+ return typeof usd === 'number' ? { unit: 'usd', usd } : null;
26
+ }
27
+ const TOKEN_CAP_RE = /^(\d+(?:\.\d+)?)([kKmM]?)$/;
28
+ /**
29
+ * `40M`, `500k`, `40000000` → whole tokens; `none` → null; anything else → undefined
30
+ * (cost-in-tokens/AC-10). A fraction is allowed only where a suffix makes it whole
31
+ * (`1.5M`), so a cap is always a whole number of tokens.
32
+ */
33
+ export function parseTokenCap(text) {
34
+ const t = text.trim();
35
+ if (t === 'none')
36
+ return null;
37
+ const m = TOKEN_CAP_RE.exec(t);
38
+ if (m === null)
39
+ return undefined;
40
+ const scale = m[2] === '' ? 1 : m[2].toLowerCase() === 'k' ? 1_000 : 1_000_000;
41
+ const n = Number(m[1]) * scale;
42
+ return Number.isSafeInteger(n) && n > 0 ? n : undefined;
43
+ }
44
+ /**
45
+ * Tokens left before the cap less a 10% margin — the same margin the dollar cap
46
+ * keeps (autopilot-reads-agent-result/AC-17). Negative once past it.
47
+ */
48
+ export function tokensLeft(capTokens, usedTokens) {
49
+ return capTokens - Math.round(capTokens / 10) - usedTokens;
50
+ }
51
+ /** `40M tokens` or `$15`: the cap in the unit it is set in (cost-in-tokens/AC-19). */
52
+ export function capText(cap) {
53
+ return cap.unit === 'tokens' ? `${fmtTokens(cap.tokens)} tokens` : `$${cap.usd}`;
54
+ }
55
+ //# sourceMappingURL=cap.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cap.js","sourceRoot":"","sources":["../../src/autop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EpE;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,cAAc,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI,CAKvG;AAYD;;;;;GAKG;AACH,wBAAgB,UAAU,CACxB,OAAO,EAAE,OAAO,EAChB,KAAK,EAAE,cAAc,EACrB,GAAG,EAAE,MAAM,EACX,QAAQ,GAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAqB,GAC/C,MAAM,CAIR;AAED,wBAAgB,SAAS,CAAC,KAAK,EAAE,cAAc,GAAG,MAAM,GAAG,IAAI,CAE9D;AAED,wBAAgB,WAAW,CAAC,GAAG,EAAE,IAAI,CAAC,SAAS,EAAE,IAAI,GAAG,OAAO,GAAG,KAAK,CAAC,EAAE,KAAK,EAAE,cAAc,GAAG,MAAM,EAAE,CAYzG"}
@@ -18,8 +18,11 @@
18
18
  import { mapUnits } from '../cost/providers/codex.js';
19
19
  import { microToUsd, priceUnits } from '../cost/rates.js';
20
20
  import { MODEL_ID_RE } from '../cost/types.js';
21
+ import { hostFromConfigText } from '../core/host.js';
21
22
  import { classify, jobRef, parseRunJobs } from './ci-jobs.js';
22
23
  import { REASON_MAX, RESET_WAIT_MAX_MS, codexEnd, emptyCodexProgress, firstLine, readClaudeResult, readCodexEvents, refusalSuffix, resetAt, stoppedBy, summaryLines, } from './result.js';
24
+ import { capInForce, tokensLeft } from './cap.js';
25
+ import { fmtTokens } from '../commands/cost.js';
23
26
  import { LEGACY_STOPS, pauseEnv, pendingReview, stopsInForce } from './stops.js';
24
27
  import { OUTCOME_SCHEMA, UUID_RE, budgetCents, resumePrompt, typedArgv, typedHarness, withOutcomeContract, } from './typed.js';
25
28
  /**
@@ -233,6 +236,8 @@ export function launchBlocked(state, now) {
233
236
  }
234
237
  /** The park reason when the item's spend has used up its cap (autopilot-reads-agent-result/AC-7, AC-18, AC-20). */
235
238
  const capReached = (cap, spentMicro) => `cost cap ${cap} USD reached — spent ${microToUsd(spentMicro)}`;
239
+ /** The park reason when the item's tokens have used up its token cap (cost-in-tokens/AC-14, AC-15). */
240
+ const tokenCapReached = (cap, used) => `token cap ${fmtTokens(cap)} reached — used ${fmtTokens(used)} tokens`;
236
241
  const logFile = (ctx, item) => `${ctx.paths.logs}/${item.name}.log`;
237
242
  /**
238
243
  * Launch the item's agent. False when nothing was launched: a session-limit wait is in
@@ -250,13 +255,20 @@ const logFile = (ctx, item) => `${ctx.paths.logs}/${item.name}.log`;
250
255
  function launchAgent(ctx, io, state, item, prompt, budget, resume) {
251
256
  if (launchBlocked(state, ctx.now()) !== null)
252
257
  return false;
253
- const cap = ctx.config?.cost_cap_usd;
258
+ const capSet = capInForce(ctx.config);
259
+ const cap = capSet?.unit === 'usd' ? capSet.usd : undefined;
254
260
  const spent = item.spent_micro_usd ?? 0;
255
261
  const cents = typeof cap === 'number' ? budgetCents(cap, spent) : null;
256
262
  if (typeof cap === 'number' && (cents ?? 0) < 1) {
257
263
  park(ctx, io, state, item, capReached(cap, spent), budget);
258
264
  return false;
259
265
  }
266
+ // A token cap is checked between sessions: Claude has a dollar budget flag and no
267
+ // token one, so `cents` stays null and none is passed (cost-in-tokens/AC-14, AC-17).
268
+ if (capSet?.unit === 'tokens' && tokensLeft(capSet.tokens, item.spent_tokens ?? 0) < 1) {
269
+ park(ctx, io, state, item, tokenCapReached(capSet.tokens, item.spent_tokens ?? 0), budget);
270
+ return false;
271
+ }
260
272
  const command = ctx.config?.agent_command ?? [];
261
273
  const harness = typedHarness(command);
262
274
  const log = logFile(ctx, item);
@@ -285,6 +297,7 @@ function launchAgent(ctx, io, state, item, prompt, budget, resume) {
285
297
  harness,
286
298
  at: new Date(ctx.now()).toISOString(),
287
299
  ...(typeof cap === 'number' ? { cap_usd: cap } : {}),
300
+ ...(capSet?.unit === 'tokens' ? { cap_tokens: capSet.tokens } : {}),
288
301
  log_offset: 0,
289
302
  ...(harness === 'codex' ? { outcome_file: outcomeFile, progress: emptyCodexProgress() } : {}),
290
303
  ...(resume === undefined ? {} : { resumes: resume.session }),
@@ -500,9 +513,22 @@ function sessionSoFar(launch, costMicro) {
500
513
  *
501
514
  * @returns whether it stopped and parked the item.
502
515
  */
503
- function stoppedAtCap(ctx, io, state, item, launch, cap, budget) {
516
+ function stoppedAtCap(ctx, io, state, item, launch, capSet, budget) {
504
517
  if ((launch.progress?.turns ?? 0) === 0)
505
518
  return false;
519
+ // Tokens need no rate, so a token cap stops a run its model's price cannot (cost-in-tokens/AC-15).
520
+ if (capSet.unit === 'tokens') {
521
+ const usage = launch.progress?.usage;
522
+ const used = (item.spent_tokens ?? 0) + (usage === undefined ? 0 : usage.input + usage.output);
523
+ if (tokensLeft(capSet.tokens, used) >= 1)
524
+ return false;
525
+ if (!ctx.dryRun && item.pid !== null)
526
+ ctx.kill(item.pid);
527
+ appendSummary(ctx, item, summaryLines(sessionSoFar(launch, launchUsageMicro(ctx, launch)), 'stopped by autopilot at the token cap'));
528
+ park(ctx, io, state, item, tokenCapReached(capSet.tokens, used), budget);
529
+ return true;
530
+ }
531
+ const cap = capSet.usd;
506
532
  const priced = launchUsageMicro(ctx, launch);
507
533
  if (priced === null) {
508
534
  noteUnpriced(ctx, item, launch);
@@ -576,6 +602,7 @@ function endSession(ctx, item, launch) {
576
602
  * is what was recorded plus this launch's (design, Risk 1). Unpriced adds nothing.
577
603
  */
578
604
  function recordSpend(item, end) {
605
+ recordTokens(item, end);
579
606
  if (end.cost_micro === null)
580
607
  return;
581
608
  const costs = item.session_costs ?? {};
@@ -588,6 +615,23 @@ function recordSpend(item, end) {
588
615
  item.session_costs = costs;
589
616
  }
590
617
  }
618
+ /**
619
+ * {@link recordSpend}'s bookkeeping in tokens: a resumed session adds only its
620
+ * increase, a Codex launch's tokens add to its session's (cost-in-tokens/AC-18).
621
+ */
622
+ function recordTokens(item, end) {
623
+ if (end.tokens === null)
624
+ return;
625
+ const used = item.session_tokens ?? {};
626
+ const id = end.session_id;
627
+ const previous = id === null ? 0 : used[id] ?? 0;
628
+ const session = end.harness === 'codex' ? previous + end.tokens : end.tokens;
629
+ item.spent_tokens = (item.spent_tokens ?? 0) + Math.max(0, session - previous);
630
+ if (id !== null) {
631
+ used[id] = Math.max(previous, session);
632
+ item.session_tokens = used;
633
+ }
634
+ }
591
635
  /** Append lines to the item's log, on a line of their own. Nothing in a dry run. */
592
636
  function appendSummary(ctx, item, lines) {
593
637
  const { append, readRange, size } = ctx.fs;
@@ -604,27 +648,34 @@ function advanceBuilding(ctx, io, state, item, budget) {
604
648
  const launch = item.launch;
605
649
  if (launch?.harness === 'codex')
606
650
  followCodex(ctx, item, launch, false);
607
- const cap = ctx.config?.cost_cap_usd;
608
- if (typeof cap === 'number') {
609
- if (launch?.harness === 'codex' && stoppedAtCap(ctx, io, state, item, launch, cap, budget))
651
+ const capSet = capInForce(ctx.config);
652
+ if (capSet !== null) {
653
+ if (launch?.harness === 'codex' && stoppedAtCap(ctx, io, state, item, launch, capSet, budget))
610
654
  return;
611
- // Every agent, typed or not: the ledger's view of the cap stands (autopilot-reads-agent-result/AC-22).
655
+ // Every agent, typed or not: the ledger's view of the cap stands (autopilot-reads-agent-result/AC-22),
656
+ // in the unit the cap is set in (cost-in-tokens/AC-16).
612
657
  const r = io.cli(['cost', item.name, '--json']);
613
658
  let micro = 0;
659
+ let tokens = 0;
614
660
  try {
615
- micro = JSON.parse(r.stdout)?.[0]?.microUsd ?? 0;
661
+ const row = JSON.parse(r.stdout)?.[0];
662
+ micro = row?.microUsd ?? 0;
663
+ tokens = row?.tokens ?? 0;
616
664
  }
617
665
  catch {
618
666
  // no cost data yet — nothing to compare
619
667
  }
620
- if (micro > cap * 1e6) {
668
+ if (capSet.unit === 'usd' ? micro > capSet.usd * 1e6 : tokens > capSet.tokens) {
621
669
  if (!ctx.dryRun)
622
670
  ctx.kill(item.pid);
623
671
  if (launch !== undefined) {
624
672
  const priced = launch.harness === 'codex' ? launchUsageMicro(ctx, launch) : null;
625
673
  appendSummary(ctx, item, summaryLines(sessionSoFar(launch, priced), 'stopped by autopilot: aidlc cost passed the cap'));
626
674
  }
627
- park(ctx, io, state, item, `cost cap ${cap} USD exceeded`, budget);
675
+ const reason = capSet.unit === 'usd'
676
+ ? `cost cap ${capSet.usd} USD exceeded`
677
+ : `token cap ${fmtTokens(capSet.tokens)} exceeded — aidlc cost reports ${fmtTokens(tokens)} tokens`;
678
+ park(ctx, io, state, item, reason, budget);
628
679
  }
629
680
  }
630
681
  return;
@@ -763,7 +814,7 @@ function byPhase(ctx, io, state, item, budget, suffix = '') {
763
814
  park(ctx, io, state, item, `agent exited before the release boundary (phase ${phase ?? 'unknown'})${suffix}`, budget);
764
815
  return;
765
816
  }
766
- openPullRequest(ctx, io, state, item);
817
+ openPullRequest(ctx, io, state, item, budget);
767
818
  }
768
819
  /**
769
820
  * What a typed session's own result says happens next — first match wins
@@ -799,7 +850,7 @@ function decideFromResult(ctx, io, state, item, launch, end, budget) {
799
850
  // `byPhase`, with the early ending where it would park.
800
851
  const phase = currentPhase(ctx, item);
801
852
  if (phase === 'deployment')
802
- openPullRequest(ctx, io, state, item);
853
+ openPullRequest(ctx, io, state, item, budget);
803
854
  else
804
855
  early(`agent exited before the release boundary (phase ${phase ?? 'unknown'}) — the agent reported no outcome`);
805
856
  return;
@@ -815,7 +866,7 @@ function decideFromResult(ctx, io, state, item, launch, end, budget) {
815
866
  return;
816
867
  }
817
868
  if (outcome === 'shipped' && phase === 'deployment') {
818
- openPullRequest(ctx, io, state, item);
869
+ openPullRequest(ctx, io, state, item, budget);
819
870
  return;
820
871
  }
821
872
  // A `paused` that awaits review was handled before this; one that does not is a stop
@@ -864,7 +915,7 @@ function advanceApproved(ctx, io, state, item, budget) {
864
915
  return;
865
916
  if (currentPhase(ctx, item) === 'deployment') {
866
917
  item.step = 'building';
867
- openPullRequest(ctx, io, state, item);
918
+ openPullRequest(ctx, io, state, item, budget);
868
919
  return;
869
920
  }
870
921
  // A relaunch is a build like any other: it waits for a slot, ahead of new items,
@@ -879,12 +930,24 @@ function advanceApproved(ctx, io, state, item, budget) {
879
930
  // The run's budget: a park for the cap here must reach `run.finished`, or `--items n` never ends.
880
931
  launchAgent(ctx, io, state, item, agentPrompt(item, itemPauses(item)), budget);
881
932
  }
882
- function openPullRequest(ctx, io, state, item) {
933
+ /** The primary checkout's `host`; absent or invalid is `github` (gitlab-and-plain-git/AC-2). */
934
+ const hostOf = (ctx) => hostFromConfigText(ctx.fs.read(`${ctx.repo}/.aidlc/config.yaml`));
935
+ function openPullRequest(ctx, io, state, item, budget) {
883
936
  const push = io.call('git', ['push', '-u', 'origin', item.branch], { cwd: item.worktree });
884
937
  if (push.status !== 0) {
885
938
  failItem(ctx, state, item, `push failed: ${fail(push)}`, 'building');
886
939
  return;
887
940
  }
941
+ // Off GitHub the pushed branch is the end: every later step is a `gh` call, and the work
942
+ // itself succeeded, so the item is dropped rather than parked (gitlab-and-plain-git/AC-15, design D3).
943
+ const host = hostOf(ctx);
944
+ if (host !== 'github') {
945
+ const said = `pushed ${item.branch} — host is ${host}, so autopilot opens no pull request; open and merge it yourself`;
946
+ tell(ctx, item, said);
947
+ notice(ctx, 'branch pushed', `${item.name}: ${said}`);
948
+ drop(state, item, budget);
949
+ return;
950
+ }
888
951
  if (!item.pr) {
889
952
  const pr = io.call('gh', ['pr', 'create', '--base', 'main', '--head', item.branch, '--fill'], { cwd: item.worktree });
890
953
  const n = /\/pull\/(\d+)/.exec(pr.stdout)?.[1];
@@ -1353,7 +1416,8 @@ function startBuilds(ctx, io, state, budget) {
1353
1416
  }
1354
1417
  // Before `aidlc start`, not at launch: a new item has spent nothing, so a cap this small
1355
1418
  // would start and park every ready item in turn (design-questions.md Q1).
1356
- const cap = ctx.config?.cost_cap_usd;
1419
+ const capSet = capInForce(ctx.config);
1420
+ const cap = capSet?.unit === 'usd' ? capSet.usd : undefined;
1357
1421
  if (typeof cap === 'number' && budgetCents(cap, 0) < 1) {
1358
1422
  ctx.say(`not starting builds: cost cap ${cap} USD leaves under a cent after the 10% margin`);
1359
1423
  return;