@phren/cli 0.3.71 → 0.3.73
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/bridge/agent-hooks.js +11 -1
- package/dist/bridge/browser-env.d.ts +5 -0
- package/dist/bridge/browser-env.js +110 -0
- package/dist/bridge/browser-protocol.d.ts +120 -0
- package/dist/bridge/browser-protocol.js +70 -0
- package/dist/bridge/browser-recordings.d.ts +63 -0
- package/dist/bridge/browser-recordings.js +148 -0
- package/dist/bridge/browser-registry.d.ts +64 -0
- package/dist/bridge/browser-registry.js +262 -0
- package/dist/bridge/browser-routes.d.ts +4 -0
- package/dist/bridge/browser-routes.js +39 -0
- package/dist/bridge/browser-shim/phren-playwright.cjs +184 -0
- package/dist/bridge/browser-socket.d.ts +2 -0
- package/dist/bridge/browser-socket.js +10 -0
- package/dist/bridge/browser-stream.d.ts +3 -0
- package/dist/bridge/browser-stream.js +129 -0
- package/dist/bridge/browser-watch.d.ts +12 -0
- package/dist/bridge/browser-watch.js +83 -0
- package/dist/bridge/claude-account-setup.js +3 -1
- package/dist/bridge/claude-accounts.d.ts +5 -1
- package/dist/bridge/claude-accounts.js +36 -6
- package/dist/bridge/codex-servers.d.ts +2 -0
- package/dist/bridge/codex-servers.js +1 -1
- package/dist/bridge/command.js +24 -5
- package/dist/bridge/dispatch-clone.d.ts +33 -0
- package/dist/bridge/dispatch-clone.js +176 -0
- package/dist/bridge/dispatch-command.d.ts +14 -0
- package/dist/bridge/dispatch-command.js +98 -13
- package/dist/bridge/dispatch-idempotency.d.ts +85 -0
- package/dist/bridge/dispatch-idempotency.js +235 -0
- package/dist/bridge/dispatch-returns.d.ts +6 -0
- package/dist/bridge/dispatch-returns.js +131 -1
- package/dist/bridge/dispatch-wait.d.ts +32 -0
- package/dist/bridge/dispatch-wait.js +177 -0
- package/dist/bridge/dispatch.d.ts +78 -2
- package/dist/bridge/dispatch.js +841 -25
- package/dist/bridge/dream-schedule.d.ts +133 -0
- package/dist/bridge/dream-schedule.js +322 -0
- package/dist/bridge/fanouts.js +20 -3
- package/dist/bridge/files.d.ts +1 -1
- package/dist/bridge/git-credential.d.ts +44 -0
- package/dist/bridge/git-credential.js +113 -0
- package/dist/bridge/git-host-auth.d.ts +9 -1
- package/dist/bridge/git-host-auth.js +18 -5
- package/dist/bridge/git-host-gitboy.js +8 -1
- package/dist/bridge/git-hosts.d.ts +12 -1
- package/dist/bridge/git-publish.js +3 -2
- package/dist/bridge/herdr.d.ts +4 -0
- package/dist/bridge/herdr.js +44 -9
- package/dist/bridge/install.d.ts +1 -1
- package/dist/bridge/install.js +12 -4
- package/dist/bridge/launch-brief.d.ts +11 -0
- package/dist/bridge/launch-brief.js +22 -0
- package/dist/bridge/launch-worktree.d.ts +2 -0
- package/dist/bridge/launch-worktree.js +5 -1
- package/dist/bridge/pane-status.js +1 -1
- package/dist/bridge/protocol.d.ts +7 -0
- package/dist/bridge/schedule-watch.js +13 -2
- package/dist/bridge/server-launch.d.ts +2 -0
- package/dist/bridge/server-launch.js +251 -145
- package/dist/bridge/server-routes.d.ts +3 -0
- package/dist/bridge/server-routes.js +33 -17
- package/dist/bridge/server-stream.d.ts +4 -0
- package/dist/bridge/server-stream.js +24 -5
- package/dist/bridge/server.js +35 -4
- package/dist/bridge/session-move.d.ts +10 -4
- package/dist/bridge/session-move.js +65 -34
- package/dist/bridge/simulator-stream.d.ts +2 -0
- package/dist/bridge/simulator-stream.js +2 -0
- package/dist/bridge/status-line-fast.d.ts +9 -0
- package/dist/bridge/status-line-fast.js +56 -0
- package/dist/bridge/tab-activity.d.ts +2 -0
- package/dist/bridge/tab-activity.js +15 -2
- package/dist/bridge/task-routes.d.ts +20 -16
- package/dist/bridge/task-routes.js +1 -1
- package/dist/bridge/terminal-herdr.d.ts +5 -1
- package/dist/bridge/terminal-herdr.js +67 -2
- package/dist/bridge/terminal-tmux.d.ts +2 -0
- package/dist/bridge/terminal-tmux.js +29 -7
- package/dist/bridge/terminal.d.ts +5 -1
- package/dist/bridge/transcript-claude.js +192 -112
- package/dist/bridge/transcript-preview.d.ts +2 -1
- package/dist/bridge/transcript-preview.js +85 -3
- package/dist/bridge/transcripts.js +17 -11
- package/dist/bridge/turn-records.js +16 -4
- package/dist/bridge/usage.d.ts +7 -1
- package/dist/bridge/usage.js +47 -31
- package/dist/bridge/worker-close.d.ts +15 -0
- package/dist/bridge/worker-close.js +304 -3
- package/dist/bridge/worker-identity.d.ts +51 -0
- package/dist/bridge/worker-identity.js +289 -0
- package/dist/bridge/worker-reports.js +15 -3
- package/dist/bridge-hook.mjs +39990 -36152
- package/dist/capabilities/mcp.js +1 -1
- package/dist/cli/browser-hint.d.ts +2 -0
- package/dist/cli/browser-hint.js +21 -0
- package/dist/cli/config-dreaming.d.ts +7 -0
- package/dist/cli/config-dreaming.js +72 -0
- package/dist/cli/config.js +6 -0
- package/dist/cli/dream.d.ts +59 -0
- package/dist/cli/dream.js +315 -0
- package/dist/cli/hooks-context.d.ts +2 -2
- package/dist/cli/hooks-context.js +3 -3
- package/dist/cli/hooks.js +20 -11
- package/dist/cli/namespaces-tasks.js +14 -0
- package/dist/cli-registry.js +28 -3
- package/dist/config/dreaming.d.ts +82 -0
- package/dist/config/dreaming.js +195 -0
- package/dist/config/resolve.js +11 -0
- package/dist/config/schema.d.ts +4 -4
- package/dist/config/schema.js +157 -1
- package/dist/content/citation-freshness.js +6 -0
- package/dist/content/learning.d.ts +1 -0
- package/dist/content/learning.js +2 -0
- package/dist/data/access.d.ts +1 -1
- package/dist/data/access.js +3 -1
- package/dist/data/task-contract.d.ts +5 -4
- package/dist/data/tasks.d.ts +5 -0
- package/dist/data/tasks.js +28 -2
- package/dist/dream/apply.d.ts +69 -0
- package/dist/dream/apply.js +372 -0
- package/dist/dream/budget.d.ts +78 -0
- package/dist/dream/budget.js +180 -0
- package/dist/dream/collect.d.ts +86 -0
- package/dist/dream/collect.js +449 -0
- package/dist/dream/eval/dream-adapter.d.ts +16 -0
- package/dist/dream/eval/dream-adapter.js +21 -0
- package/dist/dream/eval/fixture.d.ts +53 -0
- package/dist/dream/eval/fixture.js +172 -0
- package/dist/dream/eval/index.d.ts +40 -0
- package/dist/dream/eval/index.js +78 -0
- package/dist/dream/eval/score.d.ts +34 -0
- package/dist/dream/eval/score.js +99 -0
- package/dist/dream/eval/scripted-model.d.ts +19 -0
- package/dist/dream/eval/scripted-model.js +70 -0
- package/dist/dream/pages.d.ts +68 -0
- package/dist/dream/pages.js +220 -0
- package/dist/dream/privacy.d.ts +3 -0
- package/dist/dream/privacy.js +18 -0
- package/dist/dream/prompt.d.ts +13 -0
- package/dist/dream/prompt.js +84 -0
- package/dist/dream/run.d.ts +98 -0
- package/dist/dream/run.js +317 -0
- package/dist/dream/types.d.ts +74 -0
- package/dist/dream/types.js +4 -0
- package/dist/finding/lifecycle.d.ts +2 -2
- package/dist/finding/lifecycle.js +5 -2
- package/dist/finding/versions.d.ts +4 -0
- package/dist/finding/versions.js +28 -0
- package/dist/index.js +1 -0
- package/dist/modules/registry.js +10 -8
- package/dist/project-config.d.ts +3 -0
- package/dist/task/merge-links.d.ts +38 -0
- package/dist/task/merge-links.js +45 -0
- package/dist/task/reconcile.d.ts +39 -0
- package/dist/task/reconcile.js +201 -0
- package/dist/task/report-links.d.ts +10 -0
- package/dist/task/report-links.js +47 -0
- package/dist/tools/config.js +46 -4
- package/dist/tools/dispatch.js +2 -1
- package/dist/tools/dream.d.ts +3 -0
- package/dist/tools/dream.js +123 -0
- package/dist/tools/tasks.js +4 -1
- package/package.json +1 -1
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The injected layer's size, and what to demote when it is too big.
|
|
3
|
+
*
|
|
4
|
+
* What phren puts in front of every session for a project regardless of the
|
|
5
|
+
* prompt is (see `shared/retrieval.ts` and `cli/hooks.ts`):
|
|
6
|
+
* - the whole of the project's `truths.md` (canonical rows are prepended to
|
|
7
|
+
* every search for the detected project), and
|
|
8
|
+
* - the "What phren knows" block from `summary.md`, once per session, capped
|
|
9
|
+
* at 520 characters by the hook.
|
|
10
|
+
* Everything else the hook injects is chosen by relevance and already sits
|
|
11
|
+
* under its own token budget. Errors in the always-on part spread to every
|
|
12
|
+
* session, so dreaming keeps it under `dreaming.injectBudgetKB`.
|
|
13
|
+
*/
|
|
14
|
+
export interface Truth {
|
|
15
|
+
/** The truth as written, without the leading "- " and the "_(added …)_" stamp. */
|
|
16
|
+
text: string;
|
|
17
|
+
/** The full bullet line as stored, for an exact demote. */
|
|
18
|
+
line: string;
|
|
19
|
+
added?: string;
|
|
20
|
+
/** Bytes this line costs in the injected file (line plus newline). */
|
|
21
|
+
bytes: number;
|
|
22
|
+
}
|
|
23
|
+
export interface InjectedSize {
|
|
24
|
+
project: string;
|
|
25
|
+
/** Bytes of truths.md as stored; the hook injects the file as is. */
|
|
26
|
+
truthsBytes: number;
|
|
27
|
+
/** Bytes of the knows block as the hook injects it (after its trim). */
|
|
28
|
+
knowsBytes: number;
|
|
29
|
+
bytes: number;
|
|
30
|
+
kb: number;
|
|
31
|
+
truths: Truth[];
|
|
32
|
+
}
|
|
33
|
+
export interface DemotionCandidate extends Truth {
|
|
34
|
+
/** Most recent evidence that the truth was used: a lookup hit, a caller-supplied citation, or its added date. */
|
|
35
|
+
lastCited?: string;
|
|
36
|
+
}
|
|
37
|
+
export interface BudgetState {
|
|
38
|
+
project: string;
|
|
39
|
+
budgetBytes: number;
|
|
40
|
+
bytes: number;
|
|
41
|
+
over: boolean;
|
|
42
|
+
/** Bytes to free to get back under budget; 0 when under. */
|
|
43
|
+
excessBytes: number;
|
|
44
|
+
/** The shortest least-recently-cited-first prefix that, demoted, gets under budget. Empty when under. */
|
|
45
|
+
candidates: DemotionCandidate[];
|
|
46
|
+
/** Every truth, least recently cited first. */
|
|
47
|
+
ranking: DemotionCandidate[];
|
|
48
|
+
}
|
|
49
|
+
export interface OverBudgetOptions {
|
|
50
|
+
/** Extra citation dates by truth text (e.g. transcript mentions found by collect). Newer dates win. */
|
|
51
|
+
citedAt?: Map<string, string> | Record<string, string>;
|
|
52
|
+
/** Skip reading the lookup log (tests, or callers that pass citedAt themselves). */
|
|
53
|
+
skipLookupLog?: boolean;
|
|
54
|
+
}
|
|
55
|
+
export declare function parseTruths(content: string): Truth[];
|
|
56
|
+
export declare function injectedSize(store: string, project: string): InjectedSize;
|
|
57
|
+
export declare function rankTruths(store: string, project: string, truths: Truth[], opts?: OverBudgetOptions): DemotionCandidate[];
|
|
58
|
+
export declare function overBudget(store: string, project: string, budgetKB: number, opts?: OverBudgetOptions): BudgetState;
|
|
59
|
+
/**
|
|
60
|
+
* Bytes a new truth costs once `upsertCanonical` has written it: a new file is
|
|
61
|
+
* the header plus "- text _(added YYYY-MM-DD)_\n"; an existing one gets the
|
|
62
|
+
* line plus a blank-line separator inserted under "## Truths".
|
|
63
|
+
*/
|
|
64
|
+
export declare function truthCost(project: string, text: string, fileExists: boolean): number;
|
|
65
|
+
export interface PromotionCheck {
|
|
66
|
+
fits: boolean;
|
|
67
|
+
bytesBefore: number;
|
|
68
|
+
bytesAfter: number;
|
|
69
|
+
budgetBytes: number;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Whether promoting `text` to a truth keeps the injected layer under budget,
|
|
73
|
+
* counting the truths the same changeset demotes. `apply` refuses a
|
|
74
|
+
* promote_truth that does not fit.
|
|
75
|
+
*/
|
|
76
|
+
export declare function checkPromotion(store: string, project: string, budgetKB: number, text: string, demoted?: string[]): PromotionCheck;
|
|
77
|
+
/** One line for the dreaming prompt: where the injected layer stands. */
|
|
78
|
+
export declare function describeBudget(state: BudgetState): string;
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The injected layer's size, and what to demote when it is too big.
|
|
3
|
+
*
|
|
4
|
+
* What phren puts in front of every session for a project regardless of the
|
|
5
|
+
* prompt is (see `shared/retrieval.ts` and `cli/hooks.ts`):
|
|
6
|
+
* - the whole of the project's `truths.md` (canonical rows are prepended to
|
|
7
|
+
* every search for the detected project), and
|
|
8
|
+
* - the "What phren knows" block from `summary.md`, once per session, capped
|
|
9
|
+
* at 520 characters by the hook.
|
|
10
|
+
* Everything else the hook injects is chosen by relevance and already sits
|
|
11
|
+
* under its own token budget. Errors in the always-on part spread to every
|
|
12
|
+
* session, so dreaming keeps it under `dreaming.injectBudgetKB`.
|
|
13
|
+
*/
|
|
14
|
+
import * as fs from "fs";
|
|
15
|
+
import { readKnowsBlock } from "../content/summarize.js";
|
|
16
|
+
import { lookupEventsLogFile } from "../phren-paths.js";
|
|
17
|
+
import { storeAwareProjectPath } from "../store-routing.js";
|
|
18
|
+
/** The hook trims the knows block to this many characters (cli/hooks.ts). */
|
|
19
|
+
const KNOWS_INJECT_CHARS = 520;
|
|
20
|
+
/** Read at most this much of the lookup log's tail when looking for citations. */
|
|
21
|
+
const LOOKUP_TAIL_BYTES = 4 * 1024 * 1024;
|
|
22
|
+
const ADDED_RE = /\s*_\(added (\d{4}-\d{2}-\d{2})\)_\s*$/;
|
|
23
|
+
function byteLength(text) {
|
|
24
|
+
return Buffer.byteLength(text, "utf8");
|
|
25
|
+
}
|
|
26
|
+
function normalize(text) {
|
|
27
|
+
return text.replace(/\s+/g, " ").trim().toLowerCase();
|
|
28
|
+
}
|
|
29
|
+
export function parseTruths(content) {
|
|
30
|
+
const truths = [];
|
|
31
|
+
for (const line of content.split("\n")) {
|
|
32
|
+
if (!line.startsWith("- "))
|
|
33
|
+
continue;
|
|
34
|
+
const raw = line.slice(2);
|
|
35
|
+
const added = raw.match(ADDED_RE)?.[1];
|
|
36
|
+
truths.push({ text: raw.replace(ADDED_RE, "").trim(), line, added, bytes: byteLength(line) + 1 });
|
|
37
|
+
}
|
|
38
|
+
return truths;
|
|
39
|
+
}
|
|
40
|
+
function truthsPath(store, project) {
|
|
41
|
+
return storeAwareProjectPath(store, project, "truths.md");
|
|
42
|
+
}
|
|
43
|
+
export function injectedSize(store, project) {
|
|
44
|
+
const file = truthsPath(store, project);
|
|
45
|
+
let content = "";
|
|
46
|
+
try {
|
|
47
|
+
if (file)
|
|
48
|
+
content = fs.readFileSync(file, "utf8");
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
content = "";
|
|
52
|
+
}
|
|
53
|
+
let knowsBytes = 0;
|
|
54
|
+
try {
|
|
55
|
+
const knows = readKnowsBlock(store, project);
|
|
56
|
+
if (knows) {
|
|
57
|
+
const text = knows.text.length > KNOWS_INJECT_CHARS ? `${knows.text.slice(0, KNOWS_INJECT_CHARS - 1)}…` : knows.text;
|
|
58
|
+
knowsBytes = byteLength(text);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
knowsBytes = 0;
|
|
63
|
+
}
|
|
64
|
+
const truthsBytes = byteLength(content);
|
|
65
|
+
const bytes = truthsBytes + knowsBytes;
|
|
66
|
+
return { project, truthsBytes, knowsBytes, bytes, kb: Math.round((bytes / 1024) * 100) / 100, truths: parseTruths(content) };
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Latest lookup-log time at which each truth showed up in a hit's snippet for
|
|
70
|
+
* this project. The always-inject path logs the whole truths file, so only
|
|
71
|
+
* search hits that matched a truth's own words are a useful signal; a truth
|
|
72
|
+
* nobody searched into stays uncited and is demoted first.
|
|
73
|
+
*/
|
|
74
|
+
function lookupCitations(store, project, truths) {
|
|
75
|
+
const result = new Map();
|
|
76
|
+
const file = lookupEventsLogFile(store);
|
|
77
|
+
let text = "";
|
|
78
|
+
try {
|
|
79
|
+
const size = fs.statSync(file).size;
|
|
80
|
+
const start = Math.max(0, size - LOOKUP_TAIL_BYTES);
|
|
81
|
+
const fd = fs.openSync(file, "r");
|
|
82
|
+
try {
|
|
83
|
+
const buf = Buffer.alloc(size - start);
|
|
84
|
+
fs.readSync(fd, buf, 0, buf.length, start);
|
|
85
|
+
text = buf.toString("utf8");
|
|
86
|
+
}
|
|
87
|
+
finally {
|
|
88
|
+
fs.closeSync(fd);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
catch {
|
|
92
|
+
return result;
|
|
93
|
+
}
|
|
94
|
+
const keys = truths.map((t) => ({ text: t.text, key: normalize(t.text).slice(0, 60) })).filter((k) => k.key.length >= 12);
|
|
95
|
+
for (const line of text.split("\n")) {
|
|
96
|
+
if (!line.includes(project))
|
|
97
|
+
continue;
|
|
98
|
+
let event;
|
|
99
|
+
try {
|
|
100
|
+
event = JSON.parse(line);
|
|
101
|
+
}
|
|
102
|
+
catch {
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
if (event.project !== project || event.type !== "canonical" || !event.at || !event.snippet)
|
|
106
|
+
continue;
|
|
107
|
+
// A snippet carrying most of the file is the always-inject path, not a citation.
|
|
108
|
+
const snippet = normalize(event.snippet);
|
|
109
|
+
const hits = keys.filter((k) => snippet.includes(k.key));
|
|
110
|
+
if (!hits.length || (keys.length > 2 && hits.length > keys.length / 2))
|
|
111
|
+
continue;
|
|
112
|
+
for (const hit of hits) {
|
|
113
|
+
const prev = result.get(hit.text);
|
|
114
|
+
if (!prev || event.at > prev)
|
|
115
|
+
result.set(hit.text, event.at);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return result;
|
|
119
|
+
}
|
|
120
|
+
function newer(a, b) {
|
|
121
|
+
if (!a)
|
|
122
|
+
return b;
|
|
123
|
+
if (!b)
|
|
124
|
+
return a;
|
|
125
|
+
return a > b ? a : b;
|
|
126
|
+
}
|
|
127
|
+
export function rankTruths(store, project, truths, opts = {}) {
|
|
128
|
+
const looked = opts.skipLookupLog ? new Map() : lookupCitations(store, project, truths);
|
|
129
|
+
const extra = opts.citedAt instanceof Map ? opts.citedAt : new Map(Object.entries(opts.citedAt ?? {}));
|
|
130
|
+
const extraByNorm = new Map([...extra].map(([k, v]) => [normalize(k), v]));
|
|
131
|
+
return truths
|
|
132
|
+
.map((t, index) => ({ t, index, lastCited: newer(newer(t.added, looked.get(t.text)), extraByNorm.get(normalize(t.text))) }))
|
|
133
|
+
.sort((a, b) => (a.lastCited ?? "").localeCompare(b.lastCited ?? "") || b.t.bytes - a.t.bytes || a.index - b.index)
|
|
134
|
+
.map(({ t, lastCited }) => ({ ...t, lastCited }));
|
|
135
|
+
}
|
|
136
|
+
export function overBudget(store, project, budgetKB, opts = {}) {
|
|
137
|
+
const size = injectedSize(store, project);
|
|
138
|
+
const budgetBytes = Math.max(0, Math.floor(budgetKB * 1024));
|
|
139
|
+
const ranking = rankTruths(store, project, size.truths, opts);
|
|
140
|
+
const excessBytes = Math.max(0, size.bytes - budgetBytes);
|
|
141
|
+
const candidates = [];
|
|
142
|
+
let freed = 0;
|
|
143
|
+
for (const truth of ranking) {
|
|
144
|
+
if (freed >= excessBytes)
|
|
145
|
+
break;
|
|
146
|
+
candidates.push(truth);
|
|
147
|
+
freed += truth.bytes;
|
|
148
|
+
}
|
|
149
|
+
return { project, budgetBytes, bytes: size.bytes, over: excessBytes > 0, excessBytes, candidates, ranking };
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Bytes a new truth costs once `upsertCanonical` has written it: a new file is
|
|
153
|
+
* the header plus "- text _(added YYYY-MM-DD)_\n"; an existing one gets the
|
|
154
|
+
* line plus a blank-line separator inserted under "## Truths".
|
|
155
|
+
*/
|
|
156
|
+
export function truthCost(project, text, fileExists) {
|
|
157
|
+
const line = byteLength(`- ${text.replace(/^- /, "")} _(added 0000-00-00)_`);
|
|
158
|
+
return fileExists ? line + 2 : byteLength(`# ${project} Truths\n\n## Truths\n\n`) + line + 1;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Whether promoting `text` to a truth keeps the injected layer under budget,
|
|
162
|
+
* counting the truths the same changeset demotes. `apply` refuses a
|
|
163
|
+
* promote_truth that does not fit.
|
|
164
|
+
*/
|
|
165
|
+
export function checkPromotion(store, project, budgetKB, text, demoted = []) {
|
|
166
|
+
const size = injectedSize(store, project);
|
|
167
|
+
const budgetBytes = Math.max(0, Math.floor(budgetKB * 1024));
|
|
168
|
+
const gone = new Set(demoted.map((d) => normalize(d.replace(/^- /, "").replace(ADDED_RE, ""))));
|
|
169
|
+
const freed = size.truths.filter((t) => gone.has(normalize(t.text))).reduce((sum, t) => sum + t.bytes, 0);
|
|
170
|
+
const bytesAfter = size.bytes - freed + truthCost(project, text, size.truthsBytes > 0);
|
|
171
|
+
return { fits: bytesAfter <= budgetBytes, bytesBefore: size.bytes, bytesAfter, budgetBytes };
|
|
172
|
+
}
|
|
173
|
+
/** One line for the dreaming prompt: where the injected layer stands. */
|
|
174
|
+
export function describeBudget(state) {
|
|
175
|
+
const kb = (n) => (n / 1024).toFixed(1);
|
|
176
|
+
if (!state.over)
|
|
177
|
+
return `Injected layer: ${kb(state.bytes)} KB of ${kb(state.budgetBytes)} KB budget (${state.ranking.length} truths).`;
|
|
178
|
+
return `Injected layer: ${kb(state.bytes)} KB, over the ${kb(state.budgetBytes)} KB budget by ${kb(state.excessBytes)} KB. `
|
|
179
|
+
+ `Least recently cited truths: ${state.candidates.map((c) => JSON.stringify(c.text)).join("; ")}.`;
|
|
180
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
export type DreamTranscriptSource = "claude" | "codex" | "copilot" | "opencode";
|
|
2
|
+
export declare const DEFAULT_TRANSCRIPT_BUDGET_CHARS = 120000;
|
|
3
|
+
export interface DreamTranscriptRoot {
|
|
4
|
+
source: DreamTranscriptSource;
|
|
5
|
+
root: string;
|
|
6
|
+
maxDepth: number;
|
|
7
|
+
}
|
|
8
|
+
export interface DreamTranscript {
|
|
9
|
+
source: DreamTranscriptSource;
|
|
10
|
+
session: string;
|
|
11
|
+
cwd: string;
|
|
12
|
+
first: string;
|
|
13
|
+
last: string;
|
|
14
|
+
turns: number;
|
|
15
|
+
/** Trimmed rendering: `[t<n>] user|assistant|tools: ...` lines. */
|
|
16
|
+
text: string;
|
|
17
|
+
trimmed?: true;
|
|
18
|
+
}
|
|
19
|
+
export interface DreamFindingInput {
|
|
20
|
+
fid: string;
|
|
21
|
+
date: string;
|
|
22
|
+
text: string;
|
|
23
|
+
status: string;
|
|
24
|
+
citation?: string;
|
|
25
|
+
}
|
|
26
|
+
export interface DreamPageInput {
|
|
27
|
+
slug: string;
|
|
28
|
+
title: string;
|
|
29
|
+
summary: string;
|
|
30
|
+
}
|
|
31
|
+
export interface DreamBudgetState {
|
|
32
|
+
sizeBytes: number;
|
|
33
|
+
budgetBytes: number;
|
|
34
|
+
over: boolean;
|
|
35
|
+
candidates: string[];
|
|
36
|
+
}
|
|
37
|
+
export interface DreamInputs {
|
|
38
|
+
project: string;
|
|
39
|
+
from: string;
|
|
40
|
+
to: string;
|
|
41
|
+
repoDir?: string;
|
|
42
|
+
transcripts: DreamTranscript[];
|
|
43
|
+
transcriptChars: number;
|
|
44
|
+
/** Sessions in the window left out entirely for budget. */
|
|
45
|
+
transcriptsDropped: number;
|
|
46
|
+
/** Unattributed OpenCode sessions hold the watermark back. */
|
|
47
|
+
unresolvedTranscripts?: number;
|
|
48
|
+
findings: DreamFindingInput[];
|
|
49
|
+
truths: string[];
|
|
50
|
+
topics: Array<{
|
|
51
|
+
slug: string;
|
|
52
|
+
label: string;
|
|
53
|
+
}>;
|
|
54
|
+
pages: DreamPageInput[];
|
|
55
|
+
gitLog: string[];
|
|
56
|
+
journal: string[];
|
|
57
|
+
budget: DreamBudgetState;
|
|
58
|
+
}
|
|
59
|
+
export interface CollectOptions {
|
|
60
|
+
from: Date;
|
|
61
|
+
to: Date;
|
|
62
|
+
budgetChars?: number;
|
|
63
|
+
injectBudgetKB?: number;
|
|
64
|
+
/** Transcript locations; defaults to every harness Phren reads on this computer. */
|
|
65
|
+
roots?: DreamTranscriptRoot[];
|
|
66
|
+
/** Folders whose sessions belong to the project; defaults to its source path and that repo's worktrees. */
|
|
67
|
+
projectDirs?: string[];
|
|
68
|
+
/** Replace the git reader (tests); false skips git. */
|
|
69
|
+
gitLog?: false | ((dir: string) => string[]);
|
|
70
|
+
}
|
|
71
|
+
export declare function defaultTranscriptRoots(): DreamTranscriptRoot[];
|
|
72
|
+
export declare function projectStoreDir(phrenPath: string, project: string): string;
|
|
73
|
+
export declare function underDirs(cwd: string, dirs: string[]): boolean;
|
|
74
|
+
/** One transcript trimmed to the window, or undefined when it is not the project's or has nothing in the window. */
|
|
75
|
+
export declare function readTranscript(source: DreamTranscriptSource, file: string, dirs: string[], from: number, to: number, metadataCwd?: string): DreamTranscript | undefined;
|
|
76
|
+
/** Fit transcripts into the budget, newest session first; the oldest turns of a session are trimmed before it is dropped. */
|
|
77
|
+
export declare function budgetTranscripts(all: DreamTranscript[], budgetChars: number): {
|
|
78
|
+
kept: DreamTranscript[];
|
|
79
|
+
chars: number;
|
|
80
|
+
dropped: number;
|
|
81
|
+
};
|
|
82
|
+
/** The repo's own folder plus its other worktrees, where agents also work on this project. */
|
|
83
|
+
export declare function projectDirsFor(phrenPath: string, project: string): string[];
|
|
84
|
+
export declare function readTruths(phrenPath: string, project: string): string[];
|
|
85
|
+
export declare function journalFile(phrenPath: string, project: string): string;
|
|
86
|
+
export declare function collect(phrenPath: string, project: string, options: CollectOptions): Promise<DreamInputs>;
|