agent-working-memory 0.10.0 → 0.11.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/README.md +89 -19
- package/dist/adapters/common.d.ts.map +1 -1
- package/dist/adapters/common.js +5 -1
- package/dist/adapters/common.js.map +1 -1
- package/dist/api/routes.d.ts.map +1 -1
- package/dist/api/routes.js +2 -1
- package/dist/api/routes.js.map +1 -1
- package/dist/cli/migrate.js +29 -29
- package/dist/cli.js +82 -2
- package/dist/cli.js.map +1 -1
- package/dist/coordination/circuit-breaker.js +23 -23
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/mcp.js +50 -3
- package/dist/mcp.js.map +1 -1
- package/dist/onboard/index.d.ts +68 -0
- package/dist/onboard/index.d.ts.map +1 -0
- package/dist/onboard/index.js +265 -0
- package/dist/onboard/index.js.map +1 -0
- package/dist/storage/pglite-schema.js +143 -143
- package/dist/storage/postgres.js +138 -138
- package/dist/version.d.ts +2 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +27 -0
- package/dist/version.js.map +1 -0
- package/package.json +9 -1
- package/src/adapters/common.ts +5 -1
- package/src/api/index.ts +3 -3
- package/src/api/routes.ts +2 -1
- package/src/cli/migrate.ts +307 -307
- package/src/cli.ts +77 -2
- package/src/coordination/circuit-breaker.ts +83 -83
- package/src/coordination/failure-modes.ts +50 -50
- package/src/core/decay.ts +63 -63
- package/src/core/embeddings.ts +110 -110
- package/src/core/index.ts +5 -5
- package/src/core/logger.ts +36 -36
- package/src/core/ml-worker-entry.ts +194 -194
- package/src/core/ml-worker.ts +281 -281
- package/src/core/query-expander.ts +122 -122
- package/src/core/reranker.ts +119 -119
- package/src/engine/confidence.ts +120 -120
- package/src/engine/consolidation-scheduler.ts +242 -242
- package/src/engine/eval.ts +102 -102
- package/src/engine/eviction.ts +101 -101
- package/src/engine/index.ts +8 -8
- package/src/engine/retraction.ts +366 -366
- package/src/engine/staging.ts +74 -74
- package/src/index.ts +2 -1
- package/src/mcp.ts +62 -3
- package/src/onboard/index.ts +298 -0
- package/src/storage/index.ts +3 -3
- package/src/storage/pglite-schema.ts +166 -166
- package/src/storage/postgres.ts +1475 -1475
- package/src/storage/store.ts +80 -80
- package/src/types/agent.ts +67 -67
- package/src/types/checkpoint.ts +46 -46
- package/src/types/eval.ts +100 -100
- package/src/types/index.ts +6 -6
- package/src/version.ts +26 -0
package/src/cli.ts
CHANGED
|
@@ -13,10 +13,12 @@
|
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
15
|
import { readFileSync, writeFileSync, mkdirSync, existsSync } from 'node:fs';
|
|
16
|
-
import { resolve, join, dirname } from 'node:path';
|
|
16
|
+
import { resolve, join, dirname, basename } from 'node:path';
|
|
17
17
|
import { execSync } from 'node:child_process';
|
|
18
18
|
import { randomUUID } from 'node:crypto';
|
|
19
19
|
import { fileURLToPath } from 'node:url';
|
|
20
|
+
import { VERSION } from './version.js';
|
|
21
|
+
import { runOnboard, ONBOARD_SKILL } from './onboard/index.js';
|
|
20
22
|
|
|
21
23
|
const __filename = fileURLToPath(import.meta.url);
|
|
22
24
|
const __dirname = dirname(__filename);
|
|
@@ -139,6 +141,9 @@ async function setup() {
|
|
|
139
141
|
const instructionsAction = adapter.writeInstructions(ctx, skipInstructions);
|
|
140
142
|
const hooksAction = adapter.writeHooks(ctx, skipHooks);
|
|
141
143
|
|
|
144
|
+
// Seed the onboarding skill so a cold store can teach the agent how to warm itself.
|
|
145
|
+
const skillAction = await seedOnboardSkill(ctx.dbPath, ctx.agentId);
|
|
146
|
+
|
|
142
147
|
console.log(`
|
|
143
148
|
AWM configured for ${adapter.name}${isGlobal ? ' (global)' : ''}
|
|
144
149
|
|
|
@@ -147,6 +152,7 @@ AWM configured for ${adapter.name}${isGlobal ? ' (global)' : ''}
|
|
|
147
152
|
${configAction}
|
|
148
153
|
${instructionsAction}
|
|
149
154
|
${hooksAction}
|
|
155
|
+
${skillAction}
|
|
150
156
|
|
|
151
157
|
Next steps:
|
|
152
158
|
1. Restart ${adapter.name} to pick up the MCP server
|
|
@@ -352,7 +358,7 @@ async function exportMemories() {
|
|
|
352
358
|
}
|
|
353
359
|
|
|
354
360
|
const exportData = {
|
|
355
|
-
version:
|
|
361
|
+
version: VERSION,
|
|
356
362
|
exported_at: new Date().toISOString(),
|
|
357
363
|
source_backend: backend,
|
|
358
364
|
agent_filter: agentFilter,
|
|
@@ -711,6 +717,72 @@ async function migrateCmd() {
|
|
|
711
717
|
}
|
|
712
718
|
}
|
|
713
719
|
|
|
720
|
+
// ─── ONBOARD ──────────────────────────────────────
|
|
721
|
+
|
|
722
|
+
/**
|
|
723
|
+
* Seed the onboarding skill as a canonical memory (idempotent). This is what lets
|
|
724
|
+
* a cold store teach the host agent how to warm-start itself — the agent recalls
|
|
725
|
+
* the skill and follows it. Best-effort: a seeding failure never fails `awm setup`.
|
|
726
|
+
*/
|
|
727
|
+
async function seedOnboardSkill(dbPath: string, agentId: string): Promise<string> {
|
|
728
|
+
try {
|
|
729
|
+
const { store, close } = await openCliStore(dbPath);
|
|
730
|
+
try {
|
|
731
|
+
const existing = await store.findActiveMatchByConcept(agentId, ONBOARD_SKILL.concept);
|
|
732
|
+
if (existing) return 'Onboarding skill: already present';
|
|
733
|
+
await store.createEngram({
|
|
734
|
+
agentId, concept: ONBOARD_SKILL.concept, content: ONBOARD_SKILL.content,
|
|
735
|
+
tags: ONBOARD_SKILL.tags, confidence: 0.9, salience: 0.9, memoryClass: 'canonical',
|
|
736
|
+
});
|
|
737
|
+
return 'Onboarding skill: seeded (recall it on a cold store to warm-start)';
|
|
738
|
+
} finally {
|
|
739
|
+
await close();
|
|
740
|
+
}
|
|
741
|
+
} catch (e: any) {
|
|
742
|
+
return `Onboarding skill: skipped (${e?.message ?? 'store unavailable'})`;
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
function onboardCmd() {
|
|
747
|
+
const docs: string[] = [];
|
|
748
|
+
let repo: string | undefined;
|
|
749
|
+
let project = '';
|
|
750
|
+
let agentId = '';
|
|
751
|
+
let purpose: string | undefined;
|
|
752
|
+
let outDir = resolve(process.cwd(), '.awm');
|
|
753
|
+
|
|
754
|
+
for (let i = 1; i < args.length; i++) {
|
|
755
|
+
const a = args[i];
|
|
756
|
+
if (a === '--repo' && args[i + 1]) repo = args[++i];
|
|
757
|
+
else if (a === '--project' && args[i + 1]) project = args[++i];
|
|
758
|
+
else if (a === '--agent' && args[i + 1]) agentId = args[++i];
|
|
759
|
+
else if (a === '--purpose' && args[i + 1]) purpose = args[++i];
|
|
760
|
+
else if (a === '--out' && args[i + 1]) outDir = resolve(args[++i]);
|
|
761
|
+
else if (!a.startsWith('--')) docs.push(a);
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
// Default docs to the repo (or cwd) so a bare `awm onboard --repo .` works.
|
|
765
|
+
if (docs.length === 0) docs.push(repo ?? process.cwd());
|
|
766
|
+
if (!project) project = basename(repo ? resolve(repo) : (docs[0] ? resolve(docs[0]) : process.cwd()));
|
|
767
|
+
if (!agentId) agentId = project;
|
|
768
|
+
|
|
769
|
+
const { packPath, reviewPath, count } = runOnboard({ docs, repo, project, agentId, purpose, outDir });
|
|
770
|
+
console.log(`
|
|
771
|
+
AWM onboard — warm-start pack for "${project}"
|
|
772
|
+
|
|
773
|
+
Scanned: ${docs.join(', ')}${repo ? ` (+repo ${repo})` : ''}
|
|
774
|
+
Extracted: ${count} candidate memories (agent: ${agentId})
|
|
775
|
+
|
|
776
|
+
Review: ${reviewPath}
|
|
777
|
+
Pack: ${packPath}
|
|
778
|
+
|
|
779
|
+
Next:
|
|
780
|
+
1. Edit the review file / pack as needed (delete noise, answer the interview questions).
|
|
781
|
+
2. Load it: awm import ${packPath} --db <path> --dedupe
|
|
782
|
+
(embeddings backfill on the first consolidation — recall is warm immediately after)
|
|
783
|
+
`.trimEnd());
|
|
784
|
+
}
|
|
785
|
+
|
|
714
786
|
// ─── Dispatch ──────────────────────────────────────
|
|
715
787
|
|
|
716
788
|
switch (command) {
|
|
@@ -741,6 +813,9 @@ switch (command) {
|
|
|
741
813
|
case 'migrate':
|
|
742
814
|
await migrateCmd();
|
|
743
815
|
break;
|
|
816
|
+
case 'onboard':
|
|
817
|
+
onboardCmd();
|
|
818
|
+
break;
|
|
744
819
|
case '--help':
|
|
745
820
|
case '-h':
|
|
746
821
|
case undefined:
|
|
@@ -1,83 +1,83 @@
|
|
|
1
|
-
// Copyright 2026 Robert Winter / Complete Ideas
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
/**
|
|
4
|
-
* Per-worker CircuitBreaker for the coordination control layer.
|
|
5
|
-
* Prevents chronically-stale workers from poisoning the assignment queue.
|
|
6
|
-
* Part of AWM 0.8.1 — additive, no breaking changes.
|
|
7
|
-
*
|
|
8
|
-
* States:
|
|
9
|
-
* closed — normal operation
|
|
10
|
-
* open — worker blocked after FAILURE_THRESHOLD consecutive failures
|
|
11
|
-
* half_open — probe window (30s after open), allows one assignment attempt
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
import type Database from 'better-sqlite3';
|
|
15
|
-
|
|
16
|
-
export type CircuitState = 'closed' | 'open' | 'half_open';
|
|
17
|
-
|
|
18
|
-
const FAILURE_THRESHOLD = 5;
|
|
19
|
-
const HALF_OPEN_DELAY_MS = 30_000;
|
|
20
|
-
|
|
21
|
-
/** Record a worker failure. Opens the circuit when consecutive failures hit the threshold. */
|
|
22
|
-
export function recordFailure(db: Database.Database, agentId: string): void {
|
|
23
|
-
db.prepare(`
|
|
24
|
-
INSERT INTO coord_circuit_state (agent_id, consecutive_failures, last_transition_at)
|
|
25
|
-
VALUES (?, 1, datetime('now'))
|
|
26
|
-
ON CONFLICT(agent_id) DO UPDATE SET
|
|
27
|
-
consecutive_failures = consecutive_failures + 1,
|
|
28
|
-
state = CASE
|
|
29
|
-
WHEN consecutive_failures + 1 >= ${FAILURE_THRESHOLD} THEN 'open'
|
|
30
|
-
ELSE state
|
|
31
|
-
END,
|
|
32
|
-
opened_at = CASE
|
|
33
|
-
WHEN consecutive_failures + 1 >= ${FAILURE_THRESHOLD} AND (state != 'open' OR opened_at IS NULL)
|
|
34
|
-
THEN datetime('now')
|
|
35
|
-
ELSE opened_at
|
|
36
|
-
END,
|
|
37
|
-
last_transition_at = datetime('now')
|
|
38
|
-
`).run(agentId);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/** Record a worker success. Resets to closed regardless of prior state. */
|
|
42
|
-
export function recordSuccess(db: Database.Database, agentId: string): void {
|
|
43
|
-
db.prepare(`
|
|
44
|
-
INSERT INTO coord_circuit_state (agent_id, state, consecutive_failures, last_transition_at)
|
|
45
|
-
VALUES (?, 'closed', 0, datetime('now'))
|
|
46
|
-
ON CONFLICT(agent_id) DO UPDATE SET
|
|
47
|
-
state = 'closed',
|
|
48
|
-
consecutive_failures = 0,
|
|
49
|
-
opened_at = NULL,
|
|
50
|
-
last_transition_at = datetime('now')
|
|
51
|
-
`).run(agentId);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Get current circuit state for a worker.
|
|
56
|
-
* If the circuit has been open for >30s, auto-transitions to half_open.
|
|
57
|
-
*/
|
|
58
|
-
export function getState(db: Database.Database, agentId: string): CircuitState {
|
|
59
|
-
const row = db.prepare(
|
|
60
|
-
`SELECT state, opened_at FROM coord_circuit_state WHERE agent_id = ?`
|
|
61
|
-
).get(agentId) as { state: string; opened_at: string | null } | undefined;
|
|
62
|
-
|
|
63
|
-
if (!row || row.state === 'closed') return 'closed';
|
|
64
|
-
if (row.state === 'half_open') return 'half_open';
|
|
65
|
-
|
|
66
|
-
// open — check if half-open window has elapsed
|
|
67
|
-
if (row.state === 'open' && row.opened_at) {
|
|
68
|
-
const openedAt = new Date(row.opened_at.endsWith('Z') ? row.opened_at : row.opened_at + 'Z').getTime();
|
|
69
|
-
if (Date.now() - openedAt > HALF_OPEN_DELAY_MS) {
|
|
70
|
-
db.prepare(
|
|
71
|
-
`UPDATE coord_circuit_state SET state = 'half_open', last_transition_at = datetime('now') WHERE agent_id = ?`
|
|
72
|
-
).run(agentId);
|
|
73
|
-
return 'half_open';
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
return 'open';
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/** Returns true when the worker is eligible to receive an assignment. */
|
|
81
|
-
export function isAvailable(db: Database.Database, agentId: string): boolean {
|
|
82
|
-
return getState(db, agentId) !== 'open';
|
|
83
|
-
}
|
|
1
|
+
// Copyright 2026 Robert Winter / Complete Ideas
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
/**
|
|
4
|
+
* Per-worker CircuitBreaker for the coordination control layer.
|
|
5
|
+
* Prevents chronically-stale workers from poisoning the assignment queue.
|
|
6
|
+
* Part of AWM 0.8.1 — additive, no breaking changes.
|
|
7
|
+
*
|
|
8
|
+
* States:
|
|
9
|
+
* closed — normal operation
|
|
10
|
+
* open — worker blocked after FAILURE_THRESHOLD consecutive failures
|
|
11
|
+
* half_open — probe window (30s after open), allows one assignment attempt
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import type Database from 'better-sqlite3';
|
|
15
|
+
|
|
16
|
+
export type CircuitState = 'closed' | 'open' | 'half_open';
|
|
17
|
+
|
|
18
|
+
const FAILURE_THRESHOLD = 5;
|
|
19
|
+
const HALF_OPEN_DELAY_MS = 30_000;
|
|
20
|
+
|
|
21
|
+
/** Record a worker failure. Opens the circuit when consecutive failures hit the threshold. */
|
|
22
|
+
export function recordFailure(db: Database.Database, agentId: string): void {
|
|
23
|
+
db.prepare(`
|
|
24
|
+
INSERT INTO coord_circuit_state (agent_id, consecutive_failures, last_transition_at)
|
|
25
|
+
VALUES (?, 1, datetime('now'))
|
|
26
|
+
ON CONFLICT(agent_id) DO UPDATE SET
|
|
27
|
+
consecutive_failures = consecutive_failures + 1,
|
|
28
|
+
state = CASE
|
|
29
|
+
WHEN consecutive_failures + 1 >= ${FAILURE_THRESHOLD} THEN 'open'
|
|
30
|
+
ELSE state
|
|
31
|
+
END,
|
|
32
|
+
opened_at = CASE
|
|
33
|
+
WHEN consecutive_failures + 1 >= ${FAILURE_THRESHOLD} AND (state != 'open' OR opened_at IS NULL)
|
|
34
|
+
THEN datetime('now')
|
|
35
|
+
ELSE opened_at
|
|
36
|
+
END,
|
|
37
|
+
last_transition_at = datetime('now')
|
|
38
|
+
`).run(agentId);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Record a worker success. Resets to closed regardless of prior state. */
|
|
42
|
+
export function recordSuccess(db: Database.Database, agentId: string): void {
|
|
43
|
+
db.prepare(`
|
|
44
|
+
INSERT INTO coord_circuit_state (agent_id, state, consecutive_failures, last_transition_at)
|
|
45
|
+
VALUES (?, 'closed', 0, datetime('now'))
|
|
46
|
+
ON CONFLICT(agent_id) DO UPDATE SET
|
|
47
|
+
state = 'closed',
|
|
48
|
+
consecutive_failures = 0,
|
|
49
|
+
opened_at = NULL,
|
|
50
|
+
last_transition_at = datetime('now')
|
|
51
|
+
`).run(agentId);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Get current circuit state for a worker.
|
|
56
|
+
* If the circuit has been open for >30s, auto-transitions to half_open.
|
|
57
|
+
*/
|
|
58
|
+
export function getState(db: Database.Database, agentId: string): CircuitState {
|
|
59
|
+
const row = db.prepare(
|
|
60
|
+
`SELECT state, opened_at FROM coord_circuit_state WHERE agent_id = ?`
|
|
61
|
+
).get(agentId) as { state: string; opened_at: string | null } | undefined;
|
|
62
|
+
|
|
63
|
+
if (!row || row.state === 'closed') return 'closed';
|
|
64
|
+
if (row.state === 'half_open') return 'half_open';
|
|
65
|
+
|
|
66
|
+
// open — check if half-open window has elapsed
|
|
67
|
+
if (row.state === 'open' && row.opened_at) {
|
|
68
|
+
const openedAt = new Date(row.opened_at.endsWith('Z') ? row.opened_at : row.opened_at + 'Z').getTime();
|
|
69
|
+
if (Date.now() - openedAt > HALF_OPEN_DELAY_MS) {
|
|
70
|
+
db.prepare(
|
|
71
|
+
`UPDATE coord_circuit_state SET state = 'half_open', last_transition_at = datetime('now') WHERE agent_id = ?`
|
|
72
|
+
).run(agentId);
|
|
73
|
+
return 'half_open';
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return 'open';
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** Returns true when the worker is eligible to receive an assignment. */
|
|
81
|
+
export function isAvailable(db: Database.Database, agentId: string): boolean {
|
|
82
|
+
return getState(db, agentId) !== 'open';
|
|
83
|
+
}
|
|
@@ -1,50 +1,50 @@
|
|
|
1
|
-
// Copyright 2026 Robert Winter / Complete Ideas
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
/**
|
|
4
|
-
* FailureMode taxonomy and mutation-hint map for the coordination control layer.
|
|
5
|
-
* Part of AWM 0.8.1 — additive, no breaking changes.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
export enum FailureMode {
|
|
9
|
-
AGENT_STALE = 'agent_stale',
|
|
10
|
-
TIMEOUT = 'timeout',
|
|
11
|
-
OUTPUT_INVALID = 'output_invalid',
|
|
12
|
-
TEST_FAIL = 'test_fail',
|
|
13
|
-
LINT_FAIL = 'lint_fail',
|
|
14
|
-
MERGE_CONFLICT = 'merge_conflict',
|
|
15
|
-
UNKNOWN = 'unknown',
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/** Classify a failure result string into one of the known modes. */
|
|
19
|
-
export function classifyFailure(result: string | null): FailureMode {
|
|
20
|
-
if (!result) return FailureMode.UNKNOWN;
|
|
21
|
-
const r = result.toLowerCase();
|
|
22
|
-
if (r.includes('stale') || r.includes('disconnected')) return FailureMode.AGENT_STALE;
|
|
23
|
-
if (r.includes('timeout') || r.includes('timed out')) return FailureMode.TIMEOUT;
|
|
24
|
-
if (r.includes('json') || r.includes('schema') || r.includes('parse')) return FailureMode.OUTPUT_INVALID;
|
|
25
|
-
if (r.includes('test fail') || r.includes('vitest') || r.includes('jest')) return FailureMode.TEST_FAIL;
|
|
26
|
-
if (r.includes('lint') || r.includes('eslint') || r.includes('typecheck')) return FailureMode.LINT_FAIL;
|
|
27
|
-
if (r.includes('conflict')) return FailureMode.MERGE_CONFLICT;
|
|
28
|
-
return FailureMode.UNKNOWN;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Corrective guidance injected into the task description on retry.
|
|
33
|
-
* Each hint is written in the vocabulary the next worker will read.
|
|
34
|
-
*/
|
|
35
|
-
export const MUTATION_HINTS: Record<FailureMode, string> = {
|
|
36
|
-
[FailureMode.AGENT_STALE]:
|
|
37
|
-
'Previous worker disconnected before completion. Resume from last known state; check git status before re-running destructive commands.',
|
|
38
|
-
[FailureMode.TIMEOUT]:
|
|
39
|
-
'Previous attempt timed out. Break work into smaller commits; report progress every 5 minutes.',
|
|
40
|
-
[FailureMode.OUTPUT_INVALID]:
|
|
41
|
-
'Previous output failed validation. Return a single fenced code block; verify JSON parses before submitting.',
|
|
42
|
-
[FailureMode.TEST_FAIL]:
|
|
43
|
-
'Previous attempt left tests failing. Run vitest before completion; do NOT mark complete if any test fails.',
|
|
44
|
-
[FailureMode.LINT_FAIL]:
|
|
45
|
-
'Previous attempt had lint/typecheck errors. Run pnpm typecheck and pnpm lint before completion.',
|
|
46
|
-
[FailureMode.MERGE_CONFLICT]:
|
|
47
|
-
'Previous attempt left merge conflicts unresolved. git pull --rebase, resolve, then re-attempt.',
|
|
48
|
-
[FailureMode.UNKNOWN]:
|
|
49
|
-
'Previous attempt failed for an unclassified reason. Investigate the prior result before re-running.',
|
|
50
|
-
};
|
|
1
|
+
// Copyright 2026 Robert Winter / Complete Ideas
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
/**
|
|
4
|
+
* FailureMode taxonomy and mutation-hint map for the coordination control layer.
|
|
5
|
+
* Part of AWM 0.8.1 — additive, no breaking changes.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export enum FailureMode {
|
|
9
|
+
AGENT_STALE = 'agent_stale',
|
|
10
|
+
TIMEOUT = 'timeout',
|
|
11
|
+
OUTPUT_INVALID = 'output_invalid',
|
|
12
|
+
TEST_FAIL = 'test_fail',
|
|
13
|
+
LINT_FAIL = 'lint_fail',
|
|
14
|
+
MERGE_CONFLICT = 'merge_conflict',
|
|
15
|
+
UNKNOWN = 'unknown',
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** Classify a failure result string into one of the known modes. */
|
|
19
|
+
export function classifyFailure(result: string | null): FailureMode {
|
|
20
|
+
if (!result) return FailureMode.UNKNOWN;
|
|
21
|
+
const r = result.toLowerCase();
|
|
22
|
+
if (r.includes('stale') || r.includes('disconnected')) return FailureMode.AGENT_STALE;
|
|
23
|
+
if (r.includes('timeout') || r.includes('timed out')) return FailureMode.TIMEOUT;
|
|
24
|
+
if (r.includes('json') || r.includes('schema') || r.includes('parse')) return FailureMode.OUTPUT_INVALID;
|
|
25
|
+
if (r.includes('test fail') || r.includes('vitest') || r.includes('jest')) return FailureMode.TEST_FAIL;
|
|
26
|
+
if (r.includes('lint') || r.includes('eslint') || r.includes('typecheck')) return FailureMode.LINT_FAIL;
|
|
27
|
+
if (r.includes('conflict')) return FailureMode.MERGE_CONFLICT;
|
|
28
|
+
return FailureMode.UNKNOWN;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Corrective guidance injected into the task description on retry.
|
|
33
|
+
* Each hint is written in the vocabulary the next worker will read.
|
|
34
|
+
*/
|
|
35
|
+
export const MUTATION_HINTS: Record<FailureMode, string> = {
|
|
36
|
+
[FailureMode.AGENT_STALE]:
|
|
37
|
+
'Previous worker disconnected before completion. Resume from last known state; check git status before re-running destructive commands.',
|
|
38
|
+
[FailureMode.TIMEOUT]:
|
|
39
|
+
'Previous attempt timed out. Break work into smaller commits; report progress every 5 minutes.',
|
|
40
|
+
[FailureMode.OUTPUT_INVALID]:
|
|
41
|
+
'Previous output failed validation. Return a single fenced code block; verify JSON parses before submitting.',
|
|
42
|
+
[FailureMode.TEST_FAIL]:
|
|
43
|
+
'Previous attempt left tests failing. Run vitest before completion; do NOT mark complete if any test fails.',
|
|
44
|
+
[FailureMode.LINT_FAIL]:
|
|
45
|
+
'Previous attempt had lint/typecheck errors. Run pnpm typecheck and pnpm lint before completion.',
|
|
46
|
+
[FailureMode.MERGE_CONFLICT]:
|
|
47
|
+
'Previous attempt left merge conflicts unresolved. git pull --rebase, resolve, then re-attempt.',
|
|
48
|
+
[FailureMode.UNKNOWN]:
|
|
49
|
+
'Previous attempt failed for an unclassified reason. Investigate the prior result before re-running.',
|
|
50
|
+
};
|
package/src/core/decay.ts
CHANGED
|
@@ -1,63 +1,63 @@
|
|
|
1
|
-
// Copyright 2026 Robert Winter / Complete Ideas
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
/**
|
|
4
|
-
* ACT-R Base-Level Activation
|
|
5
|
-
*
|
|
6
|
-
* Based on Anderson's ACT-R cognitive architecture (1993).
|
|
7
|
-
* Memories that are accessed more recently and more frequently
|
|
8
|
-
* have higher activation — a well-established model of human memory.
|
|
9
|
-
*
|
|
10
|
-
* Formula: B(M) = ln(n + 1) - d * ln(ageDays / (n + 1))
|
|
11
|
-
*
|
|
12
|
-
* Where:
|
|
13
|
-
* n = access count
|
|
14
|
-
* d = decay exponent (default 0.5)
|
|
15
|
-
* ageDays = age of memory in days
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
export function baseLevelActivation(
|
|
19
|
-
accessCount: number,
|
|
20
|
-
ageDays: number,
|
|
21
|
-
decayExponent: number = 0.5
|
|
22
|
-
): number {
|
|
23
|
-
const n = Math.max(accessCount, 0);
|
|
24
|
-
const age = Math.max(ageDays, 0.001); // Avoid log(0)
|
|
25
|
-
return Math.log(n + 1) - decayExponent * Math.log(age / (n + 1));
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Softplus — smooth approximation of ReLU.
|
|
30
|
-
* Used to keep activation scores positive without hard clipping.
|
|
31
|
-
*/
|
|
32
|
-
export function softplus(x: number): number {
|
|
33
|
-
return Math.log(1 + Math.exp(x));
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Composite activation score combining content match, temporal decay,
|
|
38
|
-
* Hebbian boost, and confidence.
|
|
39
|
-
*
|
|
40
|
-
* Score = contentMatch * softplus(B(M) + scale * hebbianBoost) * confidence
|
|
41
|
-
*/
|
|
42
|
-
export function compositeScore(params: {
|
|
43
|
-
contentMatch: number;
|
|
44
|
-
accessCount: number;
|
|
45
|
-
ageDays: number;
|
|
46
|
-
hebbianBoost: number;
|
|
47
|
-
confidence: number;
|
|
48
|
-
decayExponent?: number;
|
|
49
|
-
hebbianScale?: number;
|
|
50
|
-
}): number {
|
|
51
|
-
const {
|
|
52
|
-
contentMatch,
|
|
53
|
-
accessCount,
|
|
54
|
-
ageDays,
|
|
55
|
-
hebbianBoost,
|
|
56
|
-
confidence,
|
|
57
|
-
decayExponent = 0.5,
|
|
58
|
-
hebbianScale = 1.0,
|
|
59
|
-
} = params;
|
|
60
|
-
|
|
61
|
-
const bm = baseLevelActivation(accessCount, ageDays, decayExponent);
|
|
62
|
-
return contentMatch * softplus(bm + hebbianScale * hebbianBoost) * confidence;
|
|
63
|
-
}
|
|
1
|
+
// Copyright 2026 Robert Winter / Complete Ideas
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
/**
|
|
4
|
+
* ACT-R Base-Level Activation
|
|
5
|
+
*
|
|
6
|
+
* Based on Anderson's ACT-R cognitive architecture (1993).
|
|
7
|
+
* Memories that are accessed more recently and more frequently
|
|
8
|
+
* have higher activation — a well-established model of human memory.
|
|
9
|
+
*
|
|
10
|
+
* Formula: B(M) = ln(n + 1) - d * ln(ageDays / (n + 1))
|
|
11
|
+
*
|
|
12
|
+
* Where:
|
|
13
|
+
* n = access count
|
|
14
|
+
* d = decay exponent (default 0.5)
|
|
15
|
+
* ageDays = age of memory in days
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
export function baseLevelActivation(
|
|
19
|
+
accessCount: number,
|
|
20
|
+
ageDays: number,
|
|
21
|
+
decayExponent: number = 0.5
|
|
22
|
+
): number {
|
|
23
|
+
const n = Math.max(accessCount, 0);
|
|
24
|
+
const age = Math.max(ageDays, 0.001); // Avoid log(0)
|
|
25
|
+
return Math.log(n + 1) - decayExponent * Math.log(age / (n + 1));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Softplus — smooth approximation of ReLU.
|
|
30
|
+
* Used to keep activation scores positive without hard clipping.
|
|
31
|
+
*/
|
|
32
|
+
export function softplus(x: number): number {
|
|
33
|
+
return Math.log(1 + Math.exp(x));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Composite activation score combining content match, temporal decay,
|
|
38
|
+
* Hebbian boost, and confidence.
|
|
39
|
+
*
|
|
40
|
+
* Score = contentMatch * softplus(B(M) + scale * hebbianBoost) * confidence
|
|
41
|
+
*/
|
|
42
|
+
export function compositeScore(params: {
|
|
43
|
+
contentMatch: number;
|
|
44
|
+
accessCount: number;
|
|
45
|
+
ageDays: number;
|
|
46
|
+
hebbianBoost: number;
|
|
47
|
+
confidence: number;
|
|
48
|
+
decayExponent?: number;
|
|
49
|
+
hebbianScale?: number;
|
|
50
|
+
}): number {
|
|
51
|
+
const {
|
|
52
|
+
contentMatch,
|
|
53
|
+
accessCount,
|
|
54
|
+
ageDays,
|
|
55
|
+
hebbianBoost,
|
|
56
|
+
confidence,
|
|
57
|
+
decayExponent = 0.5,
|
|
58
|
+
hebbianScale = 1.0,
|
|
59
|
+
} = params;
|
|
60
|
+
|
|
61
|
+
const bm = baseLevelActivation(accessCount, ageDays, decayExponent);
|
|
62
|
+
return contentMatch * softplus(bm + hebbianScale * hebbianBoost) * confidence;
|
|
63
|
+
}
|