fapony 0.1.1 → 0.1.3

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.
Files changed (44) hide show
  1. package/README.md +22 -36
  2. package/images/logo.png +0 -0
  3. package/images/logo.webp +0 -0
  4. package/images/logo@400.webp +0 -0
  5. package/images/sample.webp +0 -0
  6. package/images/summary.webp +0 -0
  7. package/package.json +10 -8
  8. package/skill/plan-with-pony/SKILL.md +1 -1
  9. package/src/analyze.ts +9 -8
  10. package/src/conventions-seed.ts +10 -10
  11. package/src/db/index.ts +1 -1
  12. package/src/db/store.ts +4 -0
  13. package/src/debt.ts +26 -22
  14. package/src/digest/collect.ts +7 -7
  15. package/src/digest/html.ts +2 -2
  16. package/src/digest/text.ts +1 -1
  17. package/src/gate.ts +3 -3
  18. package/src/hook.ts +119 -21
  19. package/src/init-mem.ts +3 -3
  20. package/src/install/opencode.ts +95 -8
  21. package/src/install/types.ts +1 -1
  22. package/src/install.ts +5 -1
  23. package/src/lint-baseline.ts +9 -9
  24. package/src/mcp/tools/mem.ts +1 -1
  25. package/src/mcp/tools/stats.ts +2 -2
  26. package/src/mcp/tools/usage.ts +3 -3
  27. package/src/mcp/tools/verdict.ts +29 -16
  28. package/src/mcp/transport.ts +1 -1
  29. package/src/plan-seed.ts +23 -21
  30. package/src/price/fetch.ts +19 -19
  31. package/src/price/resolve.ts +24 -24
  32. package/src/review-seed.ts +1 -1
  33. package/src/stats/data.ts +8 -7
  34. package/src/stats/format.ts +6 -5
  35. package/src/usage/render.ts +6 -5
  36. package/templates/PLAN.md +1 -1
  37. package/templates/mem/commands/plan.ts +44 -44
  38. package/templates/mem/commands/read.ts +5 -5
  39. package/templates/mem/commands/rotate.ts +6 -6
  40. package/templates/mem/commands/selftest.ts +14 -14
  41. package/templates/mem/commands/write.ts +13 -13
  42. package/templates/mem/mem.ts +5 -5
  43. package/templates/mem/selectors.ts +18 -18
  44. package/templates/mem/store.ts +50 -50
@@ -60,43 +60,43 @@ type LogRow = WorkRow | CloseRow | ClaimRow | ReleaseRow | SyncedRow;
60
60
  const root = Bun.spawnSync(["git", "rev-parse", "--show-toplevel"])
61
61
  .stdout.toString()
62
62
  .trim();
63
- // ponytail: worktree ชื่อ wt-<app> = monorepo scope (apps/<app>/.fapony/.memory).
64
- // fapony template: repo เดี่ยว (ไม่มี apps/) → fallback ไป .fapony/.memory ที่ root ตรงๆ
65
- // ไม่ต้อง config/flag ทั้งสองแบบ
63
+ // ponytail: worktree named wt-<app> = monorepo scope (apps/<app>/.fapony/.memory).
64
+ // fapony template: single repo (no apps/) → fallback straight to .fapony/.memory at root
65
+ // no config/flag needed for either shape
66
66
  const app = process.env.MEM_APP ?? basename(root).replace(/^wt-/, "");
67
- // โฟลเดอร์รวม app หาจาก {apps,packages,services}/<app> ตัวแรกที่มีจริง — ลำดับคงที่
68
- // apps → packages → services ตัวแรกที่เจอชนะ (ลำดับคือสัญญา ไม่ใช่บังเอิญ)
69
- // guard `unknown app` ข้างล่างยังผูกกับ apps/ เหมือนเดิม — ไม่ขยายในรอบนี้
67
+ // app container folder found from {apps,packages,services}/<app>, first that exists — fixed order
68
+ // apps → packages → services, first hit wins (the order is the contract, not an accident)
69
+ // the `unknown app` guard below is still tied to apps/ as before — not widened this round
70
70
  const appBase: string | undefined = ["apps", "packages", "services"]
71
71
  .map((d) => `${root}/${d}/${app}`)
72
72
  .find((p) => existsSync(p));
73
73
  const monorepo = appBase !== undefined;
74
74
 
75
- // สำเนาที่ `fapony init` วางไว้ อยู่ใน <project>/.fapony/.memory/ — log กับ plan ของมัน
76
- // ต้องอิงโฟลเดอร์ตัวเอง ไม่ใช่ git root: เคสที่พังจริงคือ apps/<x>/.fapony/.memory/ ใน monorepo
77
- // ซึ่ง heuristic ด้านล่างจะชี้ไป apps/<ชื่อ worktree>/.fapony/.memory = เขียน log ปนโปรเจกต์อื่น
78
- // แต่สำเนากลางที่ย้ายเข้า .fapony/.memory ที่ root ของ monorepo เอง (โค้ดชุดเดียว, log แยกราย
79
- // app — เช่น vela) ต้อง "ไม่" ถือเป็น scaffolded แม้ path จะแมตช์เหมือนกัน เพราะยังต้องเดา app
80
- // จาก monorepo อยู่ — ตัวแยกคือ "เดา app ได้ไหม" (`monorepo`) ไม่ใช่ "มีโฟลเดอร์รวม app ไหม":
81
- // แค่มี apps/ อยู่ที่ root ไม่ได้แปลว่าสำเนานี้เป็นสำเนากลาง — `fapony init <monorepo root>` ก็วาง
82
- // .fapony/.memory ที่ root เหมือนกัน แล้วมันต้องอิงโฟลเดอร์ตัวเอง ไม่งั้นตายที่ guard ข้างล่าง
83
- // ตั้งแต่คำสั่งแรกทั้งที่ plan ของมันอยู่ข้าง ๆ นั่นเอง
75
+ // The copy `fapony init` places lives in <project>/.fapony/.memory/ — its log and plan
76
+ // must key off their own folder, not the git root: the real broken case is apps/<x>/.fapony/.memory/ in a monorepo,
77
+ // where the heuristic below would point at apps/<worktree name>/.fapony/.memory = writing a log mixed into another project.
78
+ // But the central copy that was moved into .fapony/.memory at the monorepo root itself (single code copy, logs split per
79
+ // app — e.g. vela) must "not" count as scaffolded even though the path matches, because it still has to guess the app
80
+ // from the monorepo — the discriminator is "can the app be guessed" (`monorepo`), not "is there an app container folder":
81
+ // just having apps/ at the root does not make this copy the central one — `fapony init <monorepo root>` also places
82
+ // .fapony/.memory at the root, and it must key off its own folder, or it dies at the guard below
83
+ // from the very first command even though its plan sits right next to it.
84
84
  const centralAtMonorepoRoot =
85
85
  import.meta.dir === `${root}/.fapony/.memory` && monorepo;
86
86
  const scaffolded =
87
87
  import.meta.dir.includes("/.fapony/.memory") && !centralAtMonorepoRoot;
88
88
 
89
- // มี apps/ แต่ไม่มี apps/<app> = เดา app ผิด (worktree ชื่อไม่ตรง / typo ใน MEM_APP) — ตายตรงนี้
90
- // ดีกว่า fallback เงียบ ๆ ไปเขียน log ที่ root ซึ่งจะกลายเป็น log กำพร้าที่ไม่มีใครอ่าน
91
- // (สำเนาที่ scaffold ไว้ใต้ apps/<x>/.fapony/.memory/ อิงโฟลเดอร์ตัวเอง ไม่ต้องเดา จึงไม่เข้าเงื่อนไขนี้)
89
+ // apps/ exists but apps/<app> does not = guessed the app wrong (worktree name mismatch / typo in MEM_APP) — die here
90
+ // rather than fall back silently and write a log at the root that becomes an orphan nobody reads
91
+ // (a copy scaffolded under apps/<x>/.fapony/.memory/ keys off its own folder, needs no guess, so it does not hit this)
92
92
  if (!scaffolded && !monorepo && existsSync(`${root}/apps`)) {
93
93
  console.error(
94
94
  `unknown app (guessed "${app}" from ${basename(root)}) — pass MEM_APP=<app>`,
95
95
  );
96
96
  process.exit(1);
97
97
  }
98
- // default ใหม่: log อยู่ใต้ .fapony/.memory — fallback ไป .memory/ เดิมเมื่อมี log เก่าอยู่จริง
99
- // เช็ค log.jsonl ไม่ใช่ dir: โฟลเดอร์ว่างที่ใครเผลอ mkdir ทิ้งไว้ต้องไม่ล็อก repo ไว้กับ layout เก่า
98
+ // new default: log lives under .fapony/.memory — fall back to the old .memory/ only when an old log actually exists
99
+ // check for log.jsonl, not the dir: an empty folder someone accidentally mkdir'd must not lock the repo to the old layout
100
100
  const newDir = appBase
101
101
  ? `${appBase}/.fapony/.memory`
102
102
  : `${root}/.fapony/.memory`;
@@ -106,12 +106,12 @@ const dir = scaffolded
106
106
  : existsSync(`${legacyDir}/log.jsonl`)
107
107
  ? legacyDir
108
108
  : newDir;
109
- // ใครเขียนแถวนี้ — client ตั้ง MEM_AGENT ทับได้ ("claude-code", "opencode")
109
+ // who wrote this row — the client can override with MEM_AGENT ("claude-code", "opencode")
110
110
  const agent = process.env.MEM_AGENT || process.env.USER || "unknown";
111
111
 
112
- // ชื่อไฟล์ = *คน* ไม่ใช่ client ตั้งใจให้ต่างจาก agent ข้างบน: ถ้าใช้ MEM_AGENT ตั้งชื่อไฟล์
113
- // สองคนที่เปิด Claude Code จะกลับไปเขียน log.claude-code.jsonl ใบเดียวกัน = ชนเหมือนเดิม
114
- // git user.name มีอยู่แล้วทุกเครื่องที่ commit ได้ จึงไม่ต้องตั้ง env และไม่ต้องเพิ่ม config
112
+ // filename = *person*, not client, deliberately different from agent above: naming files by MEM_AGENT
113
+ // would put two people running Claude Code back into the same log.claude-code.jsonl = same collision as before
114
+ // git user.name exists on every machine that can commit, so no env to set and no config to add
115
115
  const person = (
116
116
  Bun.spawnSync(["git", "config", "user.name"]).stdout.toString().trim() ||
117
117
  process.env.USER ||
@@ -121,12 +121,12 @@ const person = (
121
121
  .replace(/[^a-z0-9._-]+/g, "-")
122
122
  .replace(/^-+|-+$/g, "");
123
123
 
124
- // เขียนไฟล์ของตัวเอง อ่านของทุกคน — สองคนไม่เคยแตะไฟล์เดียวกัน = merge conflict
125
- // เป็นศูนย์โดยโครงสร้าง ไม่ต้องพึ่ง merge=union หรือให้ GitHub ทำตัวดีตอน merge PR
124
+ // write your own file, read everyone's — two people never touch the same file = merge conflicts
125
+ // are structurally zero, no need for merge=union or GitHub behaving itself on PR merge
126
126
  const LOG = `${dir}/log.${person || "unknown"}.jsonl`;
127
127
 
128
- // log.jsonl = ของเดิมก่อนแยกไฟล์ (ยังอ่านตลอดไป ไม่ต้อง migrate)
129
- // ข้าม log.YYYY-MM-DD.jsonl ที่ rotate สร้าง ไม่งั้น rotate จะไม่ลดอะไรเลยเพราะอ่านกลับเข้ามา
128
+ // log.jsonl = the pre-split original (still read forever, no migration needed)
129
+ // skip the log.YYYY-MM-DD.jsonl that rotate creates, or rotate reduces nothing because they get read back in
130
130
  const isLogFile = (f: string): boolean =>
131
131
  f === "log.jsonl" ||
132
132
  (/^log\.[A-Za-z0-9._-]+\.jsonl$/.test(f) &&
@@ -140,17 +140,17 @@ const logFiles = (): string[] =>
140
140
  .map((f) => join(dir, f))
141
141
  : [];
142
142
 
143
- // โฟลเดอร์ที่ plan/ กับ done/ ของโปรเจกต์นี้อยู่ใต้มัน — จุดเดียวที่ประกอบ path เหล่านี้
144
- // (ก่อนหน้านี้ commands/plan.ts hardcode `apps/<app>/plan` 10 จุด = ตายสนิทกับ repo เดี่ยว)
143
+ // the folder this project's plan/ and done/ live under — the single place these paths are assembled
144
+ // (previously commands/plan.ts hardcoded `apps/<app>/plan` in 10 places = dead on arrival for a single repo)
145
145
  const planBase = scaffolded
146
146
  ? dirname(import.meta.dir) // <project>/.fapony
147
147
  : (appBase ?? root);
148
148
 
149
- // fapony.config.json คือ *ข้อตกลง* ว่า plan อยู่ไหน ส่วน planBase ข้างบนเป็นแค่การเดา —
150
- // มีไฟล์เมื่อไหร่ต้องชนะการเดาเสมอ (vela ประกาศ `apps/vela/plan` ไว้ตรง ๆ บังเอิญตรงกับที่เดาได้
151
- // แต่ repo ที่วาง plan ไว้ที่อื่นจะพังเงียบ ๆ ถ้าไม่อ่าน)
152
- // อ่านที่ระดับโปรเจกต์เท่านั้น: สำเนาที่ scaffold ใน apps/<x>/.fapony/ ต้องไม่หยิบ config ของ
153
- // monorepo ที่ root มาใช้ เพราะนั่นเป็น path ของอีกโปรเจกต์หนึ่ง
149
+ // fapony.config.json is the *agreement* on where plan lives; planBase above is only a guess —
150
+ // whenever the file exists it must beat the guess (vela declares `apps/vela/plan` outright, which happens to match the guess
151
+ // but a repo that puts plan elsewhere breaks silently if this is not read)
152
+ // read only at the project level: a copy scaffolded in apps/<x>/.fapony/ must not pick up the root
153
+ // monorepo's config, because that is another project's path
154
154
  const configDir = scaffolded ? dirname(planBase) : root;
155
155
 
156
156
  const configPaths = ((): Record<string, string> => {
@@ -158,7 +158,7 @@ const configPaths = ((): Record<string, string> => {
158
158
  const raw = readFileSync(`${configDir}/fapony.config.json`, "utf8");
159
159
  return (JSON.parse(raw)?.paths ?? {}) as Record<string, string>;
160
160
  } catch {
161
- // ไม่มีไฟล์ / JSON เสีย → ใช้ค่าที่เดาได้ ไม่ใช่ error: memory ต้องทำงานได้โดยไม่มี fapony
161
+ // no file / broken JSON → use the guessed values, not an error: memory must work without fapony
162
162
  return {};
163
163
  }
164
164
  })();
@@ -168,27 +168,27 @@ const fromConfig = (key: string): string | null =>
168
168
  ? join(configDir, configPaths[key])
169
169
  : null;
170
170
 
171
- // app ที่ย้าย plan เข้า .fapony/ แล้วให้ใช้ของใหม่ ที่ยังไม่ย้ายใช้ของเดิม — โมโนเรโปจึงย้ายทีละ app ได้
172
- // โดยไม่ต้องแตะ config (config มี planDir ค่าเดียว ประกาศเมื่อไหร่ app อื่นก็ชี้ผิดตามไปด้วย)
171
+ // an app that moved plan into .fapony/ uses the new location; one that has not uses the old — so a monorepo migrates app by app
172
+ // without touching config (config has a single planDir, so declaring it points the other apps wrong too)
173
173
  const base = existsSync(`${planBase}/.fapony`)
174
174
  ? `${planBase}/.fapony`
175
175
  : planBase;
176
176
 
177
177
  const planDir = fromConfig("planDir") ?? `${base}/plan`;
178
178
 
179
- // done/ อยู่ข้าง plan/ (ย้ายแล้วลึกเท่าเดิม ลิงก์ relative ในไฟล์รอด) — repo ที่ยัง layout เก่า
180
- // เก็บ plan/done/ ไว้ ก็ใช้ของเดิมต่อ ไม่ต้องย้ายก่อนถึงจะ sweep ได้
179
+ // done/ sits beside plan/ (same depth after the move, relative links in files survive) — a repo still on the old layout
180
+ // with plan/done/ keeps using it, no need to move before sweeping
181
181
  const doneDir =
182
182
  fromConfig("doneDir") ??
183
183
  (!existsSync(`${base}/done`) && existsSync(`${planDir}/done`)
184
184
  ? `${planDir}/done`
185
185
  : `${base}/done`);
186
186
 
187
- // path ที่เอาไว้โชว์/บันทึกลง log — อิง repo root เสมอ (`apps/vela/plan`, `.fapony/plan`)
187
+ // path used for display/logging — always relative to repo root (`apps/vela/plan`, `.fapony/plan`)
188
188
  const rel = (p: string) => relative(root, p) || ".";
189
189
 
190
- // คำสั่งที่บอกให้ผู้ใช้พิมพ์ ต้องเป็น path ของ mem.ts ตัวที่กำลังรันอยู่จริง ไม่ใช่ค่าคงที่ —
191
- // สำเนาที่ `fapony init` วางไว้อยู่ที่ .fapony/.memory/ ไม่ใช่ .memory/ ที่ help text เดิม hardcode
190
+ // the command we tell the user to type must be the path of the mem.ts actually running, not a constant —
191
+ // the copy `fapony init` places lives in .fapony/.memory/, not the .memory/ the old help text hardcoded
192
192
  const memCmd = `bun ${rel(dir)}/mem.ts`;
193
193
 
194
194
  const KINDS: WorkKind[] = ["next", "bug", "decision", "note", "hold"];
@@ -205,7 +205,7 @@ const rows = (): LogRow[] =>
205
205
  try {
206
206
  return [JSON.parse(l) as LogRow];
207
207
  } catch {
208
- // ponytail: 1 บรรทัดพัง (escape เสีย) ไม่ควรทำให้ทั้ง log อ่านไม่ได้ — ข้ามแล้วเตือน
208
+ // ponytail: one broken line (bad escape) must not make the whole log unreadable — skip it and warn
209
209
  console.error(
210
210
  `[mem] skipped ${basename(f)} line ${i + 1} (bad JSON)`,
211
211
  );
@@ -213,7 +213,7 @@ const rows = (): LogRow[] =>
213
213
  }
214
214
  }),
215
215
  )
216
- // หลายไฟล์ต่อกันแล้วลำดับเวลาสลับ — ทุก selector อ่านจากบนลงล่างโดยถือว่าเรียงตาม ts
216
+ // concatenating several files scrambles the time order — every selector reads top-down assuming ts order
217
217
  .sort((a, b) => a.ts.localeCompare(b.ts));
218
218
 
219
219
  function put(r: Omit<WorkRow, "ts" | "agent">): void;
@@ -236,9 +236,9 @@ function put(
236
236
  );
237
237
  }
