@todos-dev/cli 0.1.8 → 0.1.10

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.
Files changed (2) hide show
  1. package/dist/index.js +64 -4
  2. package/package.json +7 -7
package/dist/index.js CHANGED
@@ -15630,7 +15630,7 @@ async function postCritical(serverUrl, path, body, token) {
15630
15630
  `[machine] POST ${path}`
15631
15631
  );
15632
15632
  }
15633
- function startHeartbeat(serverUrl, stepId, onSignal, token, onRunners) {
15633
+ function startHeartbeat(serverUrl, stepId, onSignal, token, onRunners, intervalMs = 60 * 1e3) {
15634
15634
  let active = true;
15635
15635
  let inFlight = false;
15636
15636
  const tick = async () => {
@@ -15645,7 +15645,7 @@ function startHeartbeat(serverUrl, stepId, onSignal, token, onRunners) {
15645
15645
  }
15646
15646
  };
15647
15647
  void tick();
15648
- const id = setInterval(tick, 60 * 1e3);
15648
+ const id = setInterval(tick, intervalMs);
15649
15649
  return () => {
15650
15650
  active = false;
15651
15651
  clearInterval(id);
@@ -15756,6 +15756,7 @@ function attachStreamingSession(session, label, postToken, onStop) {
15756
15756
  }
15757
15757
 
15758
15758
  // src/machine.ts
15759
+ var NO_MODEL_ERROR = "No authenticated model available on this machine. Run `tds provider add` (or `tds provider login <name>`) on the machine.";
15759
15760
  function makeDone(step, serverUrl, token) {
15760
15761
  const { stepId, conversationId, mode } = step;
15761
15762
  return (payload) => postCritical(serverUrl, `/api/machine/done/${stepId}`, { conversationId, mode, ...payload }, token).catch((err) => console.error(`[step] ${stepId} done report failed:`, err.message));
@@ -15827,6 +15828,7 @@ async function downloadStepImages(step) {
15827
15828
  async function executeStep(step, serverUrl, token, tunnel) {
15828
15829
  const { stepId, conversationId } = step;
15829
15830
  if (step.mode === "restore") return executeRestore(step, serverUrl, token);
15831
+ if (step.mode === "compact") return executeCompact(step, serverUrl, token);
15830
15832
  console.log(`[step] ${stepId} start (conv ${conversationId})`);
15831
15833
  let interrupted = false;
15832
15834
  let abortRef = null;
@@ -15845,7 +15847,7 @@ async function executeStep(step, serverUrl, token, tunnel) {
15845
15847
  ensureSkillGc(agentDir);
15846
15848
  const model = resolveModel(modelRegistry, step.agent);
15847
15849
  if (!model) {
15848
- await done({ error: "No authenticated model available on this machine. Run `tds provider add` (or `tds provider login <name>`) on the machine." });
15850
+ await done({ error: NO_MODEL_ERROR });
15849
15851
  return;
15850
15852
  }
15851
15853
  console.log(`[step] ${stepId} using model ${model.provider}/${model.id}`);
@@ -15915,7 +15917,7 @@ async function executeStep(step, serverUrl, token, tunnel) {
15915
15917
  if (diff) await uploadDiff(step.diffUploadUrl, diff, stepId);
15916
15918
  }
15917
15919
  };
15918
- const donePayload = () => ({ text: stream.getFullText(), modelId: step.agent.modelId || model.id, commitSha, sessionLeafEntryId, diffHash });
15920
+ const donePayload = () => ({ text: stream.getFullText(), modelId: step.agent.modelId || model.id, commitSha, sessionLeafEntryId, diffHash, contextUsage: session.getContextUsage() });
15919
15921
  const images = await downloadStepImages(step);
15920
15922
  try {
15921
15923
  await session.prompt(step.prompt, images.length ? { images } : void 0);
@@ -15975,6 +15977,64 @@ async function executeRestore(step, serverUrl, token) {
15975
15977
  await done({ diffHash });
15976
15978
  console.log(`[restore] ${stepId} done`);
15977
15979
  }
15980
+ async function executeCompact(step, serverUrl, token) {
15981
+ const { stepId, conversationId } = step;
15982
+ console.log(`[compact] ${stepId} start (conv ${conversationId})`);
15983
+ const done = makeDone(step, serverUrl, token);
15984
+ try {
15985
+ const { sdk, authStorage, modelRegistry, agentDir } = await getPiRuntime();
15986
+ const model = resolveModel(modelRegistry, step.agent);
15987
+ if (!model) {
15988
+ await done({ error: NO_MODEL_ERROR });
15989
+ return;
15990
+ }
15991
+ const m = await materializeSession({ sdk, sessionKey: conversationId, cwd: agentDir, restoreUrl: step.sessionRestoreUrl });
15992
+ if (!m.isContinue) {
15993
+ await done({ contextUsage: void 0 });
15994
+ return;
15995
+ }
15996
+ const session = await createSession(sdk, {
15997
+ authStorage,
15998
+ modelRegistry,
15999
+ model,
16000
+ cwd: agentDir,
16001
+ agentDir,
16002
+ tools: [],
16003
+ sessionManager: m.sessionManager,
16004
+ thinkingLevel: step.agent.thinkingLevel ?? "",
16005
+ webSearch: false
16006
+ });
16007
+ let cancelled = false;
16008
+ const stopHeartbeat = startHeartbeat(serverUrl, stepId, () => {
16009
+ cancelled = true;
16010
+ session.abortCompaction();
16011
+ }, token, void 0, 2e3);
16012
+ try {
16013
+ let result;
16014
+ try {
16015
+ result = await session.compact();
16016
+ } catch (err) {
16017
+ if (!cancelled) throw err;
16018
+ console.log(`[compact] ${stepId} cancelled (aborted)`);
16019
+ await done({ error: "Cancelled" });
16020
+ return;
16021
+ }
16022
+ const res = await done({ contextUsage: session.getContextUsage(), tokensBefore: result?.tokensBefore });
16023
+ if (res?.owned) {
16024
+ await backupSession(conversationId, session.sessionFile, step.sessionBackupUrl);
16025
+ console.log(`[compact] ${stepId} done (before ~${result?.tokensBefore} tokens)`);
16026
+ } else {
16027
+ console.log(`[compact] ${stepId} superseded after compaction \u2014 discarding`);
16028
+ }
16029
+ } finally {
16030
+ stopHeartbeat();
16031
+ }
16032
+ } catch (err) {
16033
+ const msg = err instanceof Error ? err.message : String(err);
16034
+ console.error(`[compact] ${stepId} failed:`, msg);
16035
+ await done({ error: msg });
16036
+ }
16037
+ }
15978
16038
 
15979
16039
  // src/lib/daemon.ts
15980
16040
  var import_child_process2 = require("child_process");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@todos-dev/cli",
3
- "version": "0.1.8",
3
+ "version": "0.1.10",
4
4
  "bin": {
5
5
  "tds": "dist/index.js"
6
6
  },
@@ -30,12 +30,12 @@
30
30
  "@tds/types": "0.1.0"
31
31
  },
32
32
  "optionalDependencies": {
33
- "@todos-dev/cli-darwin-arm64": "0.1.8",
34
- "@todos-dev/cli-darwin-x64": "0.1.8",
35
- "@todos-dev/cli-linux-x64": "0.1.8",
36
- "@todos-dev/cli-linux-arm64": "0.1.8",
37
- "@todos-dev/cli-win32-x64": "0.1.8",
38
- "@todos-dev/cli-win32-arm64": "0.1.8"
33
+ "@todos-dev/cli-darwin-arm64": "0.1.10",
34
+ "@todos-dev/cli-darwin-x64": "0.1.10",
35
+ "@todos-dev/cli-linux-x64": "0.1.10",
36
+ "@todos-dev/cli-linux-arm64": "0.1.10",
37
+ "@todos-dev/cli-win32-x64": "0.1.10",
38
+ "@todos-dev/cli-win32-arm64": "0.1.10"
39
39
  },
40
40
  "scripts": {
41
41
  "dev": "tsx watch src/index.ts",