fapony 0.6.2 → 0.7.1
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 +144 -156
- package/package.json +5 -6
- package/skill/define-convention/SKILL.md +3 -3
- package/skill/lookup-before-edit/SKILL.md +2 -1
- package/skill/move-to-done/SKILL.md +18 -22
- package/skill/plan-with-pony/SKILL.md +4 -4
- package/skill/review-pony/SKILL.md +10 -12
- package/src/adapters/cli.ts +11 -52
- package/src/adapters/hooks/index.ts +0 -67
- package/src/adapters/hooks/mv-guard.ts +2 -2
- package/src/analyze/discover.ts +1 -1
- package/src/analyze/index.ts +0 -1
- package/src/commands.ts +8 -39
- package/src/core/config.ts +0 -6
- package/src/core/fapony-dir.ts +71 -0
- package/src/core/hook-helpers.ts +1 -2
- package/src/debt/load.ts +3 -5
- package/src/debt/promotion.ts +2 -2
- package/src/debt/scan.ts +1 -1
- package/src/digest/collect.ts +6 -7
- package/src/fael.ts +139 -0
- package/src/hook.ts +1 -81
- package/src/init.ts +30 -90
- package/src/install/antigravity.ts +8 -99
- package/src/install/claude.ts +66 -200
- package/src/install/codex.ts +6 -170
- package/src/install/detect.ts +4 -14
- package/src/install/opencode.ts +50 -486
- package/src/install/types.ts +1 -39
- package/src/install/zcode.ts +5 -91
- package/src/install.ts +9 -35
- package/src/memory.ts +10 -69
- package/src/plan/index.ts +34 -0
- package/src/plan/next.ts +181 -0
- package/src/plan/store.ts +41 -0
- package/src/{mem/commands/plan.ts → plan/sweep.ts} +66 -46
- package/src/seed/plan-seed.ts +10 -9
- package/src/setup.ts +4 -22
- package/src/update.ts +1 -1
- package/templates/PLAN.md +1 -1
- package/src/adapters/hooks/bug-markers.ts +0 -60
- package/src/adapters/hooks/context-data.ts +0 -139
- package/src/adapters/hooks/edit-hint.ts +0 -215
- package/src/adapters/hooks/read-hint.ts +0 -410
- package/src/adapters/hooks/session-start.ts +0 -112
- package/src/adapters/hooks/stop.ts +0 -768
- package/src/adapters/mcp/tools/index.ts +0 -149
- package/src/adapters/mcp/tools/mem.ts +0 -252
- package/src/adapters/mcp/transport.ts +0 -147
- package/src/analyze/cache.ts +0 -162
- package/src/core/mem-log.ts +0 -375
- package/src/init-mem.ts +0 -143
- package/src/install/cursor.ts +0 -167
- package/src/install/utils.ts +0 -29
- package/src/mem/commands/read.ts +0 -738
- package/src/mem/commands/rotate.ts +0 -59
- package/src/mem/commands/where.ts +0 -56
- package/src/mem/commands/write.ts +0 -273
- package/src/mem/engine.ts +0 -315
- package/src/mem/index.ts +0 -201
- package/src/mem/render.ts +0 -66
- package/src/mem/selectors.ts +0 -160
- package/src/mem/store.ts +0 -356
package/src/mem/store.ts
DELETED
|
@@ -1,356 +0,0 @@
|
|
|
1
|
-
// store.ts — types + config + read/write primitives for the append-only memory log
|
|
2
|
-
//
|
|
3
|
-
// Moved from templates/mem/store.ts (2026-09-19) as part of PLAN-agent-one-call chunk 1.
|
|
4
|
-
// The template was copied into every repo via `fapony init-mem`; now fapony owns the code
|
|
5
|
-
// and calls it directly via `fapony mem <sub>`. Path resolution is no longer based on
|
|
6
|
-
// import.meta.dir — initStore() receives the worktree explicitly from the CLI dispatch.
|
|
7
|
-
|
|
8
|
-
import { createHash } from "node:crypto";
|
|
9
|
-
import {
|
|
10
|
-
appendFileSync,
|
|
11
|
-
existsSync,
|
|
12
|
-
mkdirSync,
|
|
13
|
-
readdirSync,
|
|
14
|
-
readFileSync,
|
|
15
|
-
} from "node:fs";
|
|
16
|
-
import { hostname, networkInterfaces } from "node:os";
|
|
17
|
-
import { basename, dirname, join, relative } from "node:path";
|
|
18
|
-
import {
|
|
19
|
-
CONFIG_FILENAME,
|
|
20
|
-
DEFAULT_MEM_DIR,
|
|
21
|
-
FAPONY_DIR,
|
|
22
|
-
} from "../core/config.js";
|
|
23
|
-
import { whereMemDir } from "../memory.js";
|
|
24
|
-
|
|
25
|
-
// --- types ---
|
|
26
|
-
|
|
27
|
-
type WorkKind = "next" | "bug" | "decision" | "note" | "hold";
|
|
28
|
-
|
|
29
|
-
type WorkRow = {
|
|
30
|
-
ts: string;
|
|
31
|
-
agent: string;
|
|
32
|
-
id: string;
|
|
33
|
-
kind: WorkKind;
|
|
34
|
-
text: string;
|
|
35
|
-
spec?: string;
|
|
36
|
-
files?: string[];
|
|
37
|
-
key?: string;
|
|
38
|
-
v?: number;
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
type CloseRow = {
|
|
42
|
-
ts: string;
|
|
43
|
-
agent: string;
|
|
44
|
-
kind: "close";
|
|
45
|
-
ref: string;
|
|
46
|
-
text: string;
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
type ClaimRow = {
|
|
50
|
-
ts: string;
|
|
51
|
-
agent: string;
|
|
52
|
-
kind: "claim";
|
|
53
|
-
ref: string;
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
type ReleaseRow = {
|
|
57
|
-
ts: string;
|
|
58
|
-
agent: string;
|
|
59
|
-
kind: "release";
|
|
60
|
-
ref: string;
|
|
61
|
-
text?: string;
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
type SyncedRow = {
|
|
65
|
-
ts: string;
|
|
66
|
-
agent: string;
|
|
67
|
-
kind: "synced";
|
|
68
|
-
spec: string;
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
type LogRow = WorkRow | CloseRow | ClaimRow | ReleaseRow | SyncedRow;
|
|
72
|
-
|
|
73
|
-
// --- identity ---
|
|
74
|
-
//
|
|
75
|
-
// `agent` goes in every row, `person` names the file. Both used to end in
|
|
76
|
-
// "unknown", which is not a fallback: two machines with no git and no $USER
|
|
77
|
-
// wrote the same filename and their rows interleaved with no way to tell them
|
|
78
|
-
// apart. Generic OS accounts collide the same way — `admin`/`user`/`owner` are
|
|
79
|
-
// what a fresh install offers, so treat them as absent rather than as a name.
|
|
80
|
-
// git user.email is unique by construction; the machine tag is the last resort,
|
|
81
|
-
// hashed because this file is committed and a raw MAC address is not ours to
|
|
82
|
-
// publish. user.email is only spawned when the cheap sources fail — initStore
|
|
83
|
-
// sits on the mem_add hot path (git config ≈ 12ms).
|
|
84
|
-
|
|
85
|
-
const GENERIC_NAMES = new Set([
|
|
86
|
-
"admin",
|
|
87
|
-
"user",
|
|
88
|
-
"owner",
|
|
89
|
-
"root",
|
|
90
|
-
"ubuntu",
|
|
91
|
-
"ec2-user",
|
|
92
|
-
"vagrant",
|
|
93
|
-
"dev",
|
|
94
|
-
"developer",
|
|
95
|
-
"node",
|
|
96
|
-
"unknown",
|
|
97
|
-
]);
|
|
98
|
-
|
|
99
|
-
const usable = (v: string | null | undefined): string | null => {
|
|
100
|
-
const s = (v ?? "").trim();
|
|
101
|
-
return s && !GENERIC_NAMES.has(s.toLowerCase()) ? s : null;
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
// `env: process.env` is not redundant: Bun.spawnSync snapshots the environment
|
|
105
|
-
// at startup, so a variable set at runtime (GIT_CONFIG_GLOBAL in a test, MEM_*
|
|
106
|
-
// set by a wrapper) never reaches the child without passing it explicitly.
|
|
107
|
-
const gitConfig = (key: string, cwd: string): string | null =>
|
|
108
|
-
Bun.spawnSync(["git", "config", key], { cwd, env: process.env })
|
|
109
|
-
.stdout.toString()
|
|
110
|
-
.trim() || null;
|
|
111
|
-
|
|
112
|
-
function machineSeed(): string {
|
|
113
|
-
try {
|
|
114
|
-
const id = readFileSync("/etc/machine-id", "utf8").trim();
|
|
115
|
-
if (id) return id;
|
|
116
|
-
} catch {
|
|
117
|
-
// no /etc/machine-id (macOS) — fall through to the interface list
|
|
118
|
-
}
|
|
119
|
-
for (const ifaces of Object.values(networkInterfaces()))
|
|
120
|
-
for (const i of ifaces ?? [])
|
|
121
|
-
if (!i.internal && i.mac && i.mac !== "00:00:00:00:00:00") return i.mac;
|
|
122
|
-
return hostname();
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
const machineTag = (): string =>
|
|
126
|
-
`m-${createHash("sha256").update(machineSeed()).digest("hex").slice(0, 8)}`;
|
|
127
|
-
|
|
128
|
-
const slug = (v: string): string =>
|
|
129
|
-
v
|
|
130
|
-
.toLowerCase()
|
|
131
|
-
.replace(/[^a-z0-9._-]+/g, "-")
|
|
132
|
-
.replace(/^-+|-+$/g, "");
|
|
133
|
-
|
|
134
|
-
// --- mutable state (populated by initStore) ---
|
|
135
|
-
|
|
136
|
-
let root = "";
|
|
137
|
-
let dir = "";
|
|
138
|
-
let planDir = "";
|
|
139
|
-
let doneDir = "";
|
|
140
|
-
let agent = "";
|
|
141
|
-
let person = "";
|
|
142
|
-
let LOG = "";
|
|
143
|
-
let memCmd = "";
|
|
144
|
-
let planBase = "";
|
|
145
|
-
let app = "";
|
|
146
|
-
// Non-empty when the resolver found two or more app-scoped mem dirs and no
|
|
147
|
-
// single one at/above cwd — a write must die rather than start a third log.
|
|
148
|
-
let blockWrite = "";
|
|
149
|
-
|
|
150
|
-
// --- init ---
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* Initialize the store for a given worktree. Must be called before using any
|
|
154
|
-
* export. The CLI dispatch layer calls this with the resolved worktree path.
|
|
155
|
-
*
|
|
156
|
-
* `overrideMemDir` (from --mem-dir flag) skips resolution entirely.
|
|
157
|
-
* Otherwise whereMemDir() walks up from cwd — the same dir the reader
|
|
158
|
-
* (src/memory.ts) uses, so writer and reader cannot drift apart.
|
|
159
|
-
*/
|
|
160
|
-
export function initStore(worktree: string, overrideMemDir?: string): void {
|
|
161
|
-
root = Bun.spawnSync(["git", "rev-parse", "--show-toplevel"], {
|
|
162
|
-
cwd: worktree,
|
|
163
|
-
})
|
|
164
|
-
.stdout.toString()
|
|
165
|
-
.trim();
|
|
166
|
-
if (!root) root = worktree;
|
|
167
|
-
|
|
168
|
-
// An explicit --mem-dir is a promise: never silently fall back to the
|
|
169
|
-
// default when the path is wrong, or the row lands in a log nobody reads.
|
|
170
|
-
if (overrideMemDir && !existsSync(overrideMemDir)) {
|
|
171
|
-
throw new Error(`--mem-dir path does not exist: ${overrideMemDir}`);
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
// Resolution and the CLI's `mem where` share one function, so the path a row
|
|
175
|
-
// is written to is the path `mem where` reports.
|
|
176
|
-
blockWrite = "";
|
|
177
|
-
const resolved = whereMemDir(worktree, overrideMemDir);
|
|
178
|
-
if (resolved.step === "ambiguous") {
|
|
179
|
-
const list = (resolved.candidates ?? []).map((c) => ` ${c}`).join("\n");
|
|
180
|
-
blockWrite =
|
|
181
|
-
`two or more .fapony/.memory dirs under ${root} — refusing to guess:\n` +
|
|
182
|
-
`${list}\ncd into one, set paths.memDir, or pass --mem-dir`;
|
|
183
|
-
}
|
|
184
|
-
dir = resolved.dir ?? join(root, DEFAULT_MEM_DIR);
|
|
185
|
-
|
|
186
|
-
// planBase: the .fapony dir — plan/done/conventions live here.
|
|
187
|
-
// Derive from dir by going up from .fapony/.memory → .fapony
|
|
188
|
-
planBase = dirname(dir);
|
|
189
|
-
|
|
190
|
-
// app name for display — the directory containing .fapony
|
|
191
|
-
app = dirname(planBase);
|
|
192
|
-
|
|
193
|
-
// Read fapony.config.json
|
|
194
|
-
const configDir =
|
|
195
|
-
planBase === `${root}/${FAPONY_DIR}` ? root : dirname(planBase);
|
|
196
|
-
const configPaths = ((): Record<string, string> => {
|
|
197
|
-
try {
|
|
198
|
-
const raw = readFileSync(`${configDir}/${CONFIG_FILENAME}`, "utf8");
|
|
199
|
-
return (JSON.parse(raw)?.paths ?? {}) as Record<string, string>;
|
|
200
|
-
} catch {
|
|
201
|
-
return {};
|
|
202
|
-
}
|
|
203
|
-
})();
|
|
204
|
-
const fromConfig = (key: string): string | null =>
|
|
205
|
-
typeof configPaths[key] === "string"
|
|
206
|
-
? join(configDir, configPaths[key])
|
|
207
|
-
: null;
|
|
208
|
-
|
|
209
|
-
planDir = `${planBase}/plan`;
|
|
210
|
-
|
|
211
|
-
// done/ sits beside plan/ (same depth, relative links survive)
|
|
212
|
-
doneDir =
|
|
213
|
-
fromConfig("doneDir") ??
|
|
214
|
-
(!existsSync(`${planBase}/done`) && existsSync(`${planDir}/done`)
|
|
215
|
-
? `${planDir}/done`
|
|
216
|
-
: `${planBase}/done`);
|
|
217
|
-
|
|
218
|
-
let emailCache: string | null | undefined;
|
|
219
|
-
const email = (): string | null =>
|
|
220
|
-
emailCache !== undefined
|
|
221
|
-
? emailCache
|
|
222
|
-
: (emailCache = gitConfig("user.email", root));
|
|
223
|
-
|
|
224
|
-
agent =
|
|
225
|
-
process.env.MEM_AGENT?.trim() ||
|
|
226
|
-
usable(process.env.USER) ||
|
|
227
|
-
usable(email()) ||
|
|
228
|
-
machineTag();
|
|
229
|
-
|
|
230
|
-
// filename = *person*, not client — naming by MEM_AGENT would collide
|
|
231
|
-
person = slug(
|
|
232
|
-
usable(gitConfig("user.name", root)) ||
|
|
233
|
-
usable(process.env.USER) ||
|
|
234
|
-
usable(email()) ||
|
|
235
|
-
machineTag(),
|
|
236
|
-
);
|
|
237
|
-
|
|
238
|
-
LOG = `${dir}/log.${person}.jsonl`;
|
|
239
|
-
memCmd = `fapony mem`;
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
// --- log file helpers ---
|
|
243
|
-
|
|
244
|
-
const isLogFile = (f: string): boolean =>
|
|
245
|
-
f === "log.jsonl" ||
|
|
246
|
-
(/^log\.[A-Za-z0-9._-]+\.jsonl$/.test(f) &&
|
|
247
|
-
!/^log\.\d{4}-\d{2}-\d{2}\.jsonl$/.test(f));
|
|
248
|
-
|
|
249
|
-
const listLogs = (match: (f: string) => boolean): string[] =>
|
|
250
|
-
existsSync(dir)
|
|
251
|
-
? readdirSync(dir)
|
|
252
|
-
.filter(match)
|
|
253
|
-
.sort()
|
|
254
|
-
.map((f) => join(dir, f))
|
|
255
|
-
: [];
|
|
256
|
-
|
|
257
|
-
const logFiles = (): string[] => listLogs(isLogFile);
|
|
258
|
-
|
|
259
|
-
const archivedFiles = (): string[] =>
|
|
260
|
-
listLogs((f) => /^log\.\d{4}-\d{2}-\d{2}\.jsonl$/.test(f));
|
|
261
|
-
|
|
262
|
-
// --- core ---
|
|
263
|
-
|
|
264
|
-
const parseLog = (f: string): LogRow[] =>
|
|
265
|
-
readFileSync(f, "utf8")
|
|
266
|
-
.split("\n")
|
|
267
|
-
.filter(Boolean)
|
|
268
|
-
.flatMap((l: string, i: number) => {
|
|
269
|
-
try {
|
|
270
|
-
return [JSON.parse(l) as LogRow];
|
|
271
|
-
} catch {
|
|
272
|
-
console.error(`[mem] skipped ${basename(f)} line ${i + 1} (bad JSON)`);
|
|
273
|
-
return [];
|
|
274
|
-
}
|
|
275
|
-
});
|
|
276
|
-
|
|
277
|
-
const byTs = (a: LogRow, b: LogRow) => a.ts.localeCompare(b.ts);
|
|
278
|
-
|
|
279
|
-
// The live view: what `rotate` counts and what open-work commands read. It must
|
|
280
|
-
// stay archive-free or rotate re-imports the rows it just moved out and never
|
|
281
|
-
// gets under its own threshold.
|
|
282
|
-
const rows = (): LogRow[] => logFiles().flatMap(parseLog).sort(byTs);
|
|
283
|
-
|
|
284
|
-
// The recall view: rotated rows included. A bug closed six months ago is exactly
|
|
285
|
-
// what `find` exists to surface — rotate shrinks the live file, it does not
|
|
286
|
-
// decide what is still worth remembering.
|
|
287
|
-
const allRows = (): LogRow[] =>
|
|
288
|
-
[...logFiles(), ...archivedFiles()].flatMap(parseLog).sort(byTs);
|
|
289
|
-
|
|
290
|
-
function put(r: Omit<WorkRow, "ts" | "agent">): void;
|
|
291
|
-
function put(r: Omit<CloseRow, "ts" | "agent">): void;
|
|
292
|
-
function put(r: Omit<ClaimRow, "ts" | "agent">): void;
|
|
293
|
-
function put(r: Omit<ReleaseRow, "ts" | "agent">): void;
|
|
294
|
-
function put(r: Omit<SyncedRow, "ts" | "agent">): void;
|
|
295
|
-
function put(
|
|
296
|
-
r:
|
|
297
|
-
| Omit<WorkRow, "ts" | "agent">
|
|
298
|
-
| Omit<CloseRow, "ts" | "agent">
|
|
299
|
-
| Omit<ClaimRow, "ts" | "agent">
|
|
300
|
-
| Omit<ReleaseRow, "ts" | "agent">
|
|
301
|
-
| Omit<SyncedRow, "ts" | "agent">,
|
|
302
|
-
) {
|
|
303
|
-
if (blockWrite) throw new Error(blockWrite);
|
|
304
|
-
mkdirSync(dir, { recursive: true });
|
|
305
|
-
appendFileSync(
|
|
306
|
-
LOG,
|
|
307
|
-
`${JSON.stringify({ ts: new Date().toISOString(), agent, ...r })}\n`,
|
|
308
|
-
);
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
function nextId(all: LogRow[]): string {
|
|
312
|
-
const used = new Set(all.map((r) => ("id" in r ? r.id : "")));
|
|
313
|
-
let base = Date.now();
|
|
314
|
-
let id = base.toString(36);
|
|
315
|
-
while (used.has(id)) {
|
|
316
|
-
id = base.toString(36) + Math.random().toString(36).slice(2, 4);
|
|
317
|
-
base++;
|
|
318
|
-
}
|
|
319
|
-
return id;
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
const appendRaw = (path: string, r: LogRow): void =>
|
|
323
|
-
appendFileSync(path, `${JSON.stringify(r)}\n`);
|
|
324
|
-
|
|
325
|
-
const rel = (p: string) => relative(root, p) || ".";
|
|
326
|
-
|
|
327
|
-
const KINDS: WorkKind[] = ["next", "bug", "decision", "note", "hold"];
|
|
328
|
-
|
|
329
|
-
export type {
|
|
330
|
-
ClaimRow,
|
|
331
|
-
CloseRow,
|
|
332
|
-
LogRow,
|
|
333
|
-
ReleaseRow,
|
|
334
|
-
SyncedRow,
|
|
335
|
-
WorkKind,
|
|
336
|
-
WorkRow,
|
|
337
|
-
};
|
|
338
|
-
export {
|
|
339
|
-
agent,
|
|
340
|
-
allRows,
|
|
341
|
-
app,
|
|
342
|
-
appendRaw,
|
|
343
|
-
dir,
|
|
344
|
-
doneDir,
|
|
345
|
-
KINDS,
|
|
346
|
-
LOG,
|
|
347
|
-
memCmd,
|
|
348
|
-
nextId,
|
|
349
|
-
person,
|
|
350
|
-
planBase,
|
|
351
|
-
planDir,
|
|
352
|
-
put,
|
|
353
|
-
rel,
|
|
354
|
-
root,
|
|
355
|
-
rows,
|
|
356
|
-
};
|