@deksden-com/dd-flow-cli 0.9.0-beta.0 → 0.9.0-beta.1

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/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # @deksden-com/dd-flow-cli
2
2
 
3
+ ## 0.9.0-beta.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 61cc92e: Finalize run usage from provider-terminal evidence even when the agent's final
8
+ Work lifecycle call arrives afterwards.
9
+
3
10
  ## 0.9.0-beta.0
4
11
 
5
12
  ### Minor Changes
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "cli_package": "@deksden-com/dd-flow-cli",
3
- "cli_version": "0.9.0-beta.0",
4
- "cli_commit": "ade3ebb2888bf804bec3879bbf7ed4600ff651fc",
5
- "built_at": "2026-09-01T20:01:20.985Z",
3
+ "cli_version": "0.9.0-beta.1",
4
+ "cli_commit": "5e493443b9f97ad3c83e0edccc29dfbee584b92e",
5
+ "built_at": "2026-09-01T21:02:46.536Z",
6
6
  "built_with_canon": {
7
7
  "version": "4.0.0",
8
8
  "commit": "bd6494ad11bca9544d9b483bd7fe37049e6d00fe",
@@ -131,9 +131,10 @@ export function storedUsageForRun(context, input) {
131
131
  */
132
132
  export function recalculateRunUsage(context, input) {
133
133
  const observedAt = context.now();
134
- const runRow = context.db.get("SELECT index_json FROM runs WHERE project_id = ? AND id = ?", [input.projectId, input.runId]);
135
- const runCompletedAt = runRow ? terminalTimestamp(runRow.index_json) : null;
136
- const accountingAt = input.stage?.completedAt ?? runCompletedAt ?? observedAt;
134
+ // Provider completion, not the controller's later lifecycle write, is the
135
+ // accounting boundary. A final refresh must therefore see tokens emitted
136
+ // after `work finish` but before the agent's actual terminal event.
137
+ const accountingAt = observedAt;
137
138
  const links = context.db.all(`SELECT ws.id, ws.work_id, ws.session_id, ws.created_at, ws.completed_at,
138
139
  w.project_id, s.harness, s.transcript_path, s.parent_session_id, s.agent_id, s.provider_session_id
139
140
  FROM work_sessions ws
@@ -427,15 +428,6 @@ function readHarnessUsageWindow(context, harness, projectId, providerSessionId,
427
428
  }
428
429
  };
429
430
  }
430
- function terminalTimestamp(indexJson) {
431
- try {
432
- const index = JSON.parse(indexJson);
433
- return ["done", "blocked", "cancelled", "failed"].includes(index.status ?? "") && typeof index.completed_at === "string" ? index.completed_at : null;
434
- }
435
- catch {
436
- return null;
437
- }
438
- }
439
431
  function settledRunSessions(context, links, observedAt) {
440
432
  const sessions = new Map();
441
433
  for (const link of links)
@@ -444,16 +436,16 @@ function settledRunSessions(context, links, observedAt) {
444
436
  if (sessionLinks.some((link) => !link.completed_at))
445
437
  return [];
446
438
  const link = sessionLinks[0];
447
- const latestWorkFinish = sessionLinks.map((item) => Date.parse(item.completed_at)).filter(Number.isFinite).sort((left, right) => right - left)[0];
448
- if (isExternalHarness(link.harness) && link.provider_session_id && latestWorkFinish !== undefined) {
439
+ const sessionStartedAt = sessionLinks.map((item) => item.created_at).sort()[0];
440
+ if (isExternalHarness(link.harness) && link.provider_session_id) {
449
441
  const snapshot = context.db.get(`SELECT observed_at FROM harness_usage_snapshots
450
442
  WHERE project_id = ? AND harness = ? AND provider_session_id = ?
451
- AND observed_at >= ? AND observed_at <= ?
452
- ORDER BY observed_at DESC, id DESC LIMIT 1`, [link.project_id, link.harness, link.provider_session_id, new Date(latestWorkFinish).toISOString(), observedAt]);
443
+ AND completeness = 'complete' AND observed_at >= ? AND observed_at <= ?
444
+ ORDER BY observed_at DESC, id DESC LIMIT 1`, [link.project_id, link.harness, link.provider_session_id, sessionStartedAt, observedAt]);
453
445
  return snapshot ? [{ session_id: sessionId, completed_at: snapshot.observed_at }] : [];
454
446
  }
455
447
  const completed = completedProviderTurn(sessionLinks[0].transcript_path, sessionId);
456
- if (!completed || (latestWorkFinish !== undefined && Date.parse(completed.completed_at) < latestWorkFinish))
448
+ if (!completed || Date.parse(completed.completed_at) < Date.parse(sessionStartedAt))
457
449
  return [];
458
450
  return [{ session_id: sessionId, completed_at: completed.completed_at }];
459
451
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deksden-com/dd-flow-cli",
3
- "version": "0.9.0-beta.0",
3
+ "version": "0.9.0-beta.1",
4
4
  "description": "Mechanical runtime CLI for dd-flow workflows.",
5
5
  "type": "module",
6
6
  "bin": {