@esneiderbravo/speclaw 0.1.5 → 0.1.7

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.
@@ -8,6 +8,7 @@ import { AGENTS, agentById } from "../../shared/agents.js";
8
8
  import { loadPacks } from "../../modules/tools/packs.js";
9
9
  import { list } from "../lib/args.js";
10
10
  import { ui, c, banner, renderProgress, clearProgress } from "../lib/ui.js";
11
+ import { checkForUpdates } from "../lib/update-check.js";
11
12
  const PACK_LABELS = {
12
13
  agents: "dev-agents (backend · frontend · product)",
13
14
  };
@@ -36,6 +37,15 @@ export async function runInit(flags) {
36
37
  let agents;
37
38
  let packs;
38
39
  banner();
40
+ // Scaffolding with a stale version writes yesterday's foundation, so recommend
41
+ // upgrading first — prominently, before any prompts, so there's time to cancel.
42
+ // Best-effort and cache-backed (no added latency); the command still proceeds.
43
+ const upd = await checkForUpdates();
44
+ if (upd.updateAvailable && upd.latest) {
45
+ ui.warn(`You're on ${c.muted(upd.current)} — latest is ${c.bold(c.cyan(upd.latest))}.`);
46
+ ui.info(`Recommended: run ${ui.code("speclaw update")} first, then ${ui.code("speclaw init")} again.`);
47
+ ui.plain();
48
+ }
39
49
  if (interactive) {
40
50
  const answers = await clack.group({
41
51
  agents: () => clack.multiselect({
@@ -105,7 +105,9 @@ export async function maybeNotifyUpdate(cmd) {
105
105
  return;
106
106
  if (!process.stderr.isTTY)
107
107
  return;
108
- if (!cmd || ["mcp", "update", "help", "--help", "-h"].includes(cmd))
108
+ // `init` shows its own prominent up-front warning and ends on the clean
109
+ // copy-paste prompt — don't append a second notice after it.
110
+ if (!cmd || ["mcp", "update", "init", "help", "--help", "-h"].includes(cmd))
109
111
  return;
110
112
  const { current, latest, updateAvailable } = await checkForUpdates();
111
113
  if (!updateAvailable || !latest)
@@ -49,13 +49,53 @@ CREATE TABLE IF NOT EXISTS node_embeddings (
49
49
  );
50
50
  `;
51
51
  /** Schema version stamped into the `meta` table on first creation. */
52
- export const SCHEMA_VERSION = "2";
52
+ export const SCHEMA_VERSION = "3";
53
+ /** The stamped schema version, or null if the db predates versioning / has no meta table. */
54
+ function readSchemaVersion(db) {
55
+ try {
56
+ const row = db.prepare("SELECT value FROM meta WHERE key = 'schema_version'").get();
57
+ return row ? String(row.value) : null;
58
+ }
59
+ catch {
60
+ return null; // meta table doesn't exist yet
61
+ }
62
+ }
63
+ /**
64
+ * Decide whether an existing database is from an incompatible schema and must be
65
+ * rebuilt. A fresh database (no tables) needs no reset — the schema will create
66
+ * them. An existing one is stale if its stamped version differs from the current
67
+ * one, or if the `edges` table is missing a column the current code writes to
68
+ * (guards against past schema changes that weren't version-bumped).
69
+ */
70
+ function isStale(db) {
71
+ const hasEdges = db
72
+ .prepare("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = 'edges'")
73
+ .get();
74
+ if (!hasEdges)
75
+ return false;
76
+ if (readSchemaVersion(db) !== SCHEMA_VERSION)
77
+ return true;
78
+ const cols = db.prepare("PRAGMA table_info(edges)").all().map((c) => c.name);
79
+ return !cols.includes("src_node_id") || !cols.includes("dst_node_id");
80
+ }
81
+ /** Drop every table (children first) so the current schema can be recreated cleanly. */
82
+ function resetSchema(db) {
83
+ db.exec(`
84
+ DROP TABLE IF EXISTS node_embeddings;
85
+ DROP TABLE IF EXISTS edges;
86
+ DROP TABLE IF EXISTS nodes;
87
+ DROP TABLE IF EXISTS files;
88
+ DROP TABLE IF EXISTS meta;
89
+ `);
90
+ }
53
91
  /**
54
92
  * Open (creating if needed) the index database at `<projectPath>/.speclaw/index.db`.
55
93
  *
56
- * Ensures the `.speclaw` directory exists, applies the schema (idempotently),
57
- * enables WAL journaling and foreign keys, and stamps the schema version on a
58
- * fresh database.
94
+ * Ensures the `.speclaw` directory exists, enables WAL journaling and foreign
95
+ * keys, and applies the schema. If an existing database is from an incompatible
96
+ * schema (e.g. after a speclaw upgrade), it is dropped and rebuilt — `.speclaw`
97
+ * is fully regenerable, so the next index just repopulates it. The schema
98
+ * version is stamped on a fresh (or freshly reset) database.
59
99
  *
60
100
  * @param projectPath - Absolute path to the project root.
61
101
  * @returns An open connection to the index database.
@@ -65,6 +105,8 @@ export function openDb(projectPath) {
65
105
  fs.mkdirSync(dir, { recursive: true });
66
106
  const db = new DatabaseSync(path.join(dir, "index.db"));
67
107
  db.exec("PRAGMA journal_mode = WAL; PRAGMA foreign_keys = ON;");
108
+ if (isStale(db))
109
+ resetSchema(db);
68
110
  db.exec(SCHEMA);
69
111
  const row = db
70
112
  .prepare("SELECT value FROM meta WHERE key = 'schema_version'")
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@esneiderbravo/speclaw",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },