@tekmidian/pai 0.61.0 → 0.62.0
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/dist/{async-CLvuY7b-.mjs → async-DNVWtQl2.mjs} +2 -2
- package/dist/{async-CLvuY7b-.mjs.map → async-DNVWtQl2.mjs.map} +1 -1
- package/dist/{chain-C5oeyUg4.mjs → chain-CuaDawK9.mjs} +2 -2
- package/dist/{chain-C5oeyUg4.mjs.map → chain-CuaDawK9.mjs.map} +1 -1
- package/dist/cli/index.mjs +11 -11
- package/dist/cli/program.mjs +11 -11
- package/dist/{context-handover-cache-BdtJZpgv.mjs → context-handover-cache-DFNnlWv2.mjs} +2 -2
- package/dist/{context-handover-cache-BdtJZpgv.mjs.map → context-handover-cache-DFNnlWv2.mjs.map} +1 -1
- package/dist/daemon/index.mjs +8 -8
- package/dist/{daemon-DSsIEqzW.mjs → daemon-Bf7Eock4.mjs} +32 -18
- package/dist/{daemon-DSsIEqzW.mjs.map → daemon-Bf7Eock4.mjs.map} +1 -1
- package/dist/daemon-bJi1gDkG.mjs +19 -0
- package/dist/daemon-mcp/index.mjs +4 -4
- package/dist/{factory-EUUhSSoq.mjs → factory-BozZa81q.mjs} +3 -3
- package/dist/{factory-EUUhSSoq.mjs.map → factory-BozZa81q.mjs.map} +1 -1
- package/dist/{factory-DW7BCJJT.mjs → factory-UO9_DFMN.mjs} +1 -1
- package/dist/{fallback-DDbJVaR8.mjs → fallback-F0TWGVM2.mjs} +2 -2
- package/dist/{fallback-DDbJVaR8.mjs.map → fallback-F0TWGVM2.mjs.map} +1 -1
- package/dist/{helpers-D9WkIf9R.mjs → helpers-Dj-B314s.mjs} +3 -2
- package/dist/{helpers-D9WkIf9R.mjs.map → helpers-Dj-B314s.mjs.map} +1 -1
- package/dist/hooks/block-sleep-poll.mjs.map +2 -2
- package/dist/hooks/load-project-context.mjs +8513 -133
- package/dist/hooks/load-project-context.mjs.map +4 -4
- package/dist/hooks/security-validator.mjs.map +1 -1
- package/dist/hooks/worker-guard.mjs +7859 -0
- package/dist/hooks/worker-guard.mjs.map +7 -0
- package/dist/hooks/worker-status-line.mjs +101 -8
- package/dist/hooks/worker-status-line.mjs.map +4 -4
- package/dist/index.mjs +1 -1
- package/dist/{indexer-backend-DcDtin1O.mjs → indexer-backend-BN9rpp9O.mjs} +2 -2
- package/dist/{main-resolver-DIQ6m_RA.mjs → main-resolver-BIft_FVF.mjs} +3 -3
- package/dist/{main-resolver-DIQ6m_RA.mjs.map → main-resolver-BIft_FVF.mjs.map} +1 -1
- package/dist/{main-resolver-CxOsxtOr.mjs → main-resolver-C9-poMdi.mjs} +1 -1
- package/dist/{planner-D8jAr_sx.mjs → planner-BG9ivPj0.mjs} +4 -4
- package/dist/{planner-D8jAr_sx.mjs.map → planner-BG9ivPj0.mjs.map} +1 -1
- package/dist/{postgres-nvU5pShF.mjs → postgres-CxD6_Dca.mjs} +3 -3
- package/dist/{postgres-nvU5pShF.mjs.map → postgres-CxD6_Dca.mjs.map} +1 -1
- package/dist/{program-BTdspOOa.mjs → program-BRvCzhjx.mjs} +157 -40
- package/dist/program-BRvCzhjx.mjs.map +1 -0
- package/dist/{run-CxxZKEZw.mjs → run-BVQZI79D.mjs} +281 -85
- package/dist/run-BVQZI79D.mjs.map +1 -0
- package/dist/{session-keepalive-urk--pfa.mjs → session-keepalive-DJA97K2X.mjs} +2 -2
- package/dist/{session-keepalive-urk--pfa.mjs.map → session-keepalive-DJA97K2X.mjs.map} +1 -1
- package/dist/{sqlite-D9p5a4qe.mjs → sqlite-CfKfuggn.mjs} +2 -2
- package/dist/{sqlite-D9p5a4qe.mjs.map → sqlite-CfKfuggn.mjs.map} +1 -1
- package/dist/{tools-r-7ZG8B5.mjs → tools-B52IvaU6.mjs} +3 -3
- package/dist/{tools-qXyHFwNj.mjs → tools-DFdPbX-X.mjs} +2 -2
- package/dist/{tools-qXyHFwNj.mjs.map → tools-DFdPbX-X.mjs.map} +1 -1
- package/dist/{vault-indexer-DHYBpRZ5.mjs → vault-indexer-mCFus_AM.mjs} +2 -2
- package/dist/{vault-indexer-DHYBpRZ5.mjs.map → vault-indexer-mCFus_AM.mjs.map} +1 -1
- package/dist/{wakeup-C48hcN6O.mjs → wakeup-DO1O4udw.mjs} +2 -2
- package/dist/{wakeup-C48hcN6O.mjs.map → wakeup-DO1O4udw.mjs.map} +1 -1
- package/dist/{work-queue-worker-DUvPiwGO.mjs → work-queue-worker-BbrC3I_R.mjs} +2 -2
- package/dist/{work-queue-worker-DUvPiwGO.mjs.map → work-queue-worker-BbrC3I_R.mjs.map} +1 -1
- package/dist/{work-queue-worker-1_VBfI_k.mjs → work-queue-worker-z-AATZ2t.mjs} +3 -3
- package/docs/commands/README.md +2 -0
- package/docs/commands/worker.md +27 -0
- package/package.json +2 -2
- package/scripts/build-hooks.mjs +6 -5
- package/scripts/build-skill-stubs.mjs +6 -5
- package/src/hooks/ts/lib/worker-guard.test.ts +188 -0
- package/src/hooks/ts/lib/worker-guard.ts +315 -0
- package/src/hooks/ts/pre-tool-use/worker-guard.ts +75 -0
- package/src/hooks/ts/session-start/load-project-context.ts +14 -0
- package/dist/daemon-MoFF4oeg.mjs +0 -19
- package/dist/program-BTdspOOa.mjs.map +0 -1
- package/dist/run-CxxZKEZw.mjs.map +0 -1
package/dist/daemon/index.mjs
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import "../utils-C9HsYDpO.mjs";
|
|
3
3
|
import "../migrate-BD7D8EEh.mjs";
|
|
4
|
-
import "../factory-
|
|
5
|
-
import "../wakeup-
|
|
6
|
-
import "../context-handover-cache-
|
|
4
|
+
import "../factory-BozZa81q.mjs";
|
|
5
|
+
import "../wakeup-DO1O4udw.mjs";
|
|
6
|
+
import "../context-handover-cache-DFNnlWv2.mjs";
|
|
7
7
|
import { a as ensureConfigDir, s as loadConfig } from "../config-CQCmH_gV.mjs";
|
|
8
8
|
import "../run-env-BE5xyCwy.mjs";
|
|
9
|
-
import "../run-
|
|
9
|
+
import "../run-BVQZI79D.mjs";
|
|
10
10
|
import { t as PaiClient } from "../ipc-client-Dasm515c.mjs";
|
|
11
11
|
import "../server-BY6AedmC.mjs";
|
|
12
12
|
import "../state-n13uPK5B.mjs";
|
|
13
13
|
import "../aibroker-client-BK1h--W_.mjs";
|
|
14
|
-
import "../session-keepalive-
|
|
14
|
+
import "../session-keepalive-DJA97K2X.mjs";
|
|
15
15
|
import "../embeddings-DfrYNIng.mjs";
|
|
16
|
-
import { t as serve } from "../daemon-
|
|
16
|
+
import { t as serve } from "../daemon-Bf7Eock4.mjs";
|
|
17
17
|
import "../router-DjFZIoDl.mjs";
|
|
18
|
-
import "../tools-
|
|
19
|
-
import "../work-queue-worker-
|
|
18
|
+
import "../tools-DFdPbX-X.mjs";
|
|
19
|
+
import "../work-queue-worker-BbrC3I_R.mjs";
|
|
20
20
|
import { Command } from "commander";
|
|
21
21
|
|
|
22
22
|
//#region src/daemon/index.ts
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { n as createRegistryBackend, o as getBackendOutage, r as createStorageBackend } from "./factory-
|
|
2
|
-
import { a as enqueue, c as loadQueue, o as getStats } from "./context-handover-cache-
|
|
1
|
+
import { n as createRegistryBackend, o as getBackendOutage, r as createStorageBackend } from "./factory-BozZa81q.mjs";
|
|
2
|
+
import { a as enqueue, c as loadQueue, o as getStats } from "./context-handover-cache-DFNnlWv2.mjs";
|
|
3
3
|
import { S as DEFAULT_NOTIFICATION_CONFIG, d as readMainConfigRaw, f as writeMainConfigRaw } from "./config-CQCmH_gV.mjs";
|
|
4
4
|
import { E as readWorkersSection } from "./run-env-BE5xyCwy.mjs";
|
|
5
|
-
import {
|
|
5
|
+
import { A as appendLedger, B as loadStatus, P as alive, R as isChatPane, U as nowStamp, V as loadStatuses, n as runWorker, v as itermForClaudeSession } from "./run-BVQZI79D.mjs";
|
|
6
6
|
import { h as ledgerPath, m as eventsPath, v as workersLogDir } from "./server-BY6AedmC.mjs";
|
|
7
7
|
import { A as vaultIndexInProgress, C as setShutdownRequested, D as shutdownRequested, E as setVaultIndexInProgress, O as startTime, S as setRegistryBackend, T as setStorageBackend, _ as setIndexSchedulerTimer, a as indexInProgress, b as setLastVaultIndexTime, c as lastIndexTime, d as registryBackend, f as setCacheKeepaliveTimer, g as setIndexInProgress, h as setEmbedSchedulerTimer, i as embedSchedulerTimer, k as storageBackend, l as lastVaultIndexTime, m as setEmbedInProgress, n as daemonConfig, o as indexSchedulerTimer, p as setDaemonConfig, r as embedInProgress, s as lastEmbedTime, t as cacheKeepaliveTimer, u as notificationConfig, v as setLastEmbedTime, w as setStartTime, x as setNotificationConfig, y as setLastIndexTime } from "./state-n13uPK5B.mjs";
|
|
8
|
-
import { n as runSessionKeepaliveTick } from "./session-keepalive-
|
|
8
|
+
import { n as runSessionKeepaliveTick } from "./session-keepalive-DJA97K2X.mjs";
|
|
9
9
|
import { t as configureEmbeddingModel } from "./embeddings-DfrYNIng.mjs";
|
|
10
10
|
import { t as routeNotification } from "./router-DjFZIoDl.mjs";
|
|
11
|
-
import { C as toolProjectInfo, D as toolMemoryGet, O as toolMemorySearch, S as toolProjectHealth, T as toolProjectTodo, a as toolMemoryWakeup, b as toolSessionRoute, i as toolMemoryTaxonomy, n as toolMemoryFeedback, t as toolMemoryKgSearch, v as toolRegistrySearch, w as toolProjectList, x as toolProjectDetect, y as toolSessionList } from "./tools-
|
|
11
|
+
import { C as toolProjectInfo, D as toolMemoryGet, O as toolMemorySearch, S as toolProjectHealth, T as toolProjectTodo, a as toolMemoryWakeup, b as toolSessionRoute, i as toolMemoryTaxonomy, n as toolMemoryFeedback, t as toolMemoryKgSearch, v as toolRegistrySearch, w as toolProjectList, x as toolProjectDetect, y as toolSessionList } from "./tools-DFdPbX-X.mjs";
|
|
12
12
|
import { t as detectTopicShift } from "./detector-3g7XuU1r.mjs";
|
|
13
|
-
import { i as stopWorker, n as notifyNewWork, r as startWorker } from "./work-queue-worker-
|
|
13
|
+
import { i as stopWorker, n as notifyNewWork, r as startWorker } from "./work-queue-worker-BbrC3I_R.mjs";
|
|
14
14
|
import { appendFileSync, existsSync, mkdirSync, readFileSync, renameSync, unlinkSync, writeFileSync } from "node:fs";
|
|
15
15
|
import { setPriority } from "node:os";
|
|
16
16
|
import { dirname, join } from "node:path";
|
|
@@ -652,7 +652,7 @@ async function runVaultIndex() {
|
|
|
652
652
|
const t0 = Date.now();
|
|
653
653
|
process.stderr.write("[pai-daemon] Starting vault index run...\n");
|
|
654
654
|
try {
|
|
655
|
-
const { indexVault } = await import("./vault-indexer-
|
|
655
|
+
const { indexVault } = await import("./vault-indexer-mCFus_AM.mjs");
|
|
656
656
|
const r = await indexVault(storageBackend, vaultProjectId, daemonConfig.vaultPath);
|
|
657
657
|
const elapsed = Date.now() - t0;
|
|
658
658
|
setLastVaultIndexTime(Date.now());
|
|
@@ -723,7 +723,7 @@ async function runEmbed() {
|
|
|
723
723
|
const rows = await registryBackend.listProjects({ status: "active" });
|
|
724
724
|
for (const r of rows) projectNames.set(r.id, r.slug);
|
|
725
725
|
} catch {}
|
|
726
|
-
const { embedChunksWithBackend } = await import("./indexer-backend-
|
|
726
|
+
const { embedChunksWithBackend } = await import("./indexer-backend-BN9rpp9O.mjs");
|
|
727
727
|
const count = await embedChunksWithBackend(storageBackend, () => shutdownRequested, projectNames, { maxMillis: 24e4 });
|
|
728
728
|
const elapsed = Date.now() - t0;
|
|
729
729
|
setLastEmbedTime(Date.now());
|
|
@@ -770,12 +770,12 @@ const REGISTRY_SCAN_STARTUP_DELAY_MS = 1e4;
|
|
|
770
770
|
function startRegistryScanScheduler() {
|
|
771
771
|
process.stderr.write("[pai-daemon] Registry scan scheduler: every 30min (first in 10s)\n");
|
|
772
772
|
setTimeout(() => {
|
|
773
|
-
import("./work-queue-worker-
|
|
773
|
+
import("./work-queue-worker-z-AATZ2t.mjs").then(({ enqueueRegistryScan }) => enqueueRegistryScan()).catch((e) => {
|
|
774
774
|
process.stderr.write(`[pai-daemon] Startup registry scan error: ${e}\n`);
|
|
775
775
|
});
|
|
776
776
|
}, REGISTRY_SCAN_STARTUP_DELAY_MS);
|
|
777
777
|
const timer = setInterval(() => {
|
|
778
|
-
import("./work-queue-worker-
|
|
778
|
+
import("./work-queue-worker-z-AATZ2t.mjs").then(({ enqueueRegistryScan }) => enqueueRegistryScan()).catch((e) => {
|
|
779
779
|
process.stderr.write(`[pai-daemon] Scheduled registry scan error: ${e}\n`);
|
|
780
780
|
});
|
|
781
781
|
}, REGISTRY_SCAN_INTERVAL_MS);
|
|
@@ -949,7 +949,7 @@ async function dispatchTool(method, params) {
|
|
|
949
949
|
case "zettel_themes":
|
|
950
950
|
case "zettel_god_notes":
|
|
951
951
|
case "zettel_communities": {
|
|
952
|
-
const { toolZettelExplore, toolZettelHealth, toolZettelSurprise, toolZettelSuggest, toolZettelConverse, toolZettelThemes, toolZettelGodNotes, toolZettelCommunities } = await import("./tools-
|
|
952
|
+
const { toolZettelExplore, toolZettelHealth, toolZettelSurprise, toolZettelSuggest, toolZettelConverse, toolZettelThemes, toolZettelGodNotes, toolZettelCommunities } = await import("./tools-B52IvaU6.mjs");
|
|
953
953
|
switch (method) {
|
|
954
954
|
case "zettel_explore": return toolZettelExplore(storageBackend, p);
|
|
955
955
|
case "zettel_health": return toolZettelHealth(storageBackend, p);
|
|
@@ -991,7 +991,7 @@ async function dispatchTool(method, params) {
|
|
|
991
991
|
case "kg_query":
|
|
992
992
|
case "kg_invalidate":
|
|
993
993
|
case "kg_contradictions": {
|
|
994
|
-
const { toolKgAdd, toolKgQuery, toolKgInvalidate, toolKgContradictions } = await import("./tools-
|
|
994
|
+
const { toolKgAdd, toolKgQuery, toolKgInvalidate, toolKgContradictions } = await import("./tools-B52IvaU6.mjs");
|
|
995
995
|
if (!storageBackend.supportsPostgresFeatures) throw new Error(`${method} requires a Postgres storage backend`);
|
|
996
996
|
switch (method) {
|
|
997
997
|
case "kg_add": return toolKgAdd(storageBackend, p);
|
|
@@ -1002,7 +1002,7 @@ async function dispatchTool(method, params) {
|
|
|
1002
1002
|
break;
|
|
1003
1003
|
}
|
|
1004
1004
|
case "memory_tunnels": {
|
|
1005
|
-
const { toolMemoryTunnels } = await import("./tools-
|
|
1005
|
+
const { toolMemoryTunnels } = await import("./tools-B52IvaU6.mjs");
|
|
1006
1006
|
return toolMemoryTunnels(registryBackend, storageBackend, p);
|
|
1007
1007
|
}
|
|
1008
1008
|
case "memory_feedback": return await toolMemoryFeedback(storageBackend, p);
|
|
@@ -1516,7 +1516,12 @@ async function handleRequest(request, socket) {
|
|
|
1516
1516
|
//#region src/storage/postgres/fts-migration.ts
|
|
1517
1517
|
const DONE_MARKER = "fts:simple";
|
|
1518
1518
|
const PROGRESS_PREFIX = "fts:simple:inprogress:";
|
|
1519
|
-
const BATCH_SIZE =
|
|
1519
|
+
const BATCH_SIZE = 1e3;
|
|
1520
|
+
const MAX_ATTEMPTS = 5;
|
|
1521
|
+
const RETRYABLE_CODES = new Set(["40P01", "40001"]);
|
|
1522
|
+
function sleep(ms) {
|
|
1523
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
1524
|
+
}
|
|
1520
1525
|
async function migrateFtsConfig(backend) {
|
|
1521
1526
|
const pool = backend.getPool();
|
|
1522
1527
|
if ((await pool.query(`SELECT 1 FROM information_schema.tables WHERE table_name = 'pai_chunks'`)).rowCount === 0) return;
|
|
@@ -1548,9 +1553,18 @@ async function migrateFtsConfig(backend) {
|
|
|
1548
1553
|
const idRows = await pool.query(sql, params);
|
|
1549
1554
|
if (idRows.rows.length === 0) break;
|
|
1550
1555
|
const ids = idRows.rows.map((r) => r.id);
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1556
|
+
for (let attempt = 1;; attempt++) try {
|
|
1557
|
+
const result = await pool.query(`UPDATE pai_chunks c SET fts_vector = to_tsvector('simple', COALESCE(c.text, ''))
|
|
1558
|
+
FROM (SELECT id FROM pai_chunks WHERE id = ANY($1::text[]) ORDER BY id FOR UPDATE) s
|
|
1559
|
+
WHERE c.id = s.id
|
|
1560
|
+
AND c.fts_vector IS DISTINCT FROM to_tsvector('simple', COALESCE(c.text, ''))`, [ids]);
|
|
1561
|
+
totalUpdated += result.rowCount ?? 0;
|
|
1562
|
+
break;
|
|
1563
|
+
} catch (err) {
|
|
1564
|
+
const code = err.code;
|
|
1565
|
+
if (attempt >= MAX_ATTEMPTS || !code || !RETRYABLE_CODES.has(code)) throw err;
|
|
1566
|
+
await sleep(200 * attempt);
|
|
1567
|
+
}
|
|
1554
1568
|
lastId = ids[ids.length - 1];
|
|
1555
1569
|
batchN++;
|
|
1556
1570
|
if (batchN % 20 === 0) {
|
|
@@ -1723,4 +1737,4 @@ async function serve(config) {
|
|
|
1723
1737
|
|
|
1724
1738
|
//#endregion
|
|
1725
1739
|
export { serve as t };
|
|
1726
|
-
//# sourceMappingURL=daemon-
|
|
1740
|
+
//# sourceMappingURL=daemon-Bf7Eock4.mjs.map
|