@anchrd/intel-api 0.5.0 → 0.5.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.
@@ -151,10 +151,14 @@ export function createKnowledgeRepository(deps) {
151
151
  try {
152
152
  await deps.db.batch([
153
153
  deps.db
154
+ // ⚠️ `context_policy` is dead and is written anyway (#76). The column is NOT NULL
155
+ // without a DEFAULT and D1 will not let it be dropped — migration 0009 carries the
156
+ // reason. The fixed value is the price; nothing reads it, and the contract no longer
157
+ // knows the field. When the column goes (anchrd/intel#86), this line goes with it.
154
158
  .prepare(`INSERT INTO knowledge_nodes (
155
- id, parent_id, kind, title, description, owner_id,
159
+ id, parent_id, kind, title, description, context_policy, owner_id,
156
160
  current_version_id, created_at, updated_at, archived_at
157
- ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`)
161
+ ) VALUES (?, ?, ?, ?, ?, 'relevant', ?, ?, ?, ?, ?)`)
158
162
  .bind(node.id, node.parentId, node.kind, node.title, node.description, node.ownerId, node.currentVersionId, node.createdAt, node.updatedAt, node.archivedAt),
159
163
  deps.db
160
164
  .prepare(`INSERT INTO idempotency_keys (
@@ -1,51 +1,33 @@
1
- -- #76. `context_policy` leaves the tree. It was written, stored and handed back, and never once
2
- -- read to decide anything — and it could not have been: it instructed a retrieval Intel does not
3
- -- perform. Intel hands out references and the agent fetches what it needs (D24).
1
+ -- #76. `context_policy` leaves the contract, the UI and every MCP answer. The COLUMN stays.
4
2
  --
5
- -- ⚠️ SQLite cannot drop a column that a CHECK constraint names, and this one names itself. The
6
- -- table has to be rebuilt, which for `knowledge_nodes` means six foreign keys pointing at it
7
- -- including one from itself. The order below is SQLite's own twelve-step recipe, and every line of
8
- -- it is load-bearing:
3
+ -- ⚠️ That is not the intent, it is what D1 permits. SQLite cannot drop a column a CHECK names, and
4
+ -- this one names itself. The way around it is a table rebuild, and `knowledge_nodes` carries six
5
+ -- foreign keys, one of them from itself.
9
6
  --
10
- -- * `PRAGMA foreign_keys` is turned off first. Without it the DROP below would either fail or
11
- -- cascade into the rows of every referencing table.
12
- -- * The new table is created under a different name and renamed afterwards, rather than the old
13
- -- one being renamed out of the way. Renaming the OLD table would silently re-point every
14
- -- foreign key in the other five tables at `knowledge_nodes_old` SQLite updates references to
15
- -- follow a rename, and that is exactly what must not happen here.
16
- -- * The indexes are recreated, because dropping the table drops them with it.
17
- -- * `PRAGMA foreign_key_check` is the proof, not the hope. The integration test asserts it comes
18
- -- back empty.
19
- PRAGMA foreign_keys = OFF;
20
-
21
- CREATE TABLE knowledge_nodes_rebuilt (
22
- id TEXT PRIMARY KEY NOT NULL,
23
- parent_id TEXT REFERENCES knowledge_nodes(id),
24
- kind TEXT NOT NULL CHECK (kind IN ('folder', 'document', 'attachment', 'table')),
25
- title TEXT NOT NULL CHECK (length(title) BETWEEN 1 AND 240),
26
- description TEXT CHECK (description IS NULL OR length(description) <= 2000),
27
- owner_id TEXT NOT NULL,
28
- current_version_id TEXT,
29
- created_at TEXT NOT NULL,
30
- updated_at TEXT NOT NULL,
31
- archived_at TEXT
32
- );
33
-
34
- INSERT INTO knowledge_nodes_rebuilt (
35
- id, parent_id, kind, title, description, owner_id,
36
- current_version_id, created_at, updated_at, archived_at
37
- )
38
- SELECT id, parent_id, kind, title, description, owner_id,
39
- current_version_id, created_at, updated_at, archived_at
40
- FROM knowledge_nodes;
41
-
42
- DROP TABLE knowledge_nodes;
43
-
44
- ALTER TABLE knowledge_nodes_rebuilt RENAME TO knowledge_nodes;
45
-
46
- CREATE INDEX knowledge_nodes_parent_idx ON knowledge_nodes(parent_id, archived_at, title);
47
- CREATE INDEX knowledge_nodes_owner_idx ON knowledge_nodes(owner_id, archived_at);
48
-
49
- PRAGMA foreign_key_check;
50
-
51
- PRAGMA foreign_keys = ON;
7
+ -- Three attempts against the real database, three failures, each with its own lesson:
8
+ --
9
+ -- 1. `PRAGMA foreign_keys = OFF` **ignored** by D1 over its HTTP API. It works locally, because
10
+ -- miniflare honours it, so the integration test was green while production answered
11
+ -- `FOREIGN KEY constraint failed` on the DROP. ⚠️ A green migration test does not prove a D1
12
+ -- migration runs.
13
+ -- 2. `PRAGMA defer_foreign_keys = true` — it works, but the self-reference was written as
14
+ -- `REFERENCES knowledge_nodes(id)` and therefore pointed at the table this same migration was
15
+ -- about to drop. SQLite rewrites a self-reference along with the rename, so the temporary name
16
+ -- belongs there.
17
+ -- 3. Self-reference fixed → green through `wrangler d1 migrations apply --local`, still red
18
+ -- against `--remote`. The reason is the execution model: D1 commits the statements of a
19
+ -- migration file one at a time, and the deferral only lasts until the next COMMIT. After the
20
+ -- first statement the reprieve is gone and `DROP TABLE` runs unprotected.
21
+ --
22
+ -- A table rebuild with foreign keys is therefore not possible inside a migration file. It needs a
23
+ -- session that drives the transaction itself.
24
+ --
25
+ -- What holds instead: the column sits in D1, nothing reads it, and `db.ts` writes a fixed value on
26
+ -- insert because it is NOT NULL without a DEFAULT. The contract does not know it — for every
27
+ -- consumer it is gone. What remains is one dead column, and that is the price of Intel running.
28
+ --
29
+ -- How it disappears after all is anchrd/intel#86.
30
+ --
31
+ -- This file deliberately does nothing. It is where the above is written down; deleted, it would be
32
+ -- a gap in the numbering that nobody explains.
33
+ SELECT 1;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anchrd/intel-api",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
4
4
  "type": "module",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {