@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.
- package/.env.example +12 -0
- package/README.md +7 -7
- package/package.json +1 -13
- package/scripts/sync-channels.mjs +8 -90
- package/scripts/sync-events.mjs +7 -78
- package/scripts/sync-pii.mjs +7 -68
- package/src/api-compat.js +5 -294
- package/src/channels/adapters/telegram.js +3 -298
- package/src/channels/bridge.js +1 -59
- package/src/channels/eventlog.js +3 -57
- package/src/channels/gateway.js +1 -114
- package/src/channels/invoke.js +1 -172
- package/src/channels/normalize.js +1 -58
- package/src/channels/pairing.js +1 -95
- package/src/channels/service.js +1 -329
- package/src/channels/stream.js +5 -104
- package/src/cli-errors.js +3 -136
- package/src/connections.js +1 -160
- package/src/connectors.js +1 -100
- package/src/engines/antigravity.js +5 -235
- package/src/engines/args.js +1 -47
- package/src/engines/claude-warm.js +3 -0
- package/src/engines/claude.js +6 -586
- package/src/engines/cli-agents.js +7 -312
- package/src/engines/codex-appserver.js +12 -0
- package/src/engines/codex.js +6 -481
- package/src/engines/custom.js +17 -577
- package/src/engines/prompt.js +6 -32
- package/src/engines/stream-formats.js +2 -222
- package/src/entitlement.js +1 -77
- package/src/env.js +3 -628
- package/src/events/capability.js +1 -134
- package/src/events/event.js +1 -183
- package/src/events/reach.js +1 -31
- package/src/events/ref.js +1 -63
- package/src/events/scm-connection.js +1 -188
- package/src/events/scopes.js +1 -20
- package/src/events/skill-manifest.js +1 -338
- package/src/events/skill-scan.js +3 -217
- package/src/events/view.js +1 -96
- package/src/mcp-capabilities.js +2 -139
- package/src/mcp-local.js +0 -0
- package/src/mcp-quarantine.js +1 -110
- package/src/mcp-sessions.js +1 -0
- package/src/net.js +1 -107
- package/src/pii/index.js +1 -29
- package/src/pii/net.js +1 -111
- package/src/pii/pii-detect.js +2 -296
- package/src/pii/pii-redact.js +1 -470
- package/src/pii/pipeline.js +1 -137
- package/src/pii/sanitize.js +2 -179
- package/src/pii/tool-harness.js +1 -184
- package/src/pii/tool-rank.js +1 -110
- package/src/proc.js +3 -91
- package/src/relay-timeout.js +1 -21
- package/src/rpc-child.js +3 -0
- package/src/runs.js +1 -49
- package/src/sanitize.js +1 -7
- package/src/scm.js +1 -76
- package/src/server.js +10 -1492
- package/src/service.js +11 -176
- package/src/sign-in.js +1 -91
- package/src/skills.js +1 -399
- package/src/ssrf.js +1 -70
- package/src/update.js +1 -216
- package/src/warm-pool.js +1 -0
- package/src/warm.js +1 -0
- package/src/workdir.js +1 -108
- package/src/worktree.js +3 -125
package/.env.example
CHANGED
|
@@ -10,3 +10,15 @@ CHATPANEL_BRIDGE_PORT=4319
|
|
|
10
10
|
# Safety rails.
|
|
11
11
|
CHATPANEL_MAX_TURNS=20
|
|
12
12
|
CHATPANEL_CODEX_TIMEOUT_MS=180000
|
|
13
|
+
|
|
14
|
+
# Warm agent processes (Codex app-server, Claude Code stream-json): the CLI stays up between a
|
|
15
|
+
# conversation's turns so the next message skips its boot and MCP start-up, and the answer
|
|
16
|
+
# streams as it is written. Sized to the machine by default (RAM ≥32 GB: 3 per agent, ≥16 GB:
|
|
17
|
+
# 2, else 1; idle 10/5 min; ≤20% of RAM or 3 GB resident in total). Set to override.
|
|
18
|
+
# CHATPANEL_WARM=off # every turn cold, as before
|
|
19
|
+
# CHATPANEL_CODEX_APPSERVER=off # Codex only: back to `codex exec --json` (no token streaming)
|
|
20
|
+
# CHATPANEL_CLAUDE_WARM=off # Claude Code only: a fresh `claude --print` per turn
|
|
21
|
+
# CHATPANEL_WARM_MAX=2 # warm processes per agent
|
|
22
|
+
# CHATPANEL_WARM_IDLE_MS=600000 # reap an idle one after this long
|
|
23
|
+
# CHATPANEL_WARM_BUDGET_MB=1500 # resident memory every warm process may hold together
|
|
24
|
+
# CHATPANEL_WARM_LOG=1 # log start/reuse/eviction/measured size to stderr
|
package/README.md
CHANGED
|
@@ -200,13 +200,13 @@ Then `launchctl load ~/Library/LaunchAgents/app.chatpanel.bridge.plist`.
|
|
|
200
200
|
|
|
201
201
|
## License
|
|
202
202
|
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
203
|
+
[**PolyForm Shield License 1.0.0**](LICENSE) — run and modify it for your own use; you may
|
|
204
|
+
not use it to provide a product or service that **competes** with ChatPanel. The npm
|
|
205
|
+
package and the binaries ship minified. What the bridge does is documented above and
|
|
206
|
+
bounded by design: it listens on `127.0.0.1` only, drives the CLI agents you already have
|
|
207
|
+
with your own logins, and sends nothing anywhere itself — every outbound connection you
|
|
208
|
+
see from it is one of your agents talking to its own vendor. Privacy questions:
|
|
209
|
+
privacy@chatpanel.net; security reports: security@chatpanel.net.
|
|
210
210
|
|
|
211
211
|
## Trademarks & brand
|
|
212
212
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chatpanel/bridge",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Local bridge that exposes the AI coding agents installed on your machine — Claude Code (CLI), Codex (CLI), and Antigravity CLI (formerly Gemini CLI, which remains available for business/enterprise) — to the ChatPanel Chrome extension over a localhost SSE endpoint. Bring your own agent.",
|
|
6
6
|
"keywords": [
|
|
@@ -32,18 +32,6 @@
|
|
|
32
32
|
"engines": {
|
|
33
33
|
"node": ">=18"
|
|
34
34
|
},
|
|
35
|
-
"scripts": {
|
|
36
|
-
"start": "node src/server.js",
|
|
37
|
-
"dev": "node --watch src/server.js",
|
|
38
|
-
"test": "node --test tests/*.test.mjs",
|
|
39
|
-
"build:bin": "bash scripts/build-binaries.sh",
|
|
40
|
-
"sync:events": "node scripts/sync-events.mjs",
|
|
41
|
-
"test:events-sync": "node scripts/sync-events.mjs --check",
|
|
42
|
-
"sync:pii": "node scripts/sync-pii.mjs",
|
|
43
|
-
"sync:channels": "node scripts/sync-channels.mjs",
|
|
44
|
-
"test:pii-sync": "node scripts/sync-pii.mjs --check",
|
|
45
|
-
"test:channels-sync": "node scripts/sync-channels.mjs --check"
|
|
46
|
-
},
|
|
47
35
|
"dependencies": {},
|
|
48
36
|
"optionalDependencies": {
|
|
49
37
|
"@anthropic-ai/claude-agent-sdk": "^0.1.0"
|
|
@@ -1,93 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
2
|
+
import{readFileSync as h,writeFileSync as y,existsSync as p,mkdirSync as g}from"node:fs";import{fileURLToPath as j}from"node:url";import{dirname as d,join as s}from"node:path";const o=s(d(j(import.meta.url)),".."),$=["normalize.js","pairing.js","invoke.js","stream.js","bridge.js","gateway.js","eventlog.js","service.js","adapters/telegram.js"],w={"@chatpanel/pii":"../pii/index.js","@chatpanel/events/event.js":"../events/event.js","@chatpanel/events/capability.js":"../events/capability.js","@chatpanel/events/reach.js":"../events/reach.js"};function E(){return[s(o,"node_modules","@chatpanel","channels","src"),s(o,"..","chatpanel-channels","src")].find(n=>p(s(n,"service.js")))}const t=process.argv.includes("--check"),u=E();if(!u){const n="chatpanel-channels not found (check out ../chatpanel-channels).";t&&(console.error(`sync-channels --check: ${n}`),process.exit(1)),console.warn(`sync-channels: ${n} Leaving src/channels as-is.`),process.exit(0)}const k=n=>`// GENERATED — do not edit.
|
|
3
|
+
// Source of truth: chatpanel-channels/src/${n} (npm @chatpanel/channels).
|
|
4
|
+
// Edit there, then run: npm run sync:channels
|
|
3
5
|
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
// second thing a non-technical person has to install and keep alive.
|
|
9
|
-
//
|
|
10
|
-
// node scripts/sync-channels.mjs refresh src/channels/ from the package
|
|
11
|
-
// node scripts/sync-channels.mjs --check verify it matches (drift guard); exit 1 if not
|
|
12
|
-
//
|
|
13
|
-
// The package imports `@chatpanel/pii` and `@chatpanel/events/*` by name; the bridge has no
|
|
14
|
-
// node_modules, so those specifiers are REWRITTEN to the vendored copies as the files are
|
|
15
|
-
// copied. The rewrite is table-driven and fails loudly on an unknown bare import rather than
|
|
16
|
-
// emitting a file that throws at runtime inside a compiled binary.
|
|
17
|
-
|
|
18
|
-
import { readFileSync, writeFileSync, existsSync, mkdirSync } from 'node:fs';
|
|
19
|
-
import { fileURLToPath } from 'node:url';
|
|
20
|
-
import { dirname, join } from 'node:path';
|
|
21
|
-
|
|
22
|
-
const ROOT = join(dirname(fileURLToPath(import.meta.url)), '..');
|
|
23
|
-
|
|
24
|
-
// The service and everything under it. `config.js` is deliberately absent: it resolves paths
|
|
25
|
-
// and reads the bridge token from disk, and the bridge already knows both.
|
|
26
|
-
const FILES = [
|
|
27
|
-
'normalize.js', 'pairing.js', 'invoke.js', 'stream.js', 'bridge.js', 'gateway.js',
|
|
28
|
-
'eventlog.js', 'service.js', 'adapters/telegram.js',
|
|
29
|
-
];
|
|
30
|
-
|
|
31
|
-
// bare specifier → path relative to src/channels/ (adjusted per file depth below).
|
|
32
|
-
const REWRITE = {
|
|
33
|
-
'@chatpanel/pii': '../pii/index.js',
|
|
34
|
-
'@chatpanel/events/event.js': '../events/event.js',
|
|
35
|
-
'@chatpanel/events/capability.js': '../events/capability.js',
|
|
36
|
-
'@chatpanel/events/reach.js': '../events/reach.js',
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
function pkgDir() {
|
|
40
|
-
return [
|
|
41
|
-
join(ROOT, 'node_modules', '@chatpanel', 'channels', 'src'),
|
|
42
|
-
join(ROOT, '..', 'chatpanel-channels', 'src'),
|
|
43
|
-
].find((d) => existsSync(join(d, 'service.js')));
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const check = process.argv.includes('--check');
|
|
47
|
-
const src = pkgDir();
|
|
48
|
-
|
|
49
|
-
if (!src) {
|
|
50
|
-
const msg = 'chatpanel-channels not found (check out ../chatpanel-channels).';
|
|
51
|
-
if (check) { console.error(`sync-channels --check: ${msg}`); process.exit(1); }
|
|
52
|
-
console.warn(`sync-channels: ${msg} Leaving src/channels as-is.`);
|
|
53
|
-
process.exit(0);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const banner = (f) => `// GENERATED — do not edit.\n`
|
|
57
|
-
+ `// Source of truth: chatpanel-channels/src/${f} (npm @chatpanel/channels).\n`
|
|
58
|
-
+ `// Edit there, then run: npm run sync:channels\n`
|
|
59
|
-
+ `//\n`
|
|
60
|
-
+ `// Vendored rather than depended on: the bridge ships zero runtime dependencies so a\n`
|
|
61
|
-
+ `// curl one-liner install cannot fail on someone's registry, and so the compiled\n`
|
|
62
|
-
+ `// single-file binary has nothing to resolve. Package imports are rewritten to the\n`
|
|
63
|
-
+ `// vendored engines (src/pii, src/events) by the sync script.\n\n`;
|
|
64
|
-
|
|
65
|
-
// Rewrite every bare @chatpanel specifier, and refuse to emit a file with one left over.
|
|
66
|
-
function vendor(file, text) {
|
|
67
|
-
const up = '../'.repeat(file.split('/').length - 1); // adapters/telegram.js sits one deeper
|
|
68
|
-
let out = text.replace(/(from\s+['"])(@chatpanel\/[^'"]+)(['"])/g, (full, a, spec, b) => {
|
|
69
|
-
const to = REWRITE[spec];
|
|
70
|
-
if (!to) throw new Error(`sync-channels: no rewrite for '${spec}' (imported by ${file}) — add it to REWRITE`);
|
|
71
|
-
return `${a}${up}${to}${b}`;
|
|
72
|
-
});
|
|
73
|
-
const left = out.match(/from\s+['"]@chatpanel\/[^'"]+['"]/);
|
|
74
|
-
if (left) throw new Error(`sync-channels: unrewritten import in ${file}: ${left[0]}`);
|
|
75
|
-
return banner(file) + out;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
let drift = 0;
|
|
79
|
-
for (const f of FILES) {
|
|
80
|
-
const want = vendor(f, readFileSync(join(src, f), 'utf8'));
|
|
81
|
-
const dest = join(ROOT, 'src', 'channels', f);
|
|
82
|
-
if (!check) mkdirSync(dirname(dest), { recursive: true });
|
|
83
|
-
const have = existsSync(dest) ? readFileSync(dest, 'utf8') : null;
|
|
84
|
-
if (have === want) continue;
|
|
85
|
-
if (check) { console.error(`sync-channels --check: src/channels/${f} differs from chatpanel-channels`); drift += 1; continue; }
|
|
86
|
-
writeFileSync(dest, want);
|
|
87
|
-
console.log(`sync-channels: updated src/channels/${f}`);
|
|
88
|
-
}
|
|
6
|
+
// Vendored rather than depended on: the bridge ships zero runtime dependencies so a
|
|
7
|
+
// curl one-liner install cannot fail on someone's registry, and so the compiled
|
|
8
|
+
// single-file binary has nothing to resolve. Package imports are rewritten to the
|
|
9
|
+
// vendored engines (src/pii, src/events) by the sync script.
|
|
89
10
|
|
|
90
|
-
if (check) {
|
|
91
|
-
if (drift) { console.error('Run `npm run sync:channels` and commit the result.'); process.exit(1); }
|
|
92
|
-
console.log('sync-channels --check: src/channels matches chatpanel-channels ✓');
|
|
93
|
-
}
|
|
11
|
+
`;function b(n,c){const e="../".repeat(n.split("/").length-1);let r=c.replace(/(from\s+['"])(@chatpanel\/[^'"]+)(['"])/g,(R,m,i,v)=>{const l=w[i];if(!l)throw new Error(`sync-channels: no rewrite for '${i}' (imported by ${n}) — add it to REWRITE`);return`${m}${e}${l}${v}`});const a=r.match(/from\s+['"]@chatpanel\/[^'"]+['"]/);if(a)throw new Error(`sync-channels: unrewritten import in ${n}: ${a[0]}`);return k(n)+r}let f=0;for(const n of $){const c=b(n,h(s(u,n),"utf8")),e=s(o,"src","channels",n);if(t||g(d(e),{recursive:!0}),(p(e)?h(e,"utf8"):null)!==c){if(t){console.error(`sync-channels --check: src/channels/${n} differs from chatpanel-channels`),f+=1;continue}y(e,c),console.log(`sync-channels: updated src/channels/${n}`)}}t&&(f&&(console.error("Run `npm run sync:channels` and commit the result."),process.exit(1)),console.log("sync-channels --check: src/channels matches chatpanel-channels ✓"));
|
package/scripts/sync-events.mjs
CHANGED
|
@@ -1,81 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
2
|
+
import{readFileSync as r,writeFileSync as f,existsSync as i,mkdirSync as v}from"node:fs";import{fileURLToPath as d}from"node:url";import{dirname as p,join as n}from"node:path";const c=n(p(d(import.meta.url)),".."),u=["scopes.js","skill-manifest.js","skill-scan.js","ref.js","event.js","view.js","capability.js","reach.js","scm-connection.js"];function m(){return[n(c,"node_modules","@chatpanel","events"),n(c,"..","chatpanel-events")].find(e=>i(n(e,"skill-manifest.js")))}const s=process.argv.includes("--check"),a=m();if(!a){const e="chatpanel-events not found (check out ../chatpanel-events).";s&&(console.error(`sync-events --check: ${e}`),process.exit(1)),console.warn(`sync-events: ${e} Leaving src/events as-is.`),process.exit(0)}const l=n(c,"src","events");s||v(l,{recursive:!0});const y=e=>`// GENERATED — do not edit.
|
|
3
|
+
// Source of truth: chatpanel-events/${e} (npm @chatpanel/events).
|
|
4
|
+
// Edit there, then run: npm run sync:events
|
|
3
5
|
//
|
|
4
|
-
//
|
|
5
|
-
// one-liner
|
|
6
|
-
//
|
|
7
|
-
// @chatpanel/pii does: copied in, generated, never hand-edited.
|
|
8
|
-
//
|
|
9
|
-
// node scripts/sync-events.mjs refresh src/events/ from the package
|
|
10
|
-
// node scripts/sync-events.mjs --check verify they match (CI drift guard); exit 1 if not
|
|
11
|
-
//
|
|
12
|
-
// A hand-copy is how `sanitize.js` could silently diverge from the engine it came from.
|
|
13
|
-
// This makes divergence a failing test instead of a bug report.
|
|
14
|
-
|
|
15
|
-
import { readFileSync, writeFileSync, existsSync, mkdirSync } from 'node:fs';
|
|
16
|
-
import { fileURLToPath } from 'node:url';
|
|
17
|
-
import { dirname, join } from 'node:path';
|
|
18
|
-
|
|
19
|
-
const ROOT = join(dirname(fileURLToPath(import.meta.url)), '..');
|
|
20
|
-
|
|
21
|
-
// Deliberately short. `skill-manifest.js` imports only `scopes.js`, which is why that
|
|
22
|
-
// vocabulary was split out of `capability.js` — vendoring the capability machinery and
|
|
23
|
-
// the event schema to reach a five-element array would defeat the point.
|
|
24
|
-
// The channel service brings the second group: `event.js` (+ its `ref.js`) is the audit
|
|
25
|
-
// appender every channel turn writes through, `capability.js` (+ `view.js`, `scopes.js`) is
|
|
26
|
-
// the invocation contract it validates against, and `reach.js` is the ladder that caps a
|
|
27
|
-
// paired phone. `reach.js` exists as its own module for exactly this reason — the ladder is
|
|
28
|
-
// three strings, and taking it out of `router.js` would have vendored 50 KB of model routing.
|
|
29
|
-
// `scm-connection.js` (architecture-pillars.md §14) is the third group: the connection
|
|
30
|
-
// record a client keeps, the remote → connection match, a job's branch name and the
|
|
31
|
-
// process-scoped credential environment — dependency-free, and the bridge is the one
|
|
32
|
-
// process that hands a token to git.
|
|
33
|
-
const FILES = [
|
|
34
|
-
'scopes.js', 'skill-manifest.js', 'skill-scan.js',
|
|
35
|
-
'ref.js', 'event.js', 'view.js', 'capability.js', 'reach.js',
|
|
36
|
-
'scm-connection.js',
|
|
37
|
-
];
|
|
38
|
-
|
|
39
|
-
function pkgDir() {
|
|
40
|
-
return [
|
|
41
|
-
join(ROOT, 'node_modules', '@chatpanel', 'events'),
|
|
42
|
-
join(ROOT, '..', 'chatpanel-events'),
|
|
43
|
-
].find((d) => existsSync(join(d, 'skill-manifest.js')));
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const check = process.argv.includes('--check');
|
|
47
|
-
const src = pkgDir();
|
|
48
|
-
|
|
49
|
-
if (!src) {
|
|
50
|
-
const msg = 'chatpanel-events not found (check out ../chatpanel-events).';
|
|
51
|
-
if (check) { console.error(`sync-events --check: ${msg}`); process.exit(1); }
|
|
52
|
-
console.warn(`sync-events: ${msg} Leaving src/events as-is.`);
|
|
53
|
-
process.exit(0);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const outDir = join(ROOT, 'src', 'events');
|
|
57
|
-
if (!check) mkdirSync(outDir, { recursive: true });
|
|
58
|
-
|
|
59
|
-
const banner = (f) => `// GENERATED — do not edit.\n`
|
|
60
|
-
+ `// Source of truth: chatpanel-events/${f} (npm @chatpanel/events).\n`
|
|
61
|
-
+ `// Edit there, then run: npm run sync:events\n`
|
|
62
|
-
+ `//\n`
|
|
63
|
-
+ `// Vendored rather than depended on: the bridge ships zero runtime dependencies so a\n`
|
|
64
|
-
+ `// curl one-liner install cannot fail on someone's registry, and so the compiled\n`
|
|
65
|
-
+ `// single-file binary has nothing to resolve.\n\n`;
|
|
66
|
-
|
|
67
|
-
let drift = 0;
|
|
68
|
-
for (const f of FILES) {
|
|
69
|
-
const want = banner(f) + readFileSync(join(src, f), 'utf8');
|
|
70
|
-
const dest = join(outDir, f);
|
|
71
|
-
const have = existsSync(dest) ? readFileSync(dest, 'utf8') : null;
|
|
72
|
-
if (have === want) continue;
|
|
73
|
-
if (check) { console.error(`sync-events --check: src/events/${f} differs from chatpanel-events`); drift += 1; continue; }
|
|
74
|
-
writeFileSync(dest, want);
|
|
75
|
-
console.log(`sync-events: updated src/events/${f}`);
|
|
76
|
-
}
|
|
6
|
+
// Vendored rather than depended on: the bridge ships zero runtime dependencies so a
|
|
7
|
+
// curl one-liner install cannot fail on someone's registry, and so the compiled
|
|
8
|
+
// single-file binary has nothing to resolve.
|
|
77
9
|
|
|
78
|
-
if
|
|
79
|
-
if (drift) { console.error('Run `npm run sync:events` and commit the result.'); process.exit(1); }
|
|
80
|
-
console.log('sync-events --check: src/events matches chatpanel-events ✓');
|
|
81
|
-
}
|
|
10
|
+
`;let h=0;for(const e of u){const o=y(e)+r(n(a,e),"utf8"),t=n(l,e);if((i(t)?r(t,"utf8"):null)!==o){if(s){console.error(`sync-events --check: src/events/${e} differs from chatpanel-events`),h+=1;continue}f(t,o),console.log(`sync-events: updated src/events/${e}`)}}s&&(h&&(console.error("Run `npm run sync:events` and commit the result."),process.exit(1)),console.log("sync-events --check: src/events matches chatpanel-events ✓"));
|
package/scripts/sync-pii.mjs
CHANGED
|
@@ -1,71 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
2
|
+
import{readFileSync as c,writeFileSync as d,existsSync as r,mkdirSync as h}from"node:fs";import{fileURLToPath as f}from"node:url";import{dirname as u,join as n}from"node:path";const s=n(u(f(import.meta.url)),".."),m=["index.js","pii-redact.js","pii-detect.js","pipeline.js","tool-rank.js","tool-harness.js","sanitize.js","net.js"];function y(){return[n(s,"node_modules","@chatpanel","pii"),n(s,"..","chatpanel-pii")].find(i=>r(n(i,"pii-redact.js")))}const e=process.argv.includes("--check"),p=y();if(!p){const i="chatpanel-pii not found (check out ../chatpanel-pii).";e&&(console.error(`sync-pii --check: ${i}`),process.exit(1)),console.warn(`sync-pii: ${i} Leaving src/pii as-is.`),process.exit(0)}const a=n(s,"src","pii");e||h(a,{recursive:!0});const g=i=>`// GENERATED — do not edit.
|
|
3
|
+
// Source of truth: chatpanel-pii/${i} (npm @chatpanel/pii).
|
|
4
|
+
// Edit there, then run: npm run sync:pii
|
|
3
5
|
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
// hand-edited.
|
|
8
|
-
//
|
|
9
|
-
// node scripts/sync-pii.mjs refresh src/pii/ from the package
|
|
10
|
-
// node scripts/sync-pii.mjs --check verify it matches (drift guard); exit 1 if not
|
|
11
|
-
//
|
|
12
|
-
// This is also what retires the oldest hand-copy in the repo: `src/sanitize.js` used to be a
|
|
13
|
-
// manual copy of the same engine's sanitizer, kept in step by memory. It is now a two-line
|
|
14
|
-
// re-export of the vendored copy, so there is one file to diverge from and a test that notices.
|
|
15
|
-
|
|
16
|
-
import { readFileSync, writeFileSync, existsSync, mkdirSync } from 'node:fs';
|
|
17
|
-
import { fileURLToPath } from 'node:url';
|
|
18
|
-
import { dirname, join } from 'node:path';
|
|
19
|
-
|
|
20
|
-
const ROOT = join(dirname(fileURLToPath(import.meta.url)), '..');
|
|
21
|
-
|
|
22
|
-
// The whole engine, because redaction is not a subset you can take half of: `index.js` is the
|
|
23
|
-
// entry the channel core imports, and every file below it is on that graph.
|
|
24
|
-
const FILES = [
|
|
25
|
-
'index.js', 'pii-redact.js', 'pii-detect.js', 'pipeline.js',
|
|
26
|
-
'tool-rank.js', 'tool-harness.js', 'sanitize.js', 'net.js',
|
|
27
|
-
];
|
|
28
|
-
|
|
29
|
-
function pkgDir() {
|
|
30
|
-
return [
|
|
31
|
-
join(ROOT, 'node_modules', '@chatpanel', 'pii'),
|
|
32
|
-
join(ROOT, '..', 'chatpanel-pii'),
|
|
33
|
-
].find((d) => existsSync(join(d, 'pii-redact.js')));
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const check = process.argv.includes('--check');
|
|
37
|
-
const src = pkgDir();
|
|
38
|
-
|
|
39
|
-
if (!src) {
|
|
40
|
-
const msg = 'chatpanel-pii not found (check out ../chatpanel-pii).';
|
|
41
|
-
if (check) { console.error(`sync-pii --check: ${msg}`); process.exit(1); }
|
|
42
|
-
console.warn(`sync-pii: ${msg} Leaving src/pii as-is.`);
|
|
43
|
-
process.exit(0);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const outDir = join(ROOT, 'src', 'pii');
|
|
47
|
-
if (!check) mkdirSync(outDir, { recursive: true });
|
|
48
|
-
|
|
49
|
-
const banner = (f) => `// GENERATED — do not edit.\n`
|
|
50
|
-
+ `// Source of truth: chatpanel-pii/${f} (npm @chatpanel/pii).\n`
|
|
51
|
-
+ `// Edit there, then run: npm run sync:pii\n`
|
|
52
|
-
+ `//\n`
|
|
53
|
-
+ `// Vendored rather than depended on: the bridge ships zero runtime dependencies so a\n`
|
|
54
|
-
+ `// curl one-liner install cannot fail on someone's registry, and so the compiled\n`
|
|
55
|
-
+ `// single-file binary has nothing to resolve.\n\n`;
|
|
56
|
-
|
|
57
|
-
let drift = 0;
|
|
58
|
-
for (const f of FILES) {
|
|
59
|
-
const want = banner(f) + readFileSync(join(src, f), 'utf8');
|
|
60
|
-
const dest = join(outDir, f);
|
|
61
|
-
const have = existsSync(dest) ? readFileSync(dest, 'utf8') : null;
|
|
62
|
-
if (have === want) continue;
|
|
63
|
-
if (check) { console.error(`sync-pii --check: src/pii/${f} differs from chatpanel-pii`); drift += 1; continue; }
|
|
64
|
-
writeFileSync(dest, want);
|
|
65
|
-
console.log(`sync-pii: updated src/pii/${f}`);
|
|
66
|
-
}
|
|
6
|
+
// Vendored rather than depended on: the bridge ships zero runtime dependencies so a
|
|
7
|
+
// curl one-liner install cannot fail on someone's registry, and so the compiled
|
|
8
|
+
// single-file binary has nothing to resolve.
|
|
67
9
|
|
|
68
|
-
if
|
|
69
|
-
if (drift) { console.error('Run `npm run sync:pii` and commit the result.'); process.exit(1); }
|
|
70
|
-
console.log('sync-pii --check: src/pii matches chatpanel-pii ✓');
|
|
71
|
-
}
|
|
10
|
+
`;let l=0;for(const i of m){const t=g(i)+c(n(p,i),"utf8"),o=n(a,i);if((r(o)?c(o,"utf8"):null)!==t){if(e){console.error(`sync-pii --check: src/pii/${i} differs from chatpanel-pii`),l+=1;continue}d(o,t),console.log(`sync-pii: updated src/pii/${i}`)}}e&&(l&&(console.error("Run `npm run sync:pii` and commit the result."),process.exit(1)),console.log("sync-pii --check: src/pii matches chatpanel-pii ✓"));
|