@joshuafolkken/kit 1.1379.0 → 1.1387.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 (84) hide show
  1. package/.claude/skills/workflow-commands/backlogrun-progress.md +2 -3
  2. package/.claude/skills/workflow-commands/backlogrun-steps.md +2 -4
  3. package/.claude/skills/workflow-commands/retrospective.md +1 -2
  4. package/dist/hooks/batch-guard.js +6 -6
  5. package/dist/hooks/{chunk-RW4XMF47.js → chunk-2YSW3CXH.js} +133 -234
  6. package/dist/hooks/{chunk-4RWRP3FF.js → chunk-DCY2GWHC.js} +5 -5
  7. package/dist/hooks/{chunk-DHSKBAQ2.js → chunk-EAQEGME7.js} +1 -1
  8. package/dist/hooks/{chunk-E7LZL5AN.js → chunk-EBSHN25W.js} +3 -3
  9. package/dist/hooks/{chunk-HGA4EG5S.js → chunk-GJ7JPIHN.js} +15 -15
  10. package/dist/hooks/{chunk-TG2AB3W6.js → chunk-GNDJ7NJ7.js} +88 -501
  11. package/dist/hooks/{chunk-546X4PX3.js → chunk-IYVOLN6A.js} +3 -3
  12. package/dist/hooks/{chunk-NBEAGPS4.js → chunk-J3KSS7II.js} +1 -1
  13. package/dist/hooks/{chunk-7ZM464OW.js → chunk-LMWBRJIP.js} +3 -3
  14. package/dist/hooks/{chunk-TORRSNDJ.js → chunk-SL4GQ2XP.js} +3 -3
  15. package/dist/hooks/{chunk-PV3FWDSQ.js → chunk-STDSEPWU.js} +2 -2
  16. package/dist/hooks/{chunk-YSDAH73S.js → chunk-U32VSRNG.js} +420 -4
  17. package/dist/hooks/{chunk-QARPP36N.js → chunk-WNFJLBXI.js} +3 -3
  18. package/dist/hooks/codex-hook-adapter.js +13 -13
  19. package/dist/hooks/duplicate-read-guard.js +7 -7
  20. package/dist/hooks/format-edited.js +3 -3
  21. package/dist/hooks/inputs.json +213 -212
  22. package/dist/hooks/investigation-guard.js +7 -7
  23. package/dist/hooks/pretool-guard.js +12 -12
  24. package/dist/hooks/session-lang.js +65 -9
  25. package/dist/hooks/stop-guard.js +104 -32
  26. package/dist/josh.js +2 -2
  27. package/package.json +1 -1
  28. package/prompts/collaboration-workflow/upstream-interrupt.md +1 -1
  29. package/scripts/backlog/backlog-budget-cli.ts +2 -20
  30. package/scripts/backlog/backlog-budget.ts +72 -109
  31. package/scripts/backlog/backlog-drive-cli.ts +12 -7
  32. package/scripts/backlog/backlog-drive-launch.ts +2 -0
  33. package/scripts/backlog/backlog-drive-owner.ts +72 -5
  34. package/scripts/backlog/backlog-drive.ts +5 -2
  35. package/scripts/backlog/backlog-offer-cli.ts +1 -15
  36. package/scripts/backlog/backlogrun-launch.ts +56 -5
  37. package/scripts/document/document-byte-budget.ts +1 -1
  38. package/scripts/epic/epic-candidate-confirm.ts +1 -1
  39. package/scripts/epic/epic-cross-repo.ts +4 -4
  40. package/scripts/epic/epic-next.ts +1 -1
  41. package/scripts/hooks/stop-guard.ts +20 -9
  42. package/scripts/init/start-plan.ts +15 -4
  43. package/scripts/init/start-steps.ts +31 -3
  44. package/scripts/init/start.ts +20 -13
  45. package/scripts/josh/josh-commands-ai.ts +1 -1
  46. package/scripts/josh/josh-commands-project.ts +1 -1
  47. package/scripts/lane/lane-cli.ts +1 -3
  48. package/scripts/run/board/run-board-header.ts +137 -88
  49. package/scripts/run/board/run-board-labels.ts +18 -17
  50. package/scripts/run/board/run-board-machine.ts +21 -8
  51. package/scripts/run/board/run-board-read.ts +9 -2
  52. package/scripts/run/board/run-board-render.ts +1 -5
  53. package/scripts/run/board/run-board-setup.ts +73 -0
  54. package/scripts/run/board/run-board-span.ts +49 -8
  55. package/scripts/run/board/run-board-status.ts +10 -23
  56. package/scripts/run/board/run-board-tick.ts +11 -2
  57. package/scripts/run/carry/run-carry-added.ts +1 -1
  58. package/scripts/run/carry/run-carry-change.ts +1 -1
  59. package/scripts/run/carry/run-carry-cli.ts +36 -60
  60. package/scripts/run/carry/run-carry-ended.ts +10 -2
  61. package/scripts/run/carry/run-carry.ts +38 -68
  62. package/scripts/run/cut/run-cut.ts +4 -4
  63. package/scripts/run/event/run-event-render.ts +1 -1
  64. package/scripts/run/event/run-event-scope.ts +4 -8
  65. package/scripts/run/event/run-event-setup.ts +47 -0
  66. package/scripts/run/event/run-event-stream-emit.ts +0 -25
  67. package/scripts/run/event/run-event-stream.ts +41 -28
  68. package/scripts/run/merge/run-merge-collect.ts +1 -1
  69. package/scripts/run/merge/run-merge-steps.ts +1 -1
  70. package/scripts/run/progress/run-progress-read.ts +1 -1
  71. package/scripts/run/run-headless.ts +2 -2
  72. package/scripts/run/run-status-cli.ts +1 -5
  73. package/scripts/run/run-step.ts +2 -9
  74. package/scripts/run/run-stop-notify.ts +1 -1
  75. package/scripts/run/run-stranded-detect.ts +61 -15
  76. package/scripts/run/run-stranded.ts +25 -17
  77. package/scripts/run/wake/run-wake-cli.ts +58 -15
  78. package/scripts/run/wake/run-wake-describe.ts +5 -5
  79. package/scripts/run/wake/run-wake-driver.ts +13 -4
  80. package/scripts/run/wake/run-wake-handoff.ts +1 -1
  81. package/scripts/run/wake/run-wake-loop.ts +4 -21
  82. package/scripts/run/wake/run-wake-restart.ts +1 -1
  83. package/scripts/run/wake/run-wake.ts +6 -7
  84. package/scripts/backlog/backlog-idle.ts +0 -88
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  investigation_reads
3
- } from "./chunk-QARPP36N.js";
3
+ } from "./chunk-WNFJLBXI.js";
4
4
  import {
5
5
  lane_guard_policy
6
- } from "./chunk-DHSKBAQ2.js";
6
+ } from "./chunk-EAQEGME7.js";
7
7
  import {
8
8
  hook_decision
9
- } from "./chunk-E7LZL5AN.js";
9
+ } from "./chunk-EBSHN25W.js";
10
10
 
