@zieglar/pi-chat-exchange 0.2.0 → 0.2.2

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 (43) hide show
  1. package/README.md +41 -61
  2. package/dist/bin/ce-native.js +119 -0
  3. package/dist/control/mcp/server.js +1 -1
  4. package/dist/host/mcp-binding-config.js +1 -1
  5. package/dist/runtime/diagnostics.js +3 -3
  6. package/dist/runtime/executables.js +37 -30
  7. package/dist/runtime/native-readiness.js +131 -0
  8. package/dist/runtime/wrapper-identity.js +53 -0
  9. package/dist/storage/connection.js +4 -3
  10. package/dist/storage/filesystem.js +58 -3
  11. package/dist/storage/native-artifact.js +234 -0
  12. package/dist/storage/native-compat.js +65 -0
  13. package/dist/storage/runtime.js +201 -58
  14. package/dist/storage/sqlite-driver-node.js +66 -0
  15. package/dist/storage/sqlite-driver-rust.js +121 -0
  16. package/dist/storage/sqlite-driver-selection.js +86 -0
  17. package/dist/storage/sqlite-driver.js +4 -0
  18. package/dist/storage/store.js +3 -3
  19. package/dist/storage/transaction.js +20 -23
  20. package/dist/tunnel/background-manager.js +5 -52
  21. package/dist/tunnel/codes.js +1 -1
  22. package/dist/tunnel/keychain.js +1 -1
  23. package/dist/tunnel/managed-binding.js +1 -1
  24. package/dist/tunnel/manager-panel.js +1 -1
  25. package/dist/tunnel/profile.js +4 -2
  26. package/dist/tunnel/setup-ui.js +3 -3
  27. package/dist/tunnel/tunnel-id.js +4 -0
  28. package/package.json +8 -20
  29. package/pi-extension/index.ts +34 -0
  30. package/CHANGELOG.md +0 -70
  31. package/docs/architecture.md +0 -170
  32. package/docs/chatgpt-installation.md +0 -149
  33. package/docs/delivery-ack-contract.md +0 -86
  34. package/docs/independent-install.md +0 -156
  35. package/docs/multi-session-usage.md +0 -77
  36. package/docs/ownership-contract.md +0 -429
  37. package/docs/protocol-v2.md +0 -269
  38. package/docs/releases/0.2.0.md +0 -59
  39. package/docs/storage-contract.md +0 -1241
  40. package/docs/storage-security.md +0 -138
  41. package/docs/tunnel-manager-background.md +0 -169
  42. package/docs/tunnel-setup.md +0 -214
  43. package/pi-extension/README.md +0 -125
@@ -1,17 +1,17 @@
1
- import { constants } from "node:sqlite";
2
1
  export class StorageTransactionError extends Error {
3
- code;
2
+ code = "STORAGE_TRANSACTION_FAILED";
4
3
  stage;
5
- outcome;
6
4
  retryable;
7
5
  constructor(message, stage, options) {
8
6
  super(message, options);
9
7
  this.name = "StorageTransactionError";
8
+ this.stage = stage;
10
9
  this.outcome = options?.outcome ?? "INDETERMINATE";
11
10
  this.retryable = options?.busy === true && this.outcome === "ROLLED_BACK";
12
- this.code = this.retryable ? "STORAGE_TRANSACTION_BUSY" : "STORAGE_TRANSACTION_FAILED";
13
- this.stage = stage;
11
+ if (this.retryable)
12
+ this.code = "STORAGE_TRANSACTION_BUSY";
14
13
  }
14
+ outcome;
15
15
  }
16
16
  export class ConditionalMutationError extends Error {
17
17
  code = "STORAGE_CONDITIONAL_MUTATION_FAILED";
@@ -31,7 +31,7 @@ function invalidate(db) {
31
31
  catch {
32
32
  // If close itself fails, poison authorization as well as helper reuse.
33
33
  try {
34
- db.setAuthorizer(() => constants.SQLITE_DENY);
34
+ db.setAuthorizerPolicy("deny-all");
35
35
  }
36
36
  catch { /* already unusable */ }
37
37
  }
@@ -106,8 +106,6 @@ export function withImmediateTransaction(db, callback) {
106
106
  });
107
107
  }
108
108
  let capabilityActive = true;
