@principles/pd-cli 1.123.0 → 1.124.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.
@@ -1 +1 @@
1
- {"version":3,"file":"build-trajectory-evidence.d.ts","sourceRoot":"","sources":["../../src/commands/build-trajectory-evidence.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAUH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAErE;;;;;;;GAOG;AACH,wBAAgB,6BAA6B,CAC3C,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,GAAG,SAAS,EAC7B,YAAY,CAAC,EAAE,MAAM,GACpB,iBAAiB,EAAE,CAmJrB"}
1
+ {"version":3,"file":"build-trajectory-evidence.d.ts","sourceRoot":"","sources":["../../src/commands/build-trajectory-evidence.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAUH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAErE;;;;;;;GAOG;AACH,wBAAgB,6BAA6B,CAC3C,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,GAAG,SAAS,EAC7B,YAAY,CAAC,EAAE,MAAM,GACpB,iBAAiB,EAAE,CAyJrB"}
@@ -82,7 +82,7 @@ export function buildTrajectoryEvidenceFromDb(stateDir, sessionId, workspaceDir)
82
82
  // Try to read assistant turns (last 3)
83
83
  try {
84
84
  const assistantTurns = db.prepare(`
85
- SELECT id, sanitized_text, created_at
85
+ SELECT id, sanitized_text, stop_reason, created_at
86
86
  FROM assistant_turns
87
87
  WHERE session_id = ?
88
88
  ORDER BY id ASC
@@ -95,9 +95,12 @@ export function buildTrajectoryEvidenceFromDb(stateDir, sessionId, workspaceDir)
95
95
  ? turn.sanitized_text
96
96
  : '';
97
97
  const sanitizedNote = sanitizeString(sanitizedText.slice(0, MAX_EVIDENCE_NOTE_CHARS), workspaceDir);
98
+ // Enhanced: append truncation warning when stop_reason=length
99
+ const stopReason = typeof turn.stop_reason === 'string' ? turn.stop_reason : null;
100
+ const truncationWarning = stopReason === 'length' ? ' [TRUNCATED: output cut off by length limit]' : '';
98
101
  evidence.push({
99
102
  sourceRef: `agent_turn:${String(turn.created_at ?? 'unknown')}`,
100
- note: sanitizedNote,
103
+ note: sanitizedNote + truncationWarning,
101
104
  });
102
105
  }
103
106
  }
@@ -113,9 +116,9 @@ export function buildTrajectoryEvidenceFromDb(stateDir, sessionId, workspaceDir)
113
116
  // PRI-358: Try to read failed tool_calls (last 3 failures, chronological order)
114
117
  try {
115
118
  const failedToolCalls = db.prepare(`
116
- SELECT tool_name, error_type, exit_code, created_at
119
+ SELECT tool_name, error_type, exit_code, result_preview, created_at
117
120
  FROM (
118
- SELECT tool_name, error_type, exit_code, created_at
121
+ SELECT tool_name, error_type, exit_code, result_preview, created_at
119
122
  FROM tool_calls
120
123
  WHERE session_id = ? AND outcome = 'failure'
121
124
  ORDER BY created_at DESC
@@ -129,7 +132,10 @@ export function buildTrajectoryEvidenceFromDb(stateDir, sessionId, workspaceDir)
129
132
  const toolName = typeof tc.tool_name === 'string' ? tc.tool_name : 'unknown';
130
133
  const errorType = typeof tc.error_type === 'string' ? tc.error_type : 'unknown';
131
134
  const exitCode = tc.exit_code != null ? String(tc.exit_code) : 'N/A';
132
- const note = `Tool ${toolName} failed: ${errorType} (exitCode: ${exitCode})`;
135
+ // Enhanced: append resultPreview when available
136
+ const resultPreview = typeof tc.result_preview === 'string' ? tc.result_preview : null;
137
+ const previewSuffix = resultPreview ? ` | ${resultPreview.slice(0, 200)}` : '';
138
+ const note = `Tool ${toolName} failed: ${errorType} (exitCode: ${exitCode})${previewSuffix}`;
133
139
  evidence.push({
134
140
  sourceRef: `tool_call_failure:${String(tc.created_at ?? 'unknown')}`,
135
141
  note: sanitizeString(note.slice(0, MAX_EVIDENCE_NOTE_CHARS), workspaceDir),
@@ -1 +1 @@
1
- {"version":3,"file":"build-trajectory-evidence.js","sourceRo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A6E;aACpF,CAAC,CAAC;QACL,CAAC;QAED,OAAO,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,oBAAoB,CAAC,CAAC;IACjD,CAAC;YAAS,CAAC;QACT,EAAE,CAAC,KAAK,EAAE,CAAC;IACb,CAAC;AACH,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@principles/pd-cli",
3
- "version": "1.123.0",
3
+ "version": "1.124.0",
4
4
  "description": "PD CLI — Pain recording, sample management, and evolution tasks",
5
5
  "type": "module",
6
6
  "bin": {
@@ -100,7 +100,7 @@ export function buildTrajectoryEvidenceFromDb(
100
100
  // Try to read assistant turns (last 3)
101
101
  try {
102
102
  const assistantTurns = db.prepare(`
103
- SELECT id, sanitized_text, created_at
103
+ SELECT id, sanitized_text, stop_reason, created_at
104
104
  FROM assistant_turns
105
105
  WHERE session_id = ?
106
106
  ORDER BY id ASC
@@ -116,9 +116,12 @@ export function buildTrajectoryEvidenceFromDb(
116
116
  sanitizedText.slice(0, MAX_EVIDENCE_NOTE_CHARS),
117
117
  workspaceDir,
118
118
  );
119
+ // Enhanced: append truncation warning when stop_reason=length
120
+ const stopReason = typeof turn.stop_reason === 'string' ? turn.stop_reason : null;
121
+ const truncationWarning = stopReason === 'length' ? ' [TRUNCATED: output cut off by length limit]' : '';
119
122
  evidence.push({
120
123
  sourceRef: `agent_turn:${String(turn.created_at ?? 'unknown')}`,
121
- note: sanitizedNote,
124
+ note: sanitizedNote + truncationWarning,
122
125
  });
123
126
  }
124
127
  } catch {
@@ -134,9 +137,9 @@ export function buildTrajectoryEvidenceFromDb(
134
137
  // PRI-358: Try to read failed tool_calls (last 3 failures, chronological order)
135
138
  try {
136
139
  const failedToolCalls = db.prepare(`
137
- SELECT tool_name, error_type, exit_code, created_at
140
+ SELECT tool_name, error_type, exit_code, result_preview, created_at
138
141
  FROM (
139
- SELECT tool_name, error_type, exit_code, created_at
142
+ SELECT tool_name, error_type, exit_code, result_preview, created_at
140
143
  FROM tool_calls
141
144
  WHERE session_id = ? AND outcome = 'failure'
142
145
  ORDER BY created_at DESC
@@ -150,7 +153,10 @@ export function buildTrajectoryEvidenceFromDb(
150
153
  const toolName = typeof tc.tool_name === 'string' ? tc.tool_name : 'unknown';
151
154
  const errorType = typeof tc.error_type === 'string' ? tc.error_type : 'unknown';
152
155
  const exitCode = tc.exit_code != null ? String(tc.exit_code) : 'N/A';
153
- const note = `Tool ${toolName} failed: ${errorType} (exitCode: ${exitCode})`;
156
+ // Enhanced: append resultPreview when available
157
+ const resultPreview = typeof tc.result_preview === 'string' ? tc.result_preview : null;
158
+ const previewSuffix = resultPreview ? ` | ${resultPreview.slice(0, 200)}` : '';
159
+ const note = `Tool ${toolName} failed: ${errorType} (exitCode: ${exitCode})${previewSuffix}`;
154
160
  evidence.push({
155
161
  sourceRef: `tool_call_failure:${String(tc.created_at ?? 'unknown')}`,
156
162
  note: sanitizeString(note.slice(0, MAX_EVIDENCE_NOTE_CHARS), workspaceDir),
@@ -45,6 +45,8 @@ function createTrajectoryDb(): Database.Database {
45
45
  raw_text TEXT,
46
46
  sanitized_text TEXT,
47
47
  blob_ref TEXT,
48
+ stop_reason TEXT,
49
+ thinking_blocks_count INTEGER,
48
50
  created_at TEXT NOT NULL
49
51
  )
50
52
  `);
@@ -74,6 +76,7 @@ function createTrajectoryDb(): Database.Database {
74
76
  gfi_before REAL,
75
77
  gfi_after REAL,
76
78
  params_json TEXT NOT NULL DEFAULT '{}',
79
+ result_preview TEXT,
77
80
  created_at TEXT NOT NULL
78
81
  )
79
82
  `);
@@ -114,11 +117,12 @@ function insertToolCall(
114
117
  errorType: string | null,
115
118
  exitCode: number | null,
116
119
  createdAt: string,
120
+ resultPreview?: string | null,
117
121
  ): void {
118
122
  db.prepare(`
119
- INSERT INTO tool_calls (session_id, tool_name, outcome, error_type, exit_code, duration_ms, params_json, created_at)
120
- VALUES (?, ?, ?, ?, ?, ?, ?, ?)
121
- `).run(sessionId, toolName, outcome, errorType, exitCode, 100, '{}', createdAt);
123
+ INSERT INTO tool_calls (session_id, tool_name, outcome, error_type, exit_code, duration_ms, params_json, result_preview, created_at)
124
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
125
+ `).run(sessionId, toolName, outcome, errorType, exitCode, 100, '{}', resultPreview ?? null, createdAt);
122
126
  }
123
127
 
124
128
  // ── Tests ───────────────────────────────────────────────────────────────────
@@ -281,4 +285,53 @@ describe('buildTrajectoryEvidenceFromDb — PRI-341', () => {
281
285
  // and the table simply doesn't exist (not an error condition worth reporting)
282
286
  });
283
287
  });
288
+
289
+ // ── Trajectory v2 enhancement: resultPreview + stopReason ─────────────────
290
+
291
+ describe('trajectory v2 enhancement: resultPreview and stopReason', () => {
292
+ it('includes resultPreview in tool failure evidence note', () => {
293
+ const db = createTrajectoryDb();
294
+ insertToolCall(db, '123', 'bash', 'failure', 'ENOENT', 1, '2026-01-01T10:00:00Z', 'Error: no such file or directory');
295
+ db.close();
296
+
297
+ const evidence = buildTrajectoryEvidenceFromDb(stateDir, '123', tmpDir);
298
+
299
+ const failureEntry = evidence.find(e => e.sourceRef.startsWith('tool_call_failure:'));
300
+ expect(failureEntry).toBeDefined();
301
+ expect(failureEntry!.note).toContain('ENOENT');
302
+ expect(failureEntry!.note).toContain('Error: no such file or directory');
303
+ });
304
+
305
+ it('includes truncation warning when stop_reason is length', () => {
306
+ const db = createTrajectoryDb();
307
+ db.prepare(`
308
+ INSERT INTO assistant_turns (session_id, sanitized_text, stop_reason, created_at)
309
+ VALUES (?, ?, ?, ?)
310
+ `).run('123', 'Partial output truncated...', 'length', '2026-01-01T10:00:00Z');
311
+ db.close();
312
+
313
+ const evidence = buildTrajectoryEvidenceFromDb(stateDir, '123', tmpDir);
314
+
315
+ const agentEntry = evidence.find(e => e.sourceRef.startsWith('agent_turn:'));
316
+ expect(agentEntry).toBeDefined();
317
+ expect(agentEntry!.note).toContain('Partial output truncated...');
318
+ expect(agentEntry!.note).toContain('[TRUNCATED: output cut off by length limit]');
319
+ });
320
+
321
+ it('does not include truncation warning when stop_reason is end_turn', () => {
322
+ const db = createTrajectoryDb();
323
+ db.prepare(`
324
+ INSERT INTO assistant_turns (session_id, sanitized_text, stop_reason, created_at)
325
+ VALUES (?, ?, ?, ?)
326
+ `).run('123', 'Complete output', 'end_turn', '2026-01-01T10:00:00Z');
327
+ db.close();
328
+
329
+ const evidence = buildTrajectoryEvidenceFromDb(stateDir, '123', tmpDir);
330
+
331
+ const agentEntry = evidence.find(e => e.sourceRef.startsWith('agent_turn:'));
332
+ expect(agentEntry).toBeDefined();
333
+ expect(agentEntry!.note).toBe('Complete output');
334
+ expect(agentEntry!.note).not.toContain('[TRUNCATED');
335
+ });
336
+ });
284
337
  });