11
11
  // scripts/delegation/investigation-guard.ts
12
12
  import { text } from "node:stream/consumers";
@@ -2,7 +2,7 @@ import {
2
2
  ENV_FILE_NAME,
3
3
  issue_number_shape,
4
4
  lane_paths
5
- } from "./chunk-RW4XMF47.js";
5
+ } from "./chunk-2YSW3CXH.js";
6
6
 
7
7
  // scripts/josh/josh-environment-file.ts
8
8
  function load_environment_file() {
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  lane_guard_policy
3
- } from "./chunk-DHSKBAQ2.js";
3
+ } from "./chunk-EAQEGME7.js";
4
4
  import {
5
5
  hook_decision
6
- } from "./chunk-E7LZL5AN.js";
6
+ } from "./chunk-EBSHN25W.js";
7
7
  import {
8
8
  time_batch_guard
9
- } from "./chunk-TORRSNDJ.js";
9
+ } from "./chunk-SL4GQ2XP.js";
10
10
 
11
11
  // scripts/hooks/batch-guard.ts
12
12
  import { text } from "node:stream/consumers";
@@ -6,7 +6,7 @@ import {
6
6
  process_owner_schema,
7
7
  run_carry,
8
8
  time_instant
9
- } from "./chunk-RW4XMF47.js";
9
+ } from "./chunk-2YSW3CXH.js";
10
10
  import {
11
11
  PLATFORM_TEMP_ROOT,
12
12
  PROBE_TIMEOUT_MS,
@@ -739,7 +739,7 @@ var AI_COMMANDS = {
739
739
  // `.env` rather than the ambient environment: the strand notification needs the Telegram
740
740
  // credentials, the same reason `run:wake` carries these flags.
741
741
  tsx_arguments: OPTIONAL_ENV_FILE_FLAGS,
742
- description: "Report whether the run is stranded \u2014 budget handed off, owner gone, and no supervisor watching",
742
+ description: "Report whether the run is stranded \u2014 owner gone, no successor holding the budget, and no supervisor watching",
743
743
  category: "AI tools",
744
744
  reference: ["", "automation", ["processes", "notifications"]]
745
745
  },
@@ -1903,7 +1903,7 @@ var PROJECT_COMMANDS = {
1903
1903
  description: "Set a project up for the GitHub Issue workflow, from git init to the setup PR",
1904
1904
  category: "Project",
1905
1905
  reference: [
1906
- `${PROFILE_ARGUMENTS} [--yes] [--github] [--public] [--init-command <command>]`,
1906
+ `${PROFILE_ARGUMENTS} [--yes] [--github] [--public] [--init-command <command>] [--push-preflight-command <command>]`,
1907
1907
  "developer",
1908
1908
  ["files", "git", "network", "processes"]
1909
1909
  ]
@@ -5,11 +5,11 @@ import {
5
5
  import {
6
6
  ESLINT_EDIT_CACHE_FLAGS,
7
7
  time_density_hook
8
- } from "./chunk-TORRSNDJ.js";
8
+ } from "./chunk-SL4GQ2XP.js";
9
9
  import {
10
10
  file_reader,
11
11
  json_value
12
- } from "./chunk-RW4XMF47.js";
12
+ } from "./chunk-2YSW3CXH.js";
13
13
  import {
14
14
  HOOK_PROCESS_TIMEOUT_MS
15
15
  } from "./chunk-NEC4AT4Z.js";
@@ -1,6 +1,9 @@
1
+ import {
2
+ error_text
3
+ } from "./chunk-CDY4NFQG.js";
1
4
  import {
2
5
  lane_child_marker
3
- } from "./chunk-NBEAGPS4.js";
6
+ } from "./chunk-J3KSS7II.js";
4
7
  import {
5
8
  ENV_FILE_NAME,
6
9
  GIT_LOCATION_VARIABLES,
@@ -20,7 +23,7 @@ import {
20
23
  process_identity,
21
24
  process_owner_schema,
22
25
  run_carry
23
- } from "./chunk-RW4XMF47.js";
26
+ } from "./chunk-2YSW3CXH.js";
24
27
  import {
25
28
  INSTALL_TIMEOUT_MS,
26
29
  PLATFORM_TEMP_ROOT,
@@ -1327,6 +1330,418 @@ var run_headless = {
1327
1330
  must_keep_waiting
1328
1331
  };
1329
1332
 
1333
+ // scripts/run/event/run-event-stream.ts
1334
+ import { z as z3 } from "zod";
1335
+ var EVENT_PREFIX = "josh-run-events-";
1336
+ var EVENT_SUFFIX = ".jsonl";
1337
+ var EVENT_CAP = 500;
1338
+ var FIRST_POSITION = 0;
1339
+ var POSITION_INCREMENT = 1;
1340
+ var LINE_SEPARATOR = "\n";
1341
+ var WORD_SEPARATOR2 = " ";
1342
+ var STAGE_PHASE_INDEX = 2;
1343
+ var LOCK_SUFFIX = ".lock";
1344
+ var LOCK_WAIT_MS = 5e3;
1345
+ var EVENT_KIND = {
1346
+ PLAN: "plan",
1347
+ CHILD_LAUNCH: "child-launch",
1348
+ MERGE: "merge",
1349
+ PARK: "park",
1350
+ SPLIT: "split",
1351
+ OUTAGE: "outage",
1352
+ CUT: "cut",
1353
+ // A fresh session adopted an implementation cut — `run:cut --resume` answered `resume-impl`. The
1354
+ // resume clears the cut record, so without this the `cut` would stay the newest position and
1355
+ // `run:step` would keep answering the resume command it had just run.
1356
+ RESUME: "resume",
1357
+ // The backlog emptied while nothing of the run's own was in flight — the drain. It marks the position
1358
+ // at which the end-of-run retrospective is owed, *before* the idle watch opens, so `run:step` fires
1359
+ // the retrospective at the drain rather than after the watch runs its course. It is not itself a
1360
+ // stop: the run watches on once the retrospective has run, and the real `STOP` follows when the watch
1361
+ // expires.
1362
+ DRAIN: "drain",
1363
+ STOP: "stop",
1364
+ PR_OPENED: "pr-opened",
1365
+ REVIEW_ROUND: "review-round",
1366
+ // The end-of-run retrospective's result, recorded when the run marks the retrospective done. A
1367
+ // retrospective that files zero improvements and one that never ran look
1368
+ // the same from outside — no new Issue either way — so the result is put on the stream the report is
1369
+ // generated from: the issues filed (or that none were), and the candidates dropped with why. It is
1370
+ // emitted from the `run:carry --retrospective` close, so marking the retrospective done and recording
1371
+ // what it found are one action rather than two the run could do only one of.
1372
+ RETROSPECTIVE: "retrospective",
1373
+ // Ready backlog work is sitting undispatched while a lane is free and nothing has dispatched for a
1374
+ // while. Emitted once per stall episode by the stop-time detector, it is both the dedup marker —
1375
+ // `emit_once_since` refuses a second until a `CHILD_LAUNCH` intervenes — and the line a terminal
1376
+ // reader following the stream sees. `run:step` reads it as `backlog:next`, so a run that
1377
+ // stalled is pointed straight at dispatching the work rather than left waiting.
1378
+ STALL: "stall",
1379
+ // The run's own driver is gone: the cut handed the budget off, the owner has died, and no supervisor
1380
+ // is watching. Emitted once per strand episode by the stop-time detector — or by the `run:wake`
1381
+ // supervisor as it fails, leaves that state behind and has warned of it —
1382
+ // exactly as `STALL` is — the newest-event dedup keeps a run polled every stop from notifying more
1383
+ // than once, and a terminal reader following the stream sees the line. The strand is the step before
1384
+ // the stall: a stalled run still has a driver that could dispatch, a stranded one has none.
1385
+ STRANDED: "stranded",
1386
+ // One `josh ship` stage starting, succeeding or failing. It is a trace of the
1387
+ // composite's progress rather than a position the run is at — the positions a ship leaves behind are
1388
+ // the closed issue its `followup` merges, or a detached supervisor's `SHIP_LAUNCH` / `SHIP_STOP` below
1389
+ // — so it is one of the `TRACE_KINDS` the last-event read skips.
1390
+ SHIP_STAGE: "ship-stage",
1391
+ // One progress watcher line — the `at … / next …` heartbeat `run:progress` prints. Printed only to
1392
+ // the watcher's own output, a headless successor's heartbeat would be buried in its log after a cut;
1393
+ // on the stream it reaches the attached session's relay. It says
1394
+ // the run is alive rather than where it is, so it is a trace kind like `SHIP_STAGE`.
1395
+ HEARTBEAT: "heartbeat",
1396
+ // The post-implementation region handed to a detached `josh ship --detach` supervisor. Unlike a stage
1397
+ // trace it is a position: the agent has ended and the
1398
+ // supervisor carries the run, so `run:step` answers `wait` until it stops or the issue closes.
1399
+ SHIP_LAUNCH: "ship-launch",
1400
+ // The supervisor stopped at a failed stage — a red gate, a High/Medium review, a failed push, red CI
1401
+ // The position that hands control back: `run:step` prints the command that
1402
+ // shows the stopped report, so the agent fixes it and relaunches rather than rebuilding the context.
1403
+ SHIP_STOP: "ship-stop",
1404
+ // An Issue the run filed on its way, written by `issue:file`, so a run started from the command line
1405
+ // still surfaces what it found — `run:board`'s findings section reads it.
1406
+ FILED: "filed",
1407
+ // A one-line observation short of an Issue, written with `run:event --append note` and shown in the
1408
+ // same section.
1409
+ NOTE: "note",
1410
+ // A lane child reached a phase no other event marks — its first implementation edit, written by the
1411
+ // PreToolUse hook — so `run:board` draws how far the child has got. A trace,
1412
+ // like `SHIP_STAGE`: it says where the child's work is, not where the run is.
1413
+ LANE_PHASE: "lane-phase",
1414
+ // An issue `run:add` put into the live run. The parent's `--wait` watcher
1415
+ // ends on it, so the issue takes the next free lane without waiting out the arrival probe's minute. A
1416
+ // trace: it says what the run was handed, not where the run is.
1417
+ ADD: "add",
1418
+ // `josh lane:limit` raised a live run's lane limit. The `--wait` watcher's
1419
+ // arrival probe reads it as a wake: the lanes a raise frees are new room for a pool its baseline
1420
+ // already holds. A trace: it says the run gained room, not where the run is.
1421
+ LANE_LIMIT: "lane-limit",
1422
+ // One stage of the run's start — the session starting, the plan, the hand-off to the supervisor, a
1423
+ // lane opening (`run-event-setup.ts`). `run:board` draws it until the first child launches, so the
1424
+ // minutes before one read as work rather than as a run that has stopped. A trace: it says the run is
1425
+ // getting ready, not where the run is.
1426
+ SETUP: "setup"
1427
+ };
1428
+ var EVENT_KINDS = Object.values(EVENT_KIND);
1429
+ var TRACE_KINDS = /* @__PURE__ */ new Set([
1430
+ EVENT_KIND.SHIP_STAGE,
1431
+ EVENT_KIND.HEARTBEAT,
1432
+ EVENT_KIND.FILED,
1433
+ EVENT_KIND.NOTE,
1434
+ EVENT_KIND.LANE_PHASE,
1435
+ EVENT_KIND.ADD,
1436
+ EVENT_KIND.LANE_LIMIT,
1437
+ EVENT_KIND.SETUP
1438
+ ]);
1439
+ var DISPOSABLE_KINDS = /* @__PURE__ */ new Set([
1440
+ EVENT_KIND.SHIP_STAGE,
1441
+ EVENT_KIND.HEARTBEAT,
1442
+ EVENT_KIND.SETUP
1443
+ ]);
1444
+ var event_schema = z3.object({
1445
+ pos: z3.number(),
1446
+ at: z3.string(),
1447
+ kind: z3.string(),
1448
+ text: z3.string()
1449
+ });
1450
+ function is_event_kind(value) {
1451
+ return EVENT_KINDS.includes(value);
1452
+ }
1453
+ function target_of(repository2) {
1454
+ return stamp_file.stamp_path(EVENT_PREFIX, repository2, EVENT_SUFFIX);
1455
+ }
1456
+ function is_present(event) {
1457
+ return event !== void 0;
1458
+ }
1459
+ function parse_line(line) {
1460
+ return event_schema.safeParse(json_value.parse_or_undefined(line)).data;
1461
+ }
1462
+ function read_lines(target) {
1463
+ const raw = stamp_file.read_stamp_text(target);
1464
+ if (raw === void 0) return [];
1465
+ return raw.split(LINE_SEPARATOR).map((line) => line.trim()).filter((line) => line.length > 0).map((line) => parse_line(line)).filter(is_present);
1466
+ }
1467
+ function read_events(target) {
1468
+ return read_lines(target).filter((event) => is_event_kind(event.kind));
1469
+ }
1470
+ function last_position(events) {
1471
+ return events[events.length - POSITION_INCREMENT]?.pos ?? FIRST_POSITION;
1472
+ }
1473
+ function issue_of(event) {
1474
+ return event.text.split(WORD_SEPARATOR2)[FIRST_POSITION] ?? "";
1475
+ }
1476
+ function newest_stages(events) {
1477
+ const newest = /* @__PURE__ */ new Map();
1478
+ for (const event of events) {
1479
+ if (event.kind === EVENT_KIND.SHIP_STAGE) newest.set(issue_of(event), event);
1480
+ }
1481
+ return new Set(newest.values());
1482
+ }
1483
+ function is_stage_start(event) {
1484
+ if (event.kind !== EVENT_KIND.SHIP_STAGE) return false;
1485
+ return event.text.split(WORD_SEPARATOR2)[STAGE_PHASE_INDEX] === run_ship_stage.PHASE.START;
1486
+ }
1487
+ function drawn_lines(events) {
1488
+ const setup = events.findLast((event) => event.kind === EVENT_KIND.SETUP);
1489
+ return /* @__PURE__ */ new Set([...newest_stages(events), ...setup === void 0 ? [] : [setup]]);
1490
+ }
1491
+ function droppable(events) {
1492
+ const kept = drawn_lines(events);
1493
+ const disposable = events.filter((event) => DISPOSABLE_KINDS.has(event.kind) && !kept.has(event));
1494
+ return [
1495
+ ...disposable.filter((event) => !is_stage_start(event)),
1496
+ ...disposable.filter((event) => is_stage_start(event))
1497
+ ];
1498
+ }
1499
+ function bounded(events) {
1500
+ const excess = events.length - EVENT_CAP;
1501
+ if (excess <= 0) return events;
1502
+ const dropped = new Set(droppable(events).slice(0, excess));
1503
+ return events.filter((event) => !dropped.has(event)).slice(-EVENT_CAP);
1504
+ }
1505
+ function serialize(events) {
1506
+ return `${events.map((event) => JSON.stringify(event)).join(LINE_SEPARATOR)}${LINE_SEPARATOR}`;
1507
+ }
1508
+ function append_held(target, event) {
1509
+ const position = last_position(read_lines(target)) + POSITION_INCREMENT;
1510
+ const events = bounded([...read_events(target), { pos: position, ...event }]);
1511
+ stamp_file.replace_text_stamp(target, serialize(events));
1512
+ return position;
1513
+ }
1514
+ function append(target, kind, text, at) {
1515
+ if (!is_event_kind(kind)) return { appended: false, position: FIRST_POSITION };
1516
+ const lock = `${target}${LOCK_SUFFIX}`;
1517
+ const position = repository_lock.with_lock_sync(
1518
+ () => append_held(target, { at, kind, text }),
1519
+ lock,
1520
+ LOCK_WAIT_MS
1521
+ );
1522
+ if (position === void 0) {
1523
+ const message = `run event stream: gave up waiting for the lock at ${lock}`;
1524
+ process.stderr.write(`${message}
1525
+ `);
1526
+ throw new Error(message);
1527
+ }
1528
+ return { appended: true, position };
1529
+ }
1530
+ function read_from(target, position) {
1531
+ const events = read_events(target);
1532
+ return {
1533
+ events: events.filter((event) => event.pos > position),
1534
+ next_position: last_position(events)
1535
+ };
1536
+ }
1537
+ function read_last(target) {
1538
+ return read_events(target).findLast((event) => !TRACE_KINDS.has(event.kind));
1539
+ }
1540
+ function has_since(events, kind, reset_kind) {
1541
+ const reset_at = events.findLastIndex((event) => event.kind === reset_kind);
1542
+ return events.slice(reset_at + POSITION_INCREMENT).some((event) => event.kind === kind);
1543
+ }
1544
+ var FIELD_SEPARATOR = " \xB7 ";
1545
+ function format_event(event) {
1546
+ return [event.at, event.kind, event.text].join(FIELD_SEPARATOR);
1547
+ }
1548
+ var run_event_stream = {
1549
+ EVENT_CAP,
1550
+ EVENT_KIND,
1551
+ EVENT_KINDS,
1552
+ TRACE_KINDS,
1553
+ append,
1554
+ format_event,
1555
+ has_since,
1556
+ is_stage_start,
1557
+ read_events,
1558
+ read_from,
1559
+ read_last,
1560
+ target_of
1561
+ };
1562
+
1563
+ // scripts/run/event/run-event-scope.ts
1564
+ var SINCE_SCOPE = "since";
1565
+ var UNKNOWN_SCOPE = "unknown";
1566
+ var UNKNOWN_EVENT_SCOPE = { kind: UNKNOWN_SCOPE };
1567
+ function moment_of(at) {
1568
+ const parsed = Date.parse(at);
1569
+ return Number.isNaN(parsed) ? void 0 : parsed;
1570
+ }
1571
+ function is_within(event, floor) {
1572
+ const at = moment_of(event.at);
1573
+ return at !== void 0 && at >= floor;
1574
+ }
1575
+ function scoped_events(events, scope) {
1576
+ if (scope.kind === UNKNOWN_SCOPE) return void 0;
1577
+ const floor = moment_of(scope.started_at);
1578
+ if (floor === void 0) return void 0;
1579
+ return events.filter((event) => is_within(event, floor));
1580
+ }
1581
+ function scope_of(read) {
1582
+ if (read.kind !== "carried") return UNKNOWN_EVENT_SCOPE;
1583
+ return { kind: SINCE_SCOPE, started_at: read.carry.started_at };
1584
+ }
1585
+ function last_scoped_event(events, scope) {
1586
+ return scoped_events(events, scope)?.findLast(
1587
+ (event) => !run_event_stream.TRACE_KINDS.has(event.kind)
1588
+ );
1589
+ }
1590
+ var SHIP_POSITION_KINDS = /* @__PURE__ */ new Set([
1591
+ run_event_stream.EVENT_KIND.SHIP_LAUNCH,
1592
+ run_event_stream.EVENT_KIND.SHIP_STOP
1593
+ ]);
1594
+ var KIND = run_event_stream.EVENT_KIND;
1595
+ var BATCH_RECORD_KINDS = /* @__PURE__ */ new Set([
1596
+ KIND.CHILD_LAUNCH,
1597
+ KIND.PARK,
1598
+ KIND.SPLIT,
1599
+ KIND.RETROSPECTIVE,
1600
+ KIND.STRANDED
1601
+ ]);
1602
+ var ISSUE_REFERENCE = /#(\d+)/u;
1603
+ function is_foreign_ship_event(event, issue) {
1604
+ return SHIP_POSITION_KINDS.has(event.kind) && !event.text.startsWith(`${issue_cite.plain(issue)} `);
1605
+ }
1606
+ function is_own_ship_event(event, issue) {
1607
+ return SHIP_POSITION_KINDS.has(event.kind) && !is_foreign_ship_event(event, issue);
1608
+ }
1609
+ function issue_named(event) {
1610
+ return ISSUE_REFERENCE.exec(event.text)?.[1];
1611
+ }
1612
+ function names_issue(event, issue) {
1613
+ return issue_named(event) === issue;
1614
+ }
1615
+ function is_lane_position(event, issue) {
1616
+ return !BATCH_RECORD_KINDS.has(event.kind) && names_issue(event, issue);
1617
+ }
1618
+ function since_own_launch(events, issue) {
1619
+ const launch2 = events.findLastIndex(
1620
+ (event) => event.kind === KIND.CHILD_LAUNCH && names_issue(event, issue)
1621
+ );
1622
+ return events.slice(launch2 + 1);
1623
+ }
1624
+ function is_foreign_event(event, issue, is_lane_child) {
1625
+ if (is_lane_child) return !is_lane_position(event, issue);
1626
+ return is_foreign_ship_event(event, issue);
1627
+ }
1628
+ function last_issue_event(events, scope, issue, is_lane_child) {
1629
+ const attempt = is_lane_child ? since_own_launch(events, issue) : events;
1630
+ const own2 = attempt.filter((event) => !is_foreign_event(event, issue, is_lane_child));
1631
+ if (scope.kind === SINCE_SCOPE) return last_scoped_event(own2, scope);
1632
+ return own2.findLast((event) => is_own_ship_event(event, issue));
1633
+ }
1634
+ var LAUNCH_OR_SETTLE_KINDS = /* @__PURE__ */ new Set([
1635
+ KIND.CHILD_LAUNCH,
1636
+ KIND.MERGE,
1637
+ KIND.PARK,
1638
+ KIND.SPLIT
1639
+ ]);
1640
+ function is_merge_owed(events, scope, issue) {
1641
+ const newest = (scoped_events(events, scope) ?? []).findLast(
1642
+ (event) => LAUNCH_OR_SETTLE_KINDS.has(event.kind) && names_issue(event, issue)
1643
+ );
1644
+ return newest?.kind === KIND.CHILD_LAUNCH;
1645
+ }
1646
+ var run_event_scope = {
1647
+ UNKNOWN_EVENT_SCOPE,
1648
+ is_merge_owed,
1649
+ issue_named,
1650
+ last_issue_event,
1651
+ last_scoped_event,
1652
+ moment_of,
1653
+ scope_of,
1654
+ scoped_events,
1655
+ since_own_launch
1656
+ };
1657
+
1658
+ // scripts/run/event/run-event-stream-emit.ts
1659
+ function now_iso() {
1660
+ return (/* @__PURE__ */ new Date()).toISOString();
1661
+ }
1662
+ async function stream_target() {
1663
+ const repository2 = await run_carry.repository_directory();
1664
+ return repository2 === void 0 ? void 0 : run_event_stream.target_of(repository2);
1665
+ }
1666
+ async function emit(kind, text) {
1667
+ try {
1668
+ const target = await stream_target();
1669
+ if (target === void 0) return;
1670
+ run_event_stream.append(target, kind, text, now_iso());
1671
+ } catch {
1672
+ }
1673
+ }
1674
+ async function emit_once(kind, text) {
1675
+ try {
1676
+ const target = await stream_target();
1677
+ if (target === void 0 || run_event_stream.read_last(target)?.kind === kind) return false;
1678
+ return run_event_stream.append(target, kind, text, now_iso()).appended;
1679
+ } catch (error) {
1680
+ error_text.trace_swallowed("run_event_stream_emit.emit_once", error);
1681
+ return false;
1682
+ }
1683
+ }
1684
+ function invocation_events(repository2, target) {
1685
+ const events = run_event_stream.read_events(target);
1686
+ const scope = run_event_scope.scope_of(run_carry.read_carry(run_carry.carry_path(repository2)));
1687
+ return run_event_scope.scoped_events(events, scope) ?? events;
1688
+ }
1689
+ async function emit_once_since(kind, text, reset_kind) {
1690
+ try {
1691
+ const repository2 = await run_carry.repository_directory();
1692
+ if (repository2 === void 0) return false;
1693
+ const target = run_event_stream.target_of(repository2);
1694
+ if (run_event_stream.has_since(invocation_events(repository2, target), kind, reset_kind)) {
1695
+ return false;
1696
+ }
1697
+ return run_event_stream.append(target, kind, text, now_iso()).appended;
1698
+ } catch (error) {
1699
+ error_text.trace_swallowed("run_event_stream_emit.emit_once_since", error);
1700
+ return false;
1701
+ }
1702
+ }
1703
+ async function emit_heartbeat(line) {
1704
+ await emit(run_event_stream.EVENT_KIND.HEARTBEAT, line);
1705
+ }
1706
+ async function current_events() {
1707
+ try {
1708
+ const repository2 = await run_carry.repository_directory();
1709
+ if (repository2 === void 0) return [];
1710
+ const read = run_carry.read_carry(run_carry.carry_path(repository2));
1711
+ const scope = run_event_scope.scope_of(read);
1712
+ const events = run_event_stream.read_events(run_event_stream.target_of(repository2));
1713
+ return run_event_scope.scoped_events(events, scope) ?? [];
1714
+ } catch {
1715
+ return [];
1716
+ }
1717
+ }
1718
+ async function invocation_or_all_events() {
1719
+ try {
1720
+ const repository2 = await run_carry.repository_directory();
1721
+ return repository2 === void 0 ? [] : invocation_events(repository2, run_event_stream.target_of(repository2));
1722
+ } catch {
1723
+ return [];
1724
+ }
1725
+ }
1726
+ async function all_events() {
1727
+ try {
1728
+ const target = await stream_target();
1729
+ return target === void 0 ? [] : run_event_stream.read_events(target);
1730
+ } catch {
1731
+ return [];
1732
+ }
1733
+ }
1734
+ var run_event_stream_emit = {
1735
+ all_events,
1736
+ current_events,
1737
+ emit,
1738
+ emit_heartbeat,
1739
+ emit_once,
1740
+ emit_once_since,
1741
+ invocation_or_all_events,
1742
+ stream_target
1743
+ };
1744
+
1330
1745
  // scripts/run/detached-launch.ts
1331
1746
  import { spawn } from "node:child_process";
1332
1747
  import { closeSync, constants, openSync, writeSync } from "node:fs";
@@ -1547,8 +1962,9 @@ var detached_launch = {
1547
1962
  export {
1548
1963
  issue_cite,
1549
1964
  git_common_directory,
1550
- repository_lock,
1551
- run_ship_stage,
1965
+ run_event_stream,
1966
+ run_event_scope,
1967
+ run_event_stream_emit,
1552
1968
  agent_role_profile,
1553
1969
  agent_session_role,
1554
1970
  lane_child_invocation,
@@ -1,16 +1,16 @@
1
1
  import {
2
2
  hook_decision
3
- } from "./chunk-E7LZL5AN.js";
3
+ } from "./chunk-EBSHN25W.js";
4
4
  import {
5
5
  cost_blocks,
6
6
  time_batch_guard,
7
7
  time_bundle_call,
8
8
  time_shell,
9
9
  time_spans
10
- } from "./chunk-TORRSNDJ.js";
10
+ } from "./chunk-SL4GQ2XP.js";
11
11
  import {
12
12
  cost_transcript
13
- } from "./chunk-RW4XMF47.js";
13
+ } from "./chunk-2YSW3CXH.js";
14
14
 
15
15
  // scripts/delegation/investigation-reads.ts
16
16
  import path2 from "node:path";
@@ -1,33 +1,33 @@
1
1
  #!/usr/bin/env tsx
2
2
  import {
3
3
  pretool_guard
4
- } from "./chunk-HGA4EG5S.js";
5
- import "./chunk-4RWRP3FF.js";
4
+ } from "./chunk-GJ7JPIHN.js";
5
+ import "./chunk-DCY2GWHC.js";
6
6
  import {
7
7
  bounded_pool
8
- } from "./chunk-TG2AB3W6.js";
8
+ } from "./chunk-GNDJ7NJ7.js";
9
9
  import {
10
10
  build_envelope,
11
11
  compose_context,
12
12
  format_edited_payload
13
- } from "./chunk-PV3FWDSQ.js";
13
+ } from "./chunk-STDSEPWU.js";
14
14
  import "./chunk-JBBMAPC4.js";
15
- import "./chunk-YSDAH73S.js";
15
+ import "./chunk-U32VSRNG.js";
16
16
  import "./chunk-CDY4NFQG.js";
17
- import "./chunk-7ZM464OW.js";
18
- import "./chunk-546X4PX3.js";
19
- import "./chunk-QARPP36N.js";
20
- import "./chunk-DHSKBAQ2.js";
17
+ import "./chunk-LMWBRJIP.js";
18
+ import "./chunk-IYVOLN6A.js";
19
+ import "./chunk-WNFJLBXI.js";
20
+ import "./chunk-EAQEGME7.js";
21
21
  import {
22
22
  hook_decision
23
- } from "./chunk-E7LZL5AN.js";
23
+ } from "./chunk-EBSHN25W.js";
24
24
  import {
25
25
  time_density_hook
26
- } from "./chunk-TORRSNDJ.js";
27
- import "./chunk-NBEAGPS4.js";
26
+ } from "./chunk-SL4GQ2XP.js";
27
+ import "./chunk-J3KSS7II.js";
28
28
  import {
29
29
  json_value
30
- } from "./chunk-RW4XMF47.js";
30
+ } from "./chunk-2YSW3CXH.js";
31
31
  import "./chunk-NEC4AT4Z.js";