109
- let ownerControl = false;
110
- let controlAttempted = false;
111
109
  const assertActive = () => {
112
110
  if (!capabilityActive)
113
111
  throw new StorageTransactionError("transaction handle is revoked", "callback");
@@ -120,11 +118,10 @@ export function withImmediateTransaction(db, callback) {
120
118
  assertActive();
121
119
  const statement = db.prepare(sql);
122
120
  return Object.freeze({
123
- // Parameters extracts the named overload; the cast retains both overloads.
124
121
  // Every supplied argument is forwarded unchanged to SQLite's typed method.
125
- run: ((...args) => { assertActive(); return statement.run(...args); }),
126
- get: ((...args) => { assertActive(); return statement.get(...args); }),
127
- all: ((...args) => { assertActive(); return statement.all(...args); }),
122
+ run: (...args) => { assertActive(); return statement.run(...args); },
123
+ get: (...args) => { assertActive(); return statement.get(...args); },
124
+ all: (...args) => { assertActive(); return statement.all(...args); },
128
125
  });
129
126
  },
130
127
  });
@@ -132,22 +129,19 @@ export function withImmediateTransaction(db, callback) {
132
129
  try {
133
130
  // SQLite authorizes parsed actions, including previously prepared statements
134
131
  // invalidated by setAuthorizer. Not a SQL-prefix/regex filter.
135
- db.setAuthorizer((action) => {
136
- if (!ownerControl && (action === constants.SQLITE_TRANSACTION || action === constants.SQLITE_SAVEPOINT)) {
137
- controlAttempted = true;
138
- return constants.SQLITE_DENY;
139
- }
140
- return constants.SQLITE_OK;
141
- });
132
+ db.setAuthorizerPolicy("deny-transaction-control");
142
133
  assertVoidResult(callback(tx));
143
- if (controlAttempted)
134
+ if (db.authorizerDenials() > 0)
144
135
  throw new Error("callback attempted owned transaction control");
145
136
  if (!db.isTransaction)
146
137
  throw new Error("owned transaction ended unexpectedly");
147
138
  }
148
139
  catch (error) {
149
140
  capabilityActive = false;
150
- ownerControl = true;
141
+ try {
142
+ db.setAuthorizerPolicy("off");
143
+ }
144
+ catch { /* rollback classification owns closed state */ }
151
145
  rollbackOwnedTransaction(db, error);
152
146
  if (error instanceof ConditionalMutationError)
153
147
  throw error;
@@ -157,7 +151,10 @@ export function withImmediateTransaction(db, callback) {
157
151
  }
158
152
  finally {
159
153
  capabilityActive = false;
160
- ownerControl = true;
154
+ try {
155
+ db.setAuthorizerPolicy("off");
156
+ }
157
+ catch { /* do not mask the original outcome */ }
161
158
  }
162
159
  try {
163
160
  db.exec("COMMIT");
@@ -183,7 +180,7 @@ export function withImmediateTransaction(db, callback) {
183
180
  capabilityActive = false;
184
181
  if (!invalidated.has(db)) {
185
182
  try {
186
- db.setAuthorizer(null);
183
+ db.setAuthorizerPolicy("off");
187
184
  }
188
185
  catch {
189
186
  invalidate(db);
@@ -165,7 +165,9 @@ import { chmodSync, closeSync, fstatSync, lstatSync, mkdirSync, openSync, readdi
165
165
  import { homedir } from "node:os";
166
166
  import { dirname, isAbsolute, join, normalize } from "node:path";
167
167
  import { TunnelRefusal } from "./codes.js";
168
+ import { TUNNEL_ID_PATTERN } from "./tunnel-id.js";
168
169
  import { resolveTunnelClient } from "../runtime/executables.js";
170
+ import { resolveWrapperIdentityEvidence } from "../runtime/wrapper-identity.js";
169
171
  import { createHealthCompletionRecorder } from "./health.js";
170
172
  import { checkKeyFileRequirements, childEnvironment } from "./profile.js";
171
173
  import { DEFAULT_TUNNEL_TIMING, initialTunnelState, nextTunnelState, } from "./state.js";
@@ -329,7 +331,7 @@ export function parseTunnelProfile(text) {
329
331
  default: throw new TunnelRefusal("CE_TUNNEL_PROFILE_INVALID", tag);
330
332
  }
331
333
  }
332
- if (found.tunnelId === undefined || !/^tunnel_[A-Za-z0-9]{8,}$/.test(found.tunnelId)) {
334
+ if (found.tunnelId === undefined || !TUNNEL_ID_PATTERN.test(found.tunnelId)) {
333
335
  throw new TunnelRefusal("CE_TUNNEL_PROFILE_INVALID", "control_plane.tunnel_id");
334
336
  }
335
337
  if (found.apiKey === undefined) {
@@ -464,57 +466,8 @@ function defaultSpawnDaemon(logPath) {
464
466
  }
465
467
  };
466
468
  }
467
- const MAX_WRAPPER_BYTES = 4096;
468
- const SHEBANG_RE = /^#!(\/[^\s\u0000]+)$/;
469
- const WRAPPER_EXEC_RE = /^exec "(\/[^"\\\r\n\u0000]+)" "\$@"$/;
470
- export function resolveWrapperIdentityEvidence(clientPath) {
471
- let text;
472
- try {
473
- const stat = statSync(clientPath); // follows the brew bin symlink
474
- if (!stat.isFile() || stat.size === 0 || stat.size > MAX_WRAPPER_BYTES)
475
- return undefined;
476
- text = readFileSync(clientPath, "utf8");
477
- }
478
- catch {
479
- return undefined;
480
- }
481
- if (!text.startsWith("#!"))
482
- return {}; // direct binary: no wrapper forms
483
- const lines = text.split("\n");
484
- const shebang = SHEBANG_RE.exec((lines[0] ?? "").replace(/\r$/, ""));
485
- const shellPrefix = shebang !== null && /^[ -~]+$/.test(shebang[1]) && normalize(shebang[1]) === shebang[1]
486
- ? shebang[1]
487
- : undefined;
488
- const evidence = shellPrefix === undefined ? {} : { shellPrefix };
489
- // C-1 (Lane C): the exec form is accepted only when the ENTIRE file is the
490
- // canonical shim shape — shebang, then exactly ONE strict exec line, with
491
- // every other line blank or a comment. Anything else (heredocs, indented or
492
- // argument-carrying exec, conditionals, extra statements) means the file's
493
- // execution semantics are not fully understood here, so NO exec evidence is
494
- // produced (fail closed). The shell-prefix form rests on the shebang alone,
495
- // which the kernel honors regardless of the script body.
496
- const meaningful = lines.slice(1).filter((line) => {
497
- const trimmed = line.trim();
498
- return trimmed !== "" && !trimmed.startsWith("#");
499
- });
500
- if (meaningful.length !== 1)
501
- return evidence;
502
- const execMatch = WRAPPER_EXEC_RE.exec(meaningful[0]); // column-0, strict
503
- if (execMatch === null)
504
- return evidence;
505
- const target = execMatch[1];
506
- if (!/^[ -~]+$/.test(target) || normalize(target) !== target)
507
- return evidence;
508
- try {
509
- if (!statSync(target).isFile())
510
- return evidence;
511
- }
512
- catch {
513
- return evidence;
514
- }
515
- evidence.execTarget = target;
516
- return evidence;
517
- }
469
+ // Keep the existing manager export; selection and ownership share one parser.
470
+ export { resolveWrapperIdentityEvidence } from "../runtime/wrapper-identity.js";
518
471
  // ---------------------------------------------------------------------------
519
472
  // Ownership record (S7/S8): strict load, random-name O_EXCL temp, 0700 dir.
520
473
  // ---------------------------------------------------------------------------
@@ -42,7 +42,7 @@ export const TUNNEL_REFUSAL_CODES = [
42
42
  "CE_TUNNEL_STATE_CORRUPT",
43
43
  ];
44
44
  const MESSAGES = Object.freeze({
45
- CE_TUNNEL_PROFILE_INVALID: "tunnel profile shape rejected; for the MCP Node command, verify trusted absolute CE_NODE_PATH (approved Node 24.21.0 or 24.22.1)",
45
+ CE_TUNNEL_PROFILE_INVALID: "tunnel profile shape rejected; for the MCP Node command, verify trusted absolute CE_NODE_PATH (candidate Node >=24.12.0 within majors 24/25/26 with SQLite >=3.51.3 and proven capabilities)",
46
46
  CE_TUNNEL_DOCTOR_FAILED: "tunnel client preflight did not pass",
47
47
  CE_TUNNEL_SPAWN_FAILED: "tunnel client could not be started; verify trusted absolute CE_TUNNEL_CLIENT_PATH or a trusted system installation (no project PATH fallback)",
48
48
  CE_TUNNEL_READY_TIMEOUT: "tunnel client did not present health evidence in time",
@@ -35,6 +35,7 @@ import { tmpdir } from "node:os";
35
35
  import { join } from "node:path";
36
36
  import { fileURLToPath } from "node:url";
37
37
  import { TunnelRefusal } from "./codes.js";
38
+ import { TUNNEL_ID_PATTERN } from "./tunnel-id.js";
38
39
  /** Fixed service for every B1.1 item. Never derived from input. */
39
40
  export const TUNNEL_KEYCHAIN_SERVICE = "pi-chat-exchange-tunnel";
40
41
  /** Native `errSecItemNotFound`. Documented here to contrast with CLI exit 44. */
@@ -48,7 +49,6 @@ export const OFFLINE_SYNTHETIC_SCOPE = Object.freeze({
48
49
  origin: "https://offline-b11.invalid",
49
50
  tunnelId: "tunnel_b11offline",
50
51
  });
51
- const TUNNEL_ID_PATTERN = /^tunnel_[A-Za-z0-9]{8,}$/;
52
52
  const ORIGIN_PATTERN = /^https:\/\/[A-Za-z0-9.-]+(:\d{1,5})?$/;
53
53
  const ACCOUNT_PATTERN = /^v1:[0-9a-f]{64}$/;
54
54
  const SECRET_PATTERN = /^[\x21-\x7e]{1,4096}$/;
@@ -24,10 +24,10 @@ import fs from "node:fs";
24
24
  import { createHash, randomUUID } from "node:crypto";
25
25
  import { dirname, isAbsolute, join, normalize } from "node:path";
26
26
  import { TunnelRefusal } from "./codes.js";
27
+ import { TUNNEL_ID_PATTERN as TUNNEL_ID } from "./tunnel-id.js";
27
28
  import { MCP_BINDING_CONFIG_MAX_BYTES, MCP_BINDING_CONFIG_VERSION, parseMcpBindingConfig } from "../host/mcp-binding-config.js";
28
29
  /** Fixed managed directory for CE-generated bindings, beside the tunnel profile. */
29
30
  export const MANAGED_BINDING_DIRNAME = ".ce-bindings";
30
- const TUNNEL_ID = /^tunnel_[A-Za-z0-9]{8,}$/;
31
31
  const ORG_ID = /^org-[A-Za-z0-9]{1,128}$/;
32
32
  const ADAPTER = /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/;
33
33
  function invalid(field) {
@@ -22,7 +22,7 @@ const EVIDENCE = ["none", "process-identity", "health-probe", "offline-simulated
22
22
  function readProjection(projection) {
23
23
  const state = STATES.includes(projection.state) ? projection.state : "UNKNOWN";
24
24
  // A caller accidentally passing an unmasked ID cannot disclose it here.
25
- const tunnel = typeof projection.tunnelIdAlreadyMasked === "string" && /^tunnel_[A-Za-z0-9]{6}…$/.test(projection.tunnelIdAlreadyMasked)
25
+ const tunnel = typeof projection.tunnelIdAlreadyMasked === "string" && /^tunnel_(?:[A-Za-z0-9]{6}|[a-z0-9]{4}_[a-z0-9])…$/.test(projection.tunnelIdAlreadyMasked)
26
26
  ? projection.tunnelIdAlreadyMasked : "Not configured";
27
27
  const binding = projection.binding === "configured" ? "Configured"
28
28
  : projection.binding === "invalid" ? "Invalid" : "Not configured";
@@ -18,6 +18,7 @@
18
18
  */
19
19
  import { isAbsolute, join, normalize } from "node:path";
20
20
  import { TunnelRefusal } from "./codes.js";
21
+ import { TUNNEL_ID_PATTERN } from "./tunnel-id.js";
21
22
  import { APPROVED_NODE_VERSION } from "../storage/runtime.js";
22
23
  /** Configuration-shaped refusal for profile construction. */
23
24
  export class TunnelConfigError extends TunnelRefusal {
@@ -26,7 +27,6 @@ export class TunnelConfigError extends TunnelRefusal {
26
27
  this.name = "TunnelConfigError";
27
28
  }
28
29
  }
29
- const TUNNEL_ID_PATTERN = /^tunnel_[A-Za-z0-9]{8,}$/;
30
30
  const CREDENTIAL_SHAPED = /(sk-[A-Za-z0-9_-]{8,})|(cap_[0-9a-f]{16,})|(BEGIN [A-Z ]*PRIVATE KEY)/i;
31
31
  // Exact CE stdio argv, single-space separators, narrow ASCII paths. Space-
32
32
  // bearing paths use single quotes; expansions, metacharacters and escapes are
@@ -188,7 +188,9 @@ export function serializeTunnelProfile(profile) {
188
188
  */
189
189
  const ALLOWED_ENV_PATTERN = /^(PATH|HOME|TMPDIR|LANG|LC_[A-Z_]+|TZ|TERM|SSL_CERT_FILE|SSL_CERT_DIR)$/;
190
190
  export function childEnvironment(source) {
191
- const env = {};
191
+ // Keep recovery explicit: 0.0.19 otherwise restarts the MCP child internally.
192
+ // Older clients ignore this env setting; new YAML/flags would break rollback.
193
+ const env = { MCP_STDIO_FAILURE_POLICY: "exit" };
192
194
  for (const [name, value] of Object.entries(source)) {
193
195
  if (ALLOWED_ENV_PATTERN.test(name))
194
196
  env[name] = value;
@@ -13,6 +13,7 @@
13
13
  */
14
14
  import { defineMenu, runMenu, sanitizeTerminalText } from "@narumitw/pi-tui-kit";
15
15
  import { isTunnelRefusalCode, TunnelRefusal } from "./codes.js";
16
+ import { TUNNEL_ID_PATTERN as TUNNEL } from "./tunnel-id.js";
16
17
  import { captureTunnelSecret } from "./secure-input.js";
17
18
  import { formatRecipientList, parseRecipientList } from "./managed-binding.js";
18
19
  /** MESSAGING-INTEGRATION-01: the single explicitly-confirmed endpoint pair.
@@ -22,7 +23,6 @@ const PI_ENDPOINT_ID = "pi/main";
22
23
  /** Render untrusted identity/storage text as one terminal line. This projection
23
24
  * never normalizes the raw values later passed to the authorized transaction. */
24
25
  const terminalLine = (value) => sanitizeTerminalText(value).replace(/[\r\n\x00-\x1F\x7F]/g, " ");
25
- const TUNNEL = /^tunnel_[A-Za-z0-9]{8,}$/;
26
26
  const ORGANIZATION = /^org-[A-Za-z0-9]{1,128}$/;
27
27
  const cancelled = () => ({ status: "cancelled" });
28
28
  const failed = () => ({ status: "refused", code: "CE_TUNNEL_SETUP_FAILED" });
@@ -93,7 +93,7 @@ export async function runSetupWizard(ctx, options) {
93
93
  const STEPS = 4;
94
94
  /** Per-field help: what is required, in what format, and what empty means. */
95
95
  const HELP = Object.freeze({
96
- tunnel: "Required · tunnel_ followed by at least 8 alphanumeric characters",
96
+ tunnel: "Required · tunnel_ followed by at least 8 alphanumeric characters, or a 4-character namespace and 32-character ID",
97
97
  organization: "Optional · org- followed by 1-128 alphanumeric characters · leave empty if not required",
98
98
  recipients: "Optional · adapter:endpointId, comma-separated · empty keeps the CE-managed default",
99
99
  credential: "Existing credential configured · Replace opens a masked input",
@@ -427,7 +427,7 @@ export async function presentTunnelStatus(ctx, view, options = {}) {
427
427
  const configurationState = closed(view.configurationState, /^[A-Z_]{1,32}$/);
428
428
  const lines = [
429
429
  `Profile: ${sanitizeTerminalText(view.profilePath)}`,
430
- `Tunnel: ${view.maskedTunnel === undefined ? "Not configured" : closed(view.maskedTunnel, /^tunnel_[A-Za-z0-9]{1,16}\u2026?$/)}`,
430
+ `Tunnel: ${view.maskedTunnel === undefined ? "Not configured" : closed(view.maskedTunnel, /^tunnel_(?:[A-Za-z0-9]{1,16}|[a-z0-9]{4}_[a-z0-9]{1,11})…?$/)}`,
431
431
  `Organization: ${view.organization}`, `MCP binding: ${view.binding}`, `Credential: ${view.credential}`,
432
432
  `Configuration State: ${configurationState}`, `Runtime state: ${closed(view.runtimeState, /^[A-Z_]{1,32}$/)}`,
433
433
  `Evidence: ${sanitizeTerminalText(view.evidence).slice(0, 120)}`,
@@ -0,0 +1,4 @@
1
+ // Preserve CE's existing legacy IDs and the official namespaced form verbatim.
2
+ // The final assertion requires the actual end, unlike `$` before a trailing newline.
3
+ export const TUNNEL_ID_PATTERN = /^tunnel_(?:[A-Za-z0-9]{8,}|[a-z0-9]{4}_[a-z0-9]{32})(?![\s\S])/;
4
+ //# sourceMappingURL=tunnel-id.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zieglar/pi-chat-exchange",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "license": "MIT",
5
5
  "publishConfig": {
6
6
  "access": "public",
@@ -14,15 +14,17 @@
14
14
  },
15
15
  "type": "module",
16
16
  "engines": {
17
- "node": "24.21.0 || 24.22.1"
17
+ "node": ">=22.19.0"
18
18
  },
19
19
  "scripts": {
20
- "test": "CE_DEFAULT_CLIENT_GUARD=1 vitest run --exclude test/tunnel/real-client-compat.test.ts --exclude test/tunnel/offline.integration.test.ts --exclude test/host-regression/real-host-recovery.test.ts --exclude test/package/installed-host.test.ts",
20
+ "test": "CE_DEFAULT_CLIENT_GUARD=1 vitest run --exclude test/tunnel/real-client-compat.test.ts --exclude test/tunnel/offline.integration.test.ts --exclude test/host-regression/real-host-recovery.test.ts --exclude test/package/installed-host.test.ts --exclude '**/native-{artifact,value-regression,cli}.test.ts' --exclude '**/sqlite-driver-cross.test.ts'",
21
21
  "test:distribution-host": "CE_DISTRIBUTION_HOST_TEST=1 vitest run test/package/installed-host.test.ts",
22
22
  "test:distribution-npm": "CE_DISTRIBUTION_HOST_TEST=1 CE_DISTRIBUTION_MODE=managed-npm vitest run test/package/installed-host.test.ts",
23
23
  "test:installed-client": "vitest run test/tunnel/real-client-compat.test.ts test/tunnel/offline.integration.test.ts",
24
24
  "test:host-regression": "CE_HOST_REGRESSION_TEST=1 vitest run test/host-regression/real-host-recovery.test.ts",
25
- "test:storage": "vitest run test/storage",
25
+ "test:storage": "vitest run test/storage --exclude '**/native-{artifact,value-regression,cli}.test.ts' --exclude '**/sqlite-driver-cross.test.ts'",
26
+ "native": "node dist/bin/ce-native.js",
27
+ "test:rust-native": "vitest run --config test/rust-native.vitest.config.ts --dir test/storage --testTimeout 120000 --hookTimeout 120000 --exclude '**/runtime-cross-version.test.ts' --exclude '**/runtime-wal-safety.test.ts' --exclude '**/inbox-ack-volume.test.ts'",
26
28
  "test:plugin-package": "CE_PLUGIN_PACKAGE_TEST=1 vitest run test/plugin/local-plugin-package.test.ts",
27
29
  "test:watch": "vitest",
28
30
  "typecheck": "tsc --noEmit -p tsconfig.json",
@@ -31,7 +33,7 @@
31
33
  "package:desktop-plugin": "node scripts/package-local-plugin.mjs",
32
34
  "recover:ownership": "node scripts/recover-stale-ownership.mjs",
33
35
  "reconcile:session-mutex": "node scripts/reconcile-session-process-mutex.mjs",
34
- "check": "node scripts/check-contract.mjs",
36
+ "check": "node scripts/check-contract.mjs && node scripts/check-native.mjs",
35
37
  "verify": "pnpm run check && pnpm run typecheck && pnpm run build && pnpm test && pnpm run test:plugin-package"
36
38
  },
37
39
  "dependencies": {
@@ -48,25 +50,11 @@
48
50
  },
49
51
  "files": [
50
52
  "pi-extension/*.ts",
51
- "pi-extension/README.md",
52
53
  "pi-extension/allowlist.example.json",
53
54
  "dist/**/*.js",
54
55
  "native/tunnel-keychain.swift",
55
56
  "scripts/recover-stale-ownership.mjs",
56
- "scripts/reconcile-session-process-mutex.mjs",
57
- "docs/independent-install.md",
58
- "docs/tunnel-setup.md",
59
- "docs/multi-session-usage.md",
60
- "docs/chatgpt-installation.md",
61
- "docs/architecture.md",
62
- "docs/tunnel-manager-background.md",
63
- "docs/protocol-v2.md",
64
- "docs/ownership-contract.md",
65
- "docs/storage-contract.md",
66
- "docs/delivery-ack-contract.md",
67
- "docs/storage-security.md",
68
- "CHANGELOG.md",
69
- "docs/releases/0.2.0.md"
57
+ "scripts/reconcile-session-process-mutex.mjs"
70
58
  ],
71
59
  "peerDependencies": {
72
60
  "@earendil-works/pi-coding-agent": "1.3.0"
@@ -49,6 +49,7 @@ import { PI_ADAPTER_KIND } from "../dist/endpoints/pi/contract.js";
49
49
  import { initializeStore, openStore } from "../dist/storage/store.js";
50
50
  import { RuntimeEligibilityError } from "../dist/storage/runtime.js";
51
51
  import { diagnoseInstallation, hostRuntimeRepairMessage, installationDiagnosticMessage } from "../dist/runtime/diagnostics.js";
52
+ import { assertNativeReadyForTunnel, inspectNativeReadiness, runNativeCommand, NATIVE_STARTUP_WARNING } from "../dist/runtime/native-readiness.js";
52
53
  import { TunnelRefusal } from "../dist/tunnel/codes.js";
53
54
  import {
54
55
  captureTunnelSecret,
@@ -389,6 +390,14 @@ function openHostStore(allowlist: AllowlistFile) {
389
390
  const TUNNEL_STATUS_KEYS = ["ce", "ce-tunnel", "ce-client"] as const;
390
391
 
391
392
  export default function ceChatExchange(pi: ExtensionApiView): void {
393
+ // Management is registered independently of subsequent Store/session activation.
394
+ let nativeStartupWarned = false;
395
+ pi.registerCommand("ce-native", {
396
+ description: "Inspect, install or verify the trusted Native driver; check release discovery",
397
+ async handler(args, ctx) {
398
+ notify(ctx, await runNativeCommand(args), "info");
399
+ },
400
+ });
392
401
  // Transport UI, the offline manager, and any in-flight credential capture
393
402
  // belong to THIS factory instance, independently of CE generation.
394
403
  let lastUiPort: ExtensionContextView | undefined;
@@ -986,6 +995,17 @@ export default function ceChatExchange(pi: ExtensionApiView): void {
986
995
  };
987
996
 
988
997
  pi.on("session_start", async (event, ctx) => {
998
+ // The warning is about the Native default path only. An explicit node-sqlite
999
+ // compatibility selection keeps messaging available, so it must not be told
1000
+ // that messaging is disabled.
1001
+ if (!nativeStartupWarned) {
1002
+ const readiness = inspectNativeReadiness();
1003
+ if (readiness.driver === "rust-native" && readiness.state !== "READY") {
1004
+ nativeStartupWarned = true;
1005
+ notify(ctx, NATIVE_STARTUP_WARNING, "warning");
1006
+ }
1007
+ }
1008
+
989
1009
  const transport = clearTunnelStatus();
990
1010
  if (generation !== undefined || shutdownInFlight !== undefined) await shutdownCe(event.reason === "reload" ? "reload" : "new");
991
1011
  // A new session must never begin while the previous owned child is still
@@ -2004,6 +2024,9 @@ export default function ceChatExchange(pi: ExtensionApiView): void {
2004
2024
  binding: view.binding, credential: view.credentialConfigured ? "configured" : "not configured",
2005
2025
  configurationState: view.state, ...(view.errorCode === undefined ? {} : { errorCode: view.errorCode }), runtimeState, evidence,
2006
2026
  }, { signal: controller.signal });
2027
+ // Native readiness is independent evidence from the Tunnel lifecycle; never infer STOPPED.
2028
+ const native = inspectNativeReadiness();
2029
+ notify(ctx, `ce-tunnel: native=${native.state} (${native.code}) | transport lifecycle is reported separately; /ce-native for driver details`);
2007
2030
  if (!presentInteractive && !controller.signal.aborted) notify(ctx, `ce-tunnel: ce=${ceStatusText()} | tunnel(real background): ${presented.lines.join(" | ")}`);
2008
2031
  })();
2009
2032
  if (presentInteractive) managerUiTask = task;
@@ -2048,6 +2071,17 @@ export default function ceChatExchange(pi: ExtensionApiView): void {
2048
2071
  /** Direct shortcuts and the Manager invoke this same operation path. */
2049
2072
  const runTunnelCommand = async (args: string, ctx: ExtensionContextView): Promise<void> => {
2050
2073
  const sub = args.trim().split(/\s+/)[0] ?? "";
2074
+ // The start gate precedes every manager, profile and process side effect.
2075
+ if (sub === "start") {
2076
+ try { assertNativeReadyForTunnel(); }
2077
+ catch (error) {
2078
+ if (error instanceof RuntimeEligibilityError) {
2079
+ notify(ctx, `ce-tunnel: start refused ${error.code}; ${hostRuntimeRepairMessage()}`, "warning"); return;
2080
+ }
2081
+ const code = error instanceof Error && "code" in error && typeof error.code === "string" && /^CE_NATIVE_/.test(error.code) ? error.code : "CE_NATIVE_INITIALIZATION_FAILED";
2082
+ notify(ctx, `ce-tunnel: start refused ${code}; run /ce-native to inspect or install the trusted driver`, "warning"); return;
2083
+ }
2084
+ }
2051
2085
  if (sub === "doctor") {
2052
2086
  notify(ctx, installationDiagnosticMessage(diagnoseInstallation({ env: process.env }))); return;
2053
2087
  }
package/CHANGELOG.md DELETED
@@ -1,70 +0,0 @@
1
- # Changelog
2
-
3
- ## 0.2.0
4
-
5
- First packaged release line of this extension. Version 0.1.1 was an internal
6
- private version only; it was never published to npm, so nothing below is an
7
- upgrade from a public release.
8
- CE's own code is owner-authorized MIT, Copyright (c) 2026 zieglar.
9
- Third-party license evidence is complete and `private: true` is removed from the manifest.
10
-
11
- ### Messaging
12
-
13
- - Add the default-disabled, opt-in `ce_ack` MCP tool, advertised only when the
14
- binding declares the Session-authorized ACK capability. The host supplies all
15
- authority fields and equivalent calls replay the original receipt. An ACK
16
- records a recipient reception statement — not proof of delivery, reading,
17
- processing or task completion. BUSY rollback and uncertain outcomes never grant
18
- retry permission.
19
-
20
- ### Tunnel lifecycle commands
21
-
22
- - Add `/ce-tunnel doctor`: read-only qualification diagnostics. With no trusted
23
- client installed it reports a safe refusal such as `CE_EXECUTABLE_UNTRUSTED`.
24
- That refusal is the expected diagnosis, not an install failure, and `doctor` is
25
- never an exit proof.
26
- - Add `/ce-tunnel deactivate`: bounded, normal release of this Session's own
27
- binding, retaining registration and history. It is not revoke and not Recovery.
28
-
29
- ### Multi-session and runtime
30
-
31
- - Support independent Pi Sessions on a shared Tunnel: `/ce-tunnel convert` keeps
32
- the current native Session's original endpoint and `/ce-tunnel register` gives a
33
- new Session its own stable endpoint without starting transport.
34
- - Support trusted portable runtime installations for the pinned Node launch path.
35
-
36
- ### Runtime qualification
37
-
38
- - The 0.2.0 certification target is exactly **Node 24.21.0 + Pi 1.3.0 +
39
- macOS arm64**.
40
- - Node **24.22.1** was admitted earlier as a second permitted runtime and remains
41
- declared in `engines`. That historical admission is **not** part of 0.2.0's
42
- certification. Linux is experimental and unverified.
43
-
44
- ### Packaging and documentation
45
-
46
- - Prepare the prebuilt Pi extension npm distribution and consumer documentation
47
- closure. The consumer tarball ships the operating guides plus the protocol,
48
- ownership, storage, ACK and Store-security contracts, so no repository access
49
- is required to operate the package safely. `private: true` was removed once the third-party audit closed with three-layer evidence. The
50
- owner-authorized MIT LICENSE ships in the prebuilt tarball; dependency licenses
51
- remain separate and must be preserved at installation/redistribution.
52
- - Document owned transport Stop, independently confirmed STOPPED, normal binding
53
- release and then native Pi removal; Store, profile, credentials and history are
54
- retained.
55
- - Keep managed npm, physical tarball fallback and monorepo source development
56
- routes distinct.
57
- - Cloud transport is NOT_VERIFIED; offline synthetic fixtures only.
58
-
59
- ### Release-process note
60
-
61
- The queued `.changeset/ce-e2b-ack-mcp.md` patch entry describes the same `ce_ack`
62
- behavior change, and its content is already reflected in this 0.2.0 entry. It is
63
- deliberately **not** consumed by this entry: Changesets remains the repository's
64
- version authority, and a future Changesets version PR must reconcile and consume
65
- it together with this hand-written 0.2.0 entry and the 0.2.0 version pins. Root
66
- Changesets configuration and queued entries are untouched by this delta. With
67
- `private` now removed, `privatePackages.version: false` no longer keeps the queued
68
- changeset inert — the next Changesets version PR owns that reconciliation explicitly.
69
-
70
- **Third-party evidence complete; `private: true` removed.** The 101-item dependency closure is fully audited: the two former evidence gaps (pi-tui and the Host peer) closed with three-layer exact-version evidence — registry tarball MIT declarations plus the upstream `v1.3.0` tag root LICENSE (MIT, (c) 2025 Mario Zechner); their artifacts omit license text (upstream packaging omission, not incompatibility). The per-version audit record is `docs/license-audit.md`, which is repo-only and not distributed in the tarball. Owner authorization covers CE's own code only — not a grant to relicense dependencies.