@nomadop/session-watcher-dsh 0.11.0 → 0.11.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.
@@ -22,34 +22,31 @@
22
22
  //! SOFTWARE.
23
23
  import { createRequire } from 'node:module'; const require = createRequire(import.meta.url);
24
24
 
25
- // lib/harness/dsh/inner-seal-message.js
26
- var CARRIER_WORDING = {
27
- addresses: "These summaries stand in for earlier turns of this session; replacing them changed no file and no state, so the work carries on from them. Each summary line below opens with seq numbers: the addresses, in this session's log, of the events it summarizes, which the session history tools can read. A line marked user: holds the user's own words instead, cut where a marker says so.",
28
- slotLine: (seqs) => `seq ${seqs.join(", ")}: `,
29
- imageSaved: (name2) => `The image ${name2} is not in the current context; read_image can read the file below when it is needed.`,
30
- carried: "Evidence carried from the replaced context as of this summary: file text as read from disk when it was written, and skill text as the log recorded it. Each entry changes what the evidence of any earlier summary or kept file excerpt here states. The reads behind this file text still count in this session, so edit a file without reading it again.",
31
- empty: (path) => `${path} is empty.`,
32
- unreadable: (path, reason) => `${path} could not be read (${reason}). This is not its text and not a tool failure; read the file directly when it is needed.`,
33
- skill: (name2, text) => `Skill ${name2}:
34
- ${text}`,
35
- stateHeading: (seq) => `Session state as of session seq ${seq}:`,
36
- stateLabels: {
37
- workingDirectory: (tool) => `Working directory, as ${tool} would show:`,
38
- subagents: (tool) => `Running subagents, as ${tool} would show:`,
39
- jobs: (tool) => `Running jobs, as ${tool} would show:`,
40
- todos: (tool) => `Todo list, as ${tool} last left it:`
25
+ // lib/inner-seal/git-state.js
26
+ import { execFile } from "node:child_process";
27
+ import { promisify } from "node:util";
28
+ var execFileAsync = promisify(execFile);
29
+ var STATUS_COMMAND = ["status", "--short", "--branch"];
30
+ var LOG_COMMAND = ["log", "-1", "--oneline"];
31
+ function isGitStateCommand(command) {
32
+ if (typeof command !== "string") return false;
33
+ const [status, head, ...rest] = command.trim().split(/[ \t]*&&[ \t]*/u);
34
+ return rest.length === 0 && /^git[ \t]+status(?:[ \t]+--?[\w=-]+)*$/u.test(status) && (head === void 0 || head.split(/[ \t]+/u).join(" ") === `git ${LOG_COMMAND.join(" ")}`);
35
+ }
36
+ var GIT_STATE_ITEM = Object.freeze({
37
+ key: "git",
38
+ label: `Git, as \`git ${STATUS_COMMAND.join(" ")} && git ${LOG_COMMAND.join(" ")}\` would show:`,
39
+ multiline: true,
40
+ normalize: (value) => {
41
+ if (typeof value !== "string" || value === "") throw new Error("the git state is not a text");
42
+ return value;
41
43
  },
42
- stateList: (entries) => entries.map(({ id, label: label2 }) => `${id} \u2014 ${label2}`).join("; "),
43
- stateUnchanged: "unchanged since the last summary that shows it",
44
- stateEmpty: "(empty)",
45
- questionMark: "A line marked question: holds the original question.",
46
- questionLine: (question) => `question: ${question}`,
47
- userLine: (user) => `user: ${user}`,
48
- askCall: ({ id, name: name2, arguments: args }) => `Original ${name2} call ${id}, arguments:
49
- ${args}`,
50
- askResult: (id, { text, isError }) => `Original result of call ${id}${isError ? " (marked as an error)" : ""}:
51
- ${text}`
52
- };
44
+ isEmpty: () => false,
45
+ same: (a, b) => a === b,
46
+ text: (value) => value
47
+ });
48
+
49
+ // lib/harness/dsh/carrier-table.js
53
50
  var isTodoItem = (item) => item !== null && typeof item === "object" && typeof item.content === "string" && typeof item.status === "string";
54
51
  function todoItemsOf(value) {
55
52
  if (value === null) return [];
@@ -63,45 +60,66 @@ function textEntriesOf(value, fields, what) {
63
60
  return value.map((entry) => Object.fromEntries(fields.map((field) => [field, entry[field]])));
64
61
  }
65
62
  var sameEntries = (fields, a, b) => a.length === b.length && a.every((entry, at) => fields.every((field) => entry[field] === b[at][field]));
63
+ var entryList = (entries) => entries.map(({ id, label: label2 }) => `${id} \u2014 ${label2}`).join("; ");
66
64
  var AGENT_FIELDS = ["id", "label"];
67
65
  var TODO_FIELDS = ["content", "status"];
68
- var STATE_ITEMS = Object.freeze([
69
- Object.freeze({
70
- key: "workingDirectory",
71
- tool: "working_directory",
72
- normalize: (value) => {
73
- if (typeof value !== "string" || value === "") throw new Error("the working directory is not a path text");
74
- return value;
75
- },
76
- isEmpty: () => false,
77
- same: (a, b) => a === b,
78
- text: (value) => value
79
- }),
80
- Object.freeze({
81
- key: "subagents",
82
- tool: "list_agents",
83
- normalize: (value) => textEntriesOf(value, AGENT_FIELDS, "subagent list"),
84
- isEmpty: (entries) => entries.length === 0,
85
- same: (a, b) => sameEntries(AGENT_FIELDS, a, b),
86
- text: CARRIER_WORDING.stateList
87
- }),
88
- Object.freeze({
89
- key: "jobs",
90
- tool: "job_list",
91
- normalize: (value) => textEntriesOf(value, AGENT_FIELDS, "job list"),
92
- isEmpty: (entries) => entries.length === 0,
93
- same: (a, b) => sameEntries(AGENT_FIELDS, a, b),
94
- text: CARRIER_WORDING.stateList
95
- }),
96
- Object.freeze({
97
- key: "todos",
98
- tool: "todo_write",
99
- normalize: todoItemsOf,
100
- isEmpty: (items) => items.length === 0,
101
- same: (a, b) => sameEntries(TODO_FIELDS, a, b),
102
- text: (items) => JSON.stringify(items)
103
- })
104
- ]);
66
+ var stateItem = ({ tool, label: label2, ...rest }) => Object.freeze({ ...rest, tool, label: label2(tool) });
67
+ function argumentsOf(call) {
68
+ try {
69
+ return JSON.parse(call.arguments);
70
+ } catch {
71
+ return void 0;
72
+ }
73
+ }
74
+ var CARRIER_TABLE = Object.freeze({
75
+ addresses: `These summaries stand in for earlier turns of this session; replacing them changed no file and no state, so the work carries on from them. Each summary line below opens with seq numbers: the addresses, in this session's log, of the events it summarizes, which the session history tools can read. A line marked user: is that message's full text, word for word unless a marker says where it is cut.`,
76
+ editGuard: "The reads behind this file text still count in this session, so edit a file without reading it again.",
77
+ imageReadTool: "read_image",
78
+ stateItems: Object.freeze([
79
+ stateItem({
80
+ key: "workingDirectory",
81
+ tool: "working_directory",
82
+ label: (tool) => `Working directory, as ${tool} would show:`,
83
+ operation: (call) => typeof argumentsOf(call)?.cd === "string" ? "write" : "read",
84
+ normalize: (value) => {
85
+ if (typeof value !== "string" || value === "") throw new Error("the working directory is not a path text");
86
+ return value;
87
+ },
88
+ isEmpty: () => false,
89
+ same: (a, b) => a === b,
90
+ text: (value) => value
91
+ }),
92
+ stateItem({
93
+ key: "subagents",
94
+ tool: "list_agents",
95
+ label: (tool) => `Running subagents, as ${tool} would show:`,
96
+ normalize: (value) => textEntriesOf(value, AGENT_FIELDS, "subagent list"),
97
+ isEmpty: (entries) => entries.length === 0,
98
+ same: (a, b) => sameEntries(AGENT_FIELDS, a, b),
99
+ text: entryList
100
+ }),
101
+ stateItem({
102
+ key: "jobs",
103
+ tool: "job_list",
104
+ label: (tool) => `Running jobs, as ${tool} would show:`,
105
+ normalize: (value) => textEntriesOf(value, AGENT_FIELDS, "job list"),
106
+ isEmpty: (entries) => entries.length === 0,
107
+ same: (a, b) => sameEntries(AGENT_FIELDS, a, b),
108
+ text: entryList
109
+ }),
110
+ stateItem({
111
+ key: "todos",
112
+ tool: "todo_write",
113
+ operation: "write",
114
+ label: (tool) => `Todo list, as ${tool} last left it:`,
115
+ normalize: todoItemsOf,
116
+ isEmpty: (items) => items.length === 0,
117
+ same: (a, b) => sameEntries(TODO_FIELDS, a, b),
118
+ text: (items) => JSON.stringify(items)
119
+ }),
120
+ Object.freeze({ ...GIT_STATE_ITEM, matchesCall: (call) => call.name === "bash" && isGitStateCommand(argumentsOf(call)?.command) })
121
+ ])
122
+ });
105
123
 
106
124
  // dsh/vendor/dsh-llm-pi-ai/src/config.ts
107
125
  import z from "@deepseek-ai/schemastery";
@@ -1383,7 +1401,7 @@ function bootstrap(ctx, config, decorateProfiles) {
1383
1401
  return { registeredRoutes: () => [...registeredRoutes] };
1384
1402
  }
1385
1403
 
1386
- // dsh/src/carrier-cache.js
1404
+ // lib/llm-adapter/carrier-point.js
1387
1405
  var MAX_CONTROL_POINTS = 4;
1388
1406
  var ADDED = Object.freeze({ result: "added" });
1389
1407
  var NATIVE = Object.freeze({ result: "native" });
@@ -1396,9 +1414,8 @@ var UNSUPPORTED = skipped("unsupported");
1396
1414
  var LONG_RETENTION = "24h";
1397
1415
  var LONG_OPTIONS = Object.freeze({ ttl: "30m" });
1398
1416
  var textOfBlocks = (blocks) => blocks.filter((block) => block?.type === "text" && typeof block.text === "string").map((block) => block.text).join("");
1399
- function createCarrierCache({ carrierPrefix, report, observe = () => {
1400
- }, responsesBreakpoint = () => false }) {
1401
- const lastCarrier = (messages, textOf) => messages.findLastIndex((message) => message?.role === "user" && textOf(message).startsWith(carrierPrefix));
1417
+ var lastCarrier = (prefix, messages, textOf) => messages.findLastIndex((message) => message?.role === "user" && textOf(message).startsWith(prefix));
1418
+ function createCarrierPointWriter({ report, responsesBreakpoint }) {
1402
1419
  const blocksText = (content) => typeof content === "string" ? content : Array.isArray(content) ? textOfBlocks(content) : "";
1403
1420
  const controlText = (message) => blocksText(message.content);
1404
1421
  const controlled = (parts) => parts.filter((part) => part?.cache_control !== void 0);
@@ -1408,7 +1425,7 @@ function createCarrierCache({ carrierPrefix, report, observe = () => {
1408
1425
  const last = pick(blocks);
1409
1426
  if (last.cache_control !== void 0) return NATIVE;
1410
1427
  if (marked.length >= MAX_CONTROL_POINTS) {
1411
- report(`llm-pi-ai carrier cache: route "${model.provider}/${model.id}" (${model.api}) already sends ${marked.length} cache points, so the last carrier is given none`);
1428
+ report(`carrier cache: route "${model.provider}/${model.id}" (${model.api}) already sends ${marked.length} cache points, so the last carrier is given none`);
1412
1429
  return POINTS_FULL;
1413
1430
  }
1414
1431
  last.cache_control = { ...marked[0].cache_control };
@@ -1420,15 +1437,15 @@ function createCarrierCache({ carrierPrefix, report, observe = () => {
1420
1437
  ...Array.isArray(payload.tools) ? payload.tools : [],
1421
1438
  ...(Array.isArray(payload.messages) ? payload.messages : []).flatMap((message) => Array.isArray(message.content) ? message.content : [])
1422
1439
  ]);
1423
- function anthropic(payload, model) {
1440
+ function anthropic({ prefix, payload, model }) {
1424
1441
  if (!Array.isArray(payload.messages)) return UNSUPPORTED;
1425
- const at = lastCarrier(payload.messages, controlText);
1442
+ const at = lastCarrier(prefix, payload.messages, controlText);
1426
1443
  if (at < 0) return NO_CARRIER;
1427
1444
  return controlPoint({ message: payload.messages[at], marked: anthropicMarked(payload), pick: (blocks) => blocks.at(-1), model });
1428
1445
  }
1429
- function completions(payload, model) {
1446
+ function completions({ prefix, payload, model }) {
1430
1447
  if (!Array.isArray(payload.messages)) return UNSUPPORTED;
1431
- const at = lastCarrier(payload.messages, controlText);
1448
+ const at = lastCarrier(prefix, payload.messages, controlText);
1432
1449
  if (at < 0) return NO_CARRIER;
1433
1450
  const marked = controlled([
1434
1451
  ...Array.isArray(payload.tools) ? payload.tools : [],
@@ -1437,9 +1454,9 @@ function createCarrierCache({ carrierPrefix, report, observe = () => {
1437
1454
  return controlPoint({ message: payload.messages[at], marked, pick: (parts) => parts.findLast((part) => part?.type === "text"), model });
1438
1455
  }
1439
1456
  const bedrockText = (message) => Array.isArray(message.content) ? message.content.filter((block) => typeof block?.text === "string").map((block) => block.text).join("") : "";
1440
- function bedrock(payload) {
1457
+ function bedrock({ prefix, payload }) {
1441
1458
  if (!Array.isArray(payload.messages)) return UNSUPPORTED;
1442
- const at = lastCarrier(payload.messages, bedrockText);
1459
+ const at = lastCarrier(prefix, payload.messages, bedrockText);
1443
1460
  if (at < 0) return NO_CARRIER;
1444
1461
  const blocks = [...Array.isArray(payload.system) ? payload.system : [], ...payload.messages.flatMap((message) => Array.isArray(message.content) ? message.content : [])];
1445
1462
  const point = blocks.find((block) => block?.cachePoint !== void 0);
@@ -1455,7 +1472,7 @@ function createCarrierCache({ carrierPrefix, report, observe = () => {
1455
1472
  try {
1456
1473
  return responsesBreakpoint() === true;
1457
1474
  } catch {
1458
- report("llm-pi-ai carrier cache: the Responses breakpoint setting could not be read, so the request is sent without it");
1475
+ report("carrier cache: the Responses breakpoint setting could not be read, so the request is sent without it");
1459
1476
  return false;
1460
1477
  }
1461
1478
  };
@@ -1464,11 +1481,11 @@ function createCarrierCache({ carrierPrefix, report, observe = () => {
1464
1481
  delete payload.prompt_cache_retention;
1465
1482
  payload.prompt_cache_options = { ...LONG_OPTIONS };
1466
1483
  };
1467
- function responses(payload, model, options) {
1484
+ function responses({ prefix, payload, model, options }) {
1468
1485
  if (!switchedOn()) return RESPONSES_OFF;
1469
1486
  if (!Array.isArray(payload.input) || chatGptSignIn(model, options?.apiKey)) return UNSUPPORTED;
1470
1487
  if (options?.cacheRetention === "none") return NO_NATIVE_POINT;
1471
- const at = lastCarrier(payload.input, responsesText);
1488
+ const at = lastCarrier(prefix, payload.input, responsesText);
1472
1489
  if (at < 0) return NO_CARRIER;
1473
1490
  if (at === payload.input.length - 1) return NATIVE;
1474
1491
  const block = payload.input[at].content.findLast((part) => part?.type === "input_text");
@@ -1477,6 +1494,14 @@ function createCarrierCache({ carrierPrefix, report, observe = () => {
1477
1494
  return ADDED;
1478
1495
  }
1479
1496
  const WRITERS = { "anthropic-messages": anthropic, "bedrock-converse-stream": bedrock, "openai-responses": responses, "openai-completions": completions };
1497
+ return function writeCarrierPoint({ prefix, payload, model, options }) {
1498
+ return WRITERS[model.api]?.({ prefix, payload, model, options }) ?? UNSUPPORTED;
1499
+ };
1500
+ }
1501
+
1502
+ // dsh/src/carrier-cache.js
1503
+ function createCarrierCache({ carrierPrefix, report, observe, responsesBreakpoint }) {
1504
+ const writeCarrierPoint = createCarrierPointWriter({ report, responsesBreakpoint });
1480
1505
  const observed = (outcome) => {
1481
1506
  try {
1482
1507
  observe(outcome);
@@ -1487,9 +1512,9 @@ function createCarrierCache({ carrierPrefix, report, observe = () => {
1487
1512
  const hookOf = (earlier, options) => async (payload, model) => {
1488
1513
  const replaced = await earlier?.(payload, model);
1489
1514
  const body = replaced ?? payload;
1490
- const outcome = WRITERS[model.api]?.(body, model, options) ?? UNSUPPORTED;
1515
+ const outcome = writeCarrierPoint({ prefix: carrierPrefix, payload: body, model, options });
1491
1516
  observed(outcome);
1492
- return outcome === ADDED ? body : replaced;
1517
+ return outcome.result === "added" ? body : replaced;
1493
1518
  };
1494
1519
  const wrapProvider = (provider) => Object.create(provider, {
1495
1520
  streamSimple: {
@@ -1512,6 +1537,7 @@ function createCarrierCache({ carrierPrefix, report, observe = () => {
1512
1537
  var PI_AI_SERVICE = "sessionWatcherPiAi";
1513
1538
  var ORIGINAL_ROW = "include:llm-pi-ai";
1514
1539
  var CARRIER_EVIDENCE_SERVICE = "sessionWatcherCarrierEvidence";
1540
+ var CARRIER_SETTINGS_SERVICE = "sessionWatcherCarrierSettings";
1515
1541
 
1516
1542
  // dsh/src/pi-ai-index.js
1517
1543
  var inject = ["llm", "loader"];
@@ -1546,10 +1572,10 @@ function apply(ctx) {
1546
1572
  return;
1547
1573
  }
1548
1574
  const cache = createCarrierCache({
1549
- carrierPrefix: CARRIER_WORDING.addresses,
1575
+ carrierPrefix: CARRIER_TABLE.addresses,
1550
1576
  report: (message) => ctx.logger.warn(message),
1551
1577
  observe: (result) => ctx.get(CARRIER_EVIDENCE_SERVICE)?.record(result),
1552
- responsesBreakpoint: () => ctx.get(CARRIER_EVIDENCE_SERVICE)?.responsesBreakpoint?.()
1578
+ responsesBreakpoint: () => ctx.get(CARRIER_SETTINGS_SERVICE)?.responsesBreakpoint?.()
1553
1579
  });
1554
1580
  const registration = bootstrap(ctx, source.config, cache.decorateProfiles);
1555
1581
  ctx.provide(PI_AI_SERVICE, {
@@ -1,5 +1,3 @@
1
1
  - insert:
2
2
  - id: session-watcher
3
3
  name: '@nomadop/session-watcher-dsh'
4
- - id: tool-session-query
5
- name: '@deepseek-ai/dsh-tool-session-query'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nomadop/session-watcher-dsh",
3
- "version": "0.11.0",
3
+ "version": "0.11.2",
4
4
  "description": "Session Watcher as a DeepSeek Harness host plugin",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -37,6 +37,7 @@
37
37
  "@deepseek-ai/dsh-llm": ">=0.2.2-rc.1",
38
38
  "@deepseek-ai/dsh-llm-pi-ai": ">=0.2.2-rc.1",
39
39
  "@deepseek-ai/dsh-session": ">=0.2.2-rc.1",
40
+ "@deepseek-ai/dsh-session-query": ">=0.2.2-rc.1",
40
41
  "@deepseek-ai/dsh-timeout": ">=0.2.2-rc.1",
41
42
  "@deepseek-ai/dsh-tools": ">=0.2.2-rc.1",
42
43
  "@deepseek-ai/dsh-util-values": ">=0.2.2-rc.1",