principles-disciple 1.93.0 → 1.95.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.
- package/openclaw.plugin.json +1 -1
- package/package.json +1 -1
- package/src/commands/pain.ts +23 -2
- package/src/hooks/after-tool-call-helpers.ts +577 -0
- package/src/hooks/after-tool-call-types.ts +105 -0
- package/src/hooks/pain.ts +176 -482
- package/src/hooks/trajectory-evidence.ts +75 -0
- package/tests/commands/pain.test.ts +180 -1
- package/tests/hooks/pain.test.ts +225 -0
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* After-Tool-Call Decomposition Types — PRI-326
|
|
3
|
+
*
|
|
4
|
+
* Shared types for the decomposed handleAfterToolCall pipeline.
|
|
5
|
+
* These types make the pipeline stages explicit without introducing
|
|
6
|
+
* the larger RawObservation/PainEpisode/PainEvidence architecture.
|
|
7
|
+
*
|
|
8
|
+
* ERR checklist:
|
|
9
|
+
* - ERR-001: No `as` casts in this file; these are type definitions only.
|
|
10
|
+
* - ERR-002: Every decision/result carries structured reason + nextAction.
|
|
11
|
+
* - EP-01: These types document boundaries, not runtime validation targets.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import type { SessionState } from '../core/session-tracker.js';
|
|
15
|
+
|
|
16
|
+
// ── Tool Call Outcome Classification ────────────────────────────────────────
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Result of classifying what happened in a tool call event.
|
|
20
|
+
*
|
|
21
|
+
* Pure extraction — no I/O, no side effects.
|
|
22
|
+
*/
|
|
23
|
+
export interface ToolCallOutcome {
|
|
24
|
+
/** Whether the tool call is considered a failure */
|
|
25
|
+
readonly isFailure: boolean;
|
|
26
|
+
/** Resolved exit code (numeric, 0 if success/absent) */
|
|
27
|
+
readonly exitCode: number;
|
|
28
|
+
/** For failures: classified as 'tool_failure' or 'dispatch_error' */
|
|
29
|
+
readonly failureSource: 'tool_failure' | 'dispatch_error' | undefined;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// ── Tool Call Observation ───────────────────────────────────────────────────
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Normalized observation built from the tool call event and context.
|
|
36
|
+
*
|
|
37
|
+
* Used by friction tracking, event recording, and pain admission.
|
|
38
|
+
* Constructed after classification, before any I/O.
|
|
39
|
+
*/
|
|
40
|
+
export interface ToolCallObservation {
|
|
41
|
+
/** Tool parameters (typed subset) */
|
|
42
|
+
readonly params: {
|
|
43
|
+
readonly filePath?: string;
|
|
44
|
+
readonly content?: string;
|
|
45
|
+
readonly text?: string;
|
|
46
|
+
readonly newString?: string;
|
|
47
|
+
readonly query?: string;
|
|
48
|
+
readonly input?: string;
|
|
49
|
+
readonly arguments?: string;
|
|
50
|
+
};
|
|
51
|
+
/** File path relative to workspace */
|
|
52
|
+
readonly relPath: string;
|
|
53
|
+
/** Whether the file path is in the risk set */
|
|
54
|
+
readonly isRisk: boolean;
|
|
55
|
+
/** Error type classification string */
|
|
56
|
+
readonly errorType: string;
|
|
57
|
+
/** Denoised, hashed error identifier */
|
|
58
|
+
readonly errorHash: string;
|
|
59
|
+
/** Error text for logging */
|
|
60
|
+
readonly errorText: string;
|
|
61
|
+
/** Pain score (only meaningful for write-tool failures on risky paths) */
|
|
62
|
+
readonly painScore: number;
|
|
63
|
+
/** Trace ID for this observation chain */
|
|
64
|
+
readonly traceId: string;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// ── Pain Admission Decision ─────────────────────────────────────────────────
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Result of evaluating whether a tool failure should trigger pain diagnosis.
|
|
71
|
+
*
|
|
72
|
+
* Encapsulates the combined triage + PainDiagnosticGate decision.
|
|
73
|
+
*/
|
|
74
|
+
export interface PainAdmissionDecision {
|
|
75
|
+
/** Whether the tool failure should proceed to pain emission */
|
|
76
|
+
readonly admitted: boolean;
|
|
77
|
+
/** The admission stage that made the decision */
|
|
78
|
+
readonly stage: 'triage_evidence_only' | 'gate_rejected' | 'gate_admitted' | 'not_applicable';
|
|
79
|
+
/** Human-readable reason for the decision */
|
|
80
|
+
readonly reason: string;
|
|
81
|
+
/** Detail about the decision */
|
|
82
|
+
readonly detail: string;
|
|
83
|
+
/** The diagnostic gate result (if gate was evaluated) */
|
|
84
|
+
readonly gateResult?: {
|
|
85
|
+
readonly shouldDiagnose: boolean;
|
|
86
|
+
readonly reason: string;
|
|
87
|
+
readonly detail: string;
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// ── Friction Update Result ──────────────────────────────────────────────────
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Result of friction tracking for a tool call.
|
|
95
|
+
*/
|
|
96
|
+
export interface FrictionUpdateResult {
|
|
97
|
+
/** GFI before this update */
|
|
98
|
+
readonly gfiBefore: number;
|
|
99
|
+
/** GFI after this update */
|
|
100
|
+
readonly gfiAfter: number;
|
|
101
|
+
/** Updated session state (if failure) */
|
|
102
|
+
readonly sessionState: SessionState | undefined;
|
|
103
|
+
/** The error hash used for tracking */
|
|
104
|
+
readonly errorHash: string;
|
|
105
|
+
}
|