32
32
 
33
33
  // scripts/hooks/codex-hook-adapter.ts
@@ -9,13 +9,13 @@ import {
9
9
  is_enabled,
10
10
  notice_refusal_path,
11
11
  refusal_path
12
- } from "./chunk-4RWRP3FF.js";
13
- import "./chunk-QARPP36N.js";
14
- import "./chunk-DHSKBAQ2.js";
15
- import "./chunk-E7LZL5AN.js";
16
- import "./chunk-TORRSNDJ.js";
17
- import "./chunk-NBEAGPS4.js";
18
- import "./chunk-RW4XMF47.js";
12
+ } from "./chunk-DCY2GWHC.js";
13
+ import "./chunk-WNFJLBXI.js";
14
+ import "./chunk-EAQEGME7.js";
15
+ import "./chunk-EBSHN25W.js";
16
+ import "./chunk-SL4GQ2XP.js";
17
+ import "./chunk-J3KSS7II.js";
18
+ import "./chunk-2YSW3CXH.js";
19
19
  import "./chunk-NEC4AT4Z.js";
20
20
  export {
21
21
  DISABLED_VALUES,
@@ -2,10 +2,10 @@
2
2
  import {
3
3
  report_no_payload,
4
4
  run_hook
5
- } from "./chunk-PV3FWDSQ.js";
5
+ } from "./chunk-STDSEPWU.js";
6
6
  import "./chunk-JBBMAPC4.js";
7
- import "./chunk-TORRSNDJ.js";
8
- import "./chunk-RW4XMF47.js";
7
+ import "./chunk-SL4GQ2XP.js";
8
+ import "./chunk-2YSW3CXH.js";
9
9
  import "./chunk-NEC4AT4Z.js";
10
10
 
11
11
  // scripts/hooks/format-edited-cli.ts