agent-recall-core 3.4.20 → 3.4.22
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/dist/helpers/journal-files.d.ts +23 -0
- package/dist/helpers/journal-files.d.ts.map +1 -1
- package/dist/helpers/journal-files.js +99 -0
- package/dist/helpers/journal-files.js.map +1 -1
- package/dist/index.d.ts +11 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -1
- package/dist/index.js.map +1 -1
- package/dist/palace/index-manager.d.ts.map +1 -1
- package/dist/palace/index-manager.js +33 -28
- package/dist/palace/index-manager.js.map +1 -1
- package/dist/palace/rooms.d.ts +21 -3
- package/dist/palace/rooms.d.ts.map +1 -1
- package/dist/palace/rooms.js +74 -10
- package/dist/palace/rooms.js.map +1 -1
- package/dist/storage/behavior-policies.d.ts +54 -0
- package/dist/storage/behavior-policies.d.ts.map +1 -0
- package/dist/storage/behavior-policies.js +98 -0
- package/dist/storage/behavior-policies.js.map +1 -0
- package/dist/storage/cwd-allowlist.d.ts +33 -0
- package/dist/storage/cwd-allowlist.d.ts.map +1 -0
- package/dist/storage/cwd-allowlist.js +106 -0
- package/dist/storage/cwd-allowlist.js.map +1 -0
- package/dist/storage/dream-health.d.ts +19 -0
- package/dist/storage/dream-health.d.ts.map +1 -0
- package/dist/storage/dream-health.js +79 -0
- package/dist/storage/dream-health.js.map +1 -0
- package/dist/storage/project.d.ts +6 -0
- package/dist/storage/project.d.ts.map +1 -1
- package/dist/storage/project.js +26 -1
- package/dist/storage/project.js.map +1 -1
- package/dist/tools-logic/check-action.d.ts +55 -0
- package/dist/tools-logic/check-action.d.ts.map +1 -0
- package/dist/tools-logic/check-action.js +152 -0
- package/dist/tools-logic/check-action.js.map +1 -0
- package/dist/tools-logic/palace-write.d.ts.map +1 -1
- package/dist/tools-logic/palace-write.js +9 -2
- package/dist/tools-logic/palace-write.js.map +1 -1
- package/dist/tools-logic/project-status.d.ts.map +1 -1
- package/dist/tools-logic/project-status.js +30 -0
- package/dist/tools-logic/project-status.js.map +1 -1
- package/dist/tools-logic/register-rule.d.ts +15 -0
- package/dist/tools-logic/register-rule.d.ts.map +1 -0
- package/dist/tools-logic/register-rule.js +13 -0
- package/dist/tools-logic/register-rule.js.map +1 -0
- package/dist/tools-logic/session-start.d.ts +24 -0
- package/dist/tools-logic/session-start.d.ts.map +1 -1
- package/dist/tools-logic/session-start.js +124 -18
- package/dist/tools-logic/session-start.js.map +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/types.js +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Behavior policies — high-salience, always-loaded IF-THEN rules.
|
|
3
|
+
*
|
|
4
|
+
* Solves item 6 of the real-usage feedback brief: a user mid-session taught
|
|
5
|
+
* the agent "humans use voice-to-text → reorganize before acting." The agent
|
|
6
|
+
* had no tool to register this as a permanent behavior rule; it could only
|
|
7
|
+
* save it as an insight string that might or might not surface again.
|
|
8
|
+
*
|
|
9
|
+
* Storage: ~/.agent-recall/projects/<slug>/palace/behavior-policies.json
|
|
10
|
+
* Shape: { rules: [{ id, name, when, do, created, hits }] }
|
|
11
|
+
*
|
|
12
|
+
* Always-loaded at session_start with HIGH salience (above regular insights).
|
|
13
|
+
* These are behavior commitments, not facts — they police what the agent does,
|
|
14
|
+
* not what it knows.
|
|
15
|
+
*/
|
|
16
|
+
export interface BehaviorRule {
|
|
17
|
+
id: string;
|
|
18
|
+
name: string;
|
|
19
|
+
/** Trigger condition — when this rule applies. */
|
|
20
|
+
when: string;
|
|
21
|
+
/** Required action — what to do when triggered. */
|
|
22
|
+
do: string;
|
|
23
|
+
/** ISO timestamp of creation. */
|
|
24
|
+
created: string;
|
|
25
|
+
/** Times this rule was retrieved at session_start. Monotonic counter. */
|
|
26
|
+
hits: number;
|
|
27
|
+
}
|
|
28
|
+
export interface BehaviorPoliciesFile {
|
|
29
|
+
rules: BehaviorRule[];
|
|
30
|
+
}
|
|
31
|
+
export declare function readBehaviorPolicies(slug: string): BehaviorPoliciesFile;
|
|
32
|
+
export interface RegisterRuleInput {
|
|
33
|
+
project: string;
|
|
34
|
+
name: string;
|
|
35
|
+
when: string;
|
|
36
|
+
do: string;
|
|
37
|
+
}
|
|
38
|
+
export interface RegisterRuleResult {
|
|
39
|
+
success: boolean;
|
|
40
|
+
rule_id?: string;
|
|
41
|
+
total_rules?: number;
|
|
42
|
+
error?: string;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Register a new behavior policy. Idempotent: if a rule with the same name +
|
|
46
|
+
* when + do already exists, returns the existing rule_id instead of duplicating.
|
|
47
|
+
*/
|
|
48
|
+
export declare function registerBehaviorRule(input: RegisterRuleInput): RegisterRuleResult;
|
|
49
|
+
/**
|
|
50
|
+
* Increment the `hits` counter on every rule. Called from session_start when
|
|
51
|
+
* rules are loaded — lets us see which rules are "alive" via dashboard later.
|
|
52
|
+
*/
|
|
53
|
+
export declare function recordPolicyLoad(slug: string): void;
|
|
54
|
+
//# sourceMappingURL=behavior-policies.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"behavior-policies.d.ts","sourceRoot":"","sources":["../../src/storage/behavior-policies.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAOH,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,kDAAkD;IAClD,IAAI,EAAE,MAAM,CAAC;IACb,mDAAmD;IACnD,EAAE,EAAE,MAAM,CAAC;IACX,iCAAiC;IACjC,OAAO,EAAE,MAAM,CAAC;IAChB,yEAAyE;IACzE,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,oBAAoB;IACnC,KAAK,EAAE,YAAY,EAAE,CAAC;CACvB;AAUD,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,oBAAoB,CAWvE;AAED,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;CACZ;AAED,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,iBAAiB,GAAG,kBAAkB,CAgCjF;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAcnD"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Behavior policies — high-salience, always-loaded IF-THEN rules.
|
|
3
|
+
*
|
|
4
|
+
* Solves item 6 of the real-usage feedback brief: a user mid-session taught
|
|
5
|
+
* the agent "humans use voice-to-text → reorganize before acting." The agent
|
|
6
|
+
* had no tool to register this as a permanent behavior rule; it could only
|
|
7
|
+
* save it as an insight string that might or might not surface again.
|
|
8
|
+
*
|
|
9
|
+
* Storage: ~/.agent-recall/projects/<slug>/palace/behavior-policies.json
|
|
10
|
+
* Shape: { rules: [{ id, name, when, do, created, hits }] }
|
|
11
|
+
*
|
|
12
|
+
* Always-loaded at session_start with HIGH salience (above regular insights).
|
|
13
|
+
* These are behavior commitments, not facts — they police what the agent does,
|
|
14
|
+
* not what it knows.
|
|
15
|
+
*/
|
|
16
|
+
import * as fs from "node:fs";
|
|
17
|
+
import * as path from "node:path";
|
|
18
|
+
import { palaceDir } from "./paths.js";
|
|
19
|
+
import { ensureDir } from "./fs-utils.js";
|
|
20
|
+
function policyPath(slug) {
|
|
21
|
+
return path.join(palaceDir(slug), "behavior-policies.json");
|
|
22
|
+
}
|
|
23
|
+
function newRuleId() {
|
|
24
|
+
return "rule_" + Date.now().toString(36) + "_" + Math.random().toString(36).slice(2, 8);
|
|
25
|
+
}
|
|
26
|
+
export function readBehaviorPolicies(slug) {
|
|
27
|
+
const p = policyPath(slug);
|
|
28
|
+
if (!fs.existsSync(p))
|
|
29
|
+
return { rules: [] };
|
|
30
|
+
try {
|
|
31
|
+
const raw = fs.readFileSync(p, "utf-8");
|
|
32
|
+
const parsed = JSON.parse(raw);
|
|
33
|
+
if (!parsed || !Array.isArray(parsed.rules))
|
|
34
|
+
return { rules: [] };
|
|
35
|
+
return parsed;
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
return { rules: [] };
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Register a new behavior policy. Idempotent: if a rule with the same name +
|
|
43
|
+
* when + do already exists, returns the existing rule_id instead of duplicating.
|
|
44
|
+
*/
|
|
45
|
+
export function registerBehaviorRule(input) {
|
|
46
|
+
const name = (input.name ?? "").trim();
|
|
47
|
+
const when = (input.when ?? "").trim();
|
|
48
|
+
const doField = (input.do ?? "").trim();
|
|
49
|
+
if (!name)
|
|
50
|
+
return { success: false, error: "name required" };
|
|
51
|
+
if (!when)
|
|
52
|
+
return { success: false, error: "when (trigger) required" };
|
|
53
|
+
if (!doField)
|
|
54
|
+
return { success: false, error: "do (required action) required" };
|
|
55
|
+
const current = readBehaviorPolicies(input.project);
|
|
56
|
+
const existing = current.rules.find((r) => r.name === name && r.when === when && r.do === doField);
|
|
57
|
+
if (existing) {
|
|
58
|
+
return { success: true, rule_id: existing.id, total_rules: current.rules.length };
|
|
59
|
+
}
|
|
60
|
+
const rule = {
|
|
61
|
+
id: newRuleId(),
|
|
62
|
+
name,
|
|
63
|
+
when,
|
|
64
|
+
do: doField,
|
|
65
|
+
created: new Date().toISOString(),
|
|
66
|
+
hits: 0,
|
|
67
|
+
};
|
|
68
|
+
const next = { rules: [...current.rules, rule] };
|
|
69
|
+
const dir = palaceDir(input.project);
|
|
70
|
+
ensureDir(dir);
|
|
71
|
+
const target = policyPath(input.project);
|
|
72
|
+
const tmp = `${target}.tmp.${process.pid}.${Date.now()}`;
|
|
73
|
+
fs.writeFileSync(tmp, JSON.stringify(next, null, 2), { encoding: "utf-8", mode: 0o600 });
|
|
74
|
+
fs.renameSync(tmp, target);
|
|
75
|
+
return { success: true, rule_id: rule.id, total_rules: next.rules.length };
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Increment the `hits` counter on every rule. Called from session_start when
|
|
79
|
+
* rules are loaded — lets us see which rules are "alive" via dashboard later.
|
|
80
|
+
*/
|
|
81
|
+
export function recordPolicyLoad(slug) {
|
|
82
|
+
const current = readBehaviorPolicies(slug);
|
|
83
|
+
if (current.rules.length === 0)
|
|
84
|
+
return;
|
|
85
|
+
const next = {
|
|
86
|
+
rules: current.rules.map((r) => ({ ...r, hits: r.hits + 1 })),
|
|
87
|
+
};
|
|
88
|
+
const target = policyPath(slug);
|
|
89
|
+
try {
|
|
90
|
+
const tmp = `${target}.tmp.${process.pid}.${Date.now()}`;
|
|
91
|
+
fs.writeFileSync(tmp, JSON.stringify(next, null, 2), { encoding: "utf-8", mode: 0o600 });
|
|
92
|
+
fs.renameSync(tmp, target);
|
|
93
|
+
}
|
|
94
|
+
catch {
|
|
95
|
+
// best-effort — counter loss is acceptable
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=behavior-policies.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"behavior-policies.js","sourceRoot":"","sources":["../../src/storage/behavior-policies.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAmB1C,SAAS,UAAU,CAAC,IAAY;IAC9B,O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zF,EAAE,CAAC,UAAU,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;IAC7B,CAAC;IAAC,MAAM,CAAC;QACP,2CAA2C;IAC7C,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* cwd-allowlist — explicit per-project mapping from working directory to slug.
|
|
3
|
+
*
|
|
4
|
+
* Solves the wrong-project-routing bug: when an agent runs in
|
|
5
|
+
* `~/Projects/prismma-web`, name-based detection used to load the `prismma`
|
|
6
|
+
* (video-gen) project instead of `prismma-gateway`. The allowlist gives an
|
|
7
|
+
* explicit "if cwd starts with any of these paths → use this slug" mapping
|
|
8
|
+
* that wins over git/package.json/cwd-basename heuristics.
|
|
9
|
+
*
|
|
10
|
+
* Storage: ~/.agent-recall/projects/<slug>/palace/cwd-allowlist.json
|
|
11
|
+
* Shape: { "paths": ["/abs/path/one", "/abs/path/two"] }
|
|
12
|
+
* Migration: file is auto-created on first explicit session_start; existing
|
|
13
|
+
* projects without one continue to use the old heuristics.
|
|
14
|
+
*/
|
|
15
|
+
export interface CwdAllowlist {
|
|
16
|
+
paths: string[];
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Read the cwd-allowlist for a single project. Returns empty if missing.
|
|
20
|
+
*/
|
|
21
|
+
export declare function readCwdAllowlist(slug: string): CwdAllowlist;
|
|
22
|
+
/**
|
|
23
|
+
* Atomically add an absolute path to the project's cwd-allowlist (idempotent).
|
|
24
|
+
* Normalizes the path (trailing slash removed).
|
|
25
|
+
*/
|
|
26
|
+
export declare function addCwdToAllowlist(slug: string, cwdPath: string): void;
|
|
27
|
+
/**
|
|
28
|
+
* Scan every project's allowlist; return the slug whose allowlist contains a
|
|
29
|
+
* path that is a prefix of (or equal to) `cwd`. Longest-prefix wins so nested
|
|
30
|
+
* allowlists resolve correctly. Returns null when nothing matches.
|
|
31
|
+
*/
|
|
32
|
+
export declare function findProjectByCwd(cwd: string): string | null;
|
|
33
|
+
//# sourceMappingURL=cwd-allowlist.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cwd-allowlist.d.ts","sourceRoot":"","sources":["../../src/storage/cwd-allowlist.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAQH,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,MAAM,EAAE,CAAC;CACjB;AAsBD;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,CAW3D;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAarE;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAqB3D"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* cwd-allowlist — explicit per-project mapping from working directory to slug.
|
|
3
|
+
*
|
|
4
|
+
* Solves the wrong-project-routing bug: when an agent runs in
|
|
5
|
+
* `~/Projects/prismma-web`, name-based detection used to load the `prismma`
|
|
6
|
+
* (video-gen) project instead of `prismma-gateway`. The allowlist gives an
|
|
7
|
+
* explicit "if cwd starts with any of these paths → use this slug" mapping
|
|
8
|
+
* that wins over git/package.json/cwd-basename heuristics.
|
|
9
|
+
*
|
|
10
|
+
* Storage: ~/.agent-recall/projects/<slug>/palace/cwd-allowlist.json
|
|
11
|
+
* Shape: { "paths": ["/abs/path/one", "/abs/path/two"] }
|
|
12
|
+
* Migration: file is auto-created on first explicit session_start; existing
|
|
13
|
+
* projects without one continue to use the old heuristics.
|
|
14
|
+
*/
|
|
15
|
+
import * as fs from "node:fs";
|
|
16
|
+
import * as path from "node:path";
|
|
17
|
+
import { getRoot } from "../types.js";
|
|
18
|
+
import { palaceDir } from "./paths.js";
|
|
19
|
+
import { ensureDir } from "./fs-utils.js";
|
|
20
|
+
/**
|
|
21
|
+
* Normalize a filesystem path for stable matching:
|
|
22
|
+
* - Resolve symlinks (handles macOS /tmp → /private/tmp)
|
|
23
|
+
* - Strip trailing slash
|
|
24
|
+
* Falls back to the input if realpath fails (path doesn't exist yet).
|
|
25
|
+
*/
|
|
26
|
+
function normalizePath(p) {
|
|
27
|
+
let normalized = p;
|
|
28
|
+
try {
|
|
29
|
+
normalized = fs.realpathSync(p);
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
// path may not exist on disk yet; use the literal string
|
|
33
|
+
}
|
|
34
|
+
return normalized.replace(/\/+$/, "");
|
|
35
|
+
}
|
|
36
|
+
function allowlistPath(slug) {
|
|
37
|
+
return path.join(palaceDir(slug), "cwd-allowlist.json");
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Read the cwd-allowlist for a single project. Returns empty if missing.
|
|
41
|
+
*/
|
|
42
|
+
export function readCwdAllowlist(slug) {
|
|
43
|
+
const p = allowlistPath(slug);
|
|
44
|
+
if (!fs.existsSync(p))
|
|
45
|
+
return { paths: [] };
|
|
46
|
+
try {
|
|
47
|
+
const raw = fs.readFileSync(p, "utf-8");
|
|
48
|
+
const parsed = JSON.parse(raw);
|
|
49
|
+
if (!parsed || !Array.isArray(parsed.paths))
|
|
50
|
+
return { paths: [] };
|
|
51
|
+
return { paths: parsed.paths.filter((s) => typeof s === "string" && s.startsWith("/")) };
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
return { paths: [] };
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Atomically add an absolute path to the project's cwd-allowlist (idempotent).
|
|
59
|
+
* Normalizes the path (trailing slash removed).
|
|
60
|
+
*/
|
|
61
|
+
export function addCwdToAllowlist(slug, cwdPath) {
|
|
62
|
+
if (!cwdPath || !cwdPath.startsWith("/"))
|
|
63
|
+
return;
|
|
64
|
+
const normalized = normalizePath(cwdPath);
|
|
65
|
+
const current = readCwdAllowlist(slug);
|
|
66
|
+
if (current.paths.includes(normalized))
|
|
67
|
+
return;
|
|
68
|
+
const next = { paths: [...current.paths, normalized].sort() };
|
|
69
|
+
const dir = palaceDir(slug);
|
|
70
|
+
ensureDir(dir);
|
|
71
|
+
const target = allowlistPath(slug);
|
|
72
|
+
// Atomic write — tmp + rename
|
|
73
|
+
const tmp = `${target}.tmp.${process.pid}.${Date.now()}`;
|
|
74
|
+
fs.writeFileSync(tmp, JSON.stringify(next, null, 2), { encoding: "utf-8", mode: 0o600 });
|
|
75
|
+
fs.renameSync(tmp, target);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Scan every project's allowlist; return the slug whose allowlist contains a
|
|
79
|
+
* path that is a prefix of (or equal to) `cwd`. Longest-prefix wins so nested
|
|
80
|
+
* allowlists resolve correctly. Returns null when nothing matches.
|
|
81
|
+
*/
|
|
82
|
+
export function findProjectByCwd(cwd) {
|
|
83
|
+
if (!cwd || !cwd.startsWith("/"))
|
|
84
|
+
return null;
|
|
85
|
+
const normalized = normalizePath(cwd);
|
|
86
|
+
const root = getRoot();
|
|
87
|
+
const projectsDir = path.join(root, "projects");
|
|
88
|
+
if (!fs.existsSync(projectsDir))
|
|
89
|
+
return null;
|
|
90
|
+
let bestMatch = null;
|
|
91
|
+
for (const entry of fs.readdirSync(projectsDir)) {
|
|
92
|
+
if (entry.startsWith("_archived_") || entry.startsWith("."))
|
|
93
|
+
continue;
|
|
94
|
+
const list = readCwdAllowlist(entry);
|
|
95
|
+
for (const p of list.paths) {
|
|
96
|
+
// Exact match OR cwd lives strictly under p
|
|
97
|
+
if (normalized === p || normalized.startsWith(p + "/")) {
|
|
98
|
+
if (!bestMatch || p.length > bestMatch.prefixLength) {
|
|
99
|
+
bestMatch = { slug: entry, prefixLength: p.length };
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return bestMatch?.slug ?? null;
|
|
105
|
+
}
|
|
106
|
+
//# sourceMappingURL=cwd-allowlist.js.map
|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0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dream health — count consecutive failure days from AAM dream logs.
|
|
3
|
+
*
|
|
4
|
+
* Solves the "silent cron failures rot for days" pain: dream auth has been
|
|
5
|
+
* failing for 6 consecutive nights but only surfaces in stray `arstatus` output,
|
|
6
|
+
* never at session_start. This helper lets session_start emit a red banner.
|
|
7
|
+
*
|
|
8
|
+
* Log location: ~/.aam/dreams/run-YYYY-MM-DD.log (AAM-orchestrated dreams)
|
|
9
|
+
* Pattern: a day's log "succeeded" if it contains "Dream complete" or
|
|
10
|
+
* "Dream run complete"; otherwise it "failed".
|
|
11
|
+
*/
|
|
12
|
+
export interface DreamHealth {
|
|
13
|
+
consecutive_failures: number;
|
|
14
|
+
last_failed_date: string | null;
|
|
15
|
+
last_success_date: string | null;
|
|
16
|
+
banner: string | null;
|
|
17
|
+
}
|
|
18
|
+
export declare function getDreamHealth(): DreamHealth;
|
|
19
|
+
//# sourceMappingURL=dream-health.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dream-health.d.ts","sourceRoot":"","sources":["../../src/storage/dream-health.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAMH,MAAM,WAAW,WAAW;IAC1B,oBAAoB,EAAE,MAAM,CAAC;IAC7B,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,iBAAiB,EAAE,MAAM,GAAG,IAAI,CAAC;IACjC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;CACvB;AAqBD,wBAAgB,cAAc,IAAI,WAAW,CA0C5C"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dream health — count consecutive failure days from AAM dream logs.
|
|
3
|
+
*
|
|
4
|
+
* Solves the "silent cron failures rot for days" pain: dream auth has been
|
|
5
|
+
* failing for 6 consecutive nights but only surfaces in stray `arstatus` output,
|
|
6
|
+
* never at session_start. This helper lets session_start emit a red banner.
|
|
7
|
+
*
|
|
8
|
+
* Log location: ~/.aam/dreams/run-YYYY-MM-DD.log (AAM-orchestrated dreams)
|
|
9
|
+
* Pattern: a day's log "succeeded" if it contains "Dream complete" or
|
|
10
|
+
* "Dream run complete"; otherwise it "failed".
|
|
11
|
+
*/
|
|
12
|
+
import * as fs from "node:fs";
|
|
13
|
+
import * as path from "node:path";
|
|
14
|
+
import * as os from "node:os";
|
|
15
|
+
const DREAMS_DIR = path.join(os.homedir(), ".aam", "dreams");
|
|
16
|
+
const LOOKBACK_DAYS = 7;
|
|
17
|
+
const BANNER_THRESHOLD = 2; // surface when N or more consecutive failures
|
|
18
|
+
function dateNDaysAgo(n) {
|
|
19
|
+
const d = new Date();
|
|
20
|
+
d.setDate(d.getDate() - n);
|
|
21
|
+
return d.toISOString().slice(0, 10);
|
|
22
|
+
}
|
|
23
|
+
function isSuccess(logPath) {
|
|
24
|
+
try {
|
|
25
|
+
const content = fs.readFileSync(logPath, "utf-8");
|
|
26
|
+
return /Dream(?:\s+run)?\s+complete/i.test(content);
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
export function getDreamHealth() {
|
|
33
|
+
const out = {
|
|
34
|
+
consecutive_failures: 0,
|
|
35
|
+
last_failed_date: null,
|
|
36
|
+
last_success_date: null,
|
|
37
|
+
banner: null,
|
|
38
|
+
};
|
|
39
|
+
if (!fs.existsSync(DREAMS_DIR))
|
|
40
|
+
return out;
|
|
41
|
+
// Walk yesterday → 7 days ago. Today is in-progress so we don't count it.
|
|
42
|
+
for (let i = 1; i <= LOOKBACK_DAYS; i++) {
|
|
43
|
+
const dateStr = dateNDaysAgo(i);
|
|
44
|
+
const logPath = path.join(DREAMS_DIR, `run-${dateStr}.log`);
|
|
45
|
+
if (!fs.existsSync(logPath)) {
|
|
46
|
+
// No log = no run that night; treat as a failure (cron didn't fire OR
|
|
47
|
+
// it crashed before writing). Stops the streak if we'd been counting,
|
|
48
|
+
// since "no log" + "missing" are both signs of unhealthy automation.
|
|
49
|
+
if (out.last_success_date === null) {
|
|
50
|
+
out.consecutive_failures++;
|
|
51
|
+
if (out.last_failed_date === null)
|
|
52
|
+
out.last_failed_date = dateStr;
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
break;
|
|
56
|
+
}
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
if (isSuccess(logPath)) {
|
|
60
|
+
if (out.last_success_date === null)
|
|
61
|
+
out.last_success_date = dateStr;
|
|
62
|
+
break; // streak ended
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
out.consecutive_failures++;
|
|
66
|
+
if (out.last_failed_date === null)
|
|
67
|
+
out.last_failed_date = dateStr;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
if (out.consecutive_failures >= BANNER_THRESHOLD) {
|
|
71
|
+
const lastSuccess = out.last_success_date ?? `>${LOOKBACK_DAYS} days ago`;
|
|
72
|
+
out.banner =
|
|
73
|
+
`⚠ Dream cron failed ${out.consecutive_failures} nights in a row ` +
|
|
74
|
+
`(last success: ${lastSuccess}). The awareness backfill is broken — ` +
|
|
75
|
+
`check ~/.aam/dreams/run-${out.last_failed_date}.log for auth or network errors.`;
|
|
76
|
+
}
|
|
77
|
+
return out;
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=dream-health.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dream-health.js","sourceRoot":"","sources":["../../src/storage/dream-health.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAS9B,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC;AAC7D,MAAM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IAAI,EAAE,CAAC;gBACnC,GAAG,CAAC,oBAAoB,EAAE,CAAC;gBAC3B,IAAI,GAAG,CAAC,gBAAgB,KAAK,IAAI;oBAAE,GAAG,CAAC,gBAAgB,GAAG,OAAO,CAAC;YACpE,CAAC;iBAAM,CAAC;gBACN,MAAM;YACR,CAAC;YACD,SAAS;QACX,CAAC;QACD,IAAI,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC;YACvB,IAAI,GAAG,CAAC,iBAAiB,KAAK,IAAI;gBAAE,GAAG,CAAC,iBAAiB,GAAG,OAAO,CAAC;YACpE,MAAM,CAAE,eAAe;QACzB,CAAC;aAAM,CAAC;YACN,GAAG,CAAC,oBAAoB,EAAE,CAAC;YAC3B,IAAI,GAAG,CAAC,gBAAgB,KAAK,IAAI;gBAAE,GAAG,CAAC,gBAAgB,GAAG,OAAO,CAAC;QACpE,CAAC;IACH,CAAC;IAED,IAAI,GAAG,CAAC,oBAAoB,IAAI,gBAAgB,EAAE,CAAC;QACjD,MAAM,WAAW,GAAG,GAAG,CAAC,iBAAiB,IAAI,IAAI,aAAa,WAAW,CAAC;QAC1E,GAAG,CAAC,MAAM;YACR,uBAAuB,GAAG,CAAC,oBAAoB,mBAAmB;gBAClE,kBAAkB,WAAW,wCAAwC;gBACrE,2BAA2B,GAAG,CAAC,gBAAgB,kCAAkC,CAAC;IACtF,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -10,6 +10,12 @@ import type { ProjectInfo } from "../types.js";
|
|
|
10
10
|
export declare function detectProject(): Promise<string>;
|
|
11
11
|
/**
|
|
12
12
|
* Resolve "auto" project to actual slug.
|
|
13
|
+
*
|
|
14
|
+
* When a caller passes an explicit slug we auto-register the current cwd
|
|
15
|
+
* into that project's cwd-allowlist (idempotent), so future calls from the
|
|
16
|
+
* same directory route correctly without needing the explicit slug. This is
|
|
17
|
+
* the migration path for existing projects — the allowlist fills itself over
|
|
18
|
+
* normal use.
|
|
13
19
|
*/
|
|
14
20
|
export declare function resolveProject(project: string | undefined): Promise<string>;
|
|
15
21
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"project.d.ts","sourceRoot":"","sources":["../../src/storage/project.ts"],"names":[],"mappings":"AAAA;;GAEG;AAOH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAa/C;;;;GAIG;AACH,wBAAsB,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC,
|
|
1
|
+
{"version":3,"file":"project.d.ts","sourceRoot":"","sources":["../../src/storage/project.ts"],"names":[],"mappings":"AAAA;;GAEG;AAOH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAa/C;;;;GAIG;AACH,wBAAsB,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC,CA+ErD;AAED;;;;;;;;GAQG;AACH,wBAAsB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC,CAWjF;AAaD;;GAEG;AACH,wBAAgB,eAAe,IAAI,WAAW,EAAE,CAuD/C"}
|
package/dist/storage/project.js
CHANGED
|
@@ -25,7 +25,19 @@ export async function detectProject() {
|
|
|
25
25
|
if (process.env.AGENT_RECALL_PROJECT) {
|
|
26
26
|
return process.env.AGENT_RECALL_PROJECT;
|
|
27
27
|
}
|
|
28
|
-
// 2.
|
|
28
|
+
// 2. cwd-allowlist match — explicit per-project mapping wins over heuristics.
|
|
29
|
+
// Solves the wrong-project-routing bug where ~/Projects/prismma-web loaded
|
|
30
|
+
// `prismma` (video gen) instead of `prismma-gateway`.
|
|
31
|
+
try {
|
|
32
|
+
const { findProjectByCwd } = await import("./cwd-allowlist.js");
|
|
33
|
+
const hit = findProjectByCwd(process.cwd());
|
|
34
|
+
if (hit)
|
|
35
|
+
return hit;
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
// never let allowlist scan break detection
|
|
39
|
+
}
|
|
40
|
+
// 3. Git repo name (async)
|
|
29
41
|
try {
|
|
30
42
|
const { stdout } = await execFileAsync("git", ["config", "--get", "remote.origin.url"], { timeout: 3000 });
|
|
31
43
|
const remote = stdout.trim();
|
|
@@ -92,11 +104,24 @@ export async function detectProject() {
|
|
|
92
104
|
}
|
|
93
105
|
/**
|
|
94
106
|
* Resolve "auto" project to actual slug.
|
|
107
|
+
*
|
|
108
|
+
* When a caller passes an explicit slug we auto-register the current cwd
|
|
109
|
+
* into that project's cwd-allowlist (idempotent), so future calls from the
|
|
110
|
+
* same directory route correctly without needing the explicit slug. This is
|
|
111
|
+
* the migration path for existing projects — the allowlist fills itself over
|
|
112
|
+
* normal use.
|
|
95
113
|
*/
|
|
96
114
|
export async function resolveProject(project) {
|
|
97
115
|
if (!project || project === "auto") {
|
|
98
116
|
return await detectProject();
|
|
99
117
|
}
|
|
118
|
+
try {
|
|
119
|
+
const { addCwdToAllowlist } = await import("./cwd-allowlist.js");
|
|
120
|
+
addCwdToAllowlist(project, process.cwd());
|
|
121
|
+
}
|
|
122
|
+
catch {
|
|
123
|
+
// never let allowlist write break resolution
|
|
124
|
+
}
|
|
100
125
|
return project;
|
|
101
126
|
}
|
|
102
127
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"project.js","sourceRoot":"","sources":["../../src/storage/project.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAGrD,MAAM,aAAa,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC;AAE1C;;;GAGG;AACH,MAAM,aAAa,GAAG,IAAI,GAAG,CAAC;IAC5B,WAAW,EAAE,UAAU,EAAE,SAA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CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC;IAC9D,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* check_action — pre-action proactive matcher.
|
|
3
|
+
*
|
|
4
|
+
* Solves items 3 + 5 of the feedback brief:
|
|
5
|
+
* - "watch_for is too generic" — needs to fire when the agent is about to do
|
|
6
|
+
* something a past correction warned against, mid-session.
|
|
7
|
+
* - "no mid-session recall hook" — insights surface at startup and are
|
|
8
|
+
* forgotten by turn 20.
|
|
9
|
+
*
|
|
10
|
+
* Both pains share the same primitive: "before doing X, return matching
|
|
11
|
+
* rules / corrections / insights." This tool is that primitive.
|
|
12
|
+
*
|
|
13
|
+
* Deterministic keyword matching only (no LLM). The agent calls this before
|
|
14
|
+
* any non-trivial action; the result is a short list of relevant memory items
|
|
15
|
+
* that would otherwise have to be re-derived.
|
|
16
|
+
*/
|
|
17
|
+
export interface CheckActionInput {
|
|
18
|
+
/** What you're about to do — one sentence. Be specific. */
|
|
19
|
+
action_description: string;
|
|
20
|
+
project?: string;
|
|
21
|
+
/** Match threshold — minimum overlapping tokens to count as a hit. Default 1. */
|
|
22
|
+
min_overlap?: number;
|
|
23
|
+
}
|
|
24
|
+
export interface InsightMatch {
|
|
25
|
+
title: string;
|
|
26
|
+
confirmations: number;
|
|
27
|
+
severity: string;
|
|
28
|
+
matched_tokens: string[];
|
|
29
|
+
}
|
|
30
|
+
export interface CorrectionMatch {
|
|
31
|
+
id: string;
|
|
32
|
+
rule: string;
|
|
33
|
+
severity: "p0" | "p1";
|
|
34
|
+
date: string;
|
|
35
|
+
matched_tokens: string[];
|
|
36
|
+
}
|
|
37
|
+
export interface RuleMatch {
|
|
38
|
+
id: string;
|
|
39
|
+
name: string;
|
|
40
|
+
when: string;
|
|
41
|
+
do: string;
|
|
42
|
+
matched_tokens: string[];
|
|
43
|
+
}
|
|
44
|
+
export interface CheckActionResult {
|
|
45
|
+
success: boolean;
|
|
46
|
+
project: string;
|
|
47
|
+
action: string;
|
|
48
|
+
matching_rules: RuleMatch[];
|
|
49
|
+
matching_corrections: CorrectionMatch[];
|
|
50
|
+
matching_insights: InsightMatch[];
|
|
51
|
+
/** Ready-to-paste warning string for the agent to read before acting. */
|
|
52
|
+
warning: string | null;
|
|
53
|
+
}
|
|
54
|
+
export declare function checkAction(input: CheckActionInput): Promise<CheckActionResult>;
|
|
55
|
+
//# sourceMappingURL=check-action.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"check-action.d.ts","sourceRoot":"","sources":["../../src/tools-logic/check-action.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAOH,MAAM,WAAW,gBAAgB;IAC/B,2DAA2D;IAC3D,kBAAkB,EAAE,MAAM,CAAC;IAC3B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,iFAAiF;IACjF,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,aAAa,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,MAAM,CAAC;IACjB,cAAc,EAAE,MAAM,EAAE,CAAC;CAC1B;AAED,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,IAAI,GAAG,IAAI,CAAC;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,cAAc,EAAE,MAAM,EAAE,CAAC;CAC1B;AAED,MAAM,WAAW,SAAS;IACxB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,cAAc,EAAE,MAAM,EAAE,CAAC;CAC1B;AAED,MAAM,WAAW,i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