@jitsusama/agentic-harness.core 0.4.0 → 0.5.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.
@@ -52,6 +52,8 @@ CREATE TABLE IF NOT EXISTS tool_calls (
52
52
  CREATE INDEX IF NOT EXISTS tool_calls_verifier ON tool_calls (verifier_kind);
53
53
  CREATE INDEX IF NOT EXISTS tool_calls_args ON tool_calls (session_id, args_digest);
54
54
  CREATE INDEX IF NOT EXISTS tool_calls_path ON tool_calls (path);
55
+ CREATE INDEX IF NOT EXISTS tool_calls_session_verifier
56
+ ON tool_calls (session_id, timestamp) WHERE verifier_kind IS NOT NULL;
55
57
  CREATE TABLE IF NOT EXISTS dropped_calls (
56
58
  digest TEXT PRIMARY KEY,
57
59
  session_id TEXT NOT NULL,
@@ -301,18 +303,32 @@ class SqliteTurnStore {
301
303
  const changed = writtenBetween("o", "o.previous_at", "o.timestamp", scope.writers);
302
304
  const rows = await this.db.all(`WITH ordered AS (
303
305
  SELECT c.session_id, c.args_digest, c.name, c.path,
304
- c.timestamp, c.result_chars,
306
+ c.timestamp, c.result_chars, c.verifier_kind,
305
307
  LAG(c.timestamp) OVER (
306
308
  PARTITION BY c.session_id, c.args_digest
307
309
  ORDER BY c.timestamp, c.digest
308
310
  ) AS previous_at
309
311
  FROM tool_calls AS c
310
312
  WHERE ${retrieval.sql}
313
+ ),
314
+ repeats AS (
315
+ SELECT o.session_id, o.args_digest, o.name, o.result_chars,
316
+ (o.verifier_kind IS NOT NULL OR EXISTS (
317
+ SELECT 1 FROM tool_calls AS v
318
+ WHERE v.session_id = o.session_id
319
+ AND v.verifier_kind IS NOT NULL
320
+ AND v.timestamp > o.previous_at
321
+ AND v.timestamp < o.timestamp
322
+ )) AS is_appraisal
323
+ FROM ordered AS o
324
+ WHERE o.previous_at IS NOT NULL AND NOT (${changed.sql})
311
325
  )
312
326
  SELECT args_digest, name, COUNT(*) AS repeated,
313
- SUM(COALESCE(result_chars, 0)) AS repeated_chars
314
- FROM ordered AS o
315
- WHERE o.previous_at IS NOT NULL AND NOT (${changed.sql})
327
+ SUM(COALESCE(result_chars, 0)) AS repeated_chars,
328
+ SUM(is_appraisal) AS appraisal,
329
+ SUM(CASE WHEN is_appraisal THEN COALESCE(result_chars, 0) ELSE 0 END)
330
+ AS appraisal_chars
331
+ FROM repeats
316
332
  GROUP BY session_id, args_digest
317
333
  ORDER BY repeated_chars DESC`, [...retrieval.params, ...changed.params]);
318
334
  return rows.map((row) => ({
@@ -321,6 +337,10 @@ class SqliteTurnStore {
321
337
  asked: row.repeated + 1,
322
338
  repeated: row.repeated,
323
339
  repeatedChars: row.repeated_chars ?? 0,
340
+ rework: row.repeated - row.appraisal,
341
+ reworkChars: (row.repeated_chars ?? 0) - (row.appraisal_chars ?? 0),
342
+ appraisal: row.appraisal,
343
+ appraisalChars: row.appraisal_chars ?? 0,
324
344
  }));
325
345
  }
326
346
  async recordDropped(dropped) {
@@ -181,6 +181,18 @@ export interface RepeatedCall {
181
181
  readonly repeated: number;
182
182
  /** Characters the repeats re-admitted to the context. */
183
183
  readonly repeatedChars: number;
184
+ /** Repeats with no verifier since the last ask: the waste bucket. */
185
+ readonly rework: number;
186
+ /** Characters the rework repeats re-admitted. */
187
+ readonly reworkChars: number;
188
+ /**
189
+ * Repeats that are themselves a verifier, or that follow one run
190
+ * since the last ask: the model checking its work, which is cost of
191
+ * quality rather than waste.
192
+ */
193
+ readonly appraisal: number;
194
+ /** Characters the appraisal repeats re-admitted. */
195
+ readonly appraisalChars: number;
184
196
  }
185
197
  /**
186
198
  * What a session log says about itself.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jitsusama/agentic-harness.core",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "Pi-agnostic business logic for agentic-harness: state machines, guardian decisions, quest/TDD domain model.",
5
5
  "license": "MIT",
6
6
  "type": "module",