@agentproto/runtime 2.7.0 → 2.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
+ import { join, resolve } from 'path';
1
2
  import { createReadStream, promises } from 'fs';
2
3
  import { homedir } from 'os';
3
- import { join, resolve } from 'path';
4
4
  import { createInterface } from 'readline';
5
5
 
6
6
  /**
@@ -99,6 +99,10 @@ var init_tool_call_record = __esm({
99
99
  "src/tool-call-record.ts"() {
100
100
  }
101
101
  });
102
+ var init_pr_provenance = __esm({
103
+ "src/pr-provenance.ts"() {
104
+ }
105
+ });
102
106
  function sessionTranscriptDir(sessionId, baseDir) {
103
107
  return join(join(homedir(), ".agentproto", "sessions"), sessionId);
104
108
  }
@@ -108,6 +112,7 @@ function sessionEventsPath(sessionId, baseDir) {
108
112
  var init_transcript_writer = __esm({
109
113
  "src/transcript-writer.ts"() {
110
114
  init_tool_call_record();
115
+ init_pr_provenance();
111
116
  }
112
117
  });
113
118
 
@@ -219,14 +224,13 @@ function renderMarkdown(session, opts = {}) {
219
224
  function renderJson(session) {
220
225
  return JSON.stringify(session, null, 2);
221
226
  }
222
- async function exportClaudeCodeSession(adapterSessionId, cwd) {
227
+ async function exportClaudeCodeSession(adapterSessionId, cwd, configDir) {
223
228
  if (!cwd) {
224
229
  throw new Error(
225
230
  "claude-code exporter: cwd is required to locate the JSONL file.\nPass cwd explicitly or use a session id that is in the registry."
226
231
  );
227
232
  }
228
- const encoded = claudeProjectSlug(cwd);
229
- const filePath = join(homedir(), ".claude", "projects", encoded, `${adapterSessionId}.jsonl`);
233
+ const filePath = join(claudeCodeProjectDir(cwd, configDir), `${adapterSessionId}.jsonl`);
230
234
  let stream;
231
235
  try {
232
236
  stream = createReadStream(filePath, { encoding: "utf8" });
@@ -614,6 +618,10 @@ Either the session never drove an agent-cli turn, or it predates this feature.`
614
618
  flushAssistant();
615
619
  messages.push({ role: "user", text: rec.text ?? "", ...tsOrUndefined !== void 0 ? { ts: tsOrUndefined } : {} });
616
620
  break;
621
+ case "system-prompt":
622
+ flushAssistant();
623
+ messages.push({ role: "system", text: rec.text ?? "", ...tsOrUndefined !== void 0 ? { ts: tsOrUndefined } : {} });
624
+ break;
617
625
  case "text-delta":
618
626
  if (asmTs === void 0) asmTs = tsOrUndefined;
619
627
  asmText += rec.text ?? "";
@@ -1320,6 +1328,7 @@ async function exportAgentSession(input) {
1320
1328
  let adapterSlug = input.adapter;
1321
1329
  let cwd = input.cwd;
1322
1330
  let adapterSessionId = sessionId;
1331
+ let configDir;
1323
1332
  const err = (msg) => ({
1324
1333
  sessionId,
1325
1334
  adapter: adapterSlug ?? "unknown",
@@ -1332,6 +1341,7 @@ async function exportAgentSession(input) {
1332
1341
  if (desc) {
1333
1342
  adapterSlug = adapterSlug ?? desc.adapterSlug;
1334
1343
  cwd = cwd ?? desc.cwd;
1344
+ configDir = desc.adapterConfigDir;
1335
1345
  if (desc.adapterSessionId) adapterSessionId = desc.adapterSessionId;
1336
1346
  }
1337
1347
  const tryNative = async () => {
@@ -1349,7 +1359,7 @@ Pass adapter explicitly or use a known session id (sess_xxx or name).`
1349
1359
  Only sessions spawned via claude-code or hermes can be exported.`
1350
1360
  );
1351
1361
  }
1352
- return exporter.exportSession(adapterSessionId, cwd);
1362
+ return exporter.exportSession(adapterSessionId, cwd, configDir);
1353
1363
  };
1354
1364
  const tryDaemon = () => exportDaemonEventsSession(daemonSessionId, desc);
1355
1365
  let session;
@@ -1429,8 +1439,9 @@ var init_transcript_export = __esm({
1429
1439
  function claudeProjectSlug(cwd) {
1430
1440
  return cwd.replace(/[^a-zA-Z0-9]/g, "-");
1431
1441
  }
1432
- function claudeCodeProjectDir(cwd) {
1433
- return resolve(homedir(), ".claude", "projects", claudeProjectSlug(cwd));
1442
+ function claudeCodeProjectDir(cwd, configDir) {
1443
+ const base = configDir ?? resolve(homedir(), ".claude");
1444
+ return resolve(base, "projects", claudeProjectSlug(cwd));
1434
1445
  }
1435
1446
  function extractFirstText(content) {
1436
1447
  if (typeof content === "string") {
@@ -1491,8 +1502,8 @@ function claudeEntrypointFor(mode) {
1491
1502
  return mode === "native" ? "cli" : "sdk-ts";
1492
1503
  }
1493
1504
  async function discoverClaudeCode(input) {
1494
- const { cwd, since, until, attachmentMode, expectedId } = input;
1495
- const dir = claudeCodeProjectDir(cwd);
1505
+ const { cwd, since, until, attachmentMode, configDir, expectedId } = input;
1506
+ const dir = claudeCodeProjectDir(cwd, configDir);
1496
1507
  if (expectedId) {
1497
1508
  const filePath = join(dir, `${expectedId}.jsonl`);
1498
1509
  try {
@@ -1537,9 +1548,9 @@ async function discoverClaudeCode(input) {
1537
1548
  scored.sort((a, b) => b.mtimeMs - a.mtimeMs);
1538
1549
  return scored.map((s) => s.candidate);
1539
1550
  }
1540
- async function readClaudeCode(conversationId, cwd) {
1551
+ async function readClaudeCode(conversationId, cwd, configDir) {
1541
1552
  const { exportClaudeCodeSession: exportClaudeCodeSession2 } = await Promise.resolve().then(() => (init_transcript_export(), transcript_export_exports));
1542
- return exportClaudeCodeSession2(conversationId, cwd);
1553
+ return exportClaudeCodeSession2(conversationId, cwd, configDir);
1543
1554
  }
1544
1555
  async function discoverHermes(input) {
1545
1556
  const { discoverHermesSessions: discoverHermesSessions2 } = await Promise.resolve().then(() => (init_transcript_export(), transcript_export_exports));
@@ -1591,6 +1602,7 @@ var init_conversation_store = __esm({
1591
1602
  // (default). Example: `claude --resume 0e483f81-1a44-4bec-9667-b37158450296`
1592
1603
  outputHint: /claude\s+--resume\s+([0-9a-f-]{8,})/i,
1593
1604
  attachArgv: (conversationId) => ["claude", "--resume", conversationId],
1605
+ configDirEnvVar: "CLAUDE_CONFIG_DIR",
1594
1606
  discover: discoverClaudeCode,
1595
1607
  read: readClaudeCode
1596
1608
  },
@@ -1641,11 +1653,13 @@ var RESUME_STRATEGIES = Object.fromEntries(
1641
1653
  {
1642
1654
  outputHint: store.outputHint,
1643
1655
  storeAs: store.storeAs,
1644
- fsProbe: async (cwd, prevStartedAt, expectedId) => {
1656
+ ...store.configDirEnvVar ? { configDirEnvVar: store.configDirEnvVar } : {},
1657
+ fsProbe: async (cwd, prevStartedAt, expectedId, configDir) => {
1645
1658
  const candidates = await s.discover({
1646
1659
  cwd,
1647
1660
  since: prevStartedAt,
1648
- expectedId
1661
+ expectedId,
1662
+ configDir
1649
1663
  });
1650
1664
  return candidates[0]?.conversationId ?? null;
1651
1665
  },
@@ -1659,8 +1673,9 @@ function hasResumeStrategy(adapterSlug) {
1659
1673
  const s = RESUME_STRATEGIES[adapterSlug];
1660
1674
  return !!(s && (s.outputHint || s.fsProbe || s.spawnArgs));
1661
1675
  }
1662
- function decideRestartStrategy(prev) {
1663
- if (prev.adapterSlug && prev.nativeTerminalResume === true) {
1676
+ function decideRestartStrategy(prev, opts = {}) {
1677
+ const mayPreferNative = prev.pty === true || opts.preferNativeTerminal === true;
1678
+ if (prev.adapterSlug && prev.nativeTerminalResume === true && mayPreferNative) {
1664
1679
  const strategy = RESUME_STRATEGIES[prev.adapterSlug];
1665
1680
  const id = strategy?.storeAs ? prev.resumeMetadata?.[strategy.storeAs] : void 0;
1666
1681
  if (strategy?.spawnArgs && id) {
@@ -1694,7 +1709,10 @@ async function augmentWithFsResume(prev) {
1694
1709
  const id = await strategy.fsProbe(
1695
1710
  prev.cwd,
1696
1711
  prev.startedAt,
1697
- prev.adapterSessionId
1712
+ prev.adapterSessionId,
1713
+ // A config-dir-isolated session (#824) persisted its transcript under
1714
+ // its own CLAUDE_CONFIG_DIR — probe there, not the global ~/.claude.
1715
+ prev.adapterConfigDir
1698
1716
  );
1699
1717
  if (!id) return prev;
1700
1718
  return {
@@ -1712,8 +1730,9 @@ async function augmentWithFsResume(prev) {
1712
1730
  }
1713
1731
  };
1714
1732
  }
1715
- function describeResumePath(prev) {
1716
- if (prev.adapterSlug) {
1733
+ function describeResumePath(prev, opts = {}) {
1734
+ const mayPreferNative = prev.pty === true || opts.preferNativeTerminal === true;
1735
+ if (prev.adapterSlug && mayPreferNative) {
1717
1736
  const s = RESUME_STRATEGIES[prev.adapterSlug];
1718
1737
  if (s?.spawnArgs && s.storeAs && prev.resumeMetadata?.[s.storeAs]) {
1719
1738
  const sample = s.spawnArgs("\u2026")[0] ?? prev.adapterSlug;