@pmelab/gtd 36.0.0 → 38.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.
- package/.claude-plugin/plugin.json +1 -1
- package/README.md +30 -9
- package/claude/hooks/context.ts +66 -0
- package/claude/hooks/drive.ts +3 -0
- package/claude/hooks/register.tsx +69 -6
- package/dist/chunks/{reserved-BAv71I4i.mjs → reserved-sfMdy7v7.mjs} +83 -22
- package/dist/chunks/{tail-kar1zhOb.mjs → tail-Cgca5Gp-.mjs} +1 -1
- package/dist/chunks/{wire-D3Rc5r22.mjs → wire-CSsa3Wxd.mjs} +117 -2
- package/dist/gtd.bundle.mjs +498 -56
- package/dist/testkit.mjs +115 -3
- package/dist/wire.mjs +2 -2
- package/dist/workflows/cleanup.mjs +2 -2
- package/dist/workflows/feature.mjs +277 -58
- package/dist/workflows/fix.mjs +2 -2
- package/dist/workflows/review.mjs +2 -2
- package/dist/workflows/rollout.mjs +1 -1
- package/dist/workflows.mjs +355 -75
- package/package.json +1 -1
- package/src/cli/Cli.test.ts +10 -3
- package/src/cli/Cli.ts +76 -1
- package/src/cli/Program.test.ts +1 -0
- package/src/cli/Program.ts +28 -0
- package/src/cli/ToolCommands.ts +3 -0
- package/src/edge/Edge.ts +11 -0
- package/src/flows/runtime.ts +11 -0
- package/src/replay/Replay.ts +51 -2
- package/src/testkit/Layers.ts +1 -0
- package/src/testkit/steps.ts +35 -0
- package/src/wire/BeatDocument.ts +12 -2
- package/src/wire/BeatStatus.ts +3 -0
- package/src/wire/ContextLimit.fixture.ts +30 -0
- package/src/wire/ContextLimit.test.ts +96 -0
- package/src/wire/ContextLimit.ts +169 -0
- package/src/wire/index.ts +1 -0
- package/src/wire/types.ts +7 -0
- package/src/workflow/Workflow.ts +9 -1
- package/src/workflows/feature/context-limit.feature +37 -0
- package/src/workflows/feature/coverage.ts +22 -8
- package/src/workflows/feature/criteria.test.ts +17 -1
- package/src/workflows/feature/criteria.ts +26 -3
- package/src/workflows/feature/feature.ts +69 -16
- package/src/workflows/feature/index.ts +1 -0
- package/src/workflows/feature/refactor-absorbs.feature +12 -5
- package/src/workflows/feature/refactor-first.feature +11 -2
- package/src/workflows/feature/refactor-lens-models.feature +4 -0
- package/src/workflows/feature/refactor-rebuild.feature +269 -0
- package/src/workflows/feature/refactor-review.feature +45 -1
- package/src/workflows/feature/refactor.ts +9 -3
- package/src/workflows/feature/seam.test.ts +108 -3
- package/src/workflows/feature/seam.ts +169 -31
- package/src/workflows/feature/slicing-cap.feature +14 -0
- package/src/workflows/feature/slicing.feature +225 -0
- package/src/workflows/feature/slicing.test.ts +49 -0
- package/src/workflows/feature/slicing.ts +105 -0
- package/src/workflows/index.ts +1 -0
- package/src/workflows/shared/fences.ts +5 -0
- package/src/workflows/shared/options.test.ts +11 -2
- package/src/workflows/shared/options.ts +19 -4
- package/src/workflows/shared/steps.ts +2 -0
- package/src/workflows/shared/text.ts +129 -28
- package/src/workflows/shared/vars.ts +1 -0
- package/src/workflows/shared/workflows.steps.ts +13 -0
|
@@ -116,6 +116,7 @@ const statusOf = (input) => {
|
|
|
116
116
|
initial,
|
|
117
117
|
model: rendered.model,
|
|
118
118
|
system: rendered.system !== void 0 && rendered.system !== "" ? rendered.system : void 0,
|
|
119
|
+
context: rendered.context,
|
|
119
120
|
log,
|
|
120
121
|
state: rendered.state,
|
|
121
122
|
actor: rendered.actor,
|
|
@@ -169,7 +170,7 @@ const dispatchFieldsOf = (demand) => {
|
|
|
169
170
|
}
|
|
170
171
|
};
|
|
171
172
|
/**
|
|
172
|
-
* Flatten a `Demand` plus its `BeatStatus` into the single
|
|
173
|
+
* Flatten a `Demand` plus its `BeatStatus` into the single 26-key document
|
|
173
174
|
* `gtd next --json` emits — the ONLY place the two are joined. `cost`/
|
|
174
175
|
* `costByModel` are omitted together, exactly when no cost was recorded
|
|
175
176
|
* (`cost <= 0`).
|
|
@@ -186,6 +187,7 @@ const beatDocument = (demand, status) => {
|
|
|
186
187
|
session,
|
|
187
188
|
model: status.model,
|
|
188
189
|
system: status.system,
|
|
190
|
+
context: status.context,
|
|
189
191
|
validate,
|
|
190
192
|
log: status.log,
|
|
191
193
|
state: status.state,
|
|
@@ -488,4 +490,117 @@ const slicesDocument = (slices) => ({
|
|
|
488
490
|
});
|
|
489
491
|
const renderSlicesJson = (document) => JSON.stringify(document) + "\n";
|
|
490
492
|
//#endregion
|
|
491
|
-
|
|
493
|
+
//#region src/wire/ContextLimit.ts
|
|
494
|
+
const DEFAULT_CONTEXT_LIMIT = {
|
|
495
|
+
soft: .6,
|
|
496
|
+
hard: .7
|
|
497
|
+
};
|
|
498
|
+
const DEFAULT_WINDOW = 2e5;
|
|
499
|
+
const LONG_WINDOW = 1e6;
|
|
500
|
+
/** Claude Code's `[1m]` suffix selects the long window; a transcript never names it, so the driver decides from the model it passed. */
|
|
501
|
+
const contextWindowFor = (model) => model !== void 0 && /\[1m\]/i.test(model) ? LONG_WINDOW : DEFAULT_WINDOW;
|
|
502
|
+
/** A positive whole number of tokens, or `undefined` for anything else. */
|
|
503
|
+
const parseContextWindow = (raw) => {
|
|
504
|
+
const n = Number(raw);
|
|
505
|
+
return raw !== void 0 && raw.trim() !== "" && Number.isInteger(n) && n > 0 ? n : void 0;
|
|
506
|
+
};
|
|
507
|
+
/**
|
|
508
|
+
* Where a driver asks `gtd context-hook` to record a hard stop's `stopReason`:
|
|
509
|
+
* Claude Code prints it nowhere a driver reads, and `hook_stopped` alone would
|
|
510
|
+
* also name any other hook that stopped the turn.
|
|
511
|
+
*/
|
|
512
|
+
const CONTEXT_STOP_FILE_ENV = "GTD_LOOP_CONTEXT_STOP_FILE";
|
|
513
|
+
/**
|
|
514
|
+
* Why one layer of a limit (a scope's, a step's) is malformed, ignoring how its
|
|
515
|
+
* two shares relate: layers merge key by key, so only the merged limit has to
|
|
516
|
+
* keep `soft` below `hard`. Config is evaluated untyped, so anything may arrive.
|
|
517
|
+
*/
|
|
518
|
+
const contextShapeFault = (limit) => {
|
|
519
|
+
if (typeof limit !== "object" || limit === null || Array.isArray(limit)) return `context must be an object { soft, hard }, got ${JSON.stringify(limit)}`;
|
|
520
|
+
const unknown = Object.keys(limit).filter((key) => key !== "soft" && key !== "hard");
|
|
521
|
+
if (unknown.length > 0) return `unknown key(s) ${unknown.join(", ")} in context`;
|
|
522
|
+
const shares = limit;
|
|
523
|
+
for (const key of ["soft", "hard"]) {
|
|
524
|
+
const value = shares[key];
|
|
525
|
+
if (value === void 0) continue;
|
|
526
|
+
if (typeof value !== "number" || !(value > 0 && value <= 1)) return `context.${key} must be a share of the context window in (0, 1], got ${JSON.stringify(value)}`;
|
|
527
|
+
}
|
|
528
|
+
};
|
|
529
|
+
/** Why a whole limit is unusable, or `undefined` when it is fine. */
|
|
530
|
+
const contextLimitFault = (limit) => {
|
|
531
|
+
const shape = contextShapeFault(limit);
|
|
532
|
+
if (shape !== void 0) return shape;
|
|
533
|
+
const shares = limit;
|
|
534
|
+
const soft = shares.soft ?? DEFAULT_CONTEXT_LIMIT.soft;
|
|
535
|
+
const hard = shares.hard ?? DEFAULT_CONTEXT_LIMIT.hard;
|
|
536
|
+
return soft < hard ? void 0 : `context.soft (${soft}) must be below context.hard (${hard})`;
|
|
537
|
+
};
|
|
538
|
+
const record = (value) => typeof value === "object" && value !== null ? value : void 0;
|
|
539
|
+
const count = (value) => typeof value === "number" && value > 0 ? value : 0;
|
|
540
|
+
/** What a message's usage puts in the context window: its whole input, cached or not. */
|
|
541
|
+
const usageTokens = (usage) => {
|
|
542
|
+
const u = record(usage);
|
|
543
|
+
if (u === void 0) return void 0;
|
|
544
|
+
return count(u["input_tokens"]) + count(u["cache_read_input_tokens"]) + count(u["cache_creation_input_tokens"]);
|
|
545
|
+
};
|
|
546
|
+
/**
|
|
547
|
+
* The context size of the latest assistant message in a Claude Code transcript
|
|
548
|
+
* (one JSON entry per line). Usage is per message, not a running sum, so the
|
|
549
|
+
* last entry alone is the window's fill.
|
|
550
|
+
*/
|
|
551
|
+
const transcriptTokens = (transcript) => {
|
|
552
|
+
const lines = transcript.split("\n");
|
|
553
|
+
for (let i = lines.length - 1; i >= 0; i--) {
|
|
554
|
+
const line = lines[i].trim();
|
|
555
|
+
if (line === "") continue;
|
|
556
|
+
let entry;
|
|
557
|
+
try {
|
|
558
|
+
entry = JSON.parse(line);
|
|
559
|
+
} catch {
|
|
560
|
+
continue;
|
|
561
|
+
}
|
|
562
|
+
if (record(entry)?.["type"] !== "assistant") continue;
|
|
563
|
+
const tokens = usageTokens(record(record(entry)?.["message"])?.["usage"]);
|
|
564
|
+
if (tokens !== void 0) return tokens;
|
|
565
|
+
}
|
|
566
|
+
};
|
|
567
|
+
/**
|
|
568
|
+
* A worker subagent's own transcript. A hook its tool call fires is handed the
|
|
569
|
+
* MAIN session's `transcript_path`; the worker's sits beside it.
|
|
570
|
+
*/
|
|
571
|
+
const subagentTranscriptPath = (transcriptPath, agentId) => `${transcriptPath.replace(/\.jsonl$/, "")}/subagents/agent-${agentId}.jsonl`;
|
|
572
|
+
/** Every hard stop's `stopReason` starts with this: the driver's context-limit marker. */
|
|
573
|
+
const CONTEXT_LIMIT_MARKER = "gtd: context limit";
|
|
574
|
+
const percent = (share) => `${Math.round(share * 100)}%`;
|
|
575
|
+
/**
|
|
576
|
+
* What a hook answers, or `undefined` to let the run go on. Compaction about
|
|
577
|
+
* to happen means the limit was missed, so `PreCompact` is a hard stop whatever
|
|
578
|
+
* the count says.
|
|
579
|
+
*/
|
|
580
|
+
const contextHook = (input) => {
|
|
581
|
+
const { event, tokens, window, limit } = input;
|
|
582
|
+
if (event === "PreCompact") return {
|
|
583
|
+
kind: "hard",
|
|
584
|
+
stopReason: `${CONTEXT_LIMIT_MARKER}: the context is about to be compacted — the run is too big for one turn`
|
|
585
|
+
};
|
|
586
|
+
if (tokens === void 0) return void 0;
|
|
587
|
+
const used = `${tokens} of ${window} tokens`;
|
|
588
|
+
if (tokens >= limit.hard * window) return {
|
|
589
|
+
kind: "hard",
|
|
590
|
+
stopReason: `${CONTEXT_LIMIT_MARKER}: ${used}, past the ${percent(limit.hard)} hard limit`
|
|
591
|
+
};
|
|
592
|
+
if (tokens >= limit.soft * window) return {
|
|
593
|
+
kind: "soft",
|
|
594
|
+
reason: `Context limit: ${used} used, past the ${percent(limit.soft)} soft limit. Stop working now. Do not start anything new; end your turn with a short handoff note as your answer: what you touched, and what was next.`
|
|
595
|
+
};
|
|
596
|
+
};
|
|
597
|
+
/** A decision as Claude Code's settings-hook JSON output. */
|
|
598
|
+
const hookOutput = (decision) => decision.kind === "soft" ? {
|
|
599
|
+
decision: "block",
|
|
600
|
+
reason: decision.reason
|
|
601
|
+
} : {
|
|
602
|
+
continue: false,
|
|
603
|
+
stopReason: decision.stopReason
|
|
604
|
+
};
|
|
605
|
+
//#endregion
|
|
606
|
+
export { beatKindOf as A, ACCESS_REFUSAL as B, renderLandPlain as C, renderBeatJson as D, beatDocument as E, EXIT_RUNTIME_ERROR as F, WIRE_SCHEMA as H, EXIT_SIGINT as I, EXIT_SIGTERM as L, stallDiagnosis as M, EXIT_CODES as N, statusOf as O, EXIT_OK as P, EXIT_STRAYS_FOUND as R, renderLandJson as S, renderBeatPlain as T, renderFormat as U, UNATTRIBUTED_MODEL as V, selectPath as _, contextLimitFault as a, landProseText as b, hookOutput as c, transcriptTokens as d, usageTokens as f, resolveSession as g, globMatches as h, contextHook as i, demandOf as j, BEAT_KINDS as k, parseContextWindow as l, slicesDocument as m, CONTEXT_STOP_FILE_ENV as n, contextShapeFault as o, renderSlicesJson as p, DEFAULT_CONTEXT_LIMIT as r, contextWindowFor as s, CONTEXT_LIMIT_MARKER as t, subagentTranscriptPath as u, judgeJson as v, DEMAND_BRIEFING as w, noopText as x, landFields as y, EXIT_USAGE_ERROR as z };
|