context-mode 2.1.0 → 2.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -12,5 +12,5 @@
12
12
  }
13
13
  },
14
14
  "name": "context-mode",
15
- "version": "2.1.0"
15
+ "version": "2.1.2"
16
16
  }
package/run.mjs CHANGED
@@ -544,7 +544,7 @@ function outputOf(resp) {
544
544
  function textSlot(r) {
545
545
  const file = r.file;
546
546
  if (r.type === "text" && typeof file === "object" && file !== null && typeof file.content === "string") {
547
- return { text: file.content, put: (o, output) => ({ ...o, file: { ...o.file, content: output } }) };
547
+ return { text: file.content, put: (o, output) => ({ ...o, file: readFile(o.file, output) }) };
548
548
  }
549
549
  if (isGrepContent(r)) return { text: r.content, put: (o, output) => ({ ...o, content: output }) };
550
550
  if (Array.isArray(r.filenames) && r.filenames.every((f) => typeof f === "string")) {
@@ -553,13 +553,35 @@ function textSlot(r) {
553
553
  if (typeof r.result === "string") return { text: r.result, put: (o, output) => ({ ...o, result: output }) };
554
554
  return null;
555
555
  }
556
+ function readFile(file, output) {
557
+ const start = typeof file.startLine === "number" ? file.startLine : 1;
558
+ const lines = String(file.content).split("\n");
559
+ const read2 = typeof file.numLines === "number" ? file.numLines : lines.length;
560
+ const out = output.split("\n");
561
+ const run = firstRun(lines, out);
562
+ if (run === null) return { ...file, content: output, startLine: start + read2, numLines: out.length };
563
+ const kept = out.slice(0, run.length);
564
+ if (run.length < out.length) kept.push(out[out.length - 1]);
565
+ return { ...file, content: kept.join("\n"), startLine: start + run.at, numLines: kept.length };
566
+ }
567
+ function firstRun(lines, out) {
568
+ let best = null;
569
+ for (let i = 0; i < lines.length; i++) {
570
+ if (lines[i] !== out[0]) continue;
571
+ let n = 1;
572
+ while (n < out.length && i + n < lines.length && lines[i + n] === out[n]) n++;
573
+ if (best === null || n > best.length) best = { at: i, length: n };
574
+ if (n === out.length) break;
575
+ }
576
+ return best;
577
+ }
556
578
  function isShellShape(resp) {
557
579
  const r = resp;
558
580
  return typeof r.stdout === "string" || typeof r.stderr === "string";
559
581
  }
560
582
  function isGrepContent(resp) {
561
583
  const r = resp;
562
- return r.mode === "content" && typeof r.content === "string";
584
+ return (r.mode === "content" || r.mode === "count") && typeof r.content === "string";
563
585
  }
564
586
  function blocksOf(resp) {
565
587
  const parts = [];
@@ -575,6 +597,7 @@ function readResult(resp) {
575
597
  const text = outputOf(resp);
576
598
  const isError = typeof resp === "object" && resp !== null && resp.is_error === true;
577
599
  const info = { isError, bytes: Buffer.byteLength(text), text };
600
+ if (typeof resp === "object" && resp !== null && !Array.isArray(resp) && isShellShape(resp)) info.shape = resp;
578
601
  if (typeof resp === "object" && resp !== null && !Array.isArray(resp) && !isShellShape(resp)) {
579
602
  if (textSlot(resp) !== null) info.shape = resp;
580
603
  else info.keep = true;
@@ -614,8 +637,11 @@ function decodeClaudeShape(raw, agent, ownPrefix, sources) {
614
637
  return ev;
615
638
  }
616
639
  function replaceShape(ev, output) {
617
- if (ev.tool?.canonicalName === "Bash") return { stdout: output, stderr: "", interrupted: false };
618
640
  const shape = ev.result?.shape;
641
+ if (ev.tool?.canonicalName === "Bash") {
642
+ const { persistedOutputPath: _p, persistedOutputSize: _s, ...host } = shape ?? {};
643
+ return { interrupted: false, ...host, stdout: output, stderr: "" };
644
+ }
619
645
  const slot = shape === void 0 ? null : textSlot(shape);
620
646
  if (shape !== void 0 && slot !== null) return slot.put(shape, output);
621
647
  if (ev.result?.blocks === true) return [{ type: "text", text: output }];
@@ -1110,7 +1136,7 @@ var PI_EVENTS = {
1110
1136
  tool_call: { event: "PreToolUse" },
1111
1137
  tool_result: { event: "PostToolUse" }
1112
1138
  };
1113
- var NATIVE_TO_CANONICAL6 = { bash: "Bash", read: "Read" };
1139
+ var NATIVE_TO_CANONICAL6 = { bash: "Bash", read: "Read", edit: "Edit", write: "Write" };
1114
1140
  function record(v) {
1115
1141
  return typeof v === "object" && v !== null && !Array.isArray(v) ? v : {};
1116
1142
  }
@@ -1235,8 +1261,8 @@ var ADAPTERS = Object.freeze([
1235
1261
  hookTimeoutMs: HOOK_TIMEOUT_MS,
1236
1262
  denyChannel: "deny-reason",
1237
1263
  hookChannel: { kind: "package", path: "hooks/claude-code.json" },
1238
- skillChannel: { kind: "package", path: "claude-code/skills" },
1239
- // ADR-0020, D-HQ-SKILLS-2
1264
+ skillChannel: { kind: "package", path: "skills" },
1265
+ // ADR-0020, D-R33-CC-SKILLS-1: Claude Code always loads <plugin>/skills, shared with gemini and qwen
1240
1266
  decode,
1241
1267
  encode
1242
1268
  },
@@ -1380,8 +1406,9 @@ var ADAPTERS = Object.freeze([
1380
1406
  installMode: "in-process",
1381
1407
  projectSource: "pi:ctx.cwd",
1382
1408
  toolNamePrefix: TOOL_NAME_PREFIX9,
1383
- nativeTools: { shell: ["bash"], read: ["read"] },
1409
+ nativeTools: { shell: ["bash", "powershell"], read: ["read"] },
1384
1410
  execReadOnlyHint: false,
1411
+ // D-R38-PI-PWSH-1: Pi on Windows names its shell tool "powershell"
1385
1412
  eventMap: { SessionStart: "session_start", UserPromptSubmit: "input", PreToolUse: "tool_call", PostToolUse: "tool_result" },
1386
1413
  compactDelivery: "pi-flag",
1387
1414
  compactSummary: "none",
package/search.mjs CHANGED
@@ -544,7 +544,7 @@ function outputOf(resp) {
544
544
  function textSlot(r) {
545
545
  const file = r.file;
546
546
  if (r.type === "text" && typeof file === "object" && file !== null && typeof file.content === "string") {
547
- return { text: file.content, put: (o, output) => ({ ...o, file: { ...o.file, content: output } }) };
547
+ return { text: file.content, put: (o, output) => ({ ...o, file: readFile(o.file, output) }) };
548
548
  }
549
549
  if (isGrepContent(r)) return { text: r.content, put: (o, output) => ({ ...o, content: output }) };
550
550
  if (Array.isArray(r.filenames) && r.filenames.every((f) => typeof f === "string")) {
@@ -553,13 +553,35 @@ function textSlot(r) {
553
553
  if (typeof r.result === "string") return { text: r.result, put: (o, output) => ({ ...o, result: output }) };
554
554
  return null;
555
555
  }
556
+ function readFile(file, output) {
557
+ const start = typeof file.startLine === "number" ? file.startLine : 1;
558
+ const lines = String(file.content).split("\n");
559
+ const read2 = typeof file.numLines === "number" ? file.numLines : lines.length;
560
+ const out = output.split("\n");
561
+ const run = firstRun(lines, out);
562
+ if (run === null) return { ...file, content: output, startLine: start + read2, numLines: out.length };
563
+ const kept = out.slice(0, run.length);
564
+ if (run.length < out.length) kept.push(out[out.length - 1]);
565
+ return { ...file, content: kept.join("\n"), startLine: start + run.at, numLines: kept.length };
566
+ }
567
+ function firstRun(lines, out) {
568
+ let best = null;
569
+ for (let i = 0; i < lines.length; i++) {
570
+ if (lines[i] !== out[0]) continue;
571
+ let n = 1;
572
+ while (n < out.length && i + n < lines.length && lines[i + n] === out[n]) n++;
573
+ if (best === null || n > best.length) best = { at: i, length: n };
574
+ if (n === out.length) break;
575
+ }
576
+ return best;
577
+ }
556
578
  function isShellShape(resp) {
557
579
  const r = resp;
558
580
  return typeof r.stdout === "string" || typeof r.stderr === "string";
559
581
  }
560
582
  function isGrepContent(resp) {
561
583
  const r = resp;
562
- return r.mode === "content" && typeof r.content === "string";
584
+ return (r.mode === "content" || r.mode === "count") && typeof r.content === "string";
563
585
  }
564
586
  function blocksOf(resp) {
565
587
  const parts = [];
@@ -575,6 +597,7 @@ function readResult(resp) {
575
597
  const text = outputOf(resp);
576
598
  const isError = typeof resp === "object" && resp !== null && resp.is_error === true;
577
599
  const info = { isError, bytes: Buffer.byteLength(text), text };
600
+ if (typeof resp === "object" && resp !== null && !Array.isArray(resp) && isShellShape(resp)) info.shape = resp;
578
601
  if (typeof resp === "object" && resp !== null && !Array.isArray(resp) && !isShellShape(resp)) {
579
602
  if (textSlot(resp) !== null) info.shape = resp;
580
603
  else info.keep = true;
@@ -614,8 +637,11 @@ function decodeClaudeShape(raw, agent, ownPrefix, sources) {
614
637
  return ev;
615
638
  }
616
639
  function replaceShape(ev, output) {
617
- if (ev.tool?.canonicalName === "Bash") return { stdout: output, stderr: "", interrupted: false };
618
640
  const shape = ev.result?.shape;
641
+ if (ev.tool?.canonicalName === "Bash") {
642
+ const { persistedOutputPath: _p, persistedOutputSize: _s, ...host } = shape ?? {};
643
+ return { interrupted: false, ...host, stdout: output, stderr: "" };
644
+ }
619
645
  const slot = shape === void 0 ? null : textSlot(shape);
620
646
  if (shape !== void 0 && slot !== null) return slot.put(shape, output);
621
647
  if (ev.result?.blocks === true) return [{ type: "text", text: output }];
@@ -1110,7 +1136,7 @@ var PI_EVENTS = {
1110
1136
  tool_call: { event: "PreToolUse" },
1111
1137
  tool_result: { event: "PostToolUse" }
1112
1138
  };
1113
- var NATIVE_TO_CANONICAL6 = { bash: "Bash", read: "Read" };
1139
+ var NATIVE_TO_CANONICAL6 = { bash: "Bash", read: "Read", edit: "Edit", write: "Write" };
1114
1140
  function record(v) {
1115
1141
  return typeof v === "object" && v !== null && !Array.isArray(v) ? v : {};
1116
1142
  }
@@ -1235,8 +1261,8 @@ var ADAPTERS = Object.freeze([
1235
1261
  hookTimeoutMs: HOOK_TIMEOUT_MS,
1236
1262
  denyChannel: "deny-reason",
1237
1263
  hookChannel: { kind: "package", path: "hooks/claude-code.json" },
1238
- skillChannel: { kind: "package", path: "claude-code/skills" },
1239
- // ADR-0020, D-HQ-SKILLS-2
1264
+ skillChannel: { kind: "package", path: "skills" },
1265
+ // ADR-0020, D-R33-CC-SKILLS-1: Claude Code always loads <plugin>/skills, shared with gemini and qwen
1240
1266
  decode,
1241
1267
  encode
1242
1268
  },
@@ -1380,8 +1406,9 @@ var ADAPTERS = Object.freeze([
1380
1406
  installMode: "in-process",
1381
1407
  projectSource: "pi:ctx.cwd",
1382
1408
  toolNamePrefix: TOOL_NAME_PREFIX9,
1383
- nativeTools: { shell: ["bash"], read: ["read"] },
1409
+ nativeTools: { shell: ["bash", "powershell"], read: ["read"] },
1384
1410
  execReadOnlyHint: false,
1411
+ // D-R38-PI-PWSH-1: Pi on Windows names its shell tool "powershell"
1385
1412
  eventMap: { SessionStart: "session_start", UserPromptSubmit: "input", PreToolUse: "tool_call", PostToolUse: "tool_result" },
1386
1413
  compactDelivery: "pi-flag",
1387
1414
  compactSummary: "none",