@basein/runner 0.2.11 → 0.3.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 (144) hide show
  1. package/README.md +540 -350
  2. package/dist/auth/client.d.ts +65 -3
  3. package/dist/auth/client.js +305 -53
  4. package/dist/bin/bir-hooks.d.ts +72 -31
  5. package/dist/bin/bir-hooks.js +176 -284
  6. package/dist/bin/bir-proxy.d.ts +17 -2
  7. package/dist/bin/bir-proxy.js +222 -28
  8. package/dist/bin/bir-scenario.d.ts +61 -10
  9. package/dist/bin/bir-scenario.js +704 -135
  10. package/dist/bin/bir.d.ts +14 -8
  11. package/dist/bin/bir.js +2937 -488
  12. package/dist/bin/investigate.js +41 -16
  13. package/dist/bin/scenario-edit.d.ts +43 -10
  14. package/dist/bin/scenario-edit.js +281 -80
  15. package/dist/bin/scenario-liveness.d.ts +194 -0
  16. package/dist/bin/scenario-liveness.js +459 -0
  17. package/dist/bin/scenario-stderr.d.ts +43 -0
  18. package/dist/bin/scenario-stderr.js +76 -0
  19. package/dist/bin/service-read.d.ts +88 -0
  20. package/dist/bin/service-read.js +128 -0
  21. package/dist/bin/setup.d.ts +19 -0
  22. package/dist/bin/setup.js +146 -20
  23. package/dist/config/adapters/claude-code.d.ts +92 -14
  24. package/dist/config/adapters/claude-code.js +291 -101
  25. package/dist/config/adapters/generic.d.ts +4 -1
  26. package/dist/config/adapters/generic.js +13 -14
  27. package/dist/config/generate.d.ts +392 -14
  28. package/dist/config/generate.js +666 -19
  29. package/dist/config/mcp-approval.d.ts +76 -0
  30. package/dist/config/mcp-approval.js +210 -0
  31. package/dist/config/node-path.d.ts +42 -0
  32. package/dist/config/node-path.js +102 -0
  33. package/dist/config/overrides.d.ts +62 -0
  34. package/dist/config/overrides.js +136 -0
  35. package/dist/config/resolve.d.ts +70 -8
  36. package/dist/config/resolve.js +186 -15
  37. package/dist/control/client.d.ts +22 -0
  38. package/dist/control/client.js +26 -7
  39. package/dist/control/correlation.d.ts +23 -5
  40. package/dist/control/correlation.js +0 -0
  41. package/dist/control/daemon.d.ts +400 -18
  42. package/dist/control/daemon.js +1105 -102
  43. package/dist/control/discovery.d.ts +77 -5
  44. package/dist/control/discovery.js +186 -11
  45. package/dist/control/ensure-hook.d.ts +61 -0
  46. package/dist/control/ensure-hook.js +160 -8
  47. package/dist/control/paths.d.ts +26 -0
  48. package/dist/control/paths.js +34 -0
  49. package/dist/control/pin-guard.d.ts +83 -0
  50. package/dist/control/pin-guard.js +534 -0
  51. package/dist/control/recorder-keeper.d.ts +229 -0
  52. package/dist/control/recorder-keeper.js +721 -0
  53. package/dist/control/recorder-main.d.ts +73 -0
  54. package/dist/control/recorder-main.js +778 -0
  55. package/dist/control/server.d.ts +707 -31
  56. package/dist/control/server.js +2803 -306
  57. package/dist/control/transcript.d.ts +21 -1
  58. package/dist/control/transcript.js +378 -112
  59. package/dist/index.d.ts +5 -1
  60. package/dist/index.js +5 -1
  61. package/dist/jsonrpc/framing.d.ts +76 -12
  62. package/dist/jsonrpc/framing.js +216 -59
  63. package/dist/proxy/intercept.d.ts +49 -5
  64. package/dist/proxy/intercept.js +188 -59
  65. package/dist/proxy/relay.d.ts +16 -0
  66. package/dist/proxy/relay.js +77 -5
  67. package/dist/proxy/revive.d.ts +122 -0
  68. package/dist/proxy/revive.js +251 -0
  69. package/dist/proxy/session.d.ts +222 -14
  70. package/dist/proxy/session.js +708 -99
  71. package/dist/record/housekeeping.d.ts +71 -0
  72. package/dist/record/housekeeping.js +417 -0
  73. package/dist/record/recorder.d.ts +51 -3
  74. package/dist/record/recorder.js +3 -0
  75. package/dist/record/redact.d.ts +103 -9
  76. package/dist/record/redact.js +659 -30
  77. package/dist/record/remote-recorder.d.ts +327 -32
  78. package/dist/record/remote-recorder.js +1517 -187
  79. package/dist/record/switchable-recorder.d.ts +126 -0
  80. package/dist/record/switchable-recorder.js +351 -0
  81. package/dist/record/truncate.d.ts +40 -1
  82. package/dist/record/truncate.js +111 -4
  83. package/dist/replay/bash-channel.d.ts +35 -0
  84. package/dist/replay/bash-channel.js +133 -0
  85. package/dist/replay/bundle.d.ts +10 -0
  86. package/dist/replay/bundle.js +10 -0
  87. package/dist/replay/controller.d.ts +371 -20
  88. package/dist/replay/controller.js +1185 -111
  89. package/dist/replay/derive.d.ts +1 -0
  90. package/dist/replay/derive.js +81 -24
  91. package/dist/replay/executor.d.ts +51 -16
  92. package/dist/replay/executor.js +114 -41
  93. package/dist/replay/handover.d.ts +54 -1
  94. package/dist/replay/handover.js +55 -5
  95. package/dist/replay/logic.d.ts +62 -10
  96. package/dist/replay/logic.js +140 -22
  97. package/dist/replay/plan.d.ts +201 -27
  98. package/dist/replay/plan.js +581 -141
  99. package/dist/replay/safety.d.ts +72 -0
  100. package/dist/replay/safety.js +303 -0
  101. package/dist/replay/source-run.d.ts +10 -0
  102. package/dist/replay/source-run.js +80 -35
  103. package/dist/replay/targets.d.ts +15 -1
  104. package/dist/replay/targets.js +62 -4
  105. package/dist/replay/tool-error.d.ts +15 -1
  106. package/dist/replay/tool-error.js +33 -1
  107. package/dist/replay/types.d.ts +7 -4
  108. package/dist/upstream/client.d.ts +56 -3
  109. package/dist/upstream/client.js +61 -4
  110. package/dist/upstream/headers.d.ts +43 -0
  111. package/dist/upstream/headers.js +90 -0
  112. package/dist/upstream/http-client.d.ts +213 -22
  113. package/dist/upstream/http-client.js +1034 -168
  114. package/dist/upstream/http-transport.d.ts +143 -0
  115. package/dist/upstream/http-transport.js +391 -0
  116. package/dist/upstream/lazy-client.d.ts +8 -0
  117. package/dist/upstream/lazy-client.js +29 -1
  118. package/dist/upstream/sse.d.ts +78 -0
  119. package/dist/upstream/sse.js +189 -0
  120. package/dist/upstream/stdio-client.d.ts +61 -1
  121. package/dist/upstream/stdio-client.js +356 -33
  122. package/dist/util/atomic-write.d.ts +29 -0
  123. package/dist/util/atomic-write.js +96 -0
  124. package/dist/util/journal.d.ts +15 -0
  125. package/dist/util/journal.js +48 -3
  126. package/dist/util/log.d.ts +10 -0
  127. package/dist/util/log.js +28 -1
  128. package/dist/util/off-switch.d.ts +46 -0
  129. package/dist/util/off-switch.js +91 -0
  130. package/dist/util/service-health.d.ts +133 -0
  131. package/dist/util/service-health.js +217 -0
  132. package/docs/BaseInstRunner.md +694 -621
  133. package/docs/calculatedReplay.md +1625 -1244
  134. package/docs/calculatedReplayGuide.md +1212 -879
  135. package/docs/installRun.md +1013 -772
  136. package/docs/loginWeb.md +627 -607
  137. package/docs/mcpmark.md +49 -16
  138. package/docs/my-first-sample.md +569 -545
  139. package/docs/quickstart.md +384 -271
  140. package/docs/t-bench.md +406 -394
  141. package/package.json +58 -57
  142. package/production.md +1371 -0
  143. package/scripts/install.ps1 +97 -6
  144. package/scripts/install.sh +104 -7
@@ -5,7 +5,9 @@
5
5
  * Normally nobody runs it: `bir install` makes it the SessionStart hook
6
6
  * (`bir-hooks ensure`), which starts it in the background for the project when no
7
7
  * recorder is running there, and `bir up` / `bir down` start and stop that
8
- * background process by hand. Its audit lines then go to
8
+ * background process by hand. `bir-hooks revive --cwd <project>` starts it
9
+ * again mid-session: a bound proxy spawns it, detached, when the recorder it
10
+ * reported to is gone (control/daemon.ts, reviveDaemon). Its audit lines then go to
9
11
  * ~/.baseinstrunner/logs/<project-key>.log. It can still be run in a terminal:
10
12
  *
11
13
  * bir-hooks # start; Ctrl-C to stop
@@ -16,31 +18,69 @@
16
18
  * 2. accepts step reports from every `bir-proxy` that finds it;
17
19
  * 3. owns run identity, the monotonic `stepIndex`, and the recorder chain (D5).
18
20
  *
21
+ * The recorder listens first and signs in afterwards, in the background, so a
22
+ * slow or unreachable BaseIn service never holds a hook; it starts recording
23
+ * by itself when a sign-in appears (`bir login`) — no restart
24
+ * (control/recorder-main.ts, control/recorder-keeper.ts).
25
+ *
19
26
  * Environment:
20
27
  * BIR_AUTH_URL BaseIn auth-service. Unset, the address `bir setup`
21
28
  * stored in ~/.baseinstrunner/config.json is used
22
- * BIR_CONTROL_PORT preferred port (default 53411; falls back if busy)
23
- * BIR_CORRELATION_DECISION `allow` (default) or `ask` — see below
29
+ * BIR_CONTROL_PORT the port to listen on, over the project's own
30
+ * (default: the project's, else 53411, falling
31
+ * back if busy). 0 is any free port — the one
32
+ * taken is in the discovery file, /health and the
33
+ * log (tests and the smoke run; a project's hooks
34
+ * name a fixed port). A value that is not a port
35
+ * is ignored
36
+ * BIR_CORRELATION_DECISION unset (default: `auto`), `auto`, `allow` or
37
+ * `ask` — see below
24
38
  * BIR_NO_CORRELATION=1 never inject a call id; join on fingerprints
25
39
  * BIR_VERBOSE=1 per-step detail lines
40
+ * BIR_SERVICE_TIMEOUT_MS ceiling for one call to the service made off a
41
+ * hook's path (default 10000)
42
+ * BIR_SUPERSEDED_EXIT_MS how long a recorder the project's hooks moved
43
+ * away from (a reinstall on another port) must
44
+ * have had no session, run, live proxy or unsent
45
+ * step before it exits (default 86400000, a day)
46
+ * BIR_WINDOWS_LAUNCH=spawn Windows only: start the background recorder with
47
+ * a direct hidden spawn instead of PowerShell's
48
+ * Start-Process (faster by about a second; unsafe
49
+ * only when something above Claude Code captures
50
+ * its output — see control/daemon.ts)
26
51
  *
27
52
  * BIR_REPLAY=0 turn OFF calculated replay — running a scenario on
28
53
  * a similar-meaning match (docs/calculatedReplay.md).
29
54
  * ON by default; unset or any value other than "0"
30
- * keeps it on. Read §13.2: a replayed step is
31
- * auto-approved, and a directly executed one never
32
- * reaches the permission system at all.
55
+ * keeps it on (`bir replay off` stores the same
56
+ * for one project). Read §13.2: only when a prompt
57
+ * matches a scenario, that scenario's own steps run
58
+ * without a prompt of their own — a steered step is
59
+ * answered `allow`, a directly executed one never
60
+ * reaches the permission system. Never in plan
61
+ * mode; every other tool call is asked as usual.
33
62
  * BIR_REPLAY_ALLOW_SERVERS comma-separated server keys eligible for *direct*
34
63
  * execution. Unset means every wrapped server
35
64
  * BIR_MIN_STEER_SIMILARITY minimum match similarity to replay (default 0.92)
36
- * ANTHROPIC_API_KEY OPTIONAL. Derivation — reading what this turn acts
65
+ * BIR_DERIVE_API_KEY OPTIONAL. Derivation — reading what this turn acts
37
66
  * on — is done by the service for a signed-in
38
- * runner. Set this only to keep that reading on this
39
- * machine; signed out and unset, a scenario with a
40
- * target does not run (segmented.md R-PARAM-5)
67
+ * runner. Set this (an Anthropic key) only to keep
68
+ * that reading on this machine; signed out and
69
+ * unset, a scenario with a target does not run
70
+ * (segmented.md R-PARAM-5)
71
+ * BIR_USE_ANTHROPIC_API_KEY=1 let the background recorder use an
72
+ * ANTHROPIC_API_KEY from its environment for
73
+ * derivation, as older versions did. Off by
74
+ * default: a recorder the SessionStart hook starts
75
+ * has Claude Code's environment, and using the key
76
+ * found there billed the person's own account. A
77
+ * `bir-hooks` run by hand in a terminal uses that
78
+ * terminal's ANTHROPIC_API_KEY as it always did
41
79
  * BIR_DERIVE_MODEL derivation model (default claude-haiku-4-5-…)
42
- * BIR_MATCH_BUDGET_MS prompt-hook match wait (default 2500)
43
- * BIR_DERIVE_BUDGET_MS first PreToolUse derivation wait (default 8000)
80
+ * BIR_MATCH_BUDGET_MS prompt-hook match wait (default 1500)
81
+ * BIR_DERIVE_BUDGET_MS derivation wait before a direct run (default 8000);
82
+ * inside a hook it is at most BIR_HOOK_DERIVE_BUDGET_MS
83
+ * (default 4000)
44
84
  * BIR_DERIVE_RECENT_RESULTS how many of this prompt's tool results derivation
45
85
  * reads, so a target named by an earlier step can be
46
86
  * found (default 5; 0 off)
@@ -49,31 +89,32 @@
49
89
  * BIR_INTENT_REQUESTS_PER_TURN probes one turn may send (default 40).
50
90
  * Separate from BIR_INTENT_MATCHES_PER_TURN: arming
51
91
  * is a claim on the turn, counting hits is not
92
+ * BIR_INTENT_MATCH_BUDGET_MS one intent probe's own ceiling (default 4000).
93
+ * Not a wait: PreToolUse does not wait for a probe
94
+ * unless arming is on (BIR_SEGMENT_ARM=1 or
95
+ * BIR_INTENT_ARM=1), and then at most
96
+ * BIR_INTENT_ARM_BUDGET_MS (default 500)
52
97
  * BIR_SEGMENT_ARM 1 lets a handed-out segment actually run mid-task.
53
98
  * Unset is observe-only: what would have armed is
54
99
  * logged and nothing is replaced
55
100
  * BIR_MIN_SEGMENT_STEER_SIMILARITY minimum similarity to steer a segment
56
101
  * (default 0.95)
57
- * BIR_REPLAY_BUDGET_MS whole-plan ceiling, direct mode (default 120000)
102
+ * BIR_REPLAY_BUDGET_MS whole-plan ceiling, direct mode (unset: the
103
+ * controller's 100000, BIR_REPLAY_PLAN_BUDGET_MS)
58
104
  * BIR_STEP_TIMEOUT_MS one direct tools/call (default 60000)
59
105
  *
60
- * ABOUT `BIR_CORRELATION_DECISION`. Correlating a wrapped MCP call means
61
- * answering `PreToolUse` with `permissionDecision: "allow"` plus an extra
62
- * argument (Phase 6). That is what the design specifies — and it also
63
- * **auto-approves the call**, so a tool the user would have been asked about is
64
- * no longer asked about. Set `BIR_CORRELATION_DECISION=ask` to keep the prompt;
65
- * hosts that ignore `updatedInput` on a non-allow decision then fall back to
66
- * fingerprint matching, which is lossy under identical concurrent calls.
67
- */
68
- /**
69
- * Assemble the replay configuration (docs/calculatedReplay.md §5.3 of the guide).
70
- *
71
- * The steer threshold defaults **above** the service's own detection threshold
72
- * (0.9). Detection decides "do not record this again", which is cheap — the worst
73
- * case is a lost recording. Steering decides "do not think about this again",
74
- * which is a much stronger claim, and a 0.90-similar prompt usually covers only
75
- * part of the live task.
106
+ * ABOUT `BIR_CORRELATION_DECISION`. Correlating a wrapped MCP call exactly
107
+ * means answering `PreToolUse` with an extra argument, and Claude Code only
108
+ * takes that together with `permissionDecision: "allow"` — which also
109
+ * **auto-approves the call**, so a tool the user would have been asked about
110
+ * is no longer asked about. Unset (or `auto`), nothing is passed to the
111
+ * control server, which never does that for an ordinary call: it injects only
112
+ * where `allow` changes nothing the user is asked (a `bypassPermissions`
113
+ * session) and otherwise joins the proxy's report by fingerprint. `allow` is
114
+ * the behaviour of 0.2.12 and earlier, an explicit opt-in that is logged loudly at start
115
+ * — every wrapped call auto-approved and exactly correlated; `ask` keeps the
116
+ * prompt (a host that ignores the injection on a non-allow answer falls back
117
+ * to fingerprints).
76
118
  */
77
- /** Where the three replay switches came from, for `/health` and `bir doctor`. */
78
- export type ReplaySource = "env" | "sidecar" | "default";
119
+ export type { ReplaySource } from "../control/recorder-main.js";
79
120
  //# sourceMappingURL=bir-hooks.d.ts.map