@chatpanel/bridge 0.11.24 → 0.12.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 (69) hide show
  1. package/.env.example +12 -0
  2. package/README.md +7 -7
  3. package/package.json +1 -13
  4. package/scripts/sync-channels.mjs +8 -90
  5. package/scripts/sync-events.mjs +7 -78
  6. package/scripts/sync-pii.mjs +7 -68
  7. package/src/api-compat.js +5 -294
  8. package/src/channels/adapters/telegram.js +3 -298
  9. package/src/channels/bridge.js +1 -59
  10. package/src/channels/eventlog.js +3 -57
  11. package/src/channels/gateway.js +1 -114
  12. package/src/channels/invoke.js +1 -172
  13. package/src/channels/normalize.js +1 -58
  14. package/src/channels/pairing.js +1 -95
  15. package/src/channels/service.js +1 -329
  16. package/src/channels/stream.js +5 -104
  17. package/src/cli-errors.js +3 -136
  18. package/src/connections.js +1 -160
  19. package/src/connectors.js +1 -100
  20. package/src/engines/antigravity.js +5 -235
  21. package/src/engines/args.js +1 -47
  22. package/src/engines/claude-warm.js +3 -0
  23. package/src/engines/claude.js +6 -586
  24. package/src/engines/cli-agents.js +7 -312
  25. package/src/engines/codex-appserver.js +12 -0
  26. package/src/engines/codex.js +6 -481
  27. package/src/engines/custom.js +17 -577
  28. package/src/engines/prompt.js +6 -32
  29. package/src/engines/stream-formats.js +2 -222
  30. package/src/entitlement.js +1 -77
  31. package/src/env.js +3 -628
  32. package/src/events/capability.js +1 -134
  33. package/src/events/event.js +1 -183
  34. package/src/events/reach.js +1 -31
  35. package/src/events/ref.js +1 -63
  36. package/src/events/scm-connection.js +1 -188
  37. package/src/events/scopes.js +1 -20
  38. package/src/events/skill-manifest.js +1 -338
  39. package/src/events/skill-scan.js +3 -217
  40. package/src/events/view.js +1 -96
  41. package/src/mcp-capabilities.js +2 -139
  42. package/src/mcp-local.js +0 -0
  43. package/src/mcp-quarantine.js +1 -110
  44. package/src/mcp-sessions.js +1 -0
  45. package/src/net.js +1 -107
  46. package/src/pii/index.js +1 -29
  47. package/src/pii/net.js +1 -111
  48. package/src/pii/pii-detect.js +2 -296
  49. package/src/pii/pii-redact.js +1 -470
  50. package/src/pii/pipeline.js +1 -137
  51. package/src/pii/sanitize.js +2 -179
  52. package/src/pii/tool-harness.js +1 -184
  53. package/src/pii/tool-rank.js +1 -110
  54. package/src/proc.js +3 -91
  55. package/src/relay-timeout.js +1 -21
  56. package/src/rpc-child.js +3 -0
  57. package/src/runs.js +1 -49
  58. package/src/sanitize.js +1 -7
  59. package/src/scm.js +1 -76
  60. package/src/server.js +10 -1492
  61. package/src/service.js +11 -176
  62. package/src/sign-in.js +1 -91
  63. package/src/skills.js +1 -399
  64. package/src/ssrf.js +1 -70
  65. package/src/update.js +1 -216
  66. package/src/warm-pool.js +1 -0
  67. package/src/warm.js +1 -0
  68. package/src/workdir.js +1 -108
  69. package/src/worktree.js +3 -125
