agent-recall-core 3.4.18 → 3.4.21
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 +404 -981
- package/dist/index.d.ts +45 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +33 -1
- package/dist/index.js.map +1 -1
- package/dist/naming.d.ts +109 -0
- package/dist/naming.d.ts.map +1 -0
- package/dist/naming.js +198 -0
- package/dist/naming.js.map +1 -0
- package/dist/palace/awareness.d.ts +6 -0
- package/dist/palace/awareness.d.ts.map +1 -1
- package/dist/palace/awareness.js +19 -0
- package/dist/palace/awareness.js.map +1 -1
- package/dist/palace/fsrs.d.ts +64 -0
- package/dist/palace/fsrs.d.ts.map +1 -0
- package/dist/palace/fsrs.js +86 -0
- package/dist/palace/fsrs.js.map +1 -0
- package/dist/palace/hopfield.d.ts +108 -0
- package/dist/palace/hopfield.d.ts.map +1 -0
- package/dist/palace/hopfield.js +237 -0
- package/dist/palace/hopfield.js.map +1 -0
- package/dist/palace/obsidian.d.ts.map +1 -1
- package/dist/palace/obsidian.js +25 -1
- package/dist/palace/obsidian.js.map +1 -1
- package/dist/palace/pipeline.d.ts +61 -0
- package/dist/palace/pipeline.d.ts.map +1 -0
- package/dist/palace/pipeline.js +289 -0
- package/dist/palace/pipeline.js.map +1 -0
- package/dist/palace/skills.d.ts +71 -0
- package/dist/palace/skills.d.ts.map +1 -0
- package/dist/palace/skills.js +225 -0
- package/dist/palace/skills.js.map +1 -0
- 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/corrections.d.ts +54 -0
- package/dist/storage/corrections.d.ts.map +1 -1
- package/dist/storage/corrections.js +93 -4
- package/dist/storage/corrections.js.map +1 -1
- 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/paths.d.ts +12 -0
- package/dist/storage/paths.d.ts.map +1 -1
- package/dist/storage/paths.js +37 -15
- package/dist/storage/paths.js.map +1 -1
- 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/storage/session.d.ts.map +1 -1
- package/dist/storage/session.js +16 -1
- package/dist/storage/session.js.map +1 -1
- package/dist/tools-logic/bootstrap.d.ts.map +1 -1
- package/dist/tools-logic/bootstrap.js +69 -6
- package/dist/tools-logic/bootstrap.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/dashboard-export.d.ts +75 -0
- package/dist/tools-logic/dashboard-export.d.ts.map +1 -0
- package/dist/tools-logic/dashboard-export.js +271 -0
- package/dist/tools-logic/dashboard-export.js.map +1 -0
- package/dist/tools-logic/pipeline-close.d.ts +22 -0
- package/dist/tools-logic/pipeline-close.d.ts.map +1 -0
- package/dist/tools-logic/pipeline-close.js +66 -0
- package/dist/tools-logic/pipeline-close.js.map +1 -0
- package/dist/tools-logic/pipeline-current.d.ts +11 -0
- package/dist/tools-logic/pipeline-current.d.ts.map +1 -0
- package/dist/tools-logic/pipeline-current.js +8 -0
- package/dist/tools-logic/pipeline-current.js.map +1 -0
- package/dist/tools-logic/pipeline-list.d.ts +11 -0
- package/dist/tools-logic/pipeline-list.d.ts.map +1 -0
- package/dist/tools-logic/pipeline-list.js +8 -0
- package/dist/tools-logic/pipeline-list.js.map +1 -0
- package/dist/tools-logic/pipeline-open.d.ts +23 -0
- package/dist/tools-logic/pipeline-open.d.ts.map +1 -0
- package/dist/tools-logic/pipeline-open.js +109 -0
- package/dist/tools-logic/pipeline-open.js.map +1 -0
- package/dist/tools-logic/pipeline-show.d.ts +34 -0
- package/dist/tools-logic/pipeline-show.d.ts.map +1 -0
- package/dist/tools-logic/pipeline-show.js +134 -0
- package/dist/tools-logic/pipeline-show.js.map +1 -0
- 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-end-reflect.d.ts +57 -0
- package/dist/tools-logic/session-end-reflect.d.ts.map +1 -0
- package/dist/tools-logic/session-end-reflect.js +117 -0
- package/dist/tools-logic/session-end-reflect.js.map +1 -0
- package/dist/tools-logic/session-end.d.ts +29 -0
- package/dist/tools-logic/session-end.d.ts.map +1 -1
- package/dist/tools-logic/session-end.js +34 -0
- package/dist/tools-logic/session-end.js.map +1 -1
- package/dist/tools-logic/session-start-lite.d.ts +26 -0
- package/dist/tools-logic/session-start-lite.d.ts.map +1 -0
- package/dist/tools-logic/session-start-lite.js +46 -0
- package/dist/tools-logic/session-start-lite.js.map +1 -0
- package/dist/tools-logic/session-start.d.ts +26 -0
- package/dist/tools-logic/session-start.d.ts.map +1 -1
- package/dist/tools-logic/session-start.js +53 -7
- package/dist/tools-logic/session-start.js.map +1 -1
- package/dist/tools-logic/skill-list.d.ts +19 -0
- package/dist/tools-logic/skill-list.d.ts.map +1 -0
- package/dist/tools-logic/skill-list.js +20 -0
- package/dist/tools-logic/skill-list.js.map +1 -0
- package/dist/tools-logic/skill-recall.d.ts +26 -0
- package/dist/tools-logic/skill-recall.d.ts.map +1 -0
- package/dist/tools-logic/skill-recall.js +32 -0
- package/dist/tools-logic/skill-recall.js.map +1 -0
- package/dist/tools-logic/skill-write.d.ts +23 -0
- package/dist/tools-logic/skill-write.d.ts.map +1 -0
- package/dist/tools-logic/skill-write.js +46 -0
- package/dist/tools-logic/skill-write.js.map +1 -0
- package/dist/types.d.ts +1 -1
- package/dist/types.js +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,152 @@
|
|
|
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
|
+
import { resolveProject } from "../storage/project.js";
|
|
18
|
+
import { readActiveCorrections } from "./../storage/corrections.js";
|
|
19
|
+
import { readBehaviorPolicies } from "../storage/behavior-policies.js";
|
|
20
|
+
import { readAwarenessState } from "../palace/awareness.js";
|
|
21
|
+
const STOPWORDS = new Set([
|
|
22
|
+
"the", "a", "an", "and", "or", "but", "is", "are", "was", "were", "be", "been",
|
|
23
|
+
"being", "have", "has", "had", "do", "does", "did", "will", "would", "should",
|
|
24
|
+
"could", "may", "might", "must", "shall", "can", "to", "of", "in", "on", "at",
|
|
25
|
+
"by", "for", "with", "about", "against", "between", "into", "through", "during",
|
|
26
|
+
"before", "after", "above", "below", "from", "up", "down", "out", "off", "over",
|
|
27
|
+
"under", "again", "further", "then", "once", "here", "there", "when", "where",
|
|
28
|
+
"why", "how", "all", "any", "both", "each", "few", "more", "most", "other",
|
|
29
|
+
"some", "such", "no", "nor", "not", "only", "own", "same", "so", "than", "too",
|
|
30
|
+
"very", "this", "that", "these", "those", "i", "you", "he", "she", "it", "we",
|
|
31
|
+
"they", "them", "their", "what", "which", "who", "whom", "whose", "as", "if",
|
|
32
|
+
"my", "your", "our", "let", "lets", "going", "make", "made", "go", "want", "need",
|
|
33
|
+
]);
|
|
34
|
+
function tokenize(s) {
|
|
35
|
+
return new Set(s
|
|
36
|
+
.toLowerCase()
|
|
37
|
+
.normalize("NFKD")
|
|
38
|
+
.replace(/[^a-z0-9\s\-]+/g, " ")
|
|
39
|
+
.split(/\s+/)
|
|
40
|
+
.filter((w) => w.length >= 3 && !STOPWORDS.has(w)));
|
|
41
|
+
}
|
|
42
|
+
function overlap(a, b) {
|
|
43
|
+
const hits = [];
|
|
44
|
+
for (const t of a)
|
|
45
|
+
if (b.has(t))
|
|
46
|
+
hits.push(t);
|
|
47
|
+
return hits.sort();
|
|
48
|
+
}
|
|
49
|
+
export async function checkAction(input) {
|
|
50
|
+
const slug = await resolveProject(input.project);
|
|
51
|
+
const action = (input.action_description ?? "").trim();
|
|
52
|
+
if (!action) {
|
|
53
|
+
return {
|
|
54
|
+
success: false,
|
|
55
|
+
project: slug,
|
|
56
|
+
action: "",
|
|
57
|
+
matching_rules: [],
|
|
58
|
+
matching_corrections: [],
|
|
59
|
+
matching_insights: [],
|
|
60
|
+
warning: null,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
// Default min_overlap=2 — with a populated awareness store, 1-token matches
|
|
64
|
+
// produce too many false positives (single common word in dozens of insights
|
|
65
|
+
// → noise). 2 requires the action and the memory item to share at least two
|
|
66
|
+
// distinct content words, which is the right floor for relevance.
|
|
67
|
+
const minOverlap = input.min_overlap && input.min_overlap > 0 ? input.min_overlap : 2;
|
|
68
|
+
const actionTokens = tokenize(action);
|
|
69
|
+
// 1. Behavior rules — match on rule.when + rule.do + rule.name
|
|
70
|
+
const ruleMatches = [];
|
|
71
|
+
const rules = readBehaviorPolicies(slug).rules;
|
|
72
|
+
for (const r of rules) {
|
|
73
|
+
const ruleTokens = tokenize(`${r.name} ${r.when} ${r.do}`);
|
|
74
|
+
const matched = overlap(actionTokens, ruleTokens);
|
|
75
|
+
if (matched.length >= minOverlap) {
|
|
76
|
+
ruleMatches.push({ id: r.id, name: r.name, when: r.when, do: r.do, matched_tokens: matched });
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
// 2. Corrections — match on rule + context
|
|
80
|
+
const correctionMatches = [];
|
|
81
|
+
const corrections = readActiveCorrections(slug);
|
|
82
|
+
for (const c of corrections) {
|
|
83
|
+
const cTokens = tokenize(`${c.rule} ${c.context} ${(c.tags ?? []).join(" ")}`);
|
|
84
|
+
const matched = overlap(actionTokens, cTokens);
|
|
85
|
+
if (matched.length >= minOverlap) {
|
|
86
|
+
correctionMatches.push({
|
|
87
|
+
id: c.id,
|
|
88
|
+
rule: c.rule,
|
|
89
|
+
severity: c.severity,
|
|
90
|
+
date: c.date,
|
|
91
|
+
matched_tokens: matched,
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
// 3. Insights — match on insight.title
|
|
96
|
+
const insightMatches = [];
|
|
97
|
+
const awareness = readAwarenessState();
|
|
98
|
+
for (const i of awareness?.topInsights ?? []) {
|
|
99
|
+
const iTokens = tokenize(i.title);
|
|
100
|
+
const matched = overlap(actionTokens, iTokens);
|
|
101
|
+
if (matched.length >= minOverlap) {
|
|
102
|
+
insightMatches.push({
|
|
103
|
+
title: i.title,
|
|
104
|
+
confirmations: i.confirmations ?? 1,
|
|
105
|
+
severity: i.severity ?? "important",
|
|
106
|
+
matched_tokens: matched,
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
// Sort each by relevance (matched_tokens.length DESC, then severity)
|
|
111
|
+
ruleMatches.sort((a, b) => b.matched_tokens.length - a.matched_tokens.length);
|
|
112
|
+
correctionMatches.sort((a, b) => {
|
|
113
|
+
if (a.severity !== b.severity)
|
|
114
|
+
return a.severity === "p0" ? -1 : 1;
|
|
115
|
+
return b.matched_tokens.length - a.matched_tokens.length;
|
|
116
|
+
});
|
|
117
|
+
insightMatches.sort((a, b) => {
|
|
118
|
+
if (b.matched_tokens.length !== a.matched_tokens.length) {
|
|
119
|
+
return b.matched_tokens.length - a.matched_tokens.length;
|
|
120
|
+
}
|
|
121
|
+
return b.confirmations - a.confirmations;
|
|
122
|
+
});
|
|
123
|
+
// Cap to keep output small
|
|
124
|
+
const topRules = ruleMatches.slice(0, 5);
|
|
125
|
+
const topCorrections = correctionMatches.slice(0, 5);
|
|
126
|
+
const topInsights = insightMatches.slice(0, 3);
|
|
127
|
+
// Build human-readable warning if anything matched
|
|
128
|
+
let warning = null;
|
|
129
|
+
if (topRules.length + topCorrections.length + topInsights.length > 0) {
|
|
130
|
+
const parts = [`Before "${action.slice(0, 80)}":`];
|
|
131
|
+
for (const r of topRules) {
|
|
132
|
+
parts.push(` 📜 RULE [${r.name}] WHEN ${r.when} → DO ${r.do}`);
|
|
133
|
+
}
|
|
134
|
+
for (const c of topCorrections) {
|
|
135
|
+
parts.push(` ⛔ ${c.severity.toUpperCase()} (${c.date}): ${c.rule}`);
|
|
136
|
+
}
|
|
137
|
+
for (const i of topInsights) {
|
|
138
|
+
parts.push(` 💡 [${i.confirmations}×] ${i.title}`);
|
|
139
|
+
}
|
|
140
|
+
warning = parts.join("\n");
|
|
141
|
+
}
|
|
142
|
+
return {
|
|
143
|
+
success: true,
|
|
144
|
+
project: slug,
|
|
145
|
+
action,
|
|
146
|
+
matching_rules: topRules,
|
|
147
|
+
matching_corrections: topCorrections,
|
|
148
|
+
matching_insights: topInsights,
|
|
149
|
+
warning,
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
//# sourceMappingURL=check-action.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"check-action.js","sourceRoot":"","sources":["../../src/tools-logic/check-action.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,cAAc,E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G,CAAC,EAAE,CAAC;QACrE,MAAM,KAAK,GAAa,CAAC,WAAW,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC;QAC7D,KAAK,MAAM,CAAC,IAAI,QAAQ,EAAE,CAAC;YACzB,KAAK,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,IAAI,UAAU,CAAC,CAAC,IAAI,SAAS,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QAClE,CAAC;QACD,KAAK,MAAM,CAAC,IAAI,cAAc,EAAE,CAAC;YAC/B,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,QAAQ,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC,IAAI,MAAM,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;QACvE,CAAC;QACD,KAAK,MAAM,CAAC,IAAI,WAAW,EAAE,CAAC;YAC5B,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,aAAa,MAAM,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC;QACtD,CAAC;QACD,OAAO,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC7B,CAAC;IAED,OAAO;QACL,OAAO,EAAE,IAAI;QACb,OAAO,EAAE,IAAI;QACb,MAAM;QACN,cAAc,EAAE,QAAQ;QACxB,oBAAoB,EAAE,cAAc;QACpC,iBAAiB,EAAE,WAAW;QAC9B,OAAO;KACR,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* dashboard_export — V8 finding: AgentRecall's dashboard is human-only HTML.
|
|
3
|
+
* No structured view the agent can fetch to inspect its own memory in one call.
|
|
4
|
+
*
|
|
5
|
+
* This tool emits ~/.agent-recall/dashboard.json — stable schema, all-projects
|
|
6
|
+
* snapshot, suitable for both the HTML dashboard (consumed via fetch) and any
|
|
7
|
+
* agent wanting a one-call self-inspection of memory state.
|
|
8
|
+
*/
|
|
9
|
+
import { type CorrectionKPI } from "../storage/corrections.js";
|
|
10
|
+
import { type MilestoneSummary } from "../palace/pipeline.js";
|
|
11
|
+
import { type NamingIndexEntry } from "../naming.js";
|
|
12
|
+
export interface DashboardProjectSnapshot {
|
|
13
|
+
slug: string;
|
|
14
|
+
total_sessions: number;
|
|
15
|
+
first_session: string | null;
|
|
16
|
+
last_session: string | null;
|
|
17
|
+
rooms: Array<{
|
|
18
|
+
slug: string;
|
|
19
|
+
name: string;
|
|
20
|
+
salience: number;
|
|
21
|
+
updated: string;
|
|
22
|
+
topic_count: number;
|
|
23
|
+
}>;
|
|
24
|
+
skills_count: number;
|
|
25
|
+
pipeline: {
|
|
26
|
+
total: number;
|
|
27
|
+
closed: number;
|
|
28
|
+
active: number;
|
|
29
|
+
abandoned: number;
|
|
30
|
+
active_phase: string | null;
|
|
31
|
+
last_synthesis: string | null;
|
|
32
|
+
spine: MilestoneSummary[];
|
|
33
|
+
};
|
|
34
|
+
corrections: {
|
|
35
|
+
total: number;
|
|
36
|
+
p0_active: number;
|
|
37
|
+
kpis: CorrectionKPI;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Cross-project awareness insights — note: these come from the GLOBAL
|
|
41
|
+
* awareness state, not from per-project awareness. Same list appears under
|
|
42
|
+
* every project snapshot until per-project awareness is supported upstream.
|
|
43
|
+
*/
|
|
44
|
+
global_insights_top: Array<{
|
|
45
|
+
title: string;
|
|
46
|
+
confirmations: number;
|
|
47
|
+
severity: string;
|
|
48
|
+
}>;
|
|
49
|
+
}
|
|
50
|
+
export interface DashboardSnapshot {
|
|
51
|
+
generated_at: string;
|
|
52
|
+
schema_version: 1;
|
|
53
|
+
projects: DashboardProjectSnapshot[];
|
|
54
|
+
global: {
|
|
55
|
+
project_count: number;
|
|
56
|
+
awareness_insight_count: number;
|
|
57
|
+
naming_index_count: number;
|
|
58
|
+
};
|
|
59
|
+
/** Canonical naming index — every well-named file across all projects. */
|
|
60
|
+
naming_index: NamingIndexEntry[];
|
|
61
|
+
}
|
|
62
|
+
export interface DashboardExportInput {
|
|
63
|
+
format?: "json" | "both";
|
|
64
|
+
/** Optional: limit naming index size in returned payload (still written full to disk). */
|
|
65
|
+
inline_index_limit?: number;
|
|
66
|
+
}
|
|
67
|
+
export interface DashboardExportResult {
|
|
68
|
+
success: boolean;
|
|
69
|
+
json_path: string;
|
|
70
|
+
generated_at: string;
|
|
71
|
+
project_count: number;
|
|
72
|
+
snapshot: DashboardSnapshot;
|
|
73
|
+
}
|
|
74
|
+
export declare function dashboardExport(input: DashboardExportInput): Promise<DashboardExportResult>;
|
|
75
|
+
//# sourceMappingURL=dashboard-export.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dashboard-export.d.ts","sourceRoot":"","sources":["../../src/tools-logic/dashboard-export.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AA0BH,OAAO,EAA4C,KAAK,aAAa,EAAE,MAAM,2BAA2B,CAAC;AACzG,OAAO,EAAmD,KAAK,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAM/G,OAAO,EAAmB,KAAK,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAEtE,MAAM,WAAW,wBAAwB;IACvC,IAAI,EAAE,MAAM,CAAC;IACb,cAAc,EAAE,MAAM,CAAC;IACvB,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,KAAK,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACrG,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE;QACR,KAAK,EAAE,MAAM,CAAC;QACd,MAAM,EAAE,MAAM,CAAC;QACf,MAAM,EAAE,MAAM,CAAC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V8 finding: AgentRecall's dashboard is human-only HTML.
|
|
3
|
+
* No structured view the agent can fetch to inspect its own memory in one call.
|
|
4
|
+
*
|
|
5
|
+
* This tool emits ~/.agent-recall/dashboard.json — stable schema, all-projects
|
|
6
|
+
* snapshot, suitable for both the HTML dashboard (consumed via fetch) and any
|
|
7
|
+
* agent wanting a one-call self-inspection of memory state.
|
|
8
|
+
*/
|
|
9
|
+
import * as fs from "node:fs";
|
|
10
|
+
import * as path from "node:path";
|
|
11
|
+
import { getRoot } from "../types.js";
|
|
12
|
+
/**
|
|
13
|
+
* Scan for ALL projects with any memory layer (journal, palace, corrections, skills, pipeline).
|
|
14
|
+
* Stricter than listAllProjects which requires journal entries — dashboard cares about everything.
|
|
15
|
+
*/
|
|
16
|
+
function listAllProjectsForDashboard() {
|
|
17
|
+
const projectsDir = path.join(getRoot(), "projects");
|
|
18
|
+
if (!fs.existsSync(projectsDir))
|
|
19
|
+
return [];
|
|
20
|
+
const out = [];
|
|
21
|
+
for (const slug of fs.readdirSync(projectsDir)) {
|
|
22
|
+
const projectDir = path.join(projectsDir, slug);
|
|
23
|
+
if (!fs.statSync(projectDir).isDirectory())
|
|
24
|
+
continue;
|
|
25
|
+
// Include if ANY sub-dir of interest exists
|
|
26
|
+
const hasContent = ["journal", "palace", "corrections"].some((sub) => fs.existsSync(path.join(projectDir, sub)));
|
|
27
|
+
if (hasContent)
|
|
28
|
+
out.push(slug);
|
|
29
|
+
}
|
|
30
|
+
return out.sort();
|
|
31
|
+
}
|
|
32
|
+
import { listJournalFiles } from "../helpers/journal-files.js";
|
|
33
|
+
import { readActiveCorrections, getCorrectionKPIs } from "../storage/corrections.js";
|
|
34
|
+
import { listMilestones, summarize as summarizeMilestone } from "../palace/pipeline.js";
|
|
35
|
+
import { listRooms } from "../palace/rooms.js";
|
|
36
|
+
import { listSkills } from "../palace/skills.js";
|
|
37
|
+
import { readAwarenessState } from "../palace/awareness.js";
|
|
38
|
+
import { palaceDir } from "../storage/paths.js";
|
|
39
|
+
import { buildIndexEntry } from "../naming.js";
|
|
40
|
+
function countTopicsInRoom(slug, room) {
|
|
41
|
+
try {
|
|
42
|
+
const dir = path.join(palaceDir(slug), "rooms", room.slug);
|
|
43
|
+
if (!fs.existsSync(dir))
|
|
44
|
+
return 0;
|
|
45
|
+
return fs.readdirSync(dir).filter((f) => f.endsWith(".md") && f !== "README.md").length;
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
return 0;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function snapshotProject(slug) {
|
|
52
|
+
const journals = listJournalFiles(slug);
|
|
53
|
+
const dates = journals.map((j) => j.date).filter(Boolean).sort();
|
|
54
|
+
const first = dates[0] ?? null;
|
|
55
|
+
const last = dates[dates.length - 1] ?? null;
|
|
56
|
+
const rooms = listRooms(slug);
|
|
57
|
+
const milestones = listMilestones(slug);
|
|
58
|
+
const closed = milestones.filter((m) => m.meta.status === "closed");
|
|
59
|
+
const active = milestones.find((m) => m.meta.status === "active") ?? null;
|
|
60
|
+
const abandoned = milestones.filter((m) => m.meta.status === "abandoned").length;
|
|
61
|
+
const lastClosed = closed[closed.length - 1];
|
|
62
|
+
const corrections = readActiveCorrections(slug);
|
|
63
|
+
const p0Active = corrections.filter((c) => c.severity === "p0").length;
|
|
64
|
+
const kpis = getCorrectionKPIs(slug);
|
|
65
|
+
const skills = listSkills(slug);
|
|
66
|
+
// Note: readAwarenessState() returns GLOBAL awareness (not per-project).
|
|
67
|
+
// Until upstream supports per-project, every project snapshot carries the
|
|
68
|
+
// same global top. Field renamed to global_insights_top to make this honest.
|
|
69
|
+
const awareness = readAwarenessState();
|
|
70
|
+
const globalInsightsTop = (awareness?.topInsights ?? [])
|
|
71
|
+
.slice(0, 5)
|
|
72
|
+
.map((i) => ({
|
|
73
|
+
title: i.title.slice(0, 200),
|
|
74
|
+
confirmations: i.confirmations ?? 1,
|
|
75
|
+
severity: i.severity ?? "important",
|
|
76
|
+
}));
|
|
77
|
+
return {
|
|
78
|
+
slug,
|
|
79
|
+
total_sessions: journals.length,
|
|
80
|
+
first_session: first,
|
|
81
|
+
last_session: last,
|
|
82
|
+
rooms: rooms.map((r) => ({
|
|
83
|
+
slug: r.slug,
|
|
84
|
+
name: r.name,
|
|
85
|
+
salience: r.salience,
|
|
86
|
+
updated: r.updated,
|
|
87
|
+
topic_count: countTopicsInRoom(slug, r),
|
|
88
|
+
})),
|
|
89
|
+
skills_count: skills.length,
|
|
90
|
+
pipeline: {
|
|
91
|
+
total: milestones.length,
|
|
92
|
+
closed: closed.length,
|
|
93
|
+
active: active ? 1 : 0,
|
|
94
|
+
abandoned,
|
|
95
|
+
active_phase: active?.meta.phase ?? null,
|
|
96
|
+
last_synthesis: lastClosed && lastClosed.sections.synthesis && lastClosed.sections.synthesis !== "(in progress)"
|
|
97
|
+
? lastClosed.sections.synthesis
|
|
98
|
+
: null,
|
|
99
|
+
spine: milestones.map(summarizeMilestone),
|
|
100
|
+
},
|
|
101
|
+
corrections: {
|
|
102
|
+
total: corrections.length,
|
|
103
|
+
p0_active: p0Active,
|
|
104
|
+
kpis,
|
|
105
|
+
},
|
|
106
|
+
global_insights_top: globalInsightsTop,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Build the canonical naming index — includes both already-canonical files
|
|
111
|
+
* AND legacy files (journal/, palace/pipeline/, palace/skills/, corrections/),
|
|
112
|
+
* synthesizing canonical entries from legacy filenames where possible.
|
|
113
|
+
*
|
|
114
|
+
* This means agents can query the index uniformly even before migration,
|
|
115
|
+
* and the new naming grammar acts as a *view* on top of existing storage.
|
|
116
|
+
*/
|
|
117
|
+
function buildNamingIndex(snapshots) {
|
|
118
|
+
const root = getRoot();
|
|
119
|
+
const index = [];
|
|
120
|
+
for (const snap of snapshots) {
|
|
121
|
+
const projDir = path.join(root, "projects", snap.slug);
|
|
122
|
+
// 1) Pipeline (legacy NNNN-slug.md) — synthesize narrative type
|
|
123
|
+
const pipeDir = path.join(projDir, "palace", "pipeline");
|
|
124
|
+
if (fs.existsSync(pipeDir)) {
|
|
125
|
+
for (const f of fs.readdirSync(pipeDir)) {
|
|
126
|
+
if (!f.endsWith(".md") || !/^\d+-/.test(f))
|
|
127
|
+
continue;
|
|
128
|
+
const base = f.replace(/\.md$/, "");
|
|
129
|
+
const dash = base.indexOf("-");
|
|
130
|
+
const order = base.slice(0, dash);
|
|
131
|
+
const slug = base.slice(dash + 1).toLowerCase().replace(/[^a-z0-9-]/g, "-");
|
|
132
|
+
index.push({
|
|
133
|
+
canonical_path: `projects/${snap.slug}/narrative/${order.padStart(4, "0")}--${slug}.md`,
|
|
134
|
+
legacy_path: `projects/${snap.slug}/palace/pipeline/${f}`,
|
|
135
|
+
scope: "project",
|
|
136
|
+
project: snap.slug,
|
|
137
|
+
type: "narrative",
|
|
138
|
+
topic: null,
|
|
139
|
+
temporal: order.padStart(4, "0"),
|
|
140
|
+
slug,
|
|
141
|
+
updated_at: fs.statSync(path.join(pipeDir, f)).mtime.toISOString(),
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
// 2) Skills (NNNN-slug.md) — procedural
|
|
146
|
+
const skillsDir = path.join(projDir, "palace", "skills");
|
|
147
|
+
if (fs.existsSync(skillsDir)) {
|
|
148
|
+
for (const f of fs.readdirSync(skillsDir)) {
|
|
149
|
+
if (!f.endsWith(".md") || !/^\d+-/.test(f))
|
|
150
|
+
continue;
|
|
151
|
+
const base = f.replace(/\.md$/, "");
|
|
152
|
+
const dash = base.indexOf("-");
|
|
153
|
+
const order = base.slice(0, dash);
|
|
154
|
+
const slug = base.slice(dash + 1).toLowerCase().replace(/[^a-z0-9-]/g, "-");
|
|
155
|
+
index.push({
|
|
156
|
+
canonical_path: `projects/${snap.slug}/procedural/${order.padStart(4, "0")}--${slug}.md`,
|
|
157
|
+
legacy_path: `projects/${snap.slug}/palace/skills/${f}`,
|
|
158
|
+
scope: "project",
|
|
159
|
+
project: snap.slug,
|
|
160
|
+
type: "procedural",
|
|
161
|
+
topic: null,
|
|
162
|
+
temporal: order.padStart(4, "0"),
|
|
163
|
+
slug,
|
|
164
|
+
updated_at: fs.statSync(path.join(skillsDir, f)).mtime.toISOString(),
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
// 3) Journal (YYYY-MM-DD*.md) — episodic
|
|
169
|
+
const journalDir = path.join(projDir, "journal");
|
|
170
|
+
if (fs.existsSync(journalDir)) {
|
|
171
|
+
for (const f of fs.readdirSync(journalDir)) {
|
|
172
|
+
if (!f.endsWith(".md"))
|
|
173
|
+
continue;
|
|
174
|
+
const dateMatch = f.match(/^(\d{4}-\d{2}-\d{2})/);
|
|
175
|
+
if (!dateMatch)
|
|
176
|
+
continue;
|
|
177
|
+
const date = dateMatch[1];
|
|
178
|
+
const rest = f.slice(date.length).replace(/^[-_.]+|\.md$/g, "");
|
|
179
|
+
const slug = rest ? rest.toLowerCase().replace(/[^a-z0-9-]/g, "-").replace(/-+/g, "-").replace(/^-|-$/g, "") || "session" : "session";
|
|
180
|
+
index.push({
|
|
181
|
+
canonical_path: `projects/${snap.slug}/episodic/${date}--${slug}.md`,
|
|
182
|
+
legacy_path: `projects/${snap.slug}/journal/${f}`,
|
|
183
|
+
scope: "project",
|
|
184
|
+
project: snap.slug,
|
|
185
|
+
type: "episodic",
|
|
186
|
+
topic: null,
|
|
187
|
+
temporal: date,
|
|
188
|
+
slug,
|
|
189
|
+
updated_at: fs.statSync(path.join(journalDir, f)).mtime.toISOString(),
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
// 4) Corrections (YYYY-MM-DD-rule-slug.json) — correction type
|
|
194
|
+
const corrDir = path.join(projDir, "corrections");
|
|
195
|
+
if (fs.existsSync(corrDir)) {
|
|
196
|
+
for (const f of fs.readdirSync(corrDir)) {
|
|
197
|
+
if (!f.endsWith(".json"))
|
|
198
|
+
continue;
|
|
199
|
+
const m = f.match(/^(\d{4}-\d{2}-\d{2})-(.+)\.json$/);
|
|
200
|
+
if (!m)
|
|
201
|
+
continue;
|
|
202
|
+
const [, date, raw] = m;
|
|
203
|
+
const slug = raw.toLowerCase().replace(/[^a-z0-9-]/g, "-").replace(/-+/g, "-").replace(/^-|-$/g, "") || "correction";
|
|
204
|
+
index.push({
|
|
205
|
+
canonical_path: `projects/${snap.slug}/correction/${date}--${slug}.md`,
|
|
206
|
+
legacy_path: `projects/${snap.slug}/corrections/${f}`,
|
|
207
|
+
scope: "project",
|
|
208
|
+
project: snap.slug,
|
|
209
|
+
type: "correction",
|
|
210
|
+
topic: null,
|
|
211
|
+
temporal: date,
|
|
212
|
+
slug,
|
|
213
|
+
updated_at: fs.statSync(path.join(corrDir, f)).mtime.toISOString(),
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
// 5) Any already-canonical files in new dirs (forward-compat)
|
|
218
|
+
for (const sub of ["episodic", "semantic", "procedural", "narrative", "correction"]) {
|
|
219
|
+
const dir = path.join(projDir, sub);
|
|
220
|
+
if (!fs.existsSync(dir))
|
|
221
|
+
continue;
|
|
222
|
+
for (const f of fs.readdirSync(dir)) {
|
|
223
|
+
if (!f.endsWith(".md"))
|
|
224
|
+
continue;
|
|
225
|
+
const fullPath = path.relative(root, path.join(dir, f));
|
|
226
|
+
const entry = buildIndexEntry(fullPath);
|
|
227
|
+
if (entry) {
|
|
228
|
+
entry.updated_at = fs.statSync(path.join(dir, f)).mtime.toISOString();
|
|
229
|
+
index.push(entry);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
return index;
|
|
235
|
+
}
|
|
236
|
+
export async function dashboardExport(input) {
|
|
237
|
+
const root = getRoot();
|
|
238
|
+
const projects = listAllProjectsForDashboard();
|
|
239
|
+
const snapshots = projects.map(snapshotProject);
|
|
240
|
+
const namingIndex = buildNamingIndex(snapshots);
|
|
241
|
+
const awareness = readAwarenessState();
|
|
242
|
+
const snapshot = {
|
|
243
|
+
generated_at: new Date().toISOString(),
|
|
244
|
+
schema_version: 1,
|
|
245
|
+
projects: snapshots,
|
|
246
|
+
global: {
|
|
247
|
+
project_count: projects.length,
|
|
248
|
+
awareness_insight_count: (awareness?.topInsights ?? []).length,
|
|
249
|
+
naming_index_count: namingIndex.length,
|
|
250
|
+
},
|
|
251
|
+
naming_index: namingIndex,
|
|
252
|
+
};
|
|
253
|
+
const jsonPath = path.join(root, "dashboard.json");
|
|
254
|
+
// Atomic write
|
|
255
|
+
const tmp = `${jsonPath}.tmp.${process.pid}.${Date.now()}`;
|
|
256
|
+
fs.writeFileSync(tmp, JSON.stringify(snapshot, null, 2), { encoding: "utf-8", mode: 0o600 });
|
|
257
|
+
fs.renameSync(tmp, jsonPath);
|
|
258
|
+
const limit = input.inline_index_limit ?? 200;
|
|
259
|
+
const trimmed = {
|
|
260
|
+
...snapshot,
|
|
261
|
+
naming_index: snapshot.naming_index.slice(0, limit),
|
|
262
|
+
};
|
|
263
|
+
return {
|
|
264
|
+
success: true,
|
|
265
|
+
json_path: jsonPath,
|
|
266
|
+
generated_at: snapshot.generated_at,
|
|
267
|
+
project_count: projects.length,
|
|
268
|
+
snapshot: trimmed,
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
//# sourceMappingURL=dashboard-export.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dashboard-export.js","sourceRoot":"","sources":["../../src/tools-logic/dashboard-export.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAEtC;;;GAGG;AACH,SAAS,2BAA2B;IAClC,MAAM,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,UAAU,CAAC,CAAC;IACrD,IAAI,CAAC,EAAE,CAA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../palace/pipeline.js";
|
|
2
|
+
export interface PipelineCloseInput {
|
|
3
|
+
project?: string;
|
|
4
|
+
what_was_hard: string;
|
|
5
|
+
how_solved: string;
|
|
6
|
+
synthesis: string;
|
|
7
|
+
/** Final phase status. "closed" (default), "abandoned" (gave up), "pivoted" (reversed direction). */
|
|
8
|
+
status?: "closed" | "abandoned" | "pivoted";
|
|
9
|
+
related_journal?: string[];
|
|
10
|
+
related_insights?: string[];
|
|
11
|
+
}
|
|
12
|
+
export interface PipelineCloseResult {
|
|
13
|
+
success: boolean;
|
|
14
|
+
project: string;
|
|
15
|
+
order?: number;
|
|
16
|
+
phase?: string;
|
|
17
|
+
file_path?: string;
|
|
18
|
+
status?: PhaseStatus;
|
|
19
|
+
error?: string;
|
|
20
|
+
}
|
|
21
|
+
export declare function pipelineClose(input: PipelineCloseInput): Promise<PipelineCloseResult>;
|
|
22
|
+
//# sourceMappingURL=pipeline-close.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pipeline-close.d.ts","sourceRoot":"","sources":["../../src/tools-logic/pipeline-close.ts"],"names":[],"mappings":"AAIA,OAAO,EAAuC,KAAK,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAW9F,MAAM,WAAW,kBAAkB;IACjC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,qGAAqG;IACrG,MAAM,CAAC,EAAE,QAAQ,GAAG,WAAW,GAAG,SAAS,CAAC;IAC5C,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAC3B,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;CAC7B;AAED,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,wBAAsB,aAAa,CAAC,KAAK,EAAE,kBAAkB,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAuD3F"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import * as fs from "node:fs";
|
|
2
|
+
import { resolveProject } from "../storage/project.js";
|
|
3
|
+
import { withLock } from "../storage/filelock.js";
|
|
4
|
+
import { syncToSupabase } from "../supabase/sync.js";
|
|
5
|
+
import { findActiveMilestone, writeMilestone } from "../palace/pipeline.js";
|
|
6
|
+
function syncPipelineFile(filePath, project) {
|
|
7
|
+
try {
|
|
8
|
+
const content = fs.readFileSync(filePath, "utf-8");
|
|
9
|
+
syncToSupabase(filePath, content, project, "palace", "pipeline");
|
|
10
|
+
}
|
|
11
|
+
catch {
|
|
12
|
+
// Best-effort — Supabase sync failures must never break a write.
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export async function pipelineClose(input) {
|
|
16
|
+
const slug = await resolveProject(input.project);
|
|
17
|
+
const what_was_hard = (input.what_was_hard ?? "").trim();
|
|
18
|
+
const how_solved = (input.how_solved ?? "").trim();
|
|
19
|
+
const synthesis = (input.synthesis ?? "").trim();
|
|
20
|
+
if (!what_was_hard || !how_solved || !synthesis) {
|
|
21
|
+
return {
|
|
22
|
+
success: false,
|
|
23
|
+
project: slug,
|
|
24
|
+
error: "what_was_hard, how_solved, and synthesis are all required (non-empty after trim).",
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
// "pivoted" is rendered as a closed phase with a marker in synthesis;
|
|
28
|
+
// the underlying status enum is still active|closed|abandoned for parser stability.
|
|
29
|
+
const finalStatus = input.status === "abandoned" ? "abandoned" : "closed";
|
|
30
|
+
const isPivot = input.status === "pivoted";
|
|
31
|
+
return withLock(`pipeline-${slug}`, () => {
|
|
32
|
+
const active = findActiveMilestone(slug);
|
|
33
|
+
if (!active) {
|
|
34
|
+
return {
|
|
35
|
+
success: false,
|
|
36
|
+
project: slug,
|
|
37
|
+
error: "No active phase to close. Open one with pipeline_open first.",
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
const closedAt = new Date().toISOString();
|
|
41
|
+
const updatedMeta = {
|
|
42
|
+
...active.meta,
|
|
43
|
+
status: finalStatus,
|
|
44
|
+
closed: closedAt,
|
|
45
|
+
related_journal: input.related_journal ?? active.meta.related_journal,
|
|
46
|
+
related_insights: input.related_insights ?? active.meta.related_insights,
|
|
47
|
+
};
|
|
48
|
+
const sections = {
|
|
49
|
+
goal: active.sections.goal,
|
|
50
|
+
what_was_hard,
|
|
51
|
+
how_solved,
|
|
52
|
+
synthesis: isPivot ? `[pivot] ${synthesis}` : synthesis,
|
|
53
|
+
};
|
|
54
|
+
const filePath = writeMilestone(slug, updatedMeta, sections, active.file_path);
|
|
55
|
+
syncPipelineFile(filePath, slug);
|
|
56
|
+
return {
|
|
57
|
+
success: true,
|
|
58
|
+
project: slug,
|
|
59
|
+
order: active.meta.order,
|
|
60
|
+
phase: active.meta.phase,
|
|
61
|
+
file_path: filePath,
|
|
62
|
+
status: finalStatus,
|
|
63
|
+
};
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=pipeline-close.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pipeline-close.js","sourceRoot":"","sources":["../../src/tools-logic/pipeline-close.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAClD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,mBAAmB,EAAE,cAAc,EAAoB,MAAM,uBAAuB,CAAC;AAE9F,S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gBACL,OAAO,EAAE,KAAK;gBACd,OAAO,EAAE,IAAI;gBACb,KAAK,EAAE,8DAA8D;aACtE,CAAC;QACJ,CAAC;QAED,MAAM,QAAQ,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;QAC1C,MAAM,WAAW,GAAG;YAClB,GAAG,MAAM,CAAC,IAAI;YACd,MAAM,EAAE,WAAW;YACnB,MAAM,EAAE,QAAQ;YAChB,eAAe,EAAE,KAAK,CAAC,eAAe,IAAI,MAAM,CAAC,IAAI,CAAC,eAAe;YACrE,gBAAgB,EAAE,KAAK,CAAC,gBAAgB,IAAI,MAAM,CAAC,IAAI,CAAC,gBAAgB;SACzE,CAAC;QACF,MAAM,QAAQ,GAAG;YACf,IAAI,EAAE,MAAM,CAAC,QAAQ,CAAC,IAAI;YAC1B,aAAa;YACb,UAAU;YACV,SAAS,EAAE,OAAO,CAAC,CAAC,CAAC,WAAW,SAAS,EAAE,CAAC,CAAC,CAAC,SAAS;SACxD,CAAC;QACF,MAAM,QAAQ,GAAG,cAAc,CAAC,IAAI,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,CAAC,SAAS,CAAC,CAAC;QAC/E,gBAAgB,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;QAEjC,OAAO;YACL,OAAO,EAAE,IAAI;YACb,OAAO,EAAE,IAAI;YACb,KAAK,EAAE,MAAM,CAAC,IAAI,CAAC,KAAK;YACxB,KAAK,EAAE,MAAM,CAAC,IAAI,CAAC,KAAK;YACxB,SAAS,EAAE,QAAQ;YACnB,MAAM,EAAE,WAAW;SACpB,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type Milestone } from "../palace/pipeline.js";
|
|
2
|
+
export interface PipelineCurrentInput {
|
|
3
|
+
project?: string;
|
|
4
|
+
}
|
|
5
|
+
export interface PipelineCurrentResult {
|
|
6
|
+
success: boolean;
|
|
7
|
+
project: string;
|
|
8
|
+
milestone: Milestone | null;
|
|
9
|
+
}
|
|
10
|
+
export declare function pipelineCurrent(input: PipelineCurrentInput): Promise<PipelineCurrentResult>;
|
|
11
|
+
//# sourceMappingURL=pipeline-current.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pipeline-current.d.ts","sourceRoot":"","sources":["../../src/tools-logic/pipeline-current.ts"],"names":[],"mappings":"AACA,OAAO,EAAuB,KAAK,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAE5E,MAAM,WAAW,oBAAoB;IACnC,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,qBAAqB;IACpC,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,SAAS,GAAG,IAAI,CAAC;CAC7B;AAED,wBAAsB,eAAe,CAAC,KAAK,EAAE,oBAAoB,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAIjG"}
|