sphica 0.6.38 → 0.6.39

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.
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://anthropic.com/claude-code/plugin.schema.json",
3
3
  "name": "sphica",
4
- "version": "0.6.38",
4
+ "version": "0.6.39",
5
5
  "description": "Records Claude Code and Codex sessions on your machine and keeps past implementation and decisions, with their sources, for your agent to find.",
6
6
  "author": {
7
7
  "name": "iroha924",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sphica",
3
- "version": "0.6.38",
3
+ "version": "0.6.39",
4
4
  "description": "Records Claude Code and Codex sessions on your machine and keeps past implementation and decisions, with their sources, for your agent to find.",
5
5
  "author": {
6
6
  "name": "iroha924",
package/dist/deliver.js CHANGED
@@ -11552,6 +11552,17 @@ function sqliteCode(e) {
11552
11552
  const x = e;
11553
11553
  return x?.code === "ERR_SQLITE_ERROR" && typeof x.errcode === "number" ? x.errcode & 255 : null;
11554
11554
  }
11555
+ function byUnit(rows) {
11556
+ const out = new Map;
11557
+ for (const r of rows) {
11558
+ const list = out.get(r.unit_id);
11559
+ if (list)
11560
+ list.push(r);
11561
+ else
11562
+ out.set(r.unit_id, [r]);
11563
+ }
11564
+ return out;
11565
+ }
11555
11566
 
11556
11567
  // server/src/db-write.ts
11557
11568
  import { constants as C2, DatabaseSync as DatabaseSync2 } from "node:sqlite";
@@ -12901,12 +12912,15 @@ async function selectForReview(db, projectId2, files) {
12901
12912
  because: `anchored to ${a.path}${a.symbol ? ` ${a.symbol}` : ""}`
12902
12913
  });
12903
12914
  const added = files.flatMap((f) => f.added.map((l) => ({ path: f.path, text: l.normalize("NFKC").toLowerCase() })));
12904
- const free = await live.where("u.stance", "in", ["dont", "defer"]).where(({ not, exists, selectFrom }) => not(exists(selectFrom("unit_anchor as a").select("a.id").whereRef("a.unit_id", "=", "u.id").where("a.retired_at", "is", null)))).select(["u.id", "u.revision", "u.key", "u.kind", "u.stance", "u.text"]).execute();
12905
- const options = free.length ? await db.selectFrom("unit_option").select(["unit_id", "text"]).where("unit_id", "in", free.map((u) => u.id)).execute() : [];
12915
+ const locationFree = live.where("u.stance", "in", ["dont", "defer"]).where(({ not, exists, selectFrom }) => not(exists(selectFrom("unit_anchor as a").select("a.id").whereRef("a.unit_id", "=", "u.id").where("a.retired_at", "is", null))));
12916
+ const [free, options] = await Promise.all([
12917
+ locationFree.select(["u.id", "u.revision", "u.key", "u.kind", "u.stance", "u.text"]).execute(),
12918
+ db.selectFrom("unit_option").select(["unit_id", "text"]).where("unit_id", "in", locationFree.select("u.id")).orderBy("id").execute().then(byUnit)
12919
+ ]);
12906
12920
  for (const u of free) {
12907
12921
  if (out.has(u.id))
12908
12922
  continue;
12909
- for (const o of options.filter((x) => x.unit_id === u.id && x.text.trim().length >= 3)) {
12923
+ for (const o of (options.get(u.id) ?? []).filter((x) => x.text.trim().length >= 3)) {
12910
12924
  const name = o.text.normalize("NFKC").toLowerCase();
12911
12925
  const hit = added.find((l) => l.text.includes(name));
12912
12926
  if (hit) {
@@ -13260,27 +13274,38 @@ async function namedInCommand(db, projectId2, root, cwd, command) {
13260
13274
  }
13261
13275
  return [...out];
13262
13276
  };
13263
- return paths.map((r) => r.path).filter((p) => forms(p).some((t) => new RegExp(`(?:^|[${edge}])${esc(t)}(?:$|[${edge}:])`).test(command)));
13277
+ return paths.map((r) => r.path).filter((p) => command.includes(p.slice(p.lastIndexOf("/") + 1)) && forms(p).some((t) => command.includes(t) && new RegExp(`(?:^|[${edge}])${esc(t)}(?:$|[${edge}:])`).test(command)));
13264
13278
  }
13265
13279
  function pathNamed(prompt, root, rel) {
13266
13280
  const steps = (p) => p.split(/[\\/]/).map((s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("[\\\\/]");
13267
13281
  return new RegExp(`(?<![A-Za-z0-9_$.\\-/\\\\])(?:(?:\\.[\\\\/])?${steps(rel)}|${steps(path8.join(root, rel))})(?![A-Za-z0-9_$\\-/\\\\]|\\.[A-Za-z0-9_$])`).test(prompt);
13268
13282
  }
13283
+ function once(f) {
13284
+ const seen = new Map;
13285
+ return (k) => {
13286
+ if (!seen.has(k))
13287
+ seen.set(k, f(k));
13288
+ return seen.get(k);
13289
+ };
13290
+ }
13269
13291
  async function onPrompt(db, projectId2, root, prompt) {
13270
13292
  const text = prompt.normalize("NFKC");
13271
13293
  const lower = text.toLowerCase();
13272
- const word = (w, s) => new RegExp(`(?<![\\p{L}\\p{N}_$])${w.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}(?![\\p{L}\\p{N}_$])`, "u").test(s);
13273
- const named2 = (symbol) => symbol.length >= 3 && (/[^a-z]/.test(symbol) ? word(symbol, text) : text.includes(`${symbol}(`) || text.includes(`\`${symbol}\``));
13274
- const units = await deliverable(db, projectId2).select(["u.id", "u.key", "u.kind", "u.stance", "u.text"]).execute();
13275
- const ids = units.map((u) => u.id);
13276
- const [anchors, options] = ids.length ? await Promise.all([
13277
- db.selectFrom("unit_anchor").select(["unit_id", "path", "symbol"]).where("unit_id", "in", ids).where("retired_at", "is", null).execute(),
13278
- db.selectFrom("unit_option").select(["unit_id", "text", "outcome"]).where("unit_id", "in", ids).execute()
13279
- ]) : [[], []];
13294
+ const word = (w, s) => s.includes(w) && new RegExp(`(?<![\\p{L}\\p{N}_$])${w.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}(?![\\p{L}\\p{N}_$])`, "u").test(s);
13295
+ const named2 = once((symbol) => symbol.length >= 3 && (/[^a-z]/.test(symbol) ? word(symbol, text) : text.includes(`${symbol}(`) || text.includes(`\`${symbol}\``)));
13296
+ const slashed = prompt.replaceAll("\\", "/");
13297
+ const pathIn = once((rel) => slashed.includes(rel) && pathNamed(prompt, root, rel));
13298
+ const optionIn = once((option) => option.length >= 3 && word(option.normalize("NFKC").toLowerCase(), lower));
13299
+ const units = await deliverable(db, projectId2).select(["u.id", "u.key", "u.kind", "u.stance", "u.text"]).orderBy("u.kind").orderBy("u.id").execute();
13300
+ const ids = deliverable(db, projectId2).select("u.id");
13301
+ const [anchors, options] = await Promise.all([
13302
+ db.selectFrom("unit_anchor").select(["unit_id", "path", "symbol"]).where("unit_id", "in", ids).where("retired_at", "is", null).orderBy("id").execute().then(byUnit),
13303
+ db.selectFrom("unit_option").select(["unit_id", "text", "outcome"]).where("unit_id", "in", ids).orderBy("id").execute().then(byUnit)
13304
+ ]);
13280
13305
  const hits = [];
13281
13306
  for (const u of units) {
13282
- const a = anchors.find((x) => x.unit_id === u.id && (x.symbol && named2(x.symbol) || pathNamed(prompt, root, x.path)));
13283
- const o = options.find((x) => x.unit_id === u.id && x.text.length >= 3 && word(x.text.normalize("NFKC").toLowerCase(), lower));
13307
+ const a = anchors.get(u.id)?.find((x) => x.symbol && named2(x.symbol) || pathIn(x.path));
13308
+ const o = options.get(u.id)?.find((x) => optionIn(x.text));
13284
13309
  if (a)
13285
13310
  hits.push({ u, why: ` [names ${a.symbol && named2(a.symbol) ? a.symbol : a.path}]` });
13286
13311
  else if (o)
@@ -13387,12 +13412,12 @@ async function beforeReview(db, projectId2, root, call) {
13387
13412
  const base = inline(change.base);
13388
13413
  if (!n)
13389
13414
  return said(`Sphica: no local change against ${base} to check against past decisions.`, "no change");
13390
- const once = `${change.base}\x00${change.digest}`;
13415
+ const once2 = `${change.base}\x00${change.digest}`;
13391
13416
  const live = new Set((await deliverable(db, projectId2).select("u.id").execute()).map((r) => r.id));
13392
13417
  const rows = (await selectForReview(db, projectId2, change.files)).filter((a) => live.has(a.id));
13393
13418
  const checked = `checked ${n} changed path${n === 1 ? "" : "s"} against ${base}`;
13394
13419
  if (!rows.length)
13395
- return { ...said(`Sphica ${checked}: no active recorded decision applies.`, null), once };
13420
+ return { ...said(`Sphica ${checked}: no active recorded decision applies.`, null), once: once2 };
13396
13421
  const shown = rows.slice(0, LIMITS.review.units);
13397
13422
  const ai = await aiDecided(db, shown.map((u) => u.id));
13398
13423
  const f = fitMarked(shown.map((u) => line(u, ` [${inline(u.because)}]`, ai.has(u.id))), LIMITS.review.chars, `Sphica: past decisions that apply to this change (${checked}). ${NOTE}; compare the change against each:`, ai, shown.map((u) => u.id));
@@ -13404,7 +13429,7 @@ async function beforeReview(db, projectId2, root, call) {
13404
13429
  omitted,
13405
13430
  path: null,
13406
13431
  reason: null,
13407
- once
13432
+ once: once2
13408
13433
  };
13409
13434
  }
13410
13435
  function toldBefore(session, key) {
package/dist/mcp.js CHANGED
@@ -46105,6 +46105,17 @@ function kyselyOn(connect) {
46105
46105
  function openReader(file2 = dbFile()) {
46106
46106
  return kyselyOn(() => connectReader(file2));
46107
46107
  }
46108
+ function byUnit(rows) {
46109
+ const out = new Map;
46110
+ for (const r of rows) {
46111
+ const list = out.get(r.unit_id);
46112
+ if (list)
46113
+ list.push(r);
46114
+ else
46115
+ out.set(r.unit_id, [r]);
46116
+ }
46117
+ return out;
46118
+ }
46108
46119
 
46109
46120
  // server/src/knowledge.ts
46110
46121
  var UNIT_KINDS = [
@@ -47924,12 +47935,15 @@ async function selectForReview(db, projectId2, files) {
47924
47935
  because: `anchored to ${a.path}${a.symbol ? ` ${a.symbol}` : ""}`
47925
47936
  });
47926
47937
  const added = files.flatMap((f) => f.added.map((l) => ({ path: f.path, text: l.normalize("NFKC").toLowerCase() })));
47927
- const free = await live.where("u.stance", "in", ["dont", "defer"]).where(({ not, exists, selectFrom }) => not(exists(selectFrom("unit_anchor as a").select("a.id").whereRef("a.unit_id", "=", "u.id").where("a.retired_at", "is", null)))).select(["u.id", "u.revision", "u.key", "u.kind", "u.stance", "u.text"]).execute();
47928
- const options = free.length ? await db.selectFrom("unit_option").select(["unit_id", "text"]).where("unit_id", "in", free.map((u) => u.id)).execute() : [];
47938
+ const locationFree = live.where("u.stance", "in", ["dont", "defer"]).where(({ not, exists, selectFrom }) => not(exists(selectFrom("unit_anchor as a").select("a.id").whereRef("a.unit_id", "=", "u.id").where("a.retired_at", "is", null))));
47939
+ const [free, options] = await Promise.all([
47940
+ locationFree.select(["u.id", "u.revision", "u.key", "u.kind", "u.stance", "u.text"]).execute(),
47941
+ db.selectFrom("unit_option").select(["unit_id", "text"]).where("unit_id", "in", locationFree.select("u.id")).orderBy("id").execute().then(byUnit)
47942
+ ]);
47929
47943
  for (const u of free) {
47930
47944
  if (out.has(u.id))
47931
47945
  continue;
47932
- for (const o of options.filter((x) => x.unit_id === u.id && x.text.trim().length >= 3)) {
47946
+ for (const o of (options.get(u.id) ?? []).filter((x) => x.text.trim().length >= 3)) {
47933
47947
  const name = o.text.normalize("NFKC").toLowerCase();
47934
47948
  const hit = added.find((l) => l.text.includes(name));
47935
47949
  if (hit) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sphica",
3
- "version": "0.6.38",
3
+ "version": "0.6.39",
4
4
  "description": "Records Claude Code and Codex sessions on your machine and keeps past implementation and decisions, with their sources, for your agent to find.",
5
5
  "license": "MIT",
6
6
  "type": "module",