billion-context-pi 0.1.69-pr.428.222 → 0.1.69

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/dist/index.js CHANGED
@@ -3404,7 +3404,7 @@ function buildStatusReport(state, messages, countTokens, options = {}) {
3404
3404
  const limit = options.limit ?? 30;
3405
3405
  const activeBlocks2 = state.blocks.filter((b2) => b2.active).sort((a, b2) => numericPart2(a.blockId) - numericPart2(b2.blockId));
3406
3406
  if (scope === "compressed") {
3407
- return renderCompressedDrilldown(activeBlocks2, state, sort, limit, countTokens);
3407
+ return renderCompressedDrilldown(activeBlocks2, state, sort, limit, countTokens, options.meta);
3408
3408
  }
3409
3409
  const { visible, summaryTokens } = collectVisible(messages, state, countTokens);
3410
3410
  if (scope === "uncompressed") {
@@ -3413,10 +3413,23 @@ function buildStatusReport(state, messages, countTokens, options = {}) {
3413
3413
  }
3414
3414
  return renderUncompressedRanges(visible);
3415
3415
  }
3416
- return renderOverview(visible, summaryTokens, activeBlocks2, state, countTokens, limit);
3416
+ return renderOverview(visible, summaryTokens, activeBlocks2, state, countTokens, limit, options.meta);
3417
3417
  }
