context-mode 2.0.0-next.30 → 2.0.0-next.33

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/cli.mjs CHANGED
@@ -88,7 +88,7 @@ var require_src = __commonJS({
88
88
 
89
89
  // src/entries/cli.ts
90
90
  import { spawn as spawn4 } from "node:child_process";
91
- import { readFileSync as readFileSync11, realpathSync as realpathSync8 } from "node:fs";
91
+ import { readFileSync as readFileSync12, realpathSync as realpathSync9 } from "node:fs";
92
92
  import path14 from "node:path";
93
93
  import { fileURLToPath as fileURLToPath2 } from "node:url";
94
94
 
@@ -228,6 +228,7 @@ var DECAY_X1000 = Object.freeze([
228
228
  250
229
229
  ]);
230
230
  var EXEC_TIMEOUT_MS = 6e5;
231
+ var DB_TIMEOUT_MS = 5e3;
231
232
  var DB_WAL_SUFFIX = "-wal";
232
233
  var DB_SHM_SUFFIX = "-shm";
233
234
  var HOOK_TIMEOUT_MS = 5e3;
@@ -304,20 +305,27 @@ var STATS_EMPTY_LINES = Object.freeze([
304
305
  "sandbox, and only the short answer goes to the chat."
305
306
  ]);
306
307
  var STATS_KIND_LABELS = Object.freeze([
307
- ["cmd", "Tool runs"],
308
+ // D-STATS-FIX-1 (8): the first five rows are call kinds, so they add up to the calls of the scope line.
308
309
  ["index", "Content indexed"],
309
310
  ["edit", "File edits"],
310
- ["toolerr", "Errors kept"],
311
+ ["toolerr", "Issues kept"],
311
312
  ["decision", "Your decisions"],
313
+ ["cmd", "Other tool calls"],
312
314
  ["prompt", "Your prompts"]
313
315
  ]);
314
316
  var STATS_JOURNAL_HINTS = Object.freeze([
315
- "ctx_resume brings back your last task, files changed and open errors",
317
+ "ctx_resume brings back your last task, files changed and open issues",
316
318
  "after a compact or a restart; ctx_search finds indexed content by words."
317
319
  ]);
320
+ var STATS_WAYS = Object.freeze([
321
+ ["sandbox", "\u2588", "sandbox run"],
322
+ ["index", "\u2593", "index + search"],
323
+ ["redirect", "\u2592", "hook sent to sandbox"],
324
+ ["replace", "\u2591", "hook cut down"]
325
+ ]);
326
+ var STATS_INDEX_TOOLS = Object.freeze(["ctx_index", "ctx_search"]);
318
327
  var PURGE_SCOPES = Object.freeze(["session", "source", "project"]);
319
328
  var RELEASE_REPO_URL = "https://github.com/mksglu/context-mode.git";
320
- var RELEASE_BRANCH = "release";
321
329
  var DOCTOR_CHECK_ORDER = Object.freeze(["D1", "D2", "D3", "D4", "D5", "D5b", "D6", "D7", "D8", "D9", "D10", "D11"]);
322
330
  var DOCTOR_LABEL = Object.freeze({
323
331
  D1: "version",
@@ -335,7 +343,9 @@ var DOCTOR_LABEL = Object.freeze({
335
343
  });
336
344
  var REPORT_SOURCE_LABEL = "ctx_doctor:report";
337
345
  var REPORT_POINTER = `ctx_search({queries:["FAIL","PASS","UNKNOWN"], source:${JSON.stringify(REPORT_SOURCE_LABEL)}})`;
338
- var D1_GIT_CHECK_FIX = `git ls-remote ${RELEASE_REPO_URL} ${RELEASE_BRANCH}`;
346
+ var GIT_LS_REMOTE_TAG_ARGS = Object.freeze(["--tags", "--refs"]);
347
+ var RELEASE_TAG_PATTERN = "v*";
348
+ var D1_GIT_CHECK_FIX = `git ls-remote --tags --refs ${RELEASE_REPO_URL} "${RELEASE_TAG_PATTERN}"`;
339
349
  var D2_NODE_FIX = `install Node ${NODE_MIN} or later`;
340
350
  var D3_PARTS = Object.freeze(["MCP entry", "hook entries", "hook timeout"]);
341
351
  var AGENT_HOME_DIR = Object.freeze({
@@ -491,7 +501,7 @@ var V1_REASON = Object.freeze({
491
501
  dataDir: "old context-mode data dir <agent home>/context-mode/",
492
502
  dataDirShared: "old context-mode data dir ~/.gemini/context-mode/: delete only after a prompt (Antigravity shares it)",
493
503
  dataRoot: "old context-mode content under ~/.context-mode/",
494
- tmpFile: "old context-mode temp file context-mode-* under the OS temp dir: report only, no action needed"
504
+ tmpFile: "old context-mode temp file context-mode-* under the OS temp dir: report only, safe to keep"
495
505
  });
496
506
  var UPGRADE_REPORT_ONLY_REASONS = Object.freeze([V1_REASON.statusLine, V1_REASON.vscodeMcp, V1_REASON.dataDirShared, V1_REASON.tmpFile, V1_REASON.kiroSteering]);
497
507
  var OPENCODE_TOOL_PREFIX = SERVER_KEY + "_";
@@ -527,6 +537,60 @@ var OWN_MCP_ENTRY = Object.freeze({
527
537
  var REPORT_ENV_ENUMS = Object.freeze({
528
538
  NODE_ENV: Object.freeze(["development", "production", "test"])
529
539
  });
540
+ var DOCTOR_ENV_PREFIX = "Environment: ";
541
+ var DOCTOR_DOCS_LABEL = "Docs: ";
542
+ var DOCTOR_REPORT_LINE = "Report file: ";
543
+ var DOCTOR_GH_LINE = "File it: ";
544
+ var DOCTOR_URL_LINE = "Or open: ";
545
+ var DOCTOR_GH_NEXT = " --";
546
+ var DOCTOR_NOTE_PREFIXES = Object.freeze([
547
+ DOCTOR_ENV_PREFIX,
548
+ DOCTOR_DOCS_LABEL,
549
+ DOCTOR_REPORT_LINE,
550
+ DOCTOR_GH_LINE,
551
+ DOCTOR_GH_NEXT.trim(),
552
+ DOCTOR_URL_LINE
553
+ ]);
554
+ var ISSUE_REPO_SLUG = "mksglu/context-mode";
555
+ var ISSUE_FORM_FILE = "agent-report.yml";
556
+ var ISSUE_URL_MAX = 8e3;
557
+ var ISSUE_FORM_HEADINGS = Object.freeze([
558
+ "Summary",
559
+ "ctx-report",
560
+ "What happened",
561
+ "Hook errors",
562
+ "Journal rows",
563
+ "Agent config",
564
+ "Expected",
565
+ "Steps",
566
+ "Environment"
567
+ ]);
568
+ var DOCTOR_ENV_NAMES = Object.freeze([
569
+ "CODEX_HOME",
570
+ "CLAUDE_CONFIG_DIR",
571
+ "CLAUDE_PLUGIN_ROOT",
572
+ "COPILOT_HOME",
573
+ "KIRO_HOME",
574
+ "OPENCODE_CONFIG_DIR",
575
+ "PI_CODING_AGENT_DIR",
576
+ "XDG_CONFIG_HOME",
577
+ "SHELL"
578
+ ]);
579
+ var DOCTOR_PATH_TOOLS = Object.freeze(["node", "git", "sh"]);
580
+ var DOCTOR_SECRET_WORDS = Object.freeze(["token", "secret", "password", "apikey", "api_key", "authorization", "bearer"]);
581
+ var NATIVE_INSTALL = Object.freeze({
582
+ "claude-code": ["claude plugin marketplace add mksglu/context-mode#release", "claude plugin install context-mode@context-mode"],
583
+ codex: ["codex plugin marketplace add mksglu/context-mode@release", "codex plugin add context-mode@context-mode"],
584
+ gemini: ["gemini extensions install https://github.com/mksglu/context-mode --ref release"],
585
+ qwen: ["qwen extensions install https://github.com/mksglu/context-mode:context-mode --ref release"],
586
+ opencode: ["opencode plugin add context-mode@next"],
587
+ pi: ["pi install npm:context-mode@next"],
588
+ "copilot-cli": ["npm i -g context-mode@next", "context-mode setup --agents copilot-cli"],
589
+ vscode: ["npm i -g context-mode@next", "context-mode setup --agents vscode"],
590
+ kiro: ["npm i -g context-mode@next", "context-mode setup --agents kiro"],
591
+ zcode: ["npm i -g context-mode@next", "context-mode setup --agents zcode"]
592
+ });
593
+ var ISSUE_FORM_URL = `https://github.com/${ISSUE_REPO_SLUG}/issues/new?template=${ISSUE_FORM_FILE}`;
530
594
 
531
595
  // src/adapters/claude-code.ts
532
596
  var TOOL_NAME_PREFIX = "mcp__plugin_context-mode_context-mode__";
@@ -1618,9 +1682,9 @@ Examples:
1618
1682
  };
1619
1683
 
1620
1684
  // src/cli/commands.ts
1621
- import { spawnSync as spawnSync4 } from "node:child_process";
1685
+ import { spawnSync as spawnSync5 } from "node:child_process";
1622
1686
  import { createHash as createHash2 } from "node:crypto";
1623
- import { existsSync as existsSync13, mkdirSync as mkdirSync4, writeFileSync as writeFileSync3 } from "node:fs";
1687
+ import { existsSync as existsSync15, mkdirSync as mkdirSync6, writeFileSync as writeFileSync4 } from "node:fs";
1624
1688
  import os from "node:os";
1625
1689
  import path13 from "node:path";
1626
1690
 
@@ -4571,12 +4635,116 @@ function ownMcpFileOf(agent, file, env, home) {
4571
4635
  return agent === "vscode" ? join2(vscodeUserDirOf(env, home), ...file) : join2(home, ...file);
4572
4636
  }
4573
4637
 
4574
- // src/setup/registry.ts
4575
- import path3 from "node:path";
4638
+ // src/core/ops/doctor-issue.ts
4639
+ import { spawnSync } from "node:child_process";
4640
+ import { closeSync, existsSync as existsSync7, fstatSync, mkdirSync as mkdirSync4, openSync, readFileSync as readFileSync4, readSync, realpathSync as realpathSync3, writeFileSync as writeFileSync2 } from "node:fs";
4641
+ import { delimiter, join as join8 } from "node:path";
4642
+
4643
+ // src/core/hooks/fallback.ts
4644
+ import { join as join3, resolve as resolve2 } from "node:path";
4645
+ var fs = process.getBuiltinModule("node:fs");
4646
+
4647
+ // src/core/store/schema.ts
4648
+ var PRAGMAS = `
4649
+ PRAGMA busy_timeout = ${DB_TIMEOUT_MS};
4650
+ PRAGMA journal_mode = WAL;
4651
+ `;
4652
+ var FTS_TOKENIZE = "tokenize = 'porter unicode61 remove_diacritics 2'";
4653
+ var FTS_TOKENIZE_V1 = "tokenize = 'unicode61 remove_diacritics 2'";
4654
+ var DDL = `
4655
+ CREATE TABLE IF NOT EXISTS events (
4656
+ seq INTEGER PRIMARY KEY AUTOINCREMENT,
4657
+ session_id TEXT NOT NULL,
4658
+ worktree TEXT NOT NULL,
4659
+ agent TEXT NOT NULL,
4660
+ kind TEXT NOT NULL CHECK (kind IN ('prompt','edit','cmd','toolerr','index','cost','decision')),
4661
+ tool TEXT,
4662
+ key TEXT,
4663
+ path TEXT,
4664
+ ok INTEGER,
4665
+ exit_code INTEGER,
4666
+ bytes INTEGER,
4667
+ body TEXT,
4668
+ turn INTEGER NOT NULL,
4669
+ sandbox_bytes INTEGER NOT NULL DEFAULT 0,
4670
+ returned_bytes INTEGER NOT NULL DEFAULT 0,
4671
+ created_at INTEGER NOT NULL,
4672
+ accessed_at INTEGER NOT NULL
4673
+ );
4674
+ CREATE INDEX IF NOT EXISTS idx_events_session_kind_seq ON events(session_id, kind, seq);
4675
+ CREATE INDEX IF NOT EXISTS idx_events_session_kind_key_seq ON events(session_id, kind, key, seq);
4676
+
4677
+ CREATE TABLE IF NOT EXISTS sources (
4678
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
4679
+ session_id TEXT NOT NULL,
4680
+ worktree TEXT NOT NULL,
4681
+ agent TEXT NOT NULL,
4682
+ kind TEXT NOT NULL CHECK (kind IN ('path','content','url')),
4683
+ label TEXT NOT NULL,
4684
+ bytes_total INTEGER NOT NULL,
4685
+ chunk_count INTEGER NOT NULL,
4686
+ created_ts INTEGER NOT NULL,
4687
+ created_at TEXT NOT NULL,
4688
+ accessed_ts INTEGER NOT NULL
4689
+ );
4690
+ CREATE INDEX IF NOT EXISTS idx_sources_accessed ON sources(accessed_ts);
4691
+
4692
+ CREATE VIRTUAL TABLE IF NOT EXISTS chunks USING fts5(
4693
+ source_id UNINDEXED,
4694
+ session_id UNINDEXED,
4695
+ worktree UNINDEXED,
4696
+ agent UNINDEXED,
4697
+ ord UNINDEXED,
4698
+ body,
4699
+ ${FTS_TOKENIZE_V1}
4700
+ );
4701
+
4702
+ CREATE TABLE IF NOT EXISTS meta (
4703
+ key TEXT PRIMARY KEY,
4704
+ value TEXT NOT NULL
4705
+ );
4706
+ `;
4707
+ var DDL_V3 = `
4708
+ CREATE VIRTUAL TABLE chunks_v3 USING fts5(
4709
+ source_id UNINDEXED,
4710
+ session_id UNINDEXED,
4711
+ worktree UNINDEXED,
4712
+ agent UNINDEXED,
4713
+ ord UNINDEXED,
4714
+ body,
4715
+ title,
4716
+ ${FTS_TOKENIZE}
4717
+ );
4718
+ INSERT INTO chunks_v3(rowid, source_id, session_id, worktree, agent, ord, body, title)
4719
+ SELECT rowid, source_id, session_id, worktree, agent, ord, body, '' FROM chunks;
4720
+ DROP TABLE chunks;
4721
+ ALTER TABLE chunks_v3 RENAME TO chunks;
4722
+ `;
4723
+ var DDL_V5 = `
4724
+ CREATE VIRTUAL TABLE line_units USING fts5(
4725
+ body,
4726
+ source_id UNINDEXED,
4727
+ session_id UNINDEXED,
4728
+ ord UNINDEXED,
4729
+ ${FTS_TOKENIZE}
4730
+ );
4731
+ `;
4732
+
4733
+ // src/core/store/db.ts
4734
+ var { existsSync: existsSync2, linkSync, mkdirSync: mkdirSync2, rmSync } = process.getBuiltinModule("node:fs");
4735
+
4736
+ // src/core/ops/doctor-config.ts
4737
+ import { existsSync as existsSync6, readdirSync as readdirSync4 } from "node:fs";
4738
+ import { join as join7 } from "node:path";
4739
+
4740
+ // src/core/ops/detect-v1.ts
4741
+ import { existsSync as existsSync4, opendirSync, readdirSync as readdirSync2, readFileSync as readFileSync2 } from "node:fs";
4742
+ import { tmpdir } from "node:os";
4743
+ import { join as join5 } from "node:path";
4576
4744
 
4577
4745
  // src/core/ops/host-config.ts
4578
- import { existsSync as existsSync2, readFileSync } from "node:fs";
4579
- import { dirname as dirname3, join as join3 } from "node:path";
4746
+ import { existsSync as existsSync3, readFileSync } from "node:fs";
4747
+ import { dirname as dirname3, join as join4 } from "node:path";
4580
4748
 
4581
4749
  // node_modules/eslint-visitor-keys/lib/visitor-keys.js
4582
4750
  var KEYS2 = {
@@ -6622,7 +6790,7 @@ function parseTOML(code, options) {
6622
6790
  }
6623
6791
 
6624
6792
  // src/core/ops/atomic-file.ts
6625
- import { mkdirSync as mkdirSync2, renameSync, unlinkSync, writeFileSync } from "node:fs";
6793
+ import { mkdirSync as mkdirSync3, renameSync, unlinkSync, writeFileSync } from "node:fs";
6626
6794
  import path2 from "node:path";
6627
6795
  function sleepSync(ms) {
6628
6796
  Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
@@ -6673,7 +6841,7 @@ function removeTmpFile(tmp, opts = {}) {
6673
6841
  }
6674
6842
  }
6675
6843
  function atomicWriteFile(file, text2, opts = {}) {
6676
- mkdirSync2(path2.dirname(file), { recursive: true });
6844
+ mkdirSync3(path2.dirname(file), { recursive: true });
6677
6845
  const tmp = path2.join(path2.dirname(file), `${ATOMIC_TMP_PREFIX}${path2.basename(file)}${ATOMIC_TMP_MARK}${process.pid}`);
6678
6846
  try {
6679
6847
  writeFileSync(tmp, text2);
@@ -7078,14 +7246,7 @@ function editHostConfigText(agent, path15, text2, format, wanted) {
7078
7246
  return applyEdits(agent, path15, text2, format, wanted);
7079
7247
  }
7080
7248
 
7081
- // src/core/ops/doctor-config.ts
7082
- import { existsSync as existsSync5, readdirSync as readdirSync4 } from "node:fs";
7083
- import { join as join6 } from "node:path";
7084
-
7085
7249
  // src/core/ops/detect-v1.ts
7086
- import { existsSync as existsSync3, opendirSync, readdirSync as readdirSync2, readFileSync as readFileSync2 } from "node:fs";
7087
- import { tmpdir } from "node:os";
7088
- import { join as join4 } from "node:path";
7089
7250
  var isObj = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
7090
7251
  var keyPath = (...parts) => parts.join(".");
7091
7252
  var finding = (file, path15, reason) => ({ file, path: path15, reason });
@@ -7192,7 +7353,7 @@ function flatCommands(events2, prefix) {
7192
7353
  var isV1Hook = (cmd) => cmd.includes(SERVER_KEY) && (V1_SCRIPT_NAMES.some((name) => cmd.includes(name)) || cmd.includes(V1_HOOK_COMMAND));
7193
7354
  var isCodexScript = (cmd) => cmd.includes(V1_SCRIPT_EXT) && V1_PATH_SEPS.some((sep2) => cmd.includes(V1_CODEX_HOOKS_DIR.join(sep2) + sep2));
7194
7355
  function dataDir(dir, reason, out2) {
7195
- if (existsSync3(dir)) out2.push(finding(dir, "", reason));
7356
+ if (existsSync4(dir)) out2.push(finding(dir, "", reason));
7196
7357
  }
7197
7358
  function mcpEntry(file, doc, out2) {
7198
7359
  if (isObj(doc) && isObj(doc[MCP_SERVERS_KEY]) && Object.hasOwn(doc[MCP_SERVERS_KEY], SERVER_KEY)) {
@@ -7200,7 +7361,7 @@ function mcpEntry(file, doc, out2) {
7200
7361
  }
7201
7362
  }
7202
7363
  function claudeShapeSettings(agentHome, out2) {
7203
- const file = join4(agentHome, SETTINGS_FILE);
7364
+ const file = join5(agentHome, SETTINGS_FILE);
7204
7365
  const doc = readJson(file);
7205
7366
  for (const c3 of nestedCommands(doc)) {
7206
7367
  if (c3.command.includes(V1_CACHE_HEAL_NAME)) out2.push(finding(file, c3.path, V1_REASON.cacheHealHook));
@@ -7220,49 +7381,49 @@ function v1HookFile(file, out2) {
7220
7381
  function scanClaudeCode(home, agentHome, out2) {
7221
7382
  claudeShapeSettings(agentHome, out2);
7222
7383
  for (const ext of V1_CACHE_HEAL_EXTS) {
7223
- const file = join4(agentHome, V1_HOOKS_DIR_NAME, V1_CACHE_HEAL_NAME + ext);
7224
- if (existsSync3(file)) out2.push(finding(file, "", V1_REASON.cacheHealFile));
7384
+ const file = join5(agentHome, V1_HOOKS_DIR_NAME, V1_CACHE_HEAL_NAME + ext);
7385
+ if (existsSync4(file)) out2.push(finding(file, "", V1_REASON.cacheHealFile));
7225
7386
  }
7226
- const userFile = join4(home, CLAUDE_USER_CONFIG_FILE);
7387
+ const userFile = join5(home, CLAUDE_USER_CONFIG_FILE);
7227
7388
  mcpEntry(userFile, readJson(userFile), out2);
7228
- dataDir(join4(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out2);
7389
+ dataDir(join5(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out2);
7229
7390
  }
7230
7391
  function scanCodex(agentHome, out2) {
7231
- const hooksFile = join4(agentHome, HOOKS_JSON_FILE);
7392
+ const hooksFile = join5(agentHome, HOOKS_JSON_FILE);
7232
7393
  for (const c3 of nestedCommands(readJson(hooksFile))) {
7233
7394
  if (c3.command.includes(V1_CODEX_HOOK_COMMAND) || isCodexScript(c3.command)) {
7234
7395
  out2.push(finding(hooksFile, c3.path, V1_REASON.codexHook));
7235
7396
  }
7236
7397
  }
7237
- const tomlFile = join4(agentHome, CONFIG_TOML_FILE);
7398
+ const tomlFile = join5(agentHome, CONFIG_TOML_FILE);
7238
7399
  const config = readTomlValue(tomlFile);
7239
7400
  for (const span of readTomlTables(tomlFile)) {
7240
7401
  if (span.path[0] !== V1_TOML_SECTION_ROOT || span.path[1] !== SERVER_KEY) continue;
7241
7402
  if (span.path.length === 2 && isV2McpTable(hostConfigValueAt(config, span.path))) continue;
7242
7403
  out2.push(finding(tomlFile, span.header.trim(), V1_REASON.codexToml));
7243
7404
  }
7244
- dataDir(join4(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out2);
7405
+ dataDir(join5(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out2);
7245
7406
  }
7246
7407
  function scanGemini(agentHome, out2) {
7247
- const file = join4(agentHome, SETTINGS_FILE);
7408
+ const file = join5(agentHome, SETTINGS_FILE);
7248
7409
  for (const c3 of nestedCommands(readJson(file))) {
7249
7410
  if (c3.command.includes(SERVER_KEY)) out2.push(finding(file, c3.path, V1_REASON.hook));
7250
7411
  }
7251
- dataDir(join4(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDirShared, out2);
7412
+ dataDir(join5(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDirShared, out2);
7252
7413
  }
7253
7414
  function scanVscode(agentHome, project, out2) {
7254
7415
  if (project !== void 0) {
7255
- v1HookFile(join4(project, GITHUB_DIR_NAME, V1_HOOKS_DIR_NAME, OWN_HOOK_FILE), out2);
7256
- const mcpFile = join4(project, VSCODE_DIR_NAME, VSCODE_MCP_FILE);
7416
+ v1HookFile(join5(project, GITHUB_DIR_NAME, V1_HOOKS_DIR_NAME, OWN_HOOK_FILE), out2);
7417
+ const mcpFile = join5(project, VSCODE_DIR_NAME, VSCODE_MCP_FILE);
7257
7418
  const doc = readJson(mcpFile);
7258
7419
  const servers = isObj(doc) && isObj(doc[VSCODE_MCP_SERVERS_KEY]) ? doc[VSCODE_MCP_SERVERS_KEY] : {};
7259
7420
  const entry2 = Object.hasOwn(servers, SERVER_KEY) ? servers[SERVER_KEY] : void 0;
7260
7421
  if (isObj(entry2) && (entry2.command === V1_BIN_COMMAND || listOf(entry2.args).some((a2) => a2 === V1_BIN_COMMAND))) {
7261
7422
  out2.push(finding(mcpFile, keyPath(VSCODE_MCP_SERVERS_KEY, SERVER_KEY), V1_REASON.vscodeMcp));
7262
7423
  }
7263
- dataDir(join4(project, GITHUB_DIR_NAME, V1_DATA_DIR_NAME, V1_SESSIONS_DIR_NAME), V1_REASON.dataDir, out2);
7424
+ dataDir(join5(project, GITHUB_DIR_NAME, V1_DATA_DIR_NAME, V1_SESSIONS_DIR_NAME), V1_REASON.dataDir, out2);
7264
7425
  }
7265
- dataDir(join4(agentHome, V1_DATA_DIR_NAME, V1_SESSIONS_DIR_NAME), V1_REASON.dataDir, out2);
7426
+ dataDir(join5(agentHome, V1_DATA_DIR_NAME, V1_SESSIONS_DIR_NAME), V1_REASON.dataDir, out2);
7266
7427
  }
7267
7428
  function jsonFiles(dir) {
7268
7429
  try {
@@ -7272,10 +7433,10 @@ function jsonFiles(dir) {
7272
7433
  }
7273
7434
  }
7274
7435
  function scanKiro(agentHome, project, out2) {
7275
- const agentsDir = join4(agentHome, KIRO_AGENTS_DIR);
7276
- const defaultFile = join4(agentHome, ...KIRO_AGENT_FILE);
7436
+ const agentsDir = join5(agentHome, KIRO_AGENTS_DIR);
7437
+ const defaultFile = join5(agentHome, ...KIRO_AGENT_FILE);
7277
7438
  for (const name of jsonFiles(agentsDir)) {
7278
- const file = join4(agentsDir, name);
7439
+ const file = join5(agentsDir, name);
7279
7440
  const doc = readJson(file);
7280
7441
  if (isObj(doc) && doc[KIRO_AGENT_NAME_KEY] === SERVER_KEY) {
7281
7442
  out2.push(finding(file, "", V1_REASON.kiroAgentFile));
@@ -7286,25 +7447,25 @@ function scanKiro(agentHome, project, out2) {
7286
7447
  if (isV1Hook(c3.command)) out2.push(finding(file, c3.path, V1_REASON.kiroHook));
7287
7448
  }
7288
7449
  }
7289
- const steeringDocs = [join4(agentHome, ...KIRO_STEERING_FILE)];
7290
- if (project !== void 0) steeringDocs.push(join4(project, ...AGENT_HOME_DIR.kiro, ...KIRO_STEERING_FILE));
7450
+ const steeringDocs = [join5(agentHome, ...KIRO_STEERING_FILE)];
7451
+ if (project !== void 0) steeringDocs.push(join5(project, ...AGENT_HOME_DIR.kiro, ...KIRO_STEERING_FILE));
7291
7452
  for (const file of steeringDocs) {
7292
- if (existsSync3(file)) out2.push(finding(file, "", V1_REASON.kiroSteering));
7453
+ if (existsSync4(file)) out2.push(finding(file, "", V1_REASON.kiroSteering));
7293
7454
  }
7294
- dataDir(join4(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out2);
7455
+ dataDir(join5(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out2);
7295
7456
  }
7296
7457
  function scanPi(piAgentDir, agentHome, out2) {
7297
- const file = join4(piAgentDir, SETTINGS_FILE);
7458
+ const file = join5(piAgentDir, SETTINGS_FILE);
7298
7459
  const doc = readJson(file);
7299
7460
  listOf(isObj(doc) ? doc[PI_PACKAGES_KEY] : void 0).forEach((pkg, i2) => {
7300
7461
  const spec = isObj(pkg) ? pkg[PI_PACKAGE_SOURCE_KEY] : pkg;
7301
7462
  if (spec === V1_PI_PACKAGE) out2.push(finding(file, keyPath(PI_PACKAGES_KEY, i2), V1_REASON.piNpm));
7302
7463
  });
7303
- dataDir(join4(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out2);
7464
+ dataDir(join5(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out2);
7304
7465
  }
7305
7466
  function scanOpencode(agentHome, out2) {
7306
7467
  for (const name of OPENCODE_CONFIG_FILES) {
7307
- const file = join4(agentHome, name);
7468
+ const file = join5(agentHome, name);
7308
7469
  const doc = readJson(file);
7309
7470
  if (!isObj(doc) || !Array.isArray(doc[OPENCODE_PLUGIN_KEY])) continue;
7310
7471
  doc[OPENCODE_PLUGIN_KEY].forEach((spec, i2) => {
@@ -7314,13 +7475,13 @@ function scanOpencode(agentHome, out2) {
7314
7475
  }
7315
7476
  }
7316
7477
  function scanZcode(agentHome, out2) {
7317
- const configFile = join4(agentHome, ZCODE_CLI_DIR, CONFIG_JSON_FILE);
7478
+ const configFile = join5(agentHome, ZCODE_CLI_DIR, CONFIG_JSON_FILE);
7318
7479
  const config = readJson(configFile);
7319
7480
  const events2 = isObj(config) && isObj(config[HOOKS_KEY]) ? config[HOOKS_KEY][ZCODE_EVENTS_KEY] : void 0;
7320
7481
  for (const c3 of flatCommands(events2, [HOOKS_KEY, ZCODE_EVENTS_KEY])) {
7321
7482
  if (c3.command.includes(V1_HOOK_COMMAND)) out2.push(finding(configFile, c3.path, V1_REASON.zcodeHook));
7322
7483
  }
7323
- const hooksFile = join4(agentHome, ZCODE_CLI_DIR, HOOKS_JSON_FILE);
7484
+ const hooksFile = join5(agentHome, ZCODE_CLI_DIR, HOOKS_JSON_FILE);
7324
7485
  for (const c3 of nestedCommands(readJson(hooksFile))) {
7325
7486
  if (c3.command.includes(V1_HOOK_COMMAND)) out2.push(finding(hooksFile, c3.path, V1_REASON.zcodeHook));
7326
7487
  }
@@ -7344,14 +7505,14 @@ function firstTmpMatch(dir) {
7344
7505
  }
7345
7506
  }
7346
7507
  function scanAll(home, tmp, out2) {
7347
- const root = join4(home, DATA_ROOT.slice(1));
7348
- for (const name of V1_DATA_ROOT_ENTRIES) dataDir(join4(root, name), V1_REASON.dataRoot, out2);
7508
+ const root = join5(home, DATA_ROOT.slice(1));
7509
+ for (const name of V1_DATA_ROOT_ENTRIES) dataDir(join5(root, name), V1_REASON.dataRoot, out2);
7349
7510
  if (firstTmpMatch(tmp) !== null) out2.push(finding(tmp, V1_TMP_PREFIX + "*", V1_REASON.tmpFile));
7350
7511
  }
7351
7512
  function detectV1(agent, home, scope = {}) {
7352
7513
  const out2 = [];
7353
7514
  const project = scope.project;
7354
- const agentHome = agent === "claude-code" && scope.claudeDir !== void 0 ? scope.claudeDir : agent === "codex" && scope.codexDir !== void 0 ? scope.codexDir : agent === "copilot-cli" && scope.copilotDir !== void 0 ? scope.copilotDir : agent === "kiro" && scope.kiroDir !== void 0 ? scope.kiroDir : agent === "opencode" && scope.opencodeDir !== void 0 ? scope.opencodeDir : join4(home, ...AGENT_HOME_DIR[agent]);
7515
+ const agentHome = agent === "claude-code" && scope.claudeDir !== void 0 ? scope.claudeDir : agent === "codex" && scope.codexDir !== void 0 ? scope.codexDir : agent === "copilot-cli" && scope.copilotDir !== void 0 ? scope.copilotDir : agent === "kiro" && scope.kiroDir !== void 0 ? scope.kiroDir : agent === "opencode" && scope.opencodeDir !== void 0 ? scope.opencodeDir : join5(home, ...AGENT_HOME_DIR[agent]);
7355
7516
  switch (agent) {
7356
7517
  case "claude-code":
7357
7518
  scanClaudeCode(home, agentHome, out2);
@@ -7364,11 +7525,11 @@ function detectV1(agent, home, scope = {}) {
7364
7525
  break;
7365
7526
  case "qwen":
7366
7527
  claudeShapeSettings(agentHome, out2);
7367
- dataDir(join4(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out2);
7528
+ dataDir(join5(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out2);
7368
7529
  break;
7369
7530
  case "copilot-cli":
7370
- v1HookFile(join4(agentHome, V1_HOOKS_DIR_NAME, OWN_HOOK_FILE), out2);
7371
- dataDir(join4(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out2);
7531
+ v1HookFile(join5(agentHome, V1_HOOKS_DIR_NAME, OWN_HOOK_FILE), out2);
7532
+ dataDir(join5(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out2);
7372
7533
  break;
7373
7534
  case "vscode":
7374
7535
  scanVscode(agentHome, project, out2);
@@ -7377,7 +7538,7 @@ function detectV1(agent, home, scope = {}) {
7377
7538
  scanKiro(agentHome, project, out2);
7378
7539
  break;
7379
7540
  case "pi":
7380
- scanPi(scope.piAgentDir !== void 0 && scope.piAgentDir !== "" ? scope.piAgentDir : join4(agentHome, PI_AGENT_DIR), agentHome, out2);
7541
+ scanPi(scope.piAgentDir !== void 0 && scope.piAgentDir !== "" ? scope.piAgentDir : join5(agentHome, PI_AGENT_DIR), agentHome, out2);
7381
7542
  break;
7382
7543
  // D-WIN-PIDIR-1: empty is unset
7383
7544
  case "opencode":
@@ -7392,8 +7553,8 @@ function detectV1(agent, home, scope = {}) {
7392
7553
  }
7393
7554
 
7394
7555
  // src/core/ops/plugin-root.ts
7395
- import { existsSync as existsSync4, readdirSync as readdirSync3, readFileSync as readFileSync3, realpathSync as realpathSync2 } from "node:fs";
7396
- import { dirname as dirname4, isAbsolute, join as join5, sep } from "node:path";
7556
+ import { existsSync as existsSync5, readdirSync as readdirSync3, readFileSync as readFileSync3, realpathSync as realpathSync2 } from "node:fs";
7557
+ import { dirname as dirname4, isAbsolute, join as join6, sep } from "node:path";
7397
7558
  import { fileURLToPath } from "node:url";
7398
7559
 
7399
7560
  // src/core/ops/doctor-config.ts
@@ -7408,6 +7569,16 @@ function composeMatcher(row, event) {
7408
7569
  }
7409
7570
  var CODEX_PLUGIN_KEY = `${SERVER_KEY}@${SERVER_KEY}`;
7410
7571
 
7572
+ // src/core/ops/doctor-issue.ts
7573
+ function formUrl(title, summary) {
7574
+ const base = `${ISSUE_FORM_URL}&title=${encodeURIComponent(title)}`;
7575
+ const full = `${base}&summary=${encodeURIComponent(summary)}`;
7576
+ return full.length < ISSUE_URL_MAX ? full : base;
7577
+ }
7578
+
7579
+ // src/setup/registry.ts
7580
+ import path3 from "node:path";
7581
+
7411
7582
  // src/setup/hook-shapes.ts
7412
7583
  var MS_PER_SECOND = 1e3;
7413
7584
  var TOOL_EVENTS = ["PreToolUse", "PostToolUse"];
@@ -7703,7 +7874,7 @@ function assertWritable(row, file) {
7703
7874
  }
7704
7875
 
7705
7876
  // src/setup/gemini-gate.ts
7706
- import { existsSync as existsSync6, readFileSync as readFileSync4 } from "node:fs";
7877
+ import { existsSync as existsSync8, readFileSync as readFileSync5 } from "node:fs";
7707
7878
  import path4 from "node:path";
7708
7879
  var GEMINI_DIR = ".gemini";
7709
7880
  var SETTINGS_FILE2 = "settings.json";
@@ -7717,9 +7888,9 @@ function systemSettingsPath(env) {
7717
7888
  return "/etc/gemini-cli/settings.json";
7718
7889
  }
7719
7890
  function load(file) {
7720
- if (!existsSync6(file)) return void 0;
7891
+ if (!existsSync8(file)) return void 0;
7721
7892
  try {
7722
- return { file, doc: parseHostConfig(OWN_AGENT, file, hostText(readFileSync4(file, "utf8")), "jsonc") };
7893
+ return { file, doc: parseHostConfig(OWN_AGENT, file, hostText(readFileSync5(file, "utf8")), "jsonc") };
7723
7894
  } catch {
7724
7895
  return void 0;
7725
7896
  }
@@ -7751,7 +7922,7 @@ function geminiSettingsGate(env, home, cwd) {
7751
7922
  }
7752
7923
 
7753
7924
  // src/setup/zcode-gate.ts
7754
- import { existsSync as existsSync7, readFileSync as readFileSync5 } from "node:fs";
7925
+ import { existsSync as existsSync9, readFileSync as readFileSync6 } from "node:fs";
7755
7926
  import path5 from "node:path";
7756
7927
  var OWN_AGENT2 = "zcode";
7757
7928
  var EVENTS = ["SessionStart", "UserPromptSubmit", "PreToolUse", "PermissionRequest", "PostToolUse", "PostToolUseFailure", "Stop"];
@@ -7843,10 +8014,10 @@ function zcodeSchemaBad(doc) {
7843
8014
  }
7844
8015
  function zcodeConfigGate(home) {
7845
8016
  const file = path5.join(home, ".zcode", "cli", "config.json");
7846
- if (!existsSync7(file)) return void 0;
8017
+ if (!existsSync9(file)) return void 0;
7847
8018
  let doc;
7848
8019
  try {
7849
- doc = parseHostConfig(OWN_AGENT2, file, hostText(readFileSync5(file, "utf8")), "json");
8020
+ doc = parseHostConfig(OWN_AGENT2, file, hostText(readFileSync6(file, "utf8")), "json");
7850
8021
  } catch {
7851
8022
  return void 0;
7852
8023
  }
@@ -7856,7 +8027,7 @@ function zcodeConfigGate(home) {
7856
8027
  }
7857
8028
 
7858
8029
  // src/setup/pi-gate.ts
7859
- import { existsSync as existsSync8, readFileSync as readFileSync6, realpathSync as realpathSync3 } from "node:fs";
8030
+ import { existsSync as existsSync10, readFileSync as readFileSync7, realpathSync as realpathSync4 } from "node:fs";
7860
8031
  import path6 from "node:path";
7861
8032
  var OWN_FILE = "pi/index.js";
7862
8033
  var EXTENSIONS_KEY = "extensions";
@@ -7865,16 +8036,16 @@ var TRUST_FILE = "trust.json";
7865
8036
  var ALWAYS = "always";
7866
8037
  var SOURCE_PREFIXES = ["npm:", "git:"];
7867
8038
  function load2(file) {
7868
- if (!existsSync8(file)) return void 0;
8039
+ if (!existsSync10(file)) return void 0;
7869
8040
  try {
7870
- return { file, doc: parseHostConfig("pi", file, hostText(readFileSync6(file, "utf8")), "json") };
8041
+ return { file, doc: parseHostConfig("pi", file, hostText(readFileSync7(file, "utf8")), "json") };
7871
8042
  } catch {
7872
8043
  return void 0;
7873
8044
  }
7874
8045
  }
7875
8046
  var real = (p3) => {
7876
8047
  try {
7877
- return realpathSync3(p3);
8048
+ return realpathSync4(p3);
7878
8049
  } catch {
7879
8050
  return path6.resolve(p3);
7880
8051
  }
@@ -7956,7 +8127,7 @@ function piSettingsGate(env, home, pkgDir, cwd) {
7956
8127
  }
7957
8128
 
7958
8129
  // src/setup/vscode-gate.ts
7959
- import { existsSync as existsSync9, readFileSync as readFileSync7 } from "node:fs";
8130
+ import { existsSync as existsSync11, readFileSync as readFileSync8 } from "node:fs";
7960
8131
  import path7 from "node:path";
7961
8132
  var SETTINGS_FILE3 = "settings.json";
7962
8133
  var WORKSPACE_DIR = ".vscode";
@@ -7965,9 +8136,9 @@ var LOCATIONS_KEY = "chat.hookFilesLocations";
7965
8136
  var OWN_LOCATION = "~/.copilot/hooks";
7966
8137
  var MANAGED_KEYS = ["allowManagedHooksOnly", "strictPluginOnlyCustomization"];
7967
8138
  function load3(file) {
7968
- if (!existsSync9(file)) return void 0;
8139
+ if (!existsSync11(file)) return void 0;
7969
8140
  try {
7970
- return { file, doc: parseHostConfig("vscode", file, hostText(readFileSync7(file, "utf8")), "jsonc") };
8141
+ return { file, doc: parseHostConfig("vscode", file, hostText(readFileSync8(file, "utf8")), "jsonc") };
7971
8142
  } catch {
7972
8143
  return void 0;
7973
8144
  }
@@ -8007,7 +8178,7 @@ function vscodeSettingsGate(env, home, cwd, managedFile = managedSettingsPath(en
8007
8178
  }
8008
8179
 
8009
8180
  // src/setup/qwen-gate.ts
8010
- import { existsSync as existsSync10, readFileSync as readFileSync8 } from "node:fs";
8181
+ import { existsSync as existsSync12, readFileSync as readFileSync9 } from "node:fs";
8011
8182
  import path8 from "node:path";
8012
8183
  var KEY = "disableAllHooks";
8013
8184
  var SETTINGS = "settings.json";
@@ -8023,10 +8194,10 @@ function settingsFiles(env, home, cwd, platform) {
8023
8194
  }
8024
8195
  function qwenHooksOff(env, home, cwd = process.cwd(), platform = process.platform) {
8025
8196
  for (const file of settingsFiles(env, home, cwd, platform)) {
8026
- if (!existsSync10(file)) continue;
8197
+ if (!existsSync12(file)) continue;
8027
8198
  let value;
8028
8199
  try {
8029
- value = hostConfigValueAt(parseHostConfig("qwen", file, hostText(readFileSync8(file, "utf8")), "jsonc"), [KEY]);
8200
+ value = hostConfigValueAt(parseHostConfig("qwen", file, hostText(readFileSync9(file, "utf8")), "jsonc"), [KEY]);
8030
8201
  } catch {
8031
8202
  continue;
8032
8203
  }
@@ -8037,19 +8208,19 @@ function qwenHooksOff(env, home, cwd = process.cwd(), platform = process.platfor
8037
8208
 
8038
8209
  // src/setup/codex-trust.ts
8039
8210
  import { createHash } from "node:crypto";
8040
- import { existsSync as existsSync11, realpathSync as realpathSync4 } from "node:fs";
8211
+ import { existsSync as existsSync13, realpathSync as realpathSync5 } from "node:fs";
8041
8212
  import path10 from "node:path";
8042
- import { spawn, spawnSync as spawnSync2 } from "node:child_process";
8213
+ import { spawn, spawnSync as spawnSync3 } from "node:child_process";
8043
8214
 
8044
8215
  // src/setup/spawn-bin.ts
8045
- import { spawnSync } from "node:child_process";
8216
+ import { spawnSync as spawnSync2 } from "node:child_process";
8046
8217
  import { accessSync, constants as fsc, statSync } from "node:fs";
8047
8218
  import path9 from "node:path";
8048
8219
 
8049
8220
  // src/core/sandbox/path-entries.ts
8050
- function pathEntries(value, platform = process.platform, delimiter = platform === "win32" ? ";" : ":") {
8221
+ function pathEntries(value, platform = process.platform, delimiter2 = platform === "win32" ? ";" : ":") {
8051
8222
  const win = platform === "win32";
8052
- return value.split(delimiter).map((e) => win && e.length >= 2 && e.startsWith('"') && e.endsWith('"') ? e.slice(1, -1) : e).filter(Boolean);
8223
+ return value.split(delimiter2).map((e) => win && e.length >= 2 && e.startsWith('"') && e.endsWith('"') ? e.slice(1, -1) : e).filter(Boolean);
8053
8224
  }
8054
8225
 
8055
8226
  // src/setup/spawn-bin.ts
@@ -8120,7 +8291,7 @@ function spawnShim(file, args, env, opts, platform = process.platform) {
8120
8291
  const error = e instanceof Error ? e : new Error(String(e));
8121
8292
  return { pid: 0, output: [null, "", error.message], stdout: "", stderr: error.message, status: null, signal: null, error };
8122
8293
  }
8123
- return spawnSync(f2.command, f2.args, { ...opts, env, windowsVerbatimArguments: f2.windowsVerbatimArguments, windowsHide: true });
8294
+ return spawnSync2(f2.command, f2.args, { ...opts, env, windowsVerbatimArguments: f2.windowsVerbatimArguments, windowsHide: true });
8124
8295
  }
8125
8296
 
8126
8297
  // src/setup/codex-trust.ts
@@ -8145,11 +8316,11 @@ function snake(name) {
8145
8316
  function realFile(file) {
8146
8317
  let dir = path10.resolve(file);
8147
8318
  const rest = [];
8148
- while (!existsSync11(dir) && path10.dirname(dir) !== dir) {
8319
+ while (!existsSync13(dir) && path10.dirname(dir) !== dir) {
8149
8320
  rest.unshift(path10.basename(dir));
8150
8321
  dir = path10.dirname(dir);
8151
8322
  }
8152
- return path10.join(realpathSync4(dir), ...rest);
8323
+ return path10.join(realpathSync5(dir), ...rest);
8153
8324
  }
8154
8325
  var ASK_TIMEOUT_MS = 1e4;
8155
8326
  var ASK_TRIES = 3;
@@ -8235,14 +8406,14 @@ async function listPluginHooks(env, pluginId, cwd) {
8235
8406
  function askPluginHooks(env, pluginId, cwd) {
8236
8407
  const bin = whichBin("codex", env);
8237
8408
  if (!bin) return Promise.resolve({ kind: "absent" });
8238
- return new Promise((resolve2) => {
8409
+ return new Promise((resolve3) => {
8239
8410
  let asked;
8240
8411
  const done_ = (hooks) => hooks === void 0 ? { kind: "silent" } : { kind: "list", hooks, codexHome: asked };
8241
8412
  let f2;
8242
8413
  try {
8243
8414
  f2 = spawnForm(bin, ["app-server"], env);
8244
8415
  } catch {
8245
- resolve2({ kind: "silent" });
8416
+ resolve3({ kind: "silent" });
8246
8417
  return;
8247
8418
  }
8248
8419
  const child = spawn(f2.command, f2.args, { env, cwd, stdio: ["pipe", "pipe", "ignore"], windowsVerbatimArguments: f2.windowsVerbatimArguments, windowsHide: true });
@@ -8252,7 +8423,7 @@ function askPluginHooks(env, pluginId, cwd) {
8252
8423
  let result;
8253
8424
  const settle = () => {
8254
8425
  clearTimeout(grace);
8255
- resolve2(done_(result));
8426
+ resolve3(done_(result));
8256
8427
  };
8257
8428
  let grace;
8258
8429
  const finish2 = (v) => {
@@ -8309,7 +8480,7 @@ function askPluginHooks(env, pluginId, cwd) {
8309
8480
  function stopTree(pid, kill) {
8310
8481
  if (process.platform === "win32" && pid !== void 0) {
8311
8482
  try {
8312
- spawnSync2("taskkill", ["/pid", String(pid), "/T", "/F"], { windowsHide: true, stdio: "ignore", timeout: 5e3 });
8483
+ spawnSync3("taskkill", ["/pid", String(pid), "/T", "/F"], { windowsHide: true, stdio: "ignore", timeout: 5e3 });
8313
8484
  } catch {
8314
8485
  }
8315
8486
  }
@@ -8333,7 +8504,7 @@ function untrustedPluginHooksDetail(hooks) {
8333
8504
 
8334
8505
  // src/setup/copilot-hooks.ts
8335
8506
  import { spawn as spawn2 } from "node:child_process";
8336
- import { realpathSync as realpathSync5 } from "node:fs";
8507
+ import { realpathSync as realpathSync6 } from "node:fs";
8337
8508
  import path11 from "node:path";
8338
8509
  var isObj4 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
8339
8510
  var ASK_TIMEOUT_MS2 = 15e3;
@@ -8343,7 +8514,7 @@ var USER_ORIGIN = "user";
8343
8514
  function canon(p3) {
8344
8515
  let r2 = path11.resolve(p3);
8345
8516
  try {
8346
- r2 = realpathSync5(r2);
8517
+ r2 = realpathSync6(r2);
8347
8518
  } catch {
8348
8519
  }
8349
8520
  return process.platform === "win32" ? r2.toLowerCase() : r2;
@@ -8376,12 +8547,12 @@ function frame(buf) {
8376
8547
  function listCopilotHooks(env, file, cwd) {
8377
8548
  const bin = whichBin("copilot", env);
8378
8549
  if (!bin) return Promise.resolve(void 0);
8379
- return new Promise((resolve2) => {
8550
+ return new Promise((resolve3) => {
8380
8551
  let f2;
8381
8552
  try {
8382
8553
  f2 = spawnForm(bin, ["--server", "--stdio", "--no-auto-update"], env);
8383
8554
  } catch {
8384
- resolve2(void 0);
8555
+ resolve3(void 0);
8385
8556
  return;
8386
8557
  }
8387
8558
  const child = spawn2(f2.command, f2.args, { env, cwd, stdio: ["pipe", "pipe", "ignore"], windowsVerbatimArguments: f2.windowsVerbatimArguments, windowsHide: true });
@@ -8393,7 +8564,7 @@ function listCopilotHooks(env, file, cwd) {
8393
8564
  clearTimeout(timer);
8394
8565
  child.stdin.destroy();
8395
8566
  child.kill();
8396
- resolve2(v);
8567
+ resolve3(v);
8397
8568
  };
8398
8569
  const timer = setTimeout(() => finish2(void 0), ASK_TIMEOUT_MS2);
8399
8570
  child.on("error", () => finish2(void 0));
@@ -8427,8 +8598,8 @@ function listCopilotHooks(env, file, cwd) {
8427
8598
  }
8428
8599
 
8429
8600
  // src/setup/engine.ts
8430
- import { spawn as spawn3, spawnSync as spawnSync3 } from "node:child_process";
8431
- import { closeSync, existsSync as existsSync12, mkdirSync as mkdirSync3, mkdtempSync, openSync, readFileSync as readFileSync9, readSync, readdirSync as readdirSync5, realpathSync as realpathSync6, rmSync, statSync as statSync2, writeFileSync as writeFileSync2 } from "node:fs";
8601
+ import { spawn as spawn3, spawnSync as spawnSync4 } from "node:child_process";
8602
+ import { closeSync as closeSync2, existsSync as existsSync14, mkdirSync as mkdirSync5, mkdtempSync, openSync as openSync2, readFileSync as readFileSync10, readSync as readSync2, readdirSync as readdirSync5, realpathSync as realpathSync7, rmSync as rmSync2, statSync as statSync2, writeFileSync as writeFileSync3 } from "node:fs";
8432
8603
  import { tmpdir as tmpdir2 } from "node:os";
8433
8604
  import path12 from "node:path";
8434
8605
 
@@ -8502,6 +8673,7 @@ var HOOK_SAMPLES = 9;
8502
8673
  var HOOK_ROUNDS = 5;
8503
8674
  var P95 = 0.95;
8504
8675
  var VERIFY_TIMEOUT_MS = 1e4;
8676
+ var INSTALL_TIMEOUT_MS = 12e4;
8505
8677
  var MANIFEST = "manifest.json";
8506
8678
  var MANIFEST_DONE = "manifest.removed.json";
8507
8679
  var FILES = "files";
@@ -8513,11 +8685,11 @@ var REAL_HOST = Object.freeze({
8513
8685
  var BINARY_MAGICS = Object.freeze(["cffaedfe", "cefaedfe", "7f454c46", "4d5a"]);
8514
8686
  function isNativeBinary(file) {
8515
8687
  const head = Buffer.alloc(4);
8516
- const fd = openSync(file, "r");
8688
+ const fd = openSync2(file, "r");
8517
8689
  try {
8518
- readSync(fd, head, 0, 4, 0);
8690
+ readSync2(fd, head, 0, 4, 0);
8519
8691
  } finally {
8520
- closeSync(fd);
8692
+ closeSync2(fd);
8521
8693
  }
8522
8694
  const hex = head.toString("hex");
8523
8695
  return BINARY_MAGICS.some((m3) => hex.startsWith(m3));
@@ -8525,9 +8697,9 @@ function isNativeBinary(file) {
8525
8697
  function owningPackage(dir) {
8526
8698
  for (let d = dir; ; d = path12.dirname(d)) {
8527
8699
  const f2 = path12.join(d, "package.json");
8528
- if (existsSync12(f2)) {
8700
+ if (existsSync14(f2)) {
8529
8701
  try {
8530
- return String(JSON.parse(hostText(readFileSync9(f2, "utf8"))).name);
8702
+ return String(JSON.parse(hostText(readFileSync10(f2, "utf8"))).name);
8531
8703
  } catch {
8532
8704
  return void 0;
8533
8705
  }
@@ -8543,8 +8715,8 @@ function hostBin(bin, env, platform = process.platform) {
8543
8715
  for (const dir of pathEntries(get("PATH") ?? "", platform)) {
8544
8716
  const own2 = which(bin, { PATH: dir, ...get("PATHEXT") ? { PATHEXT: get("PATHEXT") } : {} }, platform);
8545
8717
  for (const f2 of [own2, ...real2.extra.map((p3) => path12.join(dir, ...p3))]) {
8546
- if (!f2 || !existsSync12(f2) || !statSync2(f2).isFile()) continue;
8547
- const file = realpathSync6(f2);
8718
+ if (!f2 || !existsSync14(f2) || !statSync2(f2).isFile()) continue;
8719
+ const file = realpathSync7(f2);
8548
8720
  if (isNativeBinary(file) || owningPackage(path12.dirname(file)) === real2.pkg) return { file, shims };
8549
8721
  shims.push(f2);
8550
8722
  }
@@ -8556,14 +8728,14 @@ function installExitOk(status, listed, platform = process.platform) {
8556
8728
  if (status === 0) return true;
8557
8729
  return platform === "win32" && status === WIN_EXIT_CRASH && listed;
8558
8730
  }
8559
- function runBin(bin, args, env, input) {
8560
- return spawnShim(hostBin(bin, env).file ?? bin, args, env, { encoding: "utf8", input, timeout: VERIFY_TIMEOUT_MS });
8731
+ function runBin(bin, args, env, input, timeout = VERIFY_TIMEOUT_MS) {
8732
+ return spawnShim(hostBin(bin, env).file ?? bin, args, env, { encoding: "utf8", input, timeout });
8561
8733
  }
8562
8734
  function readOr(file) {
8563
- return existsSync12(file) ? hostText(readFileSync9(file, "utf8")) : void 0;
8735
+ return existsSync14(file) ? hostText(readFileSync10(file, "utf8")) : void 0;
8564
8736
  }
8565
8737
  function readRaw(file) {
8566
- return existsSync12(file) ? readFileSync9(file, "utf8") : void 0;
8738
+ return existsSync14(file) ? readFileSync10(file, "utf8") : void 0;
8567
8739
  }
8568
8740
  var atomicWrite = atomicWriteFile;
8569
8741
  function pidAlive(pid) {
@@ -8708,7 +8880,7 @@ function isNativeSpec(e) {
8708
8880
  function isStaleOwnPlugin(e, entry2) {
8709
8881
  if (typeof e !== "string" || e === entry2 || !path12.isAbsolute(e)) return false;
8710
8882
  if (e === path12.join(entry2, ...OPENCODE_PLUGIN_PATH)) return true;
8711
- if (existsSync12(e)) return false;
8883
+ if (existsSync14(e)) return false;
8712
8884
  const seg = e.split("\\").join("/").split("/");
8713
8885
  const n3 = seg.length;
8714
8886
  if (n3 >= 3 && seg[n3 - 1] === "plugin.js" && seg[n3 - 2] === "opencode" && seg[n3 - 3] === "context-mode") return true;
@@ -8772,8 +8944,8 @@ function planSkills(row, edits) {
8772
8944
  const s = row.skillInstall;
8773
8945
  if (s.kind !== "dir") return;
8774
8946
  for (const f2 of s.files) {
8775
- if (!existsSync12(f2.src)) throw new Error(`preflight: ${f2.src} is missing`);
8776
- const after = renderSkill(readFileSync9(f2.src, "utf8"), s.prefixes);
8947
+ if (!existsSync14(f2.src)) throw new Error(`preflight: ${f2.src} is missing`);
8948
+ const after = renderSkill(readFileSync10(f2.src, "utf8"), s.prefixes);
8777
8949
  const before = readRaw(f2.file);
8778
8950
  if (before !== after) edits.push({ plain: true, file: f2.file, before, after, changes: [{ file: f2.file, path: f2.name, before: before === void 0 ? null : "old", after: "SKILL.md" }] });
8779
8951
  }
@@ -8876,7 +9048,7 @@ function hookEnabledCheck(row, status) {
8876
9048
  }
8877
9049
  function packageVersion(pkgDir) {
8878
9050
  try {
8879
- const v = JSON.parse(hostText(readFileSync9(path12.join(pkgDir, "package.json"), "utf8"))).version;
9051
+ const v = JSON.parse(hostText(readFileSync10(path12.join(pkgDir, "package.json"), "utf8"))).version;
8880
9052
  return typeof v === "string" ? v : void 0;
8881
9053
  } catch {
8882
9054
  return void 0;
@@ -8902,7 +9074,7 @@ function copyCheck(row, pkgDir) {
8902
9074
  return { name: "copy", ok: false, detail: `${c3.host} runs context-mode ${old}, the installed package is ${pkg}; run ${c3.bin} ${c3.refresh.join(" ")}` };
8903
9075
  }
8904
9076
  function mcpCheck(cmd, env) {
8905
- return new Promise((resolve2) => {
9077
+ return new Promise((resolve3) => {
8906
9078
  const child = spawn3(cmd[0], cmd.slice(1), { env, stdio: ["pipe", "pipe", "ignore"], detached: process.platform !== "win32", windowsHide: true });
8907
9079
  const reap = () => {
8908
9080
  child.kill();
@@ -8914,7 +9086,7 @@ function mcpCheck(cmd, env) {
8914
9086
  clearTimeout(timer);
8915
9087
  process.off("exit", reap);
8916
9088
  child.kill();
8917
- resolve2({ name: "mcp", ok, detail });
9089
+ resolve3({ name: "mcp", ok, detail });
8918
9090
  };
8919
9091
  const timer = setTimeout(() => done(false, "no MCP answer before timeout"), VERIFY_TIMEOUT_MS);
8920
9092
  child.on("error", (e) => done(false, e.message));
@@ -8959,7 +9131,7 @@ function hookRound(row, env) {
8959
9131
  const bare = [];
8960
9132
  for (let i2 = 0; i2 < HOOK_SAMPLES; i2++) {
8961
9133
  let t2 = performance.now();
8962
- const r2 = spawnSync3(cmd[0], cmd.slice(1), { env, input, encoding: "utf8", timeout: VERIFY_TIMEOUT_MS, windowsHide: true });
9134
+ const r2 = spawnSync4(cmd[0], cmd.slice(1), { env, input, encoding: "utf8", timeout: VERIFY_TIMEOUT_MS, windowsHide: true });
8963
9135
  wall.push(performance.now() - t2);
8964
9136
  if (r2.status !== 0) return { name: "hook", ok: false, detail: `hook exited ${r2.status}: ${`${r2.stderr}`.trim()}` };
8965
9137
  const out2 = `${r2.stdout}`.trim();
@@ -8972,7 +9144,7 @@ function hookRound(row, env) {
8972
9144
  if (!isObj5(j2)) return { name: "hook", ok: false, detail: `hook answer is not a JSON object: ${out2.slice(0, 200)}` };
8973
9145
  }
8974
9146
  t2 = performance.now();
8975
- spawnSync3(cmd[0], ["-e", ""], { env, timeout: VERIFY_TIMEOUT_MS, windowsHide: true });
9147
+ spawnSync4(cmd[0], ["-e", ""], { env, timeout: VERIFY_TIMEOUT_MS, windowsHide: true });
8976
9148
  bare.push(performance.now() - t2);
8977
9149
  }
8978
9150
  const wallP95Ms = Math.round(p95(wall));
@@ -9028,26 +9200,26 @@ function hookRunsCheck(row, env) {
9028
9200
  try {
9029
9201
  const home = path12.join(root, "home");
9030
9202
  const proj = path12.join(root, "proj");
9031
- mkdirSync3(home);
9032
- mkdirSync3(proj);
9203
+ mkdirSync5(home);
9204
+ mkdirSync5(proj);
9033
9205
  const text2 = sampleText();
9034
- writeFileSync2(path12.join(proj, SAMPLE_FILE), text2);
9206
+ writeFileSync3(path12.join(proj, SAMPLE_FILE), text2);
9035
9207
  const { effect, payload } = hookSample(row.id, proj, text2);
9036
9208
  const sampleEnv = { ...env, HOME: home, USERPROFILE: home };
9037
9209
  delete sampleEnv.CLAUDE_PROJECT_DIR;
9038
9210
  const cmd = row.hookRunCommand;
9039
- const r2 = spawnSync3(cmd[0], cmd.slice(1), { env: sampleEnv, cwd: proj, input: JSON.stringify(payload), encoding: "utf8", timeout: VERIFY_TIMEOUT_MS, windowsHide: true });
9211
+ const r2 = spawnSync4(cmd[0], cmd.slice(1), { env: sampleEnv, cwd: proj, input: JSON.stringify(payload), encoding: "utf8", timeout: VERIFY_TIMEOUT_MS, windowsHide: true });
9040
9212
  const bad = sampleVerdict(row.id, effect, text2, { status: r2.status, stdout: `${r2.stdout ?? ""}`, stderr: `${r2.stderr ?? ""}` });
9041
9213
  return bad === null ? { name: "hook-runs", ok: true } : { name: "hook-runs", ok: false, detail: bad };
9042
9214
  } finally {
9043
- rmSync(root, { recursive: true, force: true });
9215
+ rmSync2(root, { recursive: true, force: true });
9044
9216
  }
9045
9217
  }
9046
9218
  var SEEN_SQL = "SELECT 1 FROM events WHERE agent = ? LIMIT 1";
9047
9219
  var NOT_SEEN_LINE = "not seen yet, run one tool call";
9048
9220
  function hookSeenCheck(row, home) {
9049
9221
  const base = path12.join(home, STATE_DIR, PROJECTS_DIR_NAME);
9050
- const dirs = existsSync12(base) ? readdirSync5(base) : [];
9222
+ const dirs = existsSync14(base) ? readdirSync5(base) : [];
9051
9223
  let sqlite;
9052
9224
  try {
9053
9225
  sqlite = process.getBuiltinModule("node:sqlite");
@@ -9056,7 +9228,7 @@ function hookSeenCheck(row, home) {
9056
9228
  }
9057
9229
  for (const d of dirs) {
9058
9230
  const file = path12.join(base, d, DB_FILE_NAME);
9059
- if (!sqlite || !existsSync12(file)) continue;
9231
+ if (!sqlite || !existsSync14(file)) continue;
9060
9232
  let db;
9061
9233
  try {
9062
9234
  db = new sqlite.DatabaseSync(file, { readOnly: true });
@@ -9071,10 +9243,10 @@ function hookSeenCheck(row, home) {
9071
9243
  function skillsCheck(row, pkgDir) {
9072
9244
  const s = row.skillInstall;
9073
9245
  if (s.kind === "package") {
9074
- const miss = COMMAND_SKILLS.map((n3) => path12.join(pkgDir, s.via, n3, SKILL_FILE)).filter((f2) => !existsSync12(f2));
9246
+ const miss = COMMAND_SKILLS.map((n3) => path12.join(pkgDir, s.via, n3, SKILL_FILE)).filter((f2) => !existsSync14(f2));
9075
9247
  return { name: "skills", ok: miss.length === 0, detail: miss.length ? `missing ${miss.join(", ")}` : void 0 };
9076
9248
  }
9077
- const bad = s.files.filter((f2) => readRaw(f2.file) !== (existsSync12(f2.src) ? renderSkill(readFileSync9(f2.src, "utf8"), s.prefixes) : void 0));
9249
+ const bad = s.files.filter((f2) => readRaw(f2.file) !== (existsSync14(f2.src) ? renderSkill(readFileSync10(f2.src, "utf8"), s.prefixes) : void 0));
9078
9250
  return { name: "skills", ok: bad.length === 0, detail: bad.length ? `${bad.map((f2) => f2.file).join(", ")} missing or without the ${s.prefixes.join(" / ") || "plain"} tool prefix` : void 0 };
9079
9251
  }
9080
9252
  var PLUGIN_ENABLED = "enabled";
@@ -9326,26 +9498,26 @@ function undo(dir, entries, env) {
9326
9498
  continue;
9327
9499
  }
9328
9500
  if (!e.file) continue;
9329
- if (e.existed && e.backup) atomicWrite(e.file, readFileSync9(path12.join(dir, e.backup), "utf8"));
9501
+ if (e.existed && e.backup) atomicWrite(e.file, readFileSync10(path12.join(dir, e.backup), "utf8"));
9330
9502
  else unlinkWithRetry(e.file);
9331
9503
  }
9332
9504
  }
9333
9505
  function takeLock(root, runId) {
9334
9506
  const file = path12.join(root, LOCK_FILE);
9335
- mkdirSync3(root, { recursive: true });
9507
+ mkdirSync5(root, { recursive: true });
9336
9508
  for (let attempt = 0; attempt < 2; attempt++) {
9337
9509
  try {
9338
- writeFileSync2(file, JSON.stringify({ pid: process.pid, runId }), { flag: "wx" });
9510
+ writeFileSync3(file, JSON.stringify({ pid: process.pid, runId }), { flag: "wx" });
9339
9511
  return void 0;
9340
9512
  } catch (e) {
9341
9513
  if (e.code !== "EEXIST") throw e;
9342
9514
  let pid = 0;
9343
9515
  try {
9344
- pid = Number(JSON.parse(readFileSync9(file, "utf8")).pid);
9516
+ pid = Number(JSON.parse(readFileSync10(file, "utf8")).pid);
9345
9517
  } catch {
9346
9518
  }
9347
9519
  if (pid && pidAlive(pid)) return `setup lock ${file} is held by pid ${pid}; wait for that run or remove the lock`;
9348
- rmSync(file, { force: true });
9520
+ rmSync2(file, { force: true });
9349
9521
  }
9350
9522
  }
9351
9523
  return `setup lock ${file} could not be taken`;
@@ -9358,14 +9530,14 @@ function agentHomeDir(id, ctx) {
9358
9530
  return path12.join(ctx.home, ...AGENT_HOME_DIR[id]);
9359
9531
  }
9360
9532
  function detectAgents(reg, ctx) {
9361
- return reg.filter((r2) => existsSync12(agentHomeDir(r2.id, ctx)) || r2.listCommand && which(r2.listCommand.bin, ctx.env)).map((r2) => r2.id);
9533
+ return reg.filter((r2) => existsSync14(agentHomeDir(r2.id, ctx)) || r2.listCommand && which(r2.listCommand.bin, ctx.env)).map((r2) => r2.id);
9362
9534
  }
9363
9535
  async function runSetup(opts) {
9364
9536
  const ctx = { home: opts.home, pkgDir: opts.pkgDir, env: opts.env };
9365
9537
  const runId = opts.runId ?? (/* @__PURE__ */ new Date()).toISOString().split(":").join("-").split(".").join("-");
9366
9538
  const reg = buildRegistry(ctx);
9367
9539
  for (const f2 of ["server.mjs", "hook.mjs"]) {
9368
- if (!existsSync12(path12.join(ctx.pkgDir, f2))) return { exitCode: 1, agents: [], error: `preflight: ${path12.join(ctx.pkgDir, f2)} is missing` };
9540
+ if (!existsSync14(path12.join(ctx.pkgDir, f2))) return { exitCode: 1, agents: [], error: `preflight: ${path12.join(ctx.pkgDir, f2)} is missing` };
9369
9541
  }
9370
9542
  const ids = opts.agents ?? detectAgents(reg, ctx);
9371
9543
  const root = path12.join(ctx.home, STATE_DIR);
@@ -9378,7 +9550,7 @@ async function runSetup(opts) {
9378
9550
  let current;
9379
9551
  const onAbort = () => {
9380
9552
  if (current !== void 0 && !opts.dryRun) run.rollback(current, ctx.env);
9381
- if (!opts.dryRun) rmSync(path12.join(root, LOCK_FILE), { force: true });
9553
+ if (!opts.dryRun) rmSync2(path12.join(root, LOCK_FILE), { force: true });
9382
9554
  };
9383
9555
  opts.signal?.addEventListener("abort", onAbort, { once: true });
9384
9556
  try {
@@ -9397,7 +9569,7 @@ async function runSetup(opts) {
9397
9569
  }
9398
9570
  } finally {
9399
9571
  opts.signal?.removeEventListener("abort", onAbort);
9400
- if (!opts.dryRun) rmSync(path12.join(root, LOCK_FILE), { force: true });
9572
+ if (!opts.dryRun) rmSync2(path12.join(root, LOCK_FILE), { force: true });
9401
9573
  }
9402
9574
  return { exitCode: agents.some((a2) => a2.status === "FAIL") ? 1 : 0, agents, backupDir: run.manifest ? run.dir : void 0 };
9403
9575
  }
@@ -9431,12 +9603,12 @@ async function setupRow(row, ctx, run, dryRun) {
9431
9603
  atomicWrite(e.file, e.plain || raw === void 0 ? e.after : withLayout(e.after, hostLayout(raw)));
9432
9604
  }
9433
9605
  for (const args of plan.cli) {
9434
- const r2 = runBin(row.cli.bin, args, ctx.env, row.cli.input ?? "");
9606
+ const r2 = runBin(row.cli.bin, args, ctx.env, row.cli.input ?? "", INSTALL_TIMEOUT_MS);
9435
9607
  if (!installExitOk(r2.status, r2.status === WIN_EXIT_CRASH && listCheck(row, ctx.env)?.ok === true)) throw new Error(`${row.cli.bin} ${args.join(" ")} exited ${r2.status}: ${`${r2.stderr}`.trim()}`);
9436
9608
  }
9437
9609
  if (plan.cli.length) for (const args of row.cli.remove) run.record({ agent: row.id, undo: { bin: row.cli.bin, args } });
9438
9610
  for (const args of plan.refresh) {
9439
- const r2 = runBin(row.cli.bin, args, ctx.env);
9611
+ const r2 = runBin(row.cli.bin, args, ctx.env, void 0, INSTALL_TIMEOUT_MS);
9440
9612
  if (r2.status !== 0) throw new Error(`${row.cli.bin} ${args.join(" ")} exited ${r2.status}: ${`${r2.stderr}`.trim()}`);
9441
9613
  run.record({ agent: row.id, ran: { bin: row.cli.bin, args } });
9442
9614
  }
@@ -9456,7 +9628,7 @@ async function runDoctor(opts) {
9456
9628
  const ctx = { home: opts.home, pkgDir: opts.pkgDir, env: opts.env };
9457
9629
  const reg = buildRegistry(ctx);
9458
9630
  for (const f2 of ["server.mjs", "hook.mjs"]) {
9459
- if (!existsSync12(path12.join(ctx.pkgDir, f2))) return { exitCode: 1, agents: [], error: `preflight: ${path12.join(ctx.pkgDir, f2)} is missing` };
9631
+ if (!existsSync14(path12.join(ctx.pkgDir, f2))) return { exitCode: 1, agents: [], error: `preflight: ${path12.join(ctx.pkgDir, f2)} is missing` };
9460
9632
  }
9461
9633
  const ids = opts.agents ?? detectAgents(reg, ctx);
9462
9634
  const run = new Run(path12.join(ctx.home, STATE_DIR), "doctor");
@@ -9524,26 +9696,26 @@ function runRemove(opts) {
9524
9696
  const env = opts.env ?? process.env;
9525
9697
  const root = path12.join(opts.home, STATE_DIR);
9526
9698
  const base = path12.join(root, BACKUP_DIR);
9527
- if (!existsSync12(base)) return { exitCode: 0, restored: 0 };
9699
+ if (!existsSync14(base)) return { exitCode: 0, restored: 0 };
9528
9700
  const held = takeLock(root, "remove");
9529
9701
  if (held) return { exitCode: 1, restored: 0, error: held };
9530
9702
  let restored = 0;
9531
9703
  try {
9532
- const runs = readdirSync5(base).map((r2) => path12.join(base, r2)).filter((d) => existsSync12(path12.join(d, MANIFEST))).sort().reverse();
9704
+ const runs = readdirSync5(base).map((r2) => path12.join(base, r2)).filter((d) => existsSync14(path12.join(d, MANIFEST))).sort().reverse();
9533
9705
  for (const dir of runs) {
9534
- const m3 = JSON.parse(readFileSync9(path12.join(dir, MANIFEST), "utf8"));
9706
+ const m3 = JSON.parse(readFileSync10(path12.join(dir, MANIFEST), "utf8"));
9535
9707
  undo(dir, m3.entries, env);
9536
9708
  restored += m3.entries.length;
9537
9709
  renameWithRetry(path12.join(dir, MANIFEST), path12.join(dir, MANIFEST_DONE));
9538
9710
  }
9539
9711
  } finally {
9540
- rmSync(path12.join(root, LOCK_FILE), { force: true });
9712
+ rmSync2(path12.join(root, LOCK_FILE), { force: true });
9541
9713
  }
9542
9714
  return { exitCode: 0, restored };
9543
9715
  }
9544
9716
 
9545
9717
  // src/setup/print.ts
9546
- import { readFileSync as readFileSync10 } from "node:fs";
9718
+ import { readFileSync as readFileSync11 } from "node:fs";
9547
9719
  var SHELL_SAFE_PUNCT = "@%+=:,./-_";
9548
9720
  function isShellSafe(s) {
9549
9721
  if (s === "") return false;
@@ -9571,7 +9743,7 @@ function printPlan(row, env) {
9571
9743
  else if (h2.kind === "plugin-list") steps.push({ kind: "hook", file: h2.file, block: JSON.stringify({ [h2.key[0]]: [h2.entry] }, null, 2) + "\n" });
9572
9744
  const sk = row.skillInstall;
9573
9745
  if (sk.kind === "dir") {
9574
- for (const f2 of sk.files) steps.push({ kind: "skill", file: f2.file, block: renderSkill(readFileSync10(f2.src, "utf8"), sk.prefixes) });
9746
+ for (const f2 of sk.files) steps.push({ kind: "skill", file: f2.file, block: renderSkill(readFileSync11(f2.src, "utf8"), sk.prefixes) });
9575
9747
  }
9576
9748
  return { agent: row.id, steps, verify: `context-mode doctor --agents ${row.id}` };
9577
9749
  }
@@ -9732,23 +9904,22 @@ function buildIssueReport(command, res, ui) {
9732
9904
  return { text: redact(lines.join("\n"), ui.ctx), title };
9733
9905
  }
9734
9906
  function ghReady(env) {
9735
- const r2 = spawnSync4("gh", ["auth", "status"], { env, stdio: "ignore", timeout: 1e4, windowsHide: true });
9907
+ const r2 = spawnSync5("gh", ["auth", "status"], { env, stdio: "ignore", timeout: 1e4, windowsHide: true });
9736
9908
  return r2.status === 0;
9737
9909
  }
9738
- function issueUrl(title, body) {
9739
- const b3 = body.length > URL_BODY_MAX ? body.slice(0, URL_BODY_MAX) + "\n(cut; attach the report file)" : body;
9740
- return `https://github.com/${ISSUE_REPO}/issues/new?title=${encodeURIComponent(title)}&body=${encodeURIComponent(b3)}`;
9910
+ function issueUrl(title, summary) {
9911
+ return formUrl(title, summary.length > URL_BODY_MAX ? summary.slice(0, URL_BODY_MAX) : summary);
9741
9912
  }
9742
9913
  async function report(ui, command, res, write) {
9743
9914
  const { text: text2, title } = buildIssueReport(command, res, ui);
9744
9915
  let file = "";
9745
9916
  if (write) {
9746
9917
  const dir = path13.join(ui.ctx.home, STATE_DIR, REPORT_DIR);
9747
- mkdirSync4(dir, { recursive: true });
9918
+ mkdirSync6(dir, { recursive: true });
9748
9919
  file = path13.join(dir, `${command}-${(/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-")}.md`);
9749
- writeFileSync3(file, text2);
9920
+ writeFileSync4(file, text2);
9750
9921
  }
9751
- const gh = `gh issue create --repo ${ISSUE_REPO} --title ${JSON.stringify(title)} --body-file ${JSON.stringify(file || "<report>")}`;
9922
+ const gh = `gh issue create --repo ${ISSUE_REPO} --title ${JSON.stringify(title)} --label bug --body-file ${JSON.stringify(file || "<report>")}`;
9752
9923
  const p3 = ui.clack;
9753
9924
  if (!p3) {
9754
9925
  if (ui.f.debug) err(text2);
@@ -9763,15 +9934,15 @@ async function report(ui, command, res, write) {
9763
9934
  return;
9764
9935
  }
9765
9936
  if (file && ghReady(ui.ctx.env)) {
9766
- const r2 = spawnSync4("gh", ["issue", "create", "--repo", ISSUE_REPO, "--title", title, "--body-file", file], { env: ui.ctx.env, encoding: "utf8", timeout: 6e4, windowsHide: true });
9937
+ const r2 = spawnSync5("gh", ["issue", "create", "--repo", ISSUE_REPO, "--title", title, "--label", "bug", "--body-file", file], { env: ui.ctx.env, encoding: "utf8", timeout: 6e4, windowsHide: true });
9767
9938
  if (r2.status === 0) {
9768
9939
  p3.log.success(`Issue opened: ${`${r2.stdout}`.trim()}`);
9769
9940
  return;
9770
9941
  }
9771
9942
  p3.log.warn(`gh issue create failed: ${`${r2.stderr}`.trim()}`);
9772
9943
  }
9773
- p3.log.info(`Open this URL to file the issue:
9774
- ${issueUrl(title, text2)}`);
9944
+ p3.log.info(`Open this URL to file the issue (paste the report file into the form):
9945
+ ${issueUrl(title, title)}`);
9775
9946
  }
9776
9947
  async function apply(ui, agents, dryRun) {
9777
9948
  const ac = new AbortController();
@@ -9986,20 +10157,20 @@ async function upgrade(ui) {
9986
10157
  }
9987
10158
  const shell = process.platform === "win32";
9988
10159
  progress2(ui, `running ${install}`);
9989
- const r2 = spawnSync4(npm, ["i", "-g", spec], { env: ui.ctx.env, encoding: "utf8", shell, windowsHide: true });
10160
+ const r2 = spawnSync5(npm, ["i", "-g", spec], { env: ui.ctx.env, encoding: "utf8", shell, windowsHide: true });
9990
10161
  if (r2.status !== 0) {
9991
10162
  const why = (`${r2.stderr ?? ""}`.trim().split("\n").pop() ?? "") || (r2.error?.message ?? "");
9992
10163
  err(`FAIL upgrade: ${install} exited ${r2.status ?? "?"}${why ? `: ${why}` : ""}. Fix: ${install}`);
9993
10164
  return EXIT_FAIL;
9994
10165
  }
9995
- const root = `${spawnSync4(npm, ["root", "-g"], { env: ui.ctx.env, encoding: "utf8", shell, windowsHide: true }).stdout ?? ""}`.trim();
10166
+ const root = `${spawnSync5(npm, ["root", "-g"], { env: ui.ctx.env, encoding: "utf8", shell, windowsHide: true }).stdout ?? ""}`.trim();
9996
10167
  const cli = path13.join(root, "context-mode", "cli.mjs");
9997
- if (!root || !existsSync13(cli)) {
10168
+ if (!root || !existsSync15(cli)) {
9998
10169
  err(`FAIL upgrade: ${cli} not found after ${install}. Fix: ${install}`);
9999
10170
  return EXIT_FAIL;
10000
10171
  }
10001
10172
  progress2(ui, `running context-mode ${repairArgs.join(" ")}`);
10002
- const c3 = spawnSync4(process.execPath, [cli, ...repairArgs], { env: ui.ctx.env, stdio: "inherit", windowsHide: true });
10173
+ const c3 = spawnSync5(process.execPath, [cli, ...repairArgs], { env: ui.ctx.env, stdio: "inherit", windowsHide: true });
10003
10174
  return c3.status ?? (c3.signal === "SIGINT" ? EXIT_SIGINT : EXIT_FAIL);
10004
10175
  }
10005
10176
  async function runCommand(cmd, args, env) {
@@ -10033,12 +10204,12 @@ Run context-mode ${cmd} --help.`);
10033
10204
  }
10034
10205
 
10035
10206
  // src/entries/is-entry.ts
10036
- import { realpathSync as realpathSync7 } from "node:fs";
10207
+ import { realpathSync as realpathSync8 } from "node:fs";
10037
10208
  function isEntry(main2, argv1, self) {
10038
10209
  if (main2 !== void 0) return main2;
10039
10210
  if (argv1 === void 0 || argv1 === "") return false;
10040
10211
  try {
10041
- return realpathSync7(argv1) === realpathSync7(self);
10212
+ return realpathSync8(argv1) === realpathSync8(self);
10042
10213
  } catch {
10043
10214
  return false;
10044
10215
  }
@@ -10089,10 +10260,10 @@ function route(argv, version) {
10089
10260
  ` };
10090
10261
  }
10091
10262
  function main() {
10092
- const dir = path14.dirname(realpathSync8(fileURLToPath2(import.meta.url)));
10263
+ const dir = path14.dirname(realpathSync9(fileURLToPath2(import.meta.url)));
10093
10264
  let version = "";
10094
10265
  try {
10095
- version = String(JSON.parse(readFileSync11(path14.join(dir, PACKAGE_FILE), "utf8")).version);
10266
+ version = String(JSON.parse(readFileSync12(path14.join(dir, PACKAGE_FILE), "utf8")).version);
10096
10267
  } catch (err2) {
10097
10268
  process.stderr.write(`${SERVER_KEY}: cannot read ${PACKAGE_FILE}: ${err2.message}
10098
10269
  `);