pi-braid 0.40.0 → 0.40.2
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/CONTRIBUTING.md +27 -3
- package/README.md +39 -33
- package/TOOLS.md +27 -3
- package/build-info.json +9 -0
- package/dist/extensions/cognitive/metacognition/handlers/hypothesize.d.ts +9 -0
- package/dist/extensions/cognitive/metacognition/handlers/hypothesize.js +13 -1
- package/dist/extensions/cognitive/metacognition/handlers/verify.js +35 -4
- package/dist/extensions/core/prompt-builder/inspect.js +9 -3
- package/dist/extensions/enforcement/handlers/register-tool-result-formatting.d.ts +1 -1
- package/dist/extensions/enforcement/handlers/register-tool-result-formatting.js +1 -1
- package/dist/extensions/enforcement/handlers/turn-end-handler.js +1 -1
- package/dist/extensions/enforcement/self-state-claims.d.ts +1 -1
- package/dist/extensions/enforcement/self-state-claims.js +3 -2
- package/dist/extensions/manifest.js +2 -2
- package/dist/extensions/memory/context-manager/handlers/tool-batch-boundary.d.ts +22 -5
- package/dist/extensions/memory/context-manager/handlers/tool-batch-boundary.js +43 -11
- package/dist/extensions/memory/context-manager/handlers/tools/context-compress.js +174 -50
- package/dist/extensions/memory/context-manager/handlers/tools/context-navigate.js +4 -1
- package/dist/extensions/memory/memory-agent-bridge/memory-store-tool.js +16 -0
- package/dist/extensions/memory/memory-agent-bridge/memory-tool.js +21 -9
- package/dist/extensions/memory/scratchpad/format.js +8 -2
- package/dist/extensions/memory/scratchpad/index.js +11 -2
- package/dist/extensions/memory/session-recall/index.js +19 -6
- package/dist/extensions/memory/three-memory-stores/episodes.d.ts +1 -1
- package/dist/extensions/memory/three-memory-stores/episodes.js +2 -2
- package/dist/extensions/orchestrator/index.js +73 -8
- package/dist/extensions/self/health-maintenance/index.js +112 -9
- package/dist/lib/config/braid-settings.d.ts +21 -0
- package/dist/lib/config/braid-settings.js +36 -0
- package/dist/lib/constants/session-thresholds.d.ts +2 -3
- package/dist/lib/constants/session-thresholds.js +2 -3
- package/dist/lib/enforcement/turn-dedup.d.ts +2 -2
- package/dist/lib/enforcement/turn-dedup.js +2 -2
- package/dist/lib/harness/index.d.ts +1 -1
- package/dist/lib/harness/index.js +1 -1
- package/dist/lib/harness/types.d.ts +1 -1
- package/dist/lib/harness/types.js +1 -1
- package/dist/lib/orchestrator/index.d.ts +2 -2
- package/dist/lib/orchestrator/index.js +1 -1
- package/dist/lib/orchestrator/workers.d.ts +184 -2
- package/dist/lib/orchestrator/workers.js +521 -6
- package/dist/lib/utils/injection-tracker.js +1 -1
- package/docs/BEGINNERS.md +22 -0
- package/docs/CONTEXT-POLICY.md +13 -5
- package/docs/LOCAL_DEV.md +31 -5
- package/docs/ROADMAP.md +10 -7
- package/docs/SETUP.md +86 -42
- package/package.json +11 -8
- package/skills/braid-reference/SKILL.md +23 -23
- package/skills/release-pipeline/SKILL.md +46 -37
- package/skills/subagent-orchestration/SKILL.md +51 -1
- package/src/extensions/cognitive/metacognition/handlers/hypothesize.ts +14 -1
- package/src/extensions/cognitive/metacognition/handlers/verify.ts +39 -5
- package/src/extensions/core/prompt-builder/inspect.ts +10 -3
- package/src/extensions/enforcement/AGENTS.md +25 -19
- package/src/extensions/enforcement/handlers/register-tool-result-formatting.ts +1 -1
- package/src/extensions/enforcement/handlers/turn-end-handler.ts +1 -1
- package/src/extensions/enforcement/self-state-claims.ts +3 -2
- package/src/extensions/heartbeat/heartbeat-scheduler/AGENTS.md +6 -3
- package/src/extensions/manifest.ts +2 -2
- package/src/extensions/memory/AGENTS.md +13 -5
- package/src/extensions/memory/context-manager/handlers/tool-batch-boundary.ts +45 -11
- package/src/extensions/memory/context-manager/handlers/tools/context-compress.ts +202 -60
- package/src/extensions/memory/context-manager/handlers/tools/context-navigate.ts +4 -1
- package/src/extensions/memory/memory-agent-bridge/memory-store-tool.ts +16 -0
- package/src/extensions/memory/memory-agent-bridge/memory-tool.ts +22 -9
- package/src/extensions/memory/scratchpad/format.ts +8 -2
- package/src/extensions/memory/scratchpad/index.ts +12 -2
- package/src/extensions/memory/session-recall/index.ts +20 -8
- package/src/extensions/memory/three-memory-stores/episodes.ts +2 -2
- package/src/extensions/orchestrator/index.ts +100 -11
- package/src/extensions/scheduling/timer/AGENTS.md +7 -0
- package/src/extensions/self/health-maintenance/index.ts +143 -14
- package/src/extensions/self/watchdog/AGENTS.md +1 -0
- package/src/lib/AGENTS.md +21 -21
- package/src/lib/config/braid-settings.ts +74 -0
- package/src/lib/constants/session-thresholds.ts +2 -3
- package/src/lib/enforcement/turn-dedup.ts +2 -2
- package/src/lib/harness/AGENTS.md +1 -1
- package/src/lib/harness/index.ts +1 -1
- package/src/lib/harness/types.ts +1 -1
- package/src/lib/orchestrator/index.ts +26 -0
- package/src/lib/orchestrator/workers.ts +705 -7
- package/src/lib/utils/AGENTS.md +1 -1
- package/src/lib/utils/injection-tracker.ts +1 -1
|
@@ -210,6 +210,56 @@ When a worker signals completion, review critically before closing the pane.
|
|
|
210
210
|
- **Worker crashes mid-task**: orchestrator detects via `agent_get` status change, spawns replacement.
|
|
211
211
|
- **Orchestrator is busy**: worker retries signal with backoff (max 3, 60s apart), then writes results to a well-known path.
|
|
212
212
|
|
|
213
|
+
### Gate evidence rows and the population stamp
|
|
214
|
+
|
|
215
|
+
`close-worker` takes `gates` as `{cmd, exit}` rows, one per gate the wave ran. A gate whose
|
|
216
|
+
subject is a file or row population records what it scanned, and at which revision, as an
|
|
217
|
+
optional `stamp` on its row:
|
|
218
|
+
|
|
219
|
+
```json
|
|
220
|
+
{
|
|
221
|
+
"cmd": "node scripts/check-placement.mjs --strict",
|
|
222
|
+
"exit": 0,
|
|
223
|
+
"stamp": "scanned 914 files at <revision>"
|
|
224
|
+
}
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
`n` is a non-negative integer, `unit` one lowercase word (`files`, `rows`, `cases`, `lines`),
|
|
228
|
+
and `revision` a 7-to-40-char hex sha or a ref name. `check-result` warns; it does not fail
|
|
229
|
+
when a row whose command carries a walk, list or count verb (`ls`, `find`, `fd`, `git ls-files`,
|
|
230
|
+
`wc`, `rg`, `grep`) carries no stamp or an unreadable one.
|
|
231
|
+
|
|
232
|
+
`verify-and-merge` reads the close's stamped `files` rows and compares each number against that
|
|
233
|
+
revision's tracked-entry census. A recorded number below the census refuses the merge and names
|
|
234
|
+
the delta: the gate certified fewer files than the commit carries, which is what a run before
|
|
235
|
+
`git add` looks like. Re-run the gate on the staged tree and re-issue the close. A close with no
|
|
236
|
+
stamped `files` row prints `no recorded population` and merges.
|
|
237
|
+
|
|
238
|
+
| Setting | Default | Effect | Read cadence |
|
|
239
|
+
| -------------------------------------------- | -------- | -------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------- |
|
|
240
|
+
| `braid.orchestrator.closeGateWellFormedness` | `shadow` | `shadow` logs invalid `{cmd, exit}` rows and allows close; `enforce` refuses an invalid row; `off` skips validation. Commands are not rerun. | Re-read at use time on every `close-worker` close. |
|
|
241
|
+
|
|
242
|
+
### Claim verifiers and the instrument-capability warn
|
|
243
|
+
|
|
244
|
+
Each claim's `verified_by` is read against a small registry of instrument shapes: search and <!-- doc-ref-exempt: seat-side result-block field; the parser lives in the orchestrator seat, not this repo -->
|
|
245
|
+
count verbs (`grep`, `rg`, `wc`, `count`, `hits`), artifact citations (a report, a readme, a
|
|
246
|
+
description), execution verbs (`boot`, `install`, `exit`, `suite`), content verbs (`read`,
|
|
247
|
+
`measured`, `bytes`, `entries`), and enumeration instruments (`git ls-files`, an AST or
|
|
248
|
+
type-aware census, a suite run, a row count). The claim's wording is read against the property
|
|
249
|
+
class it asserts, and `check-result` warns; it does not fail, when the pair cannot observe
|
|
250
|
+
what the claim asserts:
|
|
251
|
+
|
|
252
|
+
- a coverage or elimination claim ("gone", "no remaining", "every reader") grounded on a
|
|
253
|
+
search or count verb with no census named;
|
|
254
|
+
- a content claim grounded only on an artifact citation (a description is not the content);
|
|
255
|
+
- a classification claim ("only", "private", "leak") grounded on a bare count with no
|
|
256
|
+
decomposition named.
|
|
257
|
+
|
|
258
|
+
The warn names the census shape it wants (`git ls-files`, an AST or type-aware census, a suite
|
|
259
|
+
run, or an explicit row count) and the counter line `claim-capability: k/n checked, m warn(s)`
|
|
260
|
+
reports the share. The tier is warn-only: a mismatched pair leaves the block valid and the exit
|
|
261
|
+
code unchanged. A verifier the registry cannot classify is left to the seat's re-derivation.
|
|
262
|
+
|
|
213
263
|
## Completion Signal
|
|
214
264
|
|
|
215
265
|
### For orchestrate-spawned workers
|
|
@@ -239,7 +289,7 @@ braid ships a context-manager: `context_navigate` (tag / checkout) and `context_
|
|
|
239
289
|
|
|
240
290
|
Enforce a HARD context budget BEFORE degradation begins. Mistakes and loop-risk rise sharply at ~75–100k tokens, independent of window size.
|
|
241
291
|
|
|
242
|
-
**Trigger (absolute, not %):** when `context_inspect` reports **>80k tokens** OR **>35% of the window** (whichever comes first):
|
|
292
|
+
**Trigger (absolute, not %):** when `context_inspect` reports **>80k tokens** OR **>35% of the window** (whichever comes first). `context_inspect` ships deferred: if it is not in your active set, find it with `tool_search` first:
|
|
243
293
|
|
|
244
294
|
1. `context_navigate action=tag name="pre-archive-<n>"` - mark your position
|
|
245
295
|
2. `context_compress action=archive topic="<task>"` - archive everything before the tag
|
|
@@ -50,6 +50,18 @@ export function emptyResponseRetryOptions(lastError: string): LlmCallOptions | n
|
|
|
50
50
|
return { temperature: 0.3, maxTokens: 4000, reasoning: "off" };
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
+
/**
|
|
54
|
+
* The hypothesis count a call asks for. Argument validation converts a blank
|
|
55
|
+
* string to 0 for `Type.Optional(Type.Number())` and the converted value passes,
|
|
56
|
+
* so a handler cannot tell a blank from a typed 0; a prompt asking the model for
|
|
57
|
+
* zero hypotheses is never a usable request, so a non-positive or non-finite
|
|
58
|
+
* value is read as absent and the documented default (3) applies. Exported pure
|
|
59
|
+
* for the fixture, like emptyResponseRetryOptions above.
|
|
60
|
+
*/
|
|
61
|
+
export function resolveMaxHypotheses(value: unknown): number {
|
|
62
|
+
return typeof value === "number" && Number.isFinite(value) && value > 0 ? value : 3;
|
|
63
|
+
}
|
|
64
|
+
|
|
53
65
|
const FORMAT_OPTIONS = ["ranked", "tree", "list"] as const;
|
|
54
66
|
|
|
55
67
|
const hypothesizeSchema = Type.Object({
|
|
@@ -133,7 +145,8 @@ export function createHypothesizeTool(): ToolDefinition<any, any, any> {
|
|
|
133
145
|
_onUpdate: unknown,
|
|
134
146
|
ctx: ExtensionContext | undefined,
|
|
135
147
|
) => {
|
|
136
|
-
const { problem, evidence,
|
|
148
|
+
const { problem, evidence, format = "ranked", verificationPlan } = params;
|
|
149
|
+
const maxHypotheses = resolveMaxHypotheses(params.maxHypotheses);
|
|
137
150
|
|
|
138
151
|
if (!ctx?.model) {
|
|
139
152
|
throw new Error(
|
|
@@ -83,6 +83,23 @@ const DEFAULT_CRITERIA: Record<VerificationTarget, string[]> = {
|
|
|
83
83
|
],
|
|
84
84
|
};
|
|
85
85
|
|
|
86
|
+
/** A blank string is "not provided": clients that emit every schema key send "" for the unused ones. */
|
|
87
|
+
function optionalString(v: unknown): string | undefined {
|
|
88
|
+
return typeof v === "string" && v.trim().length > 0 ? v : undefined;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Drop blank criteria entries before use. A list left empty names nothing
|
|
93
|
+
* usable, so the target's defaults stand in: the LLM tier must never receive
|
|
94
|
+
* an empty rubric.
|
|
95
|
+
*/
|
|
96
|
+
function resolveCriteria(provided: unknown, target: VerificationTarget): string[] {
|
|
97
|
+
const cleaned = Array.isArray(provided)
|
|
98
|
+
? provided.filter((c): c is string => typeof c === "string" && c.trim().length > 0)
|
|
99
|
+
: [];
|
|
100
|
+
return cleaned.length > 0 ? cleaned : DEFAULT_CRITERIA[target];
|
|
101
|
+
}
|
|
102
|
+
|
|
86
103
|
/** Auto-detect the most recent code/reasoning/plan from session messages. */
|
|
87
104
|
function autoDetectTarget(
|
|
88
105
|
ctx: ExtensionContext,
|
|
@@ -325,16 +342,31 @@ export function createVerifyTool(): ToolDefinition<any, any, any> {
|
|
|
325
342
|
const startMs = Date.now();
|
|
326
343
|
const target = p.target ?? "result";
|
|
327
344
|
const depth = p.depth ?? "standard";
|
|
328
|
-
const criteria = p.criteria
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
345
|
+
const criteria = resolveCriteria(p.criteria, target);
|
|
346
|
+
// A blank selector arrives as 0, and a value outside (0,1] can never
|
|
347
|
+
// gate a 0-1 confidence: both are "not provided", and the documented
|
|
348
|
+
// default is 0.5. The default is documented, so this substitutes -
|
|
349
|
+
// it never refuses the call.
|
|
350
|
+
const rawThreshold = p.confidenceThreshold;
|
|
351
|
+
const confidenceThreshold =
|
|
352
|
+
typeof rawThreshold === "number" &&
|
|
353
|
+
Number.isFinite(rawThreshold) &&
|
|
354
|
+
rawThreshold > 0 &&
|
|
355
|
+
rawThreshold <= 1
|
|
356
|
+
? rawThreshold
|
|
357
|
+
: 0.5;
|
|
358
|
+
|
|
359
|
+
// A blank targetText is "not provided" too: the documented path
|
|
360
|
+
// auto-detects from recent context. Only when that finds nothing does
|
|
361
|
+
// the tool refuse, and the refusal names auto-detection as what ran.
|
|
362
|
+
const providedText = optionalString(p.targetText);
|
|
363
|
+
const text = providedText ?? autoDetectTarget(ctx)?.text;
|
|
332
364
|
if (!text) {
|
|
333
365
|
return {
|
|
334
366
|
content: [
|
|
335
367
|
{
|
|
336
368
|
type: "text",
|
|
337
|
-
text: "[verify]
|
|
369
|
+
text: "[verify] Auto-detection ran over recent context and found no target text. Provide targetText explicitly.",
|
|
338
370
|
},
|
|
339
371
|
],
|
|
340
372
|
details: { passed: false, reason: "no-text" },
|
|
@@ -431,6 +463,8 @@ export function createVerifyTool(): ToolDefinition<any, any, any> {
|
|
|
431
463
|
suggestions: result.suggestions,
|
|
432
464
|
target: result.target,
|
|
433
465
|
checksRun: result.checksRun,
|
|
466
|
+
confidenceThreshold,
|
|
467
|
+
criteria,
|
|
434
468
|
verificationMs: result.verificationMs,
|
|
435
469
|
blockedFinalize: !passed,
|
|
436
470
|
},
|
|
@@ -30,7 +30,7 @@ const inspectSchema = Type.Object({
|
|
|
30
30
|
truncate: Type.Optional(
|
|
31
31
|
Type.Number({
|
|
32
32
|
description:
|
|
33
|
-
"Max characters
|
|
33
|
+
"Max characters before truncation (default 5000); applied after tool/skill exclusion. A blank or non-positive value applies the default.",
|
|
34
34
|
default: 5000,
|
|
35
35
|
}),
|
|
36
36
|
),
|
|
@@ -122,7 +122,14 @@ export function createPromptInspectTool() {
|
|
|
122
122
|
): Promise<any> => {
|
|
123
123
|
const showTools = params.includeTools ?? true;
|
|
124
124
|
const showSkills = params.includeSkills ?? true;
|
|
125
|
-
|
|
125
|
+
// Argument validation converts a blank truncate to 0, and the
|
|
126
|
+
// description used to define 0 as "no limit" - so a blank flipped the
|
|
127
|
+
// tool into dumping the whole assembled prompt. A deliberate 0 is
|
|
128
|
+
// indistinguishable from a blank after conversion, so the documented
|
|
129
|
+
// default wins and the old no-limit mode is no longer reachable through
|
|
130
|
+
// this selector (use `match` to read the full prompt).
|
|
131
|
+
const maxLen =
|
|
132
|
+
typeof params.truncate === "number" && params.truncate > 0 ? params.truncate : 5000;
|
|
126
133
|
|
|
127
134
|
if (!ctx) {
|
|
128
135
|
return {
|
|
@@ -202,7 +209,7 @@ export function createPromptInspectTool() {
|
|
|
202
209
|
}
|
|
203
210
|
} else {
|
|
204
211
|
// Apply truncation only when no match filter is active
|
|
205
|
-
if (
|
|
212
|
+
if (body.length > maxLen) {
|
|
206
213
|
didTruncate = true;
|
|
207
214
|
body =
|
|
208
215
|
body.slice(0, maxLen - 80) +
|
|
@@ -8,25 +8,25 @@ the wake-up policy.
|
|
|
8
8
|
|
|
9
9
|
## Files at this level
|
|
10
10
|
|
|
11
|
-
| File | Purpose
|
|
12
|
-
| ------------------------------------ |
|
|
13
|
-
| `state.ts` | Composed session-scoped state. Re-exports `ENFORCEMENT_PARAMS` and `EnforcementState` from `enforcement-types.ts`.
|
|
14
|
-
| `enforcement-types.ts` | The shared `ENFORCEMENT_PARAMS` and `EnforcementState` definitions. **Lives outside `state.ts` to break the circular dep** that would otherwise form between `state.ts <-> session-state.ts <-> verification-judge-state.ts`.
|
|
15
|
-
| `session-state.ts` | Per-turn tracking, config, topic-drift detector.
|
|
16
|
-
| `whisper.ts` | The `sendTrackedMessage` wrapper with the whisper cap and metadata.
|
|
17
|
-
| `judge-utils.ts` | Helpers for the verification judge.
|
|
18
|
-
| `signals.ts` | The signal taxonomy (severity, source, priority).
|
|
19
|
-
| `validation.ts` | Validation of whisper payloads.
|
|
20
|
-
| `similarity.ts` | Cosine similarity for dedup.
|
|
21
|
-
| `nudge-manager.ts` | Manages nudge cooldowns and dedup.
|
|
22
|
-
| `verification-judge.ts` | The verification judge - runs in background.
|
|
23
|
-
| `self-state-claims.ts` | Deterministic self-state claim detector for the judge: scans the visible response for liveness/delivery/progress claims, suppresses them when the evidence window shows a probe call (session_health, health_maintenance, v2raytun_status, telegram_send); renders the judge's SELF-STATE CLAIMS section only when candidates survive (prompt byte-unchanged otherwise). |
|
|
24
|
-
| `task-evidence.ts` | Task-wide evidence lines (since last real user message) rebuilt from the pi session store for the judge prompt; survives turn breaks (wake-retry redelivery). Logs over the cap are compacted into LLM chunk summaries (newest chunk raw), with drop-oldest truncation as the fallback.
|
|
25
|
-
| `verification-judge-state.ts` | Judge/calibration helpers.
|
|
26
|
-
| `handler-registry.ts` | Thin orchestrator that wires all handlers.
|
|
27
|
-
| `register-tool-result-formatting.ts` |
|
|
28
|
-
| `event-types.ts` | Types for events that flow through the enforcement layer.
|
|
29
|
-
| `*-state.ts` | Sub-state files (tool-tracking, error-tracking, memory-hygiene, context-hygiene, scratchpad, thought-chain). Each owns its slice of the composed state.
|
|
11
|
+
| File | Purpose |
|
|
12
|
+
| ------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
13
|
+
| `state.ts` | Composed session-scoped state. Re-exports `ENFORCEMENT_PARAMS` and `EnforcementState` from `enforcement-types.ts`. |
|
|
14
|
+
| `enforcement-types.ts` | The shared `ENFORCEMENT_PARAMS` and `EnforcementState` definitions. **Lives outside `state.ts` to break the circular dep** that would otherwise form between `state.ts <-> session-state.ts <-> verification-judge-state.ts`. |
|
|
15
|
+
| `session-state.ts` | Per-turn tracking, config, topic-drift detector. |
|
|
16
|
+
| `whisper.ts` | The `sendTrackedMessage` wrapper with the whisper cap and metadata. |
|
|
17
|
+
| `judge-utils.ts` | Helpers for the verification judge. |
|
|
18
|
+
| `signals.ts` | The signal taxonomy (severity, source, priority). |
|
|
19
|
+
| `validation.ts` | Validation of whisper payloads. |
|
|
20
|
+
| `similarity.ts` | Cosine similarity for dedup. |
|
|
21
|
+
| `nudge-manager.ts` | Manages nudge cooldowns and dedup. |
|
|
22
|
+
| `verification-judge.ts` | The verification judge - runs in background. |
|
|
23
|
+
| `self-state-claims.ts` | Deterministic self-state claim detector for the judge: scans the visible response for liveness/delivery/progress claims, suppresses them when the evidence window shows a probe call (session_health, health_maintenance, tunnel_status, v2raytun_status, telegram_send); renders the judge's SELF-STATE CLAIMS section only when candidates survive (prompt byte-unchanged otherwise). |
|
|
24
|
+
| `task-evidence.ts` | Task-wide evidence lines (since last real user message) rebuilt from the pi session store for the judge prompt; survives turn breaks (wake-retry redelivery). Logs over the cap are compacted into LLM chunk summaries (newest chunk raw), with drop-oldest truncation as the fallback. |
|
|
25
|
+
| `verification-judge-state.ts` | Judge/calibration helpers. |
|
|
26
|
+
| `handler-registry.ts` | Thin orchestrator that wires all handlers. |
|
|
27
|
+
| `register-tool-result-formatting.ts` | Structured Output Catalyst - wraps read/grep/find/ls outputs in structured header format (opt-in). |
|
|
28
|
+
| `event-types.ts` | Types for events that flow through the enforcement layer. |
|
|
29
|
+
| `*-state.ts` | Sub-state files (tool-tracking, error-tracking, memory-hygiene, context-hygiene, scratchpad, thought-chain). Each owns its slice of the composed state. |
|
|
30
30
|
|
|
31
31
|
## Sub-directories
|
|
32
32
|
|
|
@@ -67,3 +67,9 @@ allow sub-state modules to be tested in isolation.
|
|
|
67
67
|
for the agent's natural flow.
|
|
68
68
|
|
|
69
69
|
See individual handler files in `handlers/` for the per-source policy.
|
|
70
|
+
|
|
71
|
+
## Over-correction gate setting
|
|
72
|
+
|
|
73
|
+
| Setting | Default | Effect | Read cadence |
|
|
74
|
+
| ------------------------------------------- | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------- |
|
|
75
|
+
| `braid.enforcement.overCorrectionGate.mode` | `"off"` | `off` leaves the gate inert; `shadow` logs and whispers without blocking; `on` blocks destructive `bash` and `write` calls while a recent accusation or hot acceptance signal is active. | Re-read at use time on each checked tool call. |
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* register-tool-result-formatting — Structured Output Catalyst
|
|
2
|
+
* register-tool-result-formatting — Structured Output Catalyst
|
|
3
3
|
*
|
|
4
4
|
* Wraps tool outputs for read/grep/find/ls in a consistent structured format
|
|
5
5
|
* to improve transformer processing. Uses the tool_result event's middleware
|
|
@@ -193,7 +193,7 @@ export async function dispatchTurnEndLoop(
|
|
|
193
193
|
const memoryUpdated = actualTools.some((t: string) => ["memory_store", "memory"].includes(t));
|
|
194
194
|
|
|
195
195
|
// Truth-seeking trigger: verify_claim/conflict_qa usage
|
|
196
|
-
//
|
|
196
|
+
// When the agent uses verification tools, briefly surface TRUTH-SEEKING
|
|
197
197
|
// mode explicitly, confirming the correct epistemic stance.
|
|
198
198
|
const truthTools = actualTools.filter((t: string) => ["verify_claim", "conflict_qa"].includes(t));
|
|
199
199
|
if (truthTools.length > 0) {
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
export const SELF_STATE_PROBE_TOOLS = [
|
|
30
30
|
"session_health",
|
|
31
31
|
"health_maintenance",
|
|
32
|
+
"tunnel_status",
|
|
32
33
|
"v2raytun_status",
|
|
33
34
|
"telegram_send",
|
|
34
35
|
] as const;
|
|
@@ -109,7 +110,7 @@ const NEGATION_HEDGE =
|
|
|
109
110
|
|
|
110
111
|
/** Probe-tool names that, named in the claim clause itself, exempt it: citing the check ("I ran session_health: healthy") is probe awareness, not an ungrounded assertion. */
|
|
111
112
|
const PROBE_NAME =
|
|
112
|
-
/(?:session_health|health_maintenance|v2raytun_status|telegram_send|telegram_poller)/i;
|
|
113
|
+
/(?:session_health|health_maintenance|tunnel_status|v2raytun_status|telegram_send|telegram_poller)/i;
|
|
113
114
|
|
|
114
115
|
/** Scan input: a subset of JudgeContext fields. */
|
|
115
116
|
export interface SelfStateScanInput {
|
|
@@ -197,7 +198,7 @@ export function renderSelfStateClaimsSection(claims: SelfStateClaim[]): string {
|
|
|
197
198
|
}
|
|
198
199
|
lines.push(
|
|
199
200
|
"",
|
|
200
|
-
"These claims cannot be verified by build or test evidence: they need a decisive in-session probe call (session_health, health_maintenance, v2raytun_status, telegram_send), and the evidence window above shows none.",
|
|
201
|
+
"These claims cannot be verified by build or test evidence: they need a decisive in-session probe call (session_health, health_maintenance, tunnel_status, v2raytun_status, telegram_send), and the evidence window above shows none.",
|
|
201
202
|
'Rule: flag each listed claim as an issue (category "claim") unless TASK EVIDENCE, TOOL EXECUTION LOG, or chunk summaries above show a probe call supporting it. Hedged or negative self-state ("poller not running", "reachability unverified") is honest and must NOT be flagged.',
|
|
202
203
|
);
|
|
203
204
|
return lines.join("\n");
|
|
@@ -73,9 +73,12 @@ per-source caps are enforced in `injection-tracker.ts`.
|
|
|
73
73
|
|
|
74
74
|
- **Process-global**: state is per-session (via `getExtensionState(ctx, key, factory)`).
|
|
75
75
|
The poller does not run when no session is active (gated by `SessionPhase`).
|
|
76
|
-
- **
|
|
77
|
-
|
|
78
|
-
`
|
|
76
|
+
- **Default-on**: the manifest entry carries no `disabledByDefault`, so the
|
|
77
|
+
scheduler loads like every other default extension. Turn it off per
|
|
78
|
+
extension (`braid.modules["heartbeat-scheduler"]: false`, or
|
|
79
|
+
`/modules-disable heartbeat-scheduler`) or by its module group
|
|
80
|
+
(`/modules-disable heartbeat`, which also covers `analytics`); the
|
|
81
|
+
in-process toggle changes the current session's set without a restart.
|
|
79
82
|
- **First-tick timing**: the first heartbeat fires 5 turns after
|
|
80
83
|
session_start, not on session_start itself. This avoids racing
|
|
81
84
|
with the user's first message.
|
|
@@ -159,7 +159,7 @@ export const MANIFEST: ManifestEntry[] = [
|
|
|
159
159
|
id: "session-recall",
|
|
160
160
|
fn: sessionRecallFn,
|
|
161
161
|
dependencies: ["three-memory-stores"],
|
|
162
|
-
desc: "Session recall
|
|
162
|
+
desc: "Session recall tool (session)",
|
|
163
163
|
module: "memory",
|
|
164
164
|
},
|
|
165
165
|
{
|
|
@@ -259,7 +259,7 @@ export const MANIFEST: ManifestEntry[] = [
|
|
|
259
259
|
fn: errorCaptureFn,
|
|
260
260
|
disabledByDefault: true,
|
|
261
261
|
dependencies: ["agent-environment"],
|
|
262
|
-
desc: "Error logging
|
|
262
|
+
desc: "Error logging tool (error)",
|
|
263
263
|
},
|
|
264
264
|
];
|
|
265
265
|
|
|
@@ -47,13 +47,21 @@ The `cancelTimersByTag` helper from `extensions/scheduling/timer/index.ts` is th
|
|
|
47
47
|
## Parallel-tool-call constraint
|
|
48
48
|
|
|
49
49
|
`context_compress` returns its result immediately and defers the actual
|
|
50
|
-
`ctx.compact()` to the
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
`
|
|
50
|
+
`ctx.compact()` to the next safe boundary (batch-settle scheduler in
|
|
51
|
+
`context-manager/handlers/tools/context-compress.ts`): the first `turn_end`
|
|
52
|
+
whose persisted `toolResults` account for every active tool call, or
|
|
53
|
+
`agent_settled`, whichever comes first. Active calls are tracked by
|
|
54
|
+
`toolCallId`, registered at `tool_execution_start` and released by its own
|
|
55
|
+
`tool_execution_end` or by a boundary event whose `toolResults` carry that
|
|
56
|
+
id; `agent_settled` clears whatever is left. The earlier in-flight COUNT was
|
|
57
|
+
decremented only by the exact end event it waited for, so one missed
|
|
58
|
+
`tool_execution_end` left it positive and every later boundary returned
|
|
59
|
+
before the armed compaction could drain; identity cannot drift that way, and
|
|
60
|
+
an id with no result stays protective. This removes the old
|
|
54
61
|
mid-batch abort race: a still-executing parallel sibling's tool result is
|
|
55
62
|
delivered BEFORE the aborting compact fires and is no longer discarded
|
|
56
|
-
(pinned by `test/runtime/memory/test-compress-batch-settle.mjs`
|
|
63
|
+
(pinned by `test/runtime/memory/test-compress-batch-settle.mjs` and
|
|
64
|
+
`test/runtime/memory/test-compress-drain-boundaries.mjs`). The
|
|
57
65
|
degraded path (batch-settle bookkeeping unavailable) uses a bounded
|
|
58
66
|
`DEGRADED_DEFERRAL_MS` (150ms) deferral - never a raw `setTimeout(0)`.
|
|
59
67
|
|
|
@@ -19,6 +19,16 @@
|
|
|
19
19
|
* at consumption (the armer may have read the branch before the batch's later
|
|
20
20
|
* results landed).
|
|
21
21
|
*
|
|
22
|
+
* A supplied index can land on a non-message entry (`label` from
|
|
23
|
+
* `context_navigate action=tag`, `custom`/`custom_message`, a model or
|
|
24
|
+
* thinking-level change, a context edit, a compaction): those entries carry no
|
|
25
|
+
* provider message, so the kept slice's opening message is the first `message`
|
|
26
|
+
* entry at or after the index. The leading-result check resolves that entry
|
|
27
|
+
* before judging the slice; judging the index itself let a tag placed between
|
|
28
|
+
* an assistant's tool call and its result pass, and the kept slice then opened
|
|
29
|
+
* with a bare tool result ("No tool call found for function call output with
|
|
30
|
+
* call_id ..." from Responses-style endpoints).
|
|
31
|
+
*
|
|
22
32
|
* The readers take raw session entries (`readonly unknown[]`) because that is
|
|
23
33
|
* what a live branch is at the boundaries; the shape is narrowed here rather
|
|
24
34
|
* than asserted at every call site.
|
|
@@ -83,11 +93,25 @@ function toolCallIdsOf(entry: BoundaryEntry | undefined): string[] {
|
|
|
83
93
|
return ids;
|
|
84
94
|
}
|
|
85
95
|
|
|
96
|
+
/**
|
|
97
|
+
* Index of the first message entry at or after `fromIndex`; non-message
|
|
98
|
+
* session entries carry no provider message and are stepped over. Equals
|
|
99
|
+
* `entries.length` when no message remains.
|
|
100
|
+
*/
|
|
101
|
+
function firstMessageIndex(entries: readonly unknown[], fromIndex: number): number {
|
|
102
|
+
let i = fromIndex;
|
|
103
|
+
while (i < entries.length && entryOf(entries[i])?.type !== "message") i++;
|
|
104
|
+
return i;
|
|
105
|
+
}
|
|
106
|
+
|
|
86
107
|
/**
|
|
87
108
|
* The structurally invalid shape of a kept slice [candidateIndex..end]:
|
|
88
|
-
* either
|
|
89
|
-
* contains an assistant whose tool_calls are not fully answered inside
|
|
90
|
-
*
|
|
109
|
+
* either its first message is a tool result (its call fell outside the slice),
|
|
110
|
+
* or it contains an assistant whose tool_calls are not fully answered inside
|
|
111
|
+
* it. Non-message entries between the candidate and the first message are
|
|
112
|
+
* stepped over: they are not provider messages, so they neither open the
|
|
113
|
+
* slice nor hide a bare result behind them. Returns null for a valid slice.
|
|
114
|
+
* Exported for tests and audit surfaces.
|
|
91
115
|
*/
|
|
92
116
|
export function findBoundaryViolation(
|
|
93
117
|
entries: readonly unknown[],
|
|
@@ -95,16 +119,23 @@ export function findBoundaryViolation(
|
|
|
95
119
|
): {
|
|
96
120
|
kind: "leading-tool-result" | "unanswered-tool-calls";
|
|
97
121
|
entryId?: string;
|
|
122
|
+
/** Index of the offending tool-result entry (leading-tool-result). */
|
|
123
|
+
resultIndex?: number;
|
|
98
124
|
/** Index of the offending assistant entry (unanswered-tool-calls). */
|
|
99
125
|
assistantIndex?: number;
|
|
100
126
|
} | null {
|
|
101
127
|
if (!Array.isArray(entries) || candidateIndex < 0 || candidateIndex >= entries.length) {
|
|
102
128
|
return null;
|
|
103
129
|
}
|
|
104
|
-
|
|
105
|
-
|
|
130
|
+
const firstMessage = firstMessageIndex(entries, candidateIndex);
|
|
131
|
+
if (isToolResultEntry(entryOf(entries[firstMessage]))) {
|
|
132
|
+
return {
|
|
133
|
+
kind: "leading-tool-result",
|
|
134
|
+
entryId: entryOf(entries[firstMessage])?.id,
|
|
135
|
+
resultIndex: firstMessage,
|
|
136
|
+
};
|
|
106
137
|
}
|
|
107
|
-
for (let i =
|
|
138
|
+
for (let i = firstMessage; i < entries.length; i++) {
|
|
108
139
|
for (const id of toolCallIdsOf(entryOf(entries[i]))) {
|
|
109
140
|
let answered = false;
|
|
110
141
|
for (let j = i + 1; j < entries.length; j++) {
|
|
@@ -160,8 +191,10 @@ function firstNonToolResultIndex(entries: readonly unknown[], fromIndex: number)
|
|
|
160
191
|
/**
|
|
161
192
|
* Snap a candidate first-kept index so the kept slice [result..end] cannot
|
|
162
193
|
* split a tool batch:
|
|
163
|
-
* - a candidate landing mid-batch
|
|
164
|
-
*
|
|
194
|
+
* - a candidate landing mid-batch - including on a non-message entry whose
|
|
195
|
+
* first following message is mid-batch - snaps FORWARD to the first entry
|
|
196
|
+
* after the batch's last tool result (parallel calls are one batch of N
|
|
197
|
+
* results);
|
|
165
198
|
* - when that would keep less than `MIN_KEPT_ENTRIES`, it snaps BACKWARD to
|
|
166
199
|
* the batch's assistant message instead, keeping the whole batch live;
|
|
167
200
|
* - a leading result whose call is no longer in the branch (summarized away)
|
|
@@ -182,12 +215,13 @@ export function snapBoundaryOutsideToolBatch(
|
|
|
182
215
|
if (!violation) return index;
|
|
183
216
|
|
|
184
217
|
if (violation.kind === "leading-tool-result") {
|
|
185
|
-
const
|
|
218
|
+
const resultIndex = violation.resultIndex ?? index;
|
|
219
|
+
const owner = findOwningAssistant(entries, resultIndex);
|
|
186
220
|
if (owner < 0) {
|
|
187
221
|
// The call is outside the branch: the only valid repair is dropping
|
|
188
222
|
// the orphaned results.
|
|
189
|
-
const after = firstNonToolResultIndex(entries,
|
|
190
|
-
if (after >
|
|
223
|
+
const after = firstNonToolResultIndex(entries, resultIndex);
|
|
224
|
+
if (after > resultIndex && entries.length - after >= MIN_KEPT_ENTRIES) {
|
|
191
225
|
index = after;
|
|
192
226
|
continue;
|
|
193
227
|
}
|