3418
- function renderOverview(visible, summaryTokens, blocks, state, countTokens, limit) {
3418
+ function surfaceLine(meta) {
3419
+ if (!meta) return null;
3420
+ const parts = [];
3421
+ if (meta.pack) parts.push(`pack=${meta.pack}${meta.packVersion ? ` v${meta.packVersion}` : ""}`);
3422
+ if (meta.host) parts.push(`host=${meta.host}`);
3423
+ if (parts.length === 0) return null;
3424
+ return `ACTIVE SURFACE: ${parts.join(" | ")}`;
3425
+ }
3426
+ function renderOverview(visible, summaryTokens, blocks, state, countTokens, limit, meta) {
3419
3427
  const lines = [];
3428
+ const surface = surfaceLine(meta);
3429
+ if (surface) {
3430
+ lines.push(surface);
3431
+ lines.push("");
3432
+ }
3420
3433
  const toolTypeMap = /* @__PURE__ */ new Map();
3421
3434
  for (const message of visible) {
3422
3435
  toolTypeMap.set(message.tool, (toolTypeMap.get(message.tool) ?? 0) + message.tokens);
@@ -3533,7 +3546,7 @@ function renderMessageDrilldown(visible, toolFilter, sort, limit) {
3533
3546
  }
3534
3547
  return lines.join("\n");
3535
3548
  }
3536
- function renderCompressedDrilldown(blocks, state, sort, limit, countTokens) {
3549
+ function renderCompressedDrilldown(blocks, state, sort, limit, countTokens, meta) {
3537
3550
  let sorted = [...blocks];
3538
3551
  if (sort === "time") sorted.sort((a, b2) => a.createdAt - b2.createdAt);
3539
3552
  else if (sort === "age") sorted.sort((a, b2) => b2.survivedCount - a.survivedCount);
@@ -3546,9 +3559,15 @@ function renderCompressedDrilldown(blocks, state, sort, limit, countTokens) {
3546
3559
  (s, b2) => s + effectiveCompressedTokens(b2, state, countTokens),
3547
3560
  0
3548
3561
  );
3549
- const lines = [
3562
+ const lines = [];
3563
+ const surface = surfaceLine(meta);
3564
+ if (surface) {
3565
+ lines.push(surface);
3566
+ lines.push("");
3567
+ }
3568
+ lines.push(
3550
3569
  `COMPRESSED \u2014 ${sorted.length} blocks | ${formatTokens2(totalEffective)} original \u2192 ${formatTokens2(totalSummary)} summary`
3551
- ];
3570
+ );
3552
3571
  const breakdown = tierBreakdown(sorted, countTokens);
3553
3572
  if (breakdown) lines.push(`Tier usage: ${breakdown}`);
3554
3573
  lines.push("");
@@ -5189,6 +5208,7 @@ var SessionStateStore = class {
5189
5208
  let state = createInitialState();
5190
5209
  let liveRefOrigins = [];
5191
5210
  let derivedFrom = null;
5211
+ let activePack;
5192
5212
  if (file) {
5193
5213
  try {
5194
5214
  const raw = await fs.readFile(file, "utf8");
@@ -5197,6 +5217,7 @@ var SessionStateStore = class {
5197
5217
  state = mergeInitialState(parsed);
5198
5218
  liveRefOrigins = parseLiveRefOrigins(parsed.liveRefOrigins);
5199
5219
  derivedFrom = parseDerivedFrom(parsed.derivedFrom);
5220
+ if (typeof parsed.activePack === "string" && parsed.activePack) activePack = parsed.activePack;
5200
5221
  }
5201
5222
  } catch (e) {
5202
5223
  const code = e.code;
@@ -5209,16 +5230,27 @@ var SessionStateStore = class {
5209
5230
  if (parentState) state = parentState;
5210
5231
  }
5211
5232
  }
5212
- this.cache.set(key, { state, liveRefOrigins, derivedFrom });
5233
+ this.cache.set(key, { state, liveRefOrigins, derivedFrom, activePack });
5213
5234
  return state;
5214
5235
  }
5236
+ /** Stamp the effective prompt pack for the live session (audit trail:
5237
+ * persisted into the sidecar on the next save). */
5238
+ setActivePack(sessionFile, sessionId, activePack) {
5239
+ const key = cacheKey(sessionFile, sessionId);
5240
+ const slot = this.cache.get(key);
5241
+ if (slot) this.cache.set(key, { ...slot, activePack });
5242
+ }
5243
+ getActivePack(sessionFile, sessionId) {
5244
+ return this.cache.get(cacheKey(sessionFile, sessionId))?.activePack;
5245
+ }
5215
5246
  async save(state, sessionFile, sessionId) {
5216
5247
  const file = stateFileFor(sessionFile);
5217
5248
  const key = cacheKey(sessionFile, sessionId);
5218
5249
  const prev = this.cache.get(key);
5219
5250
  const liveRefOrigins = prev?.liveRefOrigins ?? [];
5220
5251
  const derivedFrom = prev?.derivedFrom ?? null;
5221
- this.cache.set(key, { state, liveRefOrigins, derivedFrom });
5252
+ const activePack = prev?.activePack;
5253
+ this.cache.set(key, { state, liveRefOrigins, derivedFrom, activePack });
5222
5254
  if (!file) return;
5223
5255
  const dir = path3.dirname(file);
5224
5256
  await fs.mkdir(dir, { recursive: true }).catch((e) => {
@@ -5228,6 +5260,7 @@ var SessionStateStore = class {
5228
5260
  try {
5229
5261
  const payload = { ...state, liveRefOrigins };
5230
5262
  if (derivedFrom) payload.derivedFrom = derivedFrom;
5263
+ if (activePack) payload.activePack = activePack;
5231
5264
  await fs.writeFile(tmp, JSON.stringify(payload), "utf8");
5232
5265
  await fs.rename(tmp, file);
5233
5266
  } catch (e) {
@@ -11542,6 +11575,147 @@ function formatSize(tokens) {
11542
11575
  return `${(tokens / 1e6).toFixed(1)}M`;
11543
11576
  }
11544
11577
 
11578
+ // src/prompt-pack.ts
11579
+ import { readFileSync as readFileSync4 } from "fs";
11580
+ import * as path6 from "path";
11581
+ import { homedir as homedir5 } from "os";
11582
+ function defaultPackSources2(cwd) {
11583
+ return defaultPackSources({
11584
+ projectDir: path6.join(cwd, CONFIG_DIR_NAME2, "acp", "packs"),
11585
+ userDirs: [path6.join(homedir5(), CONFIG_DIR_NAME2, "acp", "packs")]
11586
+ });
11587
+ }
11588
+ function packResolver(cwd) {
11589
+ return createPackResolver(defaultPackSources2(cwd));
11590
+ }
11591
+ function resolvePackName(adapter, provider, modelId) {
11592
+ const raw = resolveCompress(adapter.compress, provider, modelId).promptPack;
11593
+ return typeof raw === "string" && isValidPackName(raw) ? raw : "default";
11594
+ }
11595
+ function resolveActivePack(adapter, cwd, provider, modelId, resolver) {
11596
+ const name = resolvePackName(adapter, provider, modelId);
11597
+ if (name === "default") return defaultPack;
11598
+ const r = resolver ?? packResolver(cwd);
11599
+ return r.resolve(name) ?? defaultPack;
11600
+ }
11601
+ var HOST_VERSION = (() => {
11602
+ try {
11603
+ return "0.1.69";
11604
+ } catch {
11605
+ return "dev";
11606
+ }
11607
+ })();
11608
+ function surfaceMetaOf(pack, requested) {
11609
+ const resolved = requested !== "default" && pack.name === requested ? requested : "default";
11610
+ return { pack: resolved, packVersion: pack.version, host: `billion-context-pi ${HOST_VERSION}` };
11611
+ }
11612
+ function resolveSurfaceMeta(adapter, cwd, provider, modelId, resolver) {
11613
+ return surfaceMetaOf(
11614
+ resolveActivePack(adapter, cwd, provider, modelId, resolver),
11615
+ resolvePackName(adapter, provider, modelId)
11616
+ );
11617
+ }
11618
+ var ACP_TOOLS = /* @__PURE__ */ new Set(["compress", "decompress", "search_context", "acp_status"]);
11619
+ function piAdapterSurface(pack) {
11620
+ const raw = pack.surface.adapters?.pi;
11621
+ const rec = raw && typeof raw === "object" && !Array.isArray(raw) ? raw : {};
11622
+ const toolExtras = {};
11623
+ const extrasRaw = rec.toolExtras;
11624
+ if (extrasRaw && typeof extrasRaw === "object" && !Array.isArray(extrasRaw)) {
11625
+ for (const [tool, value] of Object.entries(extrasRaw)) {
11626
+ if (!ACP_TOOLS.has(tool) || !value || typeof value !== "object") continue;
11627
+ const src = value;
11628
+ const entry = {};
11629
+ if (typeof src.promptSnippet === "string") entry.promptSnippet = src.promptSnippet;
11630
+ if (typeof src.promptGuidelines === "string") {
11631
+ entry.promptGuidelines = [src.promptGuidelines];
11632
+ } else if (Array.isArray(src.promptGuidelines)) {
11633
+ const guidelines = src.promptGuidelines.filter((g2) => typeof g2 === "string");
11634
+ if (guidelines.length === src.promptGuidelines.length) entry.promptGuidelines = guidelines;
11635
+ }
11636
+ if (Object.keys(entry).length > 0) toolExtras[tool] = entry;
11637
+ }
11638
+ }
11639
+ const surface = {
11640
+ promptSections: sanitizePromptSections(rec.promptSections),
11641
+ toolExtras
11642
+ };
11643
+ if (typeof rec.delegatePrompt === "string" || rec.delegatePrompt === null) {
11644
+ surface.delegatePrompt = rec.delegatePrompt;
11645
+ }
11646
+ return surface;
11647
+ }
11648
+ function packToolPrompts(pack) {
11649
+ const out = {};
11650
+ const toolPrompts = pack?.surface.toolPrompts;
11651
+ if (toolPrompts) {
11652
+ for (const [tool, overrides] of Object.entries(toolPrompts)) {
11653
+ if (ACP_TOOLS.has(tool)) out[tool] = { ...overrides };
11654
+ }
11655
+ }
11656
+ if (pack) {
11657
+ for (const [tool, extras] of Object.entries(piAdapterSurface(pack).toolExtras)) {
11658
+ out[tool] = { ...out[tool], ...extras };
11659
+ }
11660
+ }
11661
+ return out;
11662
+ }
11663
+ function mergeToolPrompts(pack, inline) {
11664
+ if (!pack) return inline ?? {};
11665
+ if (!inline) return pack;
11666
+ const out = {};
11667
+ for (const name of /* @__PURE__ */ new Set([...Object.keys(pack), ...Object.keys(inline)])) {
11668
+ const p = pack[name];
11669
+ const i = inline[name];
11670
+ if (!i) {
11671
+ out[name] = p;
11672
+ continue;
11673
+ }
11674
+ if (!p) {
11675
+ out[name] = i;
11676
+ continue;
11677
+ }
11678
+ out[name] = {
11679
+ ...p,
11680
+ ...i,
11681
+ paramDescriptions: { ...p.paramDescriptions, ...i.paramDescriptions }
11682
+ };
11683
+ }
11684
+ return out;
11685
+ }
11686
+ function mergeSurface(pack, inline) {
11687
+ const s = pack?.surface ?? {};
11688
+ const pi = pack ? piAdapterSurface(pack) : { promptSections: {}, toolExtras: {} };
11689
+ return {
11690
+ prompts: { ...s.prompts ?? {}, ...inline.prompts ?? {} },
11691
+ promptSections: { ...pi.promptSections, ...inline.promptSections ?? {} },
11692
+ nudgeSections: { ...s.nudgeSections ?? {}, ...inline.nudgeSections ?? {} },
11693
+ toolPrompts: mergeToolPrompts(packToolPrompts(pack), inline.toolPrompts),
11694
+ delegatePrompt: inline.delegatePrompt !== void 0 ? inline.delegatePrompt : pi.delegatePrompt
11695
+ };
11696
+ }
11697
+ function readToolSurfaceWithPacks(cwd) {
11698
+ const home = homedir5();
11699
+ let inline = {};
11700
+ let packName = "default";
11701
+ for (const base of [path6.join(home, CONFIG_DIR_NAME2), path6.join(cwd, CONFIG_DIR_NAME2)]) {
11702
+ try {
11703
+ const parsed = JSON.parse(readFileSync4(path6.join(base, "acp.json"), "utf8"));
11704
+ if (parsed && typeof parsed === "object") {
11705
+ const rec = parsed;
11706
+ if (rec.toolPrompts) inline = sanitizeToolPrompts(rec.toolPrompts);
11707
+ const c = rec.compress;
11708
+ if (c && typeof c === "object" && typeof c.promptPack === "string") {
11709
+ packName = c.promptPack;
11710
+ }
11711
+ }
11712
+ } catch {
11713
+ }
11714
+ }
11715
+ const pack = packName === "default" || !isValidPackName(packName) ? null : packResolver(cwd).resolve(packName);
11716
+ return mergeToolPrompts(packToolPrompts(pack), inline);
11717
+ }
11718
+
11545
11719
  // src/floor-stale.ts
11546
11720
  function validAnchorUsage(u) {
11547
11721
  if (!u) return false;
@@ -11570,7 +11744,7 @@ import {
11570
11744
  import { createWriteStream, existsSync as existsSync3 } from "fs";
11571
11745
  import { mkdir as mkdir2, mkdtemp, writeFile as writeFile2, rm, appendFile, readFile, copyFile } from "fs/promises";
11572
11746
  import { tmpdir as tmpdir2 } from "os";
11573
- import { dirname as dirname4, join as join8, resolve as resolvePath } from "path";
11747
+ import { dirname as dirname4, join as join9, resolve as resolvePath } from "path";
11574
11748
 
11575
11749
  // src/footer-status.ts
11576
11750
  var FOOTER_STATUS_KEY = "billion-context-pi";
@@ -11989,7 +12163,7 @@ var EOF_GRACE_MS = 1e4;
11989
12163
  var SETTLED_GRACE_MS = 1e4;
11990
12164
  var KILL_GRACE_MS = 1e4;
11991
12165
  var RESULT_SUMMARY_CHARS = 500;
11992
- var OUT_DIR = join8(tmpdir2(), "acp-delegate");
12166
+ var OUT_DIR = join9(tmpdir2(), "acp-delegate");
11993
12167
  var NOTIFY_COALESCE_MS = 2e3;
11994
12168
  var NOTIFY_COALESCE_MAX_MS = 1e4;
11995
12169
  var SESSION_EXT = ".session.jsonl";
@@ -12019,11 +12193,11 @@ function delegateChildEnv(parentDepth, maxDepth) {
12019
12193
  };
12020
12194
  }
12021
12195
  var PI_CLI_ENTRY_RE = /[\\/]pi-coding-agent[\\/]dist[\\/]cli\.js$/;
12022
- var PI_PACKAGE_REL = join8("@earendil-works", "pi-coding-agent", "dist", "cli.js");
12196
+ var PI_PACKAGE_REL = join9("@earendil-works", "pi-coding-agent", "dist", "cli.js");
12023
12197
  function probeUpFromArgv(argv1) {
12024
12198
  let dir = resolvePath(dirname4(argv1) || process.cwd());
12025
12199
  for (; ; ) {
12026
- const candidate = join8(dir, "node_modules", PI_PACKAGE_REL);
12200
+ const candidate = join9(dir, "node_modules", PI_PACKAGE_REL);
12027
12201
  if (existsSync3(candidate)) return candidate;
12028
12202
  const parent = dirname4(dir);
12029
12203
  if (parent === dir) return null;
@@ -12033,12 +12207,12 @@ function probeUpFromArgv(argv1) {
12033
12207
  function piCliGlobalCandidates(env) {
12034
12208
  const candidates = [];
12035
12209
  if (process.platform === "win32") {
12036
- if (env.APPDATA) candidates.push(join8(env.APPDATA, "npm", "node_modules", PI_PACKAGE_REL));
12210
+ if (env.APPDATA) candidates.push(join9(env.APPDATA, "npm", "node_modules", PI_PACKAGE_REL));
12037
12211
  } else {
12038
12212
  const home = env.HOME ?? env.USERPROFILE;
12039
- if (home) candidates.push(join8(home, ".local", "lib", "node_modules", PI_PACKAGE_REL));
12040
- candidates.push(join8("/usr/local", "lib", "node_modules", PI_PACKAGE_REL));
12041
- candidates.push(join8("/usr", "lib", "node_modules", PI_PACKAGE_REL));
12213
+ if (home) candidates.push(join9(home, ".local", "lib", "node_modules", PI_PACKAGE_REL));
12214
+ candidates.push(join9("/usr/local", "lib", "node_modules", PI_PACKAGE_REL));
12215
+ candidates.push(join9("/usr", "lib", "node_modules", PI_PACKAGE_REL));
12042
12216
  }
12043
12217
  return candidates;
12044
12218
  }
@@ -12056,7 +12230,7 @@ function resolvePiCliEntry(argv1, env = process.env, piHost = true) {
12056
12230
  }
12057
12231
  return argv1;
12058
12232
  }
12059
- var ACP_TOOLS = ["compress", "decompress", "search_context", "acp_status"];
12233
+ var ACP_TOOLS2 = ["compress", "decompress", "search_context", "acp_status"];
12060
12234
  var RESTRICTED_TOOLS = "read,bash,grep,find,ls";
12061
12235
  var AGENTS = {
12062
12236
  reviewer: {
@@ -12198,7 +12372,7 @@ function markDelegateResultRead(filePath) {
12198
12372
  const abs = resolvePath(filePath);
12199
12373
  let matched = false;
12200
12374
  for (const run of runs.values()) {
12201
- if (join8(OUT_DIR, `${run.runId}.out`) === abs) {
12375
+ if (join9(OUT_DIR, `${run.runId}.out`) === abs) {
12202
12376
  run.readAt = Date.now();
12203
12377
  suppressIfReadNow(run);
12204
12378
  matched = true;
@@ -12247,9 +12421,9 @@ function toFleetRunView(r) {
12247
12421
  exitLabel: exitLabel(r.exitCode ?? null, r.exitSignal),
12248
12422
  timedOut: r.timedOut,
12249
12423
  resumedFrom: r.resumedFrom,
12250
- replyFile: r.result?.file ?? join8(OUT_DIR, `${r.runId}.out`),
12424
+ replyFile: r.result?.file ?? join9(OUT_DIR, `${r.runId}.out`),
12251
12425
  activityFile: r.activityFile,
12252
- sessionFile: join8(OUT_DIR, `${r.runId}${SESSION_EXT}`),
12426
+ sessionFile: join9(OUT_DIR, `${r.runId}${SESSION_EXT}`),
12253
12427
  usage: r.usage
12254
12428
  };
12255
12429
  }
@@ -12708,7 +12882,7 @@ function makeDelegateWaitTool(_pi) {
12708
12882
  const displayMode = delegateDisplayUsage;
12709
12883
  if (run.status === "cancelled") {
12710
12884
  run.consumed = true;
12711
- const file = run.result?.file || join8(OUT_DIR, `${args.runId}.out`);
12885
+ const file = run.result?.file || join9(OUT_DIR, `${args.runId}.out`);
12712
12886
  return buildWaitResult(run, `Delegate \`${args.runId}\` was cancelled. ${cancelledFileNote(args.runId, file)}${remainingLineForWait(args.runId)}`, displayMode);
12713
12887
  }
12714
12888
  if (run.status === "completed" || run.status === "failed") {
@@ -12744,7 +12918,7 @@ function makeDelegateWaitTool(_pi) {
12744
12918
  run.waiter = () => {
12745
12919
  run.consumed = true;
12746
12920
  if (run.status === "cancelled") {
12747
- const file = run.result?.file || join8(OUT_DIR, `${run.runId}.out`);
12921
+ const file = run.result?.file || join9(OUT_DIR, `${run.runId}.out`);
12748
12922
  finish2(buildWaitResult(run, `Delegate \`${run.runId}\` was cancelled. ${cancelledFileNote(run.runId, file)}${remainingLineForWait(run.runId)}`, displayMode));
12749
12923
  return;
12750
12924
  }
@@ -12798,7 +12972,7 @@ function makeDelegateCancelTool(_pi) {
12798
12972
  }
12799
12973
  delegateStatusWidget.poke();
12800
12974
  const displayMode = delegateDisplayUsage;
12801
- const file = join8(OUT_DIR, `${runId}.out`);
12975
+ const file = join9(OUT_DIR, `${runId}.out`);
12802
12976
  return buildCancelResult(run, `Cancelled ${runId} (${run.agent}). ${cancelledFileNote(runId, file)}`, displayMode);
12803
12977
  };
12804
12978
  return {
@@ -12850,7 +13024,7 @@ async function runDelegate(pi, args, ctx, signal) {
12850
13024
  if (prev && (prev.status === "running" || prev.status === "queued")) {
12851
13025
  return `Cannot resume from run \`${args.resumeFrom}\`: it has not finished yet (${prev.status}). Wait for it to finish first, then resume from its final session.`;
12852
13026
  }
12853
- prevSession = join8(OUT_DIR, `${args.resumeFrom}${SESSION_EXT}`);
13027
+ prevSession = join9(OUT_DIR, `${args.resumeFrom}${SESSION_EXT}`);
12854
13028
  if (!existsSync3(prevSession)) {
12855
13029
  return `Cannot resume ${args.resumeFrom}: no session file at ${prevSession} (the run produced no assistant output, or the file was cleaned up). Re-dispatch the task fresh instead.`;
12856
13030
  }
@@ -12874,8 +13048,8 @@ async function runDelegate(pi, args, ctx, signal) {
12874
13048
  await copyFile(prevSession, sessionFile);
12875
13049
  }
12876
13050
  if (isAsync) {
12877
- const replyFile = join8(OUT_DIR, `${runId}.out`);
12878
- const activityFile = join8(OUT_DIR, `${runId}.activity`);
13051
+ const replyFile = join9(OUT_DIR, `${runId}.out`);
13052
+ const activityFile = join9(OUT_DIR, `${runId}.activity`);
12879
13053
  const run = {
12880
13054
  runId,
12881
13055
  agent: args.agent,
@@ -13102,8 +13276,8 @@ ${output}`);
13102
13276
  return formatSyncResult(args.agent, runId, taskText, result, file);
13103
13277
  }
13104
13278
  async function buildChildArgs(args, rolePrompt, ctx, runId) {
13105
- const tmpDir = await mkdtemp(join8(tmpdir2(), "acp-delegate-"));
13106
- const promptFile = join8(tmpDir, "role.md");
13279
+ const tmpDir = await mkdtemp(join9(tmpdir2(), "acp-delegate-"));
13280
+ const promptFile = join9(tmpDir, "role.md");
13107
13281
  await writeFile2(promptFile, `${rolePrompt}
13108
13282
 
13109
13283
  ---
@@ -13112,12 +13286,12 @@ Complete the task below.`, "utf8");
13112
13286
  const isAsync = args.async !== false && ctx.mode !== "print" && ctx.mode !== "json";
13113
13287
  const useJsonStream = isAsync && isPiHost(ctx.sessionManager);
13114
13288
  const useSession = isPiHost(ctx.sessionManager);
13115
- const sessionFile = useSession ? join8(OUT_DIR, `${runId}${SESSION_EXT}`) : null;
13289
+ const sessionFile = useSession ? join9(OUT_DIR, `${runId}${SESSION_EXT}`) : null;
13116
13290
  const sessionArgs = sessionFile ? ["--session", sessionFile, "--session-dir", OUT_DIR] : ["--no-session"];
13117
13291
  const cliArgs = useJsonStream ? ["--mode", "json", ...sessionArgs, "--append-system-prompt", promptFile] : ["-p", ...sessionArgs, "--append-system-prompt", promptFile];
13118
13292
  const agentDef = AGENTS[args.agent];
13119
13293
  if (agentDef?.restricted) {
13120
- const merged = [.../* @__PURE__ */ new Set([...agentDef.tools.split(",").map((s) => s.trim()), ...ACP_TOOLS])];
13294
+ const merged = [.../* @__PURE__ */ new Set([...agentDef.tools.split(",").map((s) => s.trim()), ...ACP_TOOLS2])];
13121
13295
  cliArgs.push("--tools", merged.join(","));
13122
13296
  }
13123
13297
  const roleCfg = delegateDefaults.agents?.[args.agent];
@@ -13349,7 +13523,7 @@ async function persistResult(runId, body) {
13349
13523
  await mkdir2(OUT_DIR, { recursive: true });
13350
13524
  } catch {
13351
13525
  }
13352
- const file = join8(OUT_DIR, `${runId}.out`);
13526
+ const file = join9(OUT_DIR, `${runId}.out`);
13353
13527
  try {
13354
13528
  await writeFile2(file, body, "utf8");
13355
13529
  return file;
@@ -13422,12 +13596,15 @@ async function handleStatus(args, runtime, ctx) {
13422
13596
  tokenCount: anchorStale ? viewSentTokens : Math.max(viewSentTokens, providerReal)
13423
13597
  });
13424
13598
  const processed = turn.messages;
13599
+ const modelInfo = ctx.model;
13600
+ const meta = resolveSurfaceMeta(runtime.adapter, ctx?.cwd ?? process.cwd(), modelInfo?.provider, modelInfo?.id);
13425
13601
  const base = buildStatusReport(turn.state, processed, defaultCountTokens, {
13426
13602
  scope: args.scope,
13427
13603
  view: args.view,
13428
13604
  tool: args.tool,
13429
13605
  sort: args.sort,
13430
- limit: args.limit
13606
+ limit: args.limit,
13607
+ meta
13431
13608
  });
13432
13609
  if (args.scope) return base;
13433
13610
  const nudge = turn.nudge;
@@ -13472,12 +13649,12 @@ ${extra.join("\n")}` : base;
13472
13649
  }
13473
13650
 
13474
13651
  // src/commands.ts
13475
- import * as path11 from "path";
13652
+ import * as path12 from "path";
13476
13653
 
13477
13654
  // src/export.ts
13478
13655
  import { mkdirSync as mkdirSync2, writeFileSync } from "fs";
13479
13656
  import { promises as fs3 } from "fs";
13480
- import * as path6 from "path";
13657
+ import * as path7 from "path";
13481
13658
  import { SessionManager } from "@earendil-works/pi-coding-agent";
13482
13659
  var ACP_STATE_SUFFIX = ".acp.json";
13483
13660
  function truncate3(text, max) {
@@ -13521,7 +13698,7 @@ async function loadAllSessions(sessionDir) {
13521
13698
  if (!name.endsWith(ACP_STATE_SUFFIX)) continue;
13522
13699
  const jsonl = name.slice(0, -ACP_STATE_SUFFIX.length);
13523
13700
  try {
13524
- sessions.push(await loadSession(path6.join(sessionDir, jsonl), store));
13701
+ sessions.push(await loadSession(path7.join(sessionDir, jsonl), store));
13525
13702
  } catch {
13526
13703
  }
13527
13704
  }
@@ -13561,7 +13738,7 @@ async function exportSession(selector, opts, sessionDir) {
13561
13738
  }
13562
13739
  });
13563
13740
  if (opts.output) {
13564
- mkdirSync2(path6.dirname(path6.resolve(opts.output)), { recursive: true });
13741
+ mkdirSync2(path7.dirname(path7.resolve(opts.output)), { recursive: true });
13565
13742
  writeFileSync(opts.output, markdown, "utf8");
13566
13743
  return `written to ${opts.output}`;
13567
13744
  }
@@ -15251,12 +15428,12 @@ var KITTY_PRINTABLE_ALLOWED_MODIFIERS = MODIFIERS.shift | LOCK_MASK;
15251
15428
  // node_modules/@earendil-works/pi-tui/dist/tui.js
15252
15429
  import * as fs4 from "fs";
15253
15430
  import * as os from "os";
15254
- import * as path7 from "path";
15431
+ import * as path8 from "path";
15255
15432
  import { performance } from "perf_hooks";
15256
15433
 
15257
15434
  // node_modules/@earendil-works/pi-tui/dist/terminal-image.js
15258
15435
  import { execSync } from "child_process";
15259
- import { homedir as homedir5 } from "os";
15436
+ import { homedir as homedir6 } from "os";
15260
15437
  import { isAbsolute as isAbsolute2 } from "path";
15261
15438
  import { pathToFileURL } from "url";
15262
15439
  var cachedCapabilities = null;
@@ -17193,12 +17370,12 @@ var Markdown = class {
17193
17370
  // node_modules/@earendil-works/pi-tui/dist/terminal.js
17194
17371
  import * as fs5 from "fs";
17195
17372
  import { createRequire as createRequire3 } from "module";
17196
- import * as path9 from "path";
17373
+ import * as path10 from "path";
17197
17374
  import { fileURLToPath as fileURLToPath2 } from "url";
17198
17375
 
17199
17376
  // node_modules/@earendil-works/pi-tui/dist/native-modifiers.js
17200
17377
  import { createRequire as createRequire2 } from "module";
17201
- import * as path8 from "path";
17378
+ import * as path9 from "path";
17202
17379
  import { fileURLToPath } from "url";
17203
17380
  var cjsRequire = createRequire2(import.meta.url);
17204
17381
 
@@ -17716,16 +17893,16 @@ async function openFleetInspector(ctx) {
17716
17893
  // src/setup-subagent-tools.ts
17717
17894
  import * as fs6 from "fs";
17718
17895
  import * as os2 from "os";
17719
- import * as path10 from "path";
17720
- var ACP_TOOLS2 = ["compress", "decompress", "search_context", "acp_status"];
17896
+ import * as path11 from "path";
17897
+ var ACP_TOOLS3 = ["compress", "decompress", "search_context", "acp_status"];
17721
17898
  function resolveAgentDir() {
17722
17899
  const envDir = process.env.PI_CODING_AGENT_DIR;
17723
17900
  if (envDir) {
17724
17901
  if (envDir === "~") return os2.homedir();
17725
- if (envDir.startsWith("~/")) return path10.join(os2.homedir(), envDir.slice(2));
17902
+ if (envDir.startsWith("~/")) return path11.join(os2.homedir(), envDir.slice(2));
17726
17903
  return envDir;
17727
17904
  }
17728
- return path10.join(os2.homedir(), CONFIG_DIR_NAME2, "agent");
17905
+ return path11.join(os2.homedir(), CONFIG_DIR_NAME2, "agent");
17729
17906
  }
17730
17907
  function parseFrontmatterTools(content) {
17731
17908
  const match = content.match(/^---\r?\n([\s\S]*?)\r?\n---/);
@@ -17750,15 +17927,15 @@ function parseFrontmatterTools(content) {
17750
17927
  }
17751
17928
  function findPiSubagentsInstall(agentDir, cwd) {
17752
17929
  const candidates = [
17753
- path10.join(agentDir, "npm", "node_modules", "pi-subagents"),
17754
- path10.join(cwd, CONFIG_DIR_NAME2, "npm", "node_modules", "pi-subagents")
17930
+ path11.join(agentDir, "npm", "node_modules", "pi-subagents"),
17931
+ path11.join(cwd, CONFIG_DIR_NAME2, "npm", "node_modules", "pi-subagents")
17755
17932
  ];
17756
17933
  const extensionRoots = [
17757
- path10.join(agentDir, "extensions"),
17758
- path10.join(cwd, CONFIG_DIR_NAME2, "extensions")
17934
+ path11.join(agentDir, "extensions"),
17935
+ path11.join(cwd, CONFIG_DIR_NAME2, "extensions")
17759
17936
  ];
17760
17937
  for (const dir of candidates) {
17761
- if (fs6.existsSync(path10.join(dir, "package.json"))) return dir;
17938
+ if (fs6.existsSync(path11.join(dir, "package.json"))) return dir;
17762
17939
  }
17763
17940
  for (const root of extensionRoots) {
17764
17941
  let entries;
@@ -17769,10 +17946,10 @@ function findPiSubagentsInstall(agentDir, cwd) {
17769
17946
  }
17770
17947
  for (const entry of entries) {
17771
17948
  if (!entry.isDirectory()) continue;
17772
- const pkgPath = path10.join(root, entry.name, "package.json");
17949
+ const pkgPath = path11.join(root, entry.name, "package.json");
17773
17950
  try {
17774
17951
  if (JSON.parse(fs6.readFileSync(pkgPath, "utf-8")).name === "pi-subagents") {
17775
- return path10.join(root, entry.name);
17952
+ return path11.join(root, entry.name);
17776
17953
  }
17777
17954
  } catch {
17778
17955
  }
@@ -17781,7 +17958,7 @@ function findPiSubagentsInstall(agentDir, cwd) {
17781
17958
  return null;
17782
17959
  }
17783
17960
  function discoverBuiltinAgents(installDir) {
17784
- const agentsDir = path10.join(installDir, "agents");
17961
+ const agentsDir = path11.join(installDir, "agents");
17785
17962
  let entries;
17786
17963
  try {
17787
17964
  entries = fs6.readdirSync(agentsDir, { withFileTypes: true });
@@ -17792,7 +17969,7 @@ function discoverBuiltinAgents(installDir) {
17792
17969
  for (const entry of entries) {
17793
17970
  if (!entry.isFile() || !entry.name.endsWith(".md")) continue;
17794
17971
  try {
17795
- const result = parseFrontmatterTools(fs6.readFileSync(path10.join(agentsDir, entry.name), "utf-8"));
17972
+ const result = parseFrontmatterTools(fs6.readFileSync(path11.join(agentsDir, entry.name), "utf-8"));
17796
17973
  if (result) parsed.push(result);
17797
17974
  } catch {
17798
17975
  }
@@ -17801,7 +17978,7 @@ function discoverBuiltinAgents(installDir) {
17801
17978
  }
17802
17979
  function desiredTools(baseTools) {
17803
17980
  const tools = baseTools ? [...baseTools] : [];
17804
- for (const tool of ACP_TOOLS2) {
17981
+ for (const tool of ACP_TOOLS3) {
17805
17982
  if (!tools.includes(tool)) tools.push(tool);
17806
17983
  }
17807
17984
  return tools;
@@ -17809,11 +17986,11 @@ function desiredTools(baseTools) {
17809
17986
  function ensureSubagentAcpTools(settingsPath, options) {
17810
17987
  const agentDir = options?.agentDir ?? resolveAgentDir();
17811
17988
  const cwd = options?.cwd ?? process.cwd();
17812
- const path_ = settingsPath ?? path10.join(agentDir, "settings.json");
17989
+ const path_ = settingsPath ?? path11.join(agentDir, "settings.json");
17813
17990
  let installDir;
17814
17991
  if (options?.installDir) {
17815
- installDir = path10.resolve(options.installDir);
17816
- if (!fs6.existsSync(path10.join(installDir, "package.json"))) {
17992
+ installDir = path11.resolve(options.installDir);
17993
+ if (!fs6.existsSync(path11.join(installDir, "package.json"))) {
17817
17994
  return { path: path_, action: "failed", reason: `not a package: ${installDir}` };
17818
17995
  }
17819
17996
  } else {
@@ -17887,7 +18064,7 @@ function ensureSubagentAcpTools(settingsPath, options) {
17887
18064
  for (const b2 of builtins) {
17888
18065
  const entry = writtenOverrides[b2.name];
17889
18066
  const tools = entry?.tools ?? [];
17890
- if (frontmatterByName.get(b2.name) !== void 0 && !ACP_TOOLS2.every((t) => tools.includes(t))) {
18067
+ if (frontmatterByName.get(b2.name) !== void 0 && !ACP_TOOLS3.every((t) => tools.includes(t))) {
17891
18068
  fs6.copyFileSync(backupPath, path_);
17892
18069
  return { path: path_, action: "failed", reason: "post-write verification failed" };
17893
18070
  }
@@ -18060,7 +18237,7 @@ function resolveSessionDir(sm) {
18060
18237
  const dir = typeof sm.getSessionDir === "function" ? sm.getSessionDir() : void 0;
18061
18238
  if (dir) return dir;
18062
18239
  const file = sm.getSessionFile();
18063
- return file ? path11.dirname(file) : void 0;
18240
+ return file ? path12.dirname(file) : void 0;
18064
18241
  }
18065
18242
  async function statusReport(runtime, ctx) {
18066
18243
  const { state, coreMessages, entries } = await runtime.stateFor(ctx);
@@ -18077,7 +18254,7 @@ async function statusReport(runtime, ctx) {
18077
18254
  const sentTokens = estimateTokens(coreMessages, coveredIds, imageTokens) + systemPromptTokens;
18078
18255
  const viewSentTokens = adjustedTokenCount(runtime.core, coreMessages, state, config, sentTokens, imageTokens, systemPromptTokens);
18079
18256
  const turn = runtime.core.processTurn({ messages: coreMessages, state, config, tokenCount: anchorStale ? viewSentTokens : Math.max(viewSentTokens, realUsage?.tokens ?? 0) });
18080
- const versionStr = "0.1.69" ? `billion-context-pi@${"0.1.69"}` : void 0;
18257
+ const versionStr = "0.1.69" ? `billion-context-pi@${"0.1.69"} \xB7 pack: ${resolveSurfaceMeta(runtime.adapter, ctx?.cwd ?? process.cwd(), ctx?.model?.provider, ctx?.model?.id).pack}` : void 0;
18081
18258
  let text = buildStatusPanel({
18082
18259
  version: versionStr,
18083
18260
  tokenCount: sessionTokens,
@@ -18098,130 +18275,6 @@ async function statusReport(runtime, ctx) {
18098
18275
  return text;
18099
18276
  }
18100
18277
 
18101
- // src/prompt-pack.ts
18102
- import { readFileSync as readFileSync5 } from "fs";
18103
- import * as path12 from "path";
18104
- import { homedir as homedir8 } from "os";
18105
- function defaultPackSources2(cwd) {
18106
- return defaultPackSources({
18107
- projectDir: path12.join(cwd, CONFIG_DIR_NAME2, "acp", "packs"),
18108
- userDirs: [path12.join(homedir8(), CONFIG_DIR_NAME2, "acp", "packs")]
18109
- });
18110
- }
18111
- function packResolver(cwd) {
18112
- return createPackResolver(defaultPackSources2(cwd));
18113
- }
18114
- function resolvePackName(adapter, provider, modelId) {
18115
- const raw = resolveCompress(adapter.compress, provider, modelId).promptPack;
18116
- return typeof raw === "string" && isValidPackName(raw) ? raw : "default";
18117
- }
18118
- function resolveActivePack(adapter, cwd, provider, modelId, resolver) {
18119
- const name = resolvePackName(adapter, provider, modelId);
18120
- if (name === "default") return defaultPack;
18121
- const r = resolver ?? packResolver(cwd);
18122
- return r.resolve(name) ?? defaultPack;
18123
- }
18124
- var ACP_TOOLS3 = /* @__PURE__ */ new Set(["compress", "decompress", "search_context", "acp_status"]);
18125
- function piAdapterSurface(pack) {
18126
- const raw = pack.surface.adapters?.pi;
18127
- const rec = raw && typeof raw === "object" && !Array.isArray(raw) ? raw : {};
18128
- const toolExtras = {};
18129
- const extrasRaw = rec.toolExtras;
18130
- if (extrasRaw && typeof extrasRaw === "object" && !Array.isArray(extrasRaw)) {
18131
- for (const [tool, value] of Object.entries(extrasRaw)) {
18132
- if (!ACP_TOOLS3.has(tool) || !value || typeof value !== "object") continue;
18133
- const src = value;
18134
- const entry = {};
18135
- if (typeof src.promptSnippet === "string") entry.promptSnippet = src.promptSnippet;
18136
- if (typeof src.promptGuidelines === "string") {
18137
- entry.promptGuidelines = [src.promptGuidelines];
18138
- } else if (Array.isArray(src.promptGuidelines)) {
18139
- const guidelines = src.promptGuidelines.filter((g2) => typeof g2 === "string");
18140
- if (guidelines.length === src.promptGuidelines.length) entry.promptGuidelines = guidelines;
18141
- }
18142
- if (Object.keys(entry).length > 0) toolExtras[tool] = entry;
18143
- }
18144
- }
18145
- const surface = {
18146
- promptSections: sanitizePromptSections(rec.promptSections),
18147
- toolExtras
18148
- };
18149
- if (typeof rec.delegatePrompt === "string" || rec.delegatePrompt === null) {
18150
- surface.delegatePrompt = rec.delegatePrompt;
18151
- }
18152
- return surface;
18153
- }
18154
- function packToolPrompts(pack) {
18155
- const out = {};
18156
- const toolPrompts = pack?.surface.toolPrompts;
18157
- if (toolPrompts) {
18158
- for (const [tool, overrides] of Object.entries(toolPrompts)) {
18159
- if (ACP_TOOLS3.has(tool)) out[tool] = { ...overrides };
18160
- }
18161
- }
18162
- if (pack) {
18163
- for (const [tool, extras] of Object.entries(piAdapterSurface(pack).toolExtras)) {
18164
- out[tool] = { ...out[tool], ...extras };
18165
- }
18166
- }
18167
- return out;
18168
- }
18169
- function mergeToolPrompts(pack, inline) {
18170
- if (!pack) return inline ?? {};
18171
- if (!inline) return pack;
18172
- const out = {};
18173
- for (const name of /* @__PURE__ */ new Set([...Object.keys(pack), ...Object.keys(inline)])) {
18174
- const p = pack[name];
18175
- const i = inline[name];
18176
- if (!i) {
18177
- out[name] = p;
18178
- continue;
18179
- }
18180
- if (!p) {
18181
- out[name] = i;
18182
- continue;
18183
- }
18184
- out[name] = {
18185
- ...p,
18186
- ...i,
18187
- paramDescriptions: { ...p.paramDescriptions, ...i.paramDescriptions }
18188
- };
18189
- }
18190
- return out;
18191
- }
18192
- function mergeSurface(pack, inline) {
18193
- const s = pack?.surface ?? {};
18194
- const pi = pack ? piAdapterSurface(pack) : { promptSections: {}, toolExtras: {} };
18195
- return {
18196
- prompts: { ...s.prompts ?? {}, ...inline.prompts ?? {} },
18197
- promptSections: { ...pi.promptSections, ...inline.promptSections ?? {} },
18198
- nudgeSections: { ...s.nudgeSections ?? {}, ...inline.nudgeSections ?? {} },
18199
- toolPrompts: mergeToolPrompts(packToolPrompts(pack), inline.toolPrompts),
18200
- delegatePrompt: inline.delegatePrompt !== void 0 ? inline.delegatePrompt : pi.delegatePrompt
18201
- };
18202
- }
18203
- function readToolSurfaceWithPacks(cwd) {
18204
- const home = homedir8();
18205
- let inline = {};
18206
- let packName = "default";
18207
- for (const base of [path12.join(home, CONFIG_DIR_NAME2), path12.join(cwd, CONFIG_DIR_NAME2)]) {
18208
- try {
18209
- const parsed = JSON.parse(readFileSync5(path12.join(base, "acp.json"), "utf8"));
18210
- if (parsed && typeof parsed === "object") {
18211
- const rec = parsed;
18212
- if (rec.toolPrompts) inline = sanitizeToolPrompts(rec.toolPrompts);
18213
- const c = rec.compress;
18214
- if (c && typeof c === "object" && typeof c.promptPack === "string") {
18215
- packName = c.promptPack;
18216
- }
18217
- }
18218
- } catch {
18219
- }
18220
- }
18221
- const pack = packName === "default" || !isValidPackName(packName) ? null : packResolver(cwd).resolve(packName);
18222
- return mergeToolPrompts(packToolPrompts(pack), inline);
18223
- }
18224
-
18225
18278
  // src/degeneration.ts
18226
18279
  var DEFAULT_DEGENERATION_GUARD = { enabled: true, minRun: 200 };
18227
18280
  var MIN_VALID_MIN_RUN = 8;
@@ -19341,7 +19394,14 @@ function wireSystemPrompt(pi, runtime) {
19341
19394
  if (runtime.refused) return;
19342
19395
  const m2 = ctx?.model;
19343
19396
  const cwd = ctx?.cwd ?? process.cwd();
19344
- const merged = mergeSurface(resolveActivePack(runtime.adapter, cwd, m2?.provider, m2?.id), runtime.adapter);
19397
+ const requested = resolvePackName(runtime.adapter, m2?.provider, m2?.id);
19398
+ const activePack = resolveActivePack(runtime.adapter, cwd, m2?.provider, m2?.id);
19399
+ const merged = mergeSurface(activePack, runtime.adapter);
19400
+ try {
19401
+ const sid = ctx?.sessionManager?.getSessionId();
19402
+ if (sid) runtime.store.setActivePack(ctx?.sessionManager?.getSessionFile?.(), sid, surfaceMetaOf(activePack, requested).pack);
19403
+ } catch {
19404
+ }
19345
19405
  try {
19346
19406
  runtime.setPrompts(resolvePrompts(merged.prompts, { acknowledgeRisk: runtime.adapter.acknowledgePromptsRisk === true }));
19347
19407
  } catch (e) {