package/src/runs.js CHANGED
@@ -1,49 +1 @@
1
- // Every in-flight run, so Stop is an INSTRUCTION rather than an inference.
2
- //
3
- // Cancellation used to depend on Node noticing the client's socket close and firing
4
- // `req.on('close')`. That is a signal about a socket, not about intent: it can arrive late,
5
- // and on a request whose body was already consumed it does not reliably arrive at all — so
6
- // a codex `shell:` step ran on for minutes after Stop with nothing left listening to it.
7
- //
8
- // A run registered here can be cancelled by name. The socket-close path stays as a safety
9
- // net for a panel that is closed or crashes, but the button no longer depends on it.
10
- const runs = new Map();
11
-
12
- export function startRun(id) {
13
- const ac = new AbortController();
14
- const children = new Set();
15
- const run = {
16
- id,
17
- signal: ac.signal,
18
- // Children are tracked as well as signalled, because an agent that spawns sub-agents
19
- // spawns processes this module never sees at spawn time. Whoever creates one registers
20
- // it, and Stop reaches all of them.
21
- track(child) { if (child?.pid) { children.add(child); child.once?.('exit', () => children.delete(child)); } },
22
- cancel(reason = 'stopped') {
23
- if (run.cancelled) return false;
24
- run.cancelled = reason;
25
- ac.abort();
26
- return true;
27
- },
28
- cancelled: null,
29
- children,
30
- };
31
- runs.set(id, run);
32
- return run;
33
- }
34
-
35
- export function endRun(id) { runs.delete(id); }
36
-
37
- export function cancelRun(id, reason = 'stopped') {
38
- const run = runs.get(id);
39
- return run ? run.cancel(reason) : false;
40
- }
41
-
42
- /** Used on shutdown: leaving a CLI running after the bridge exits is how orphans are made. */
43
- export function cancelAll(reason = 'shutdown') {
44
- let n = 0;
45
- for (const run of runs.values()) if (run.cancel(reason)) n += 1;
46
- return n;
47
- }
48
-
49
- export const activeRuns = () => runs.size;
1
+ const r=new Map;function l(n){const t=new AbortController,e=new Set,o={id:n,signal:t.signal,track(c){c?.pid&&(e.add(c),c.once?.("exit",()=>e.delete(c)))},cancel(c="stopped"){return o.cancelled?!1:(o.cancelled=c,t.abort(),!0)},cancelled:null,children:e};return r.set(n,o),o}function u(n){r.delete(n)}function a(n,t="stopped"){const e=r.get(n);return e?e.cancel(t):!1}function s(n="shutdown"){let t=0;for(const e of r.values())e.cancel(n)&&(t+=1);return t}const f=()=>r.size;export{f as activeRuns,s as cancelAll,a as cancelRun,u as endRun,l as startRun};
package/src/sanitize.js CHANGED
@@ -1,7 +1 @@
1
- // The Unicode sanitizer, from the one engine that owns it.
2
- //
3
- // This file used to be a HAND copy of chatpanel-pii/sanitize.js, kept in step by memory — the
4
- // exact drift the vendoring scripts exist to prevent. The engine is now vendored properly under
5
- // src/pii/ (npm run sync:pii, with a --check drift guard), so this is a re-export and there is
6
- // only one copy in the repo to diverge from. Existing importers are unchanged.
7
- export { hasHiddenChars, sanitizeUnicode, stripHidden, SANITIZE_RANGES } from './pii/sanitize.js';
1
+ import{hasHiddenChars as e,sanitizeUnicode as n,stripHidden as r,SANITIZE_RANGES as s}from"./pii/sanitize.js";export{s as SANITIZE_RANGES,e as hasHiddenChars,n as sanitizeUnicode,r as stripHidden};
package/src/scm.js CHANGED
@@ -1,76 +1 @@
1
- // scm.js — what a run did in a git checkout, said on the record.
2
- //
3
- // The repository is the source of truth for a project that is code (architecture-pillars.md
4
- // §14): the board holds the conversation, the job board the intent, but what an agent DID
5
- // lives in branches and commits in the hub the organisation already uses. The bridge adds
6
- // no git client — the coding agents know `git` — but it is the one process that knows
7
- // where the agent worked and can look before and after, so it reports: which repo, which
8
- // branch, HEAD when the run started, HEAD when it ended, and how many commits lie between.
9
- // The runner puts that on the task and on the agent's scorecard, where a merged PR will be
10
- // the one outcome fact that does not come from a judge.
11
- //
12
- // Read-only, never writes, never fails a run: a directory that is not a checkout, or a
13
- // machine without git, is `null` and nothing is announced. Every call is bounded by a short
14
- // timeout — `git` on a network filesystem must not stall a chat.
15
-
16
- import { execFile } from 'node:child_process';
17
-
18
- const GIT_TIMEOUT_MS = 2500;
19
-
20
- /** One git query; '' on any failure (no git, not a repo, timed out). */
21
- function git(dir, args, { exec = execFile } = {}) {
22
- return new Promise((resolve) => {
23
- let done = false;
24
- const finish = (v) => { if (!done) { done = true; resolve(v); } };
25
- try {
26
- exec('git', ['-C', dir, ...args], { timeout: GIT_TIMEOUT_MS, windowsHide: true, maxBuffer: 1 << 20 }, (err, stdout) => finish(err ? '' : String(stdout || '').trim()));
27
- } catch { finish(''); }
28
- });
29
- }
30
-
31
- /**
32
- * The checkout at `dir`, or null. `{ repo, remote, branch, head, dirty }` — `repo` is the
33
- * worktree's top level, `remote` the origin URL when there is one (with any credential
34
- * stripped: a token in a URL is not something to put on a record), `branch` the current one
35
- * ('HEAD' when detached), `head` the full commit, `dirty` whether anything is uncommitted.
36
- */
37
- export async function gitState(dir, opts = {}) {
38
- if (!dir) return null;
39
- const repo = await git(dir, ['rev-parse', '--show-toplevel'], opts);
40
- if (!repo) return null;
41
- const [branch, head, remote, status] = await Promise.all([
42
- git(dir, ['rev-parse', '--abbrev-ref', 'HEAD'], opts),
43
- git(dir, ['rev-parse', 'HEAD'], opts),
44
- git(dir, ['remote', 'get-url', 'origin'], opts),
45
- git(dir, ['status', '--porcelain', '--untracked-files=no'], opts),
46
- ]);
47
- return {
48
- repo,
49
- ...(remote ? { remote: stripCredential(remote) } : {}),
50
- branch: branch || 'HEAD',
51
- ...(head ? { head } : {}),
52
- dirty: status.length > 0,
53
- };
54
- }
55
-
56
- /** `https://user:token@host/…` → `https://host/…`. */
57
- export function stripCredential(url) {
58
- return String(url || '').replace(/^([a-z][a-z0-9+.-]*:\/\/)[^@/]+@/i, '$1');
59
- }
60
-
61
- /**
62
- * What the run changed: the state after, plus `commits` — how many lie between the HEAD it
63
- * started at and the HEAD it ended at (0 when unchanged or unknowable). `before` is what
64
- * `gitState` returned at the start; a run that began outside a checkout can still end in
65
- * one (an agent that cloned), so `after` is read regardless.
66
- */
67
- export async function gitDelta(dir, before, opts = {}) {
68
- const after = await gitState(dir, opts);
69
- if (!after) return null;
70
- let commits = 0;
71
- if (before?.head && after.head && before.head !== after.head) {
72
- const n = await git(dir, ['rev-list', '--count', `${before.head}..${after.head}`], opts);
73
- commits = Number(n) || 0;
74
- }
75
- return { ...after, ...(before?.head ? { headBefore: before.head } : {}), commits };
76
- }
1
+ import{execFile as l}from"node:child_process";const s=2500;function u(e,t,{exec:a=l}={}){return new Promise(r=>{let n=!1;const i=o=>{n||(n=!0,r(o))};try{a("git",["-C",e,...t],{timeout:s,windowsHide:!0,maxBuffer:1<<20},(o,c)=>i(o?"":String(c||"").trim()))}catch{i("")}})}async function h(e,t={}){if(!e)return null;const a=await u(e,["rev-parse","--show-toplevel"],t);if(!a)return null;const[r,n,i,o]=await Promise.all([u(e,["rev-parse","--abbrev-ref","HEAD"],t),u(e,["rev-parse","HEAD"],t),u(e,["remote","get-url","origin"],t),u(e,["status","--porcelain","--untracked-files=no"],t)]);return{repo:a,...i?{remote:f(i)}:{},branch:r||"HEAD",...n?{head:n}:{},dirty:o.length>0}}function f(e){return String(e||"").replace(/^([a-z][a-z0-9+.-]*:\/\/)[^@/]+@/i,"$1")}async function d(e,t,a={}){const r=await h(e,a);if(!r)return null;let n=0;if(t?.head&&r.head&&t.head!==r.head){const i=await u(e,["rev-list","--count",`${t.head}..${r.head}`],a);n=Number(i)||0}return{...r,...t?.head?{headBefore:t.head}:{},commits:n}}export{d as gitDelta,h as gitState,f as stripCredential};