238
238
 
239
- // ponytail: กัน id ชน — base36 + increment ต่อ retry + random suffix
240
- // ใช้ร่วมกันทุกที่ที่ต้อง generate WorkRow.id (cmdAdd, ship-log ใน cmdPlanSweep)
241
- // ห้าม copy loop นี้ไปวางที่ใหม่ — แก้ scheme ที่นี่ที่เดียว
239
+ // ponytail: prevent id collisions — base36 + increment per retry + random suffix
240
+ // shared everywhere a WorkRow.id must be generated (cmdAdd, ship-log in cmdPlanSweep)
241
+ // do not copy this loop elsewhere — change the scheme here only
242
242
  function nextId(all: LogRow[]): string {
243
243
  const used = new Set(all.map((r) => ("id" in r ? r.id : "")));
244
244
  let base = Date.now();
@@ -250,8 +250,8 @@ function nextId(all: LogRow[]): string {
250
250
  return id;
251
251
  }
252
252
 
253
- // เขียนแถวดิบ (ts/agent เดิม ไม่ generate ใหม่) — ใช้ตอน rotate ย้าย row เก่าไปไฟล์ใหม่
254
- // ปกติเขียน log ต้องผ่าน put() เท่านั้น อันนี้ทางเดียวที่ยกเว้น
253
+ // write a raw row (original ts/agent, no regeneration) — used when rotate moves old rows to a new file
254
+ // normally writing to the log must go through put(); this is the only exception
255
255
  const appendRaw = (path: string, r: LogRow): void =>
256
256
  appendFileSync(path, `${JSON.stringify(r)}\n`);
257
257