worktrust 0.11.2 → 0.11.4
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/README.md +31 -0
- package/count-behaviour.mjs +14 -8
- package/engine-release.json +1 -1
- package/git-commits.mjs +9 -6
- package/log-session.mjs +15 -15
- package/package-release.json +1 -1
- package/package.json +8 -2
- package/project-modes.mjs +184 -0
- package/remote-adapter-opencode.mjs +175 -0
- package/remote-agent-switch.mjs +33 -0
- package/remote-cli.mjs +12 -17
- package/remote-inventory.mjs +8 -4
- package/remote-opencode-events.mjs +90 -0
- package/remote-opencode-session.mjs +24 -0
- package/remote-sessions.mjs +13 -6
- package/remote-steered.mjs +7 -1
- package/remote-store.mjs +1 -1
- package/session-databases.mjs +6 -7
- package/session-local-models.mjs +165 -0
- package/worktrust.mjs +26 -7
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LOCAL MODELS, READ WHERE THEIR CHATS ARE KEPT (owner, 2026-11-09: "local models through Ollama with Qwen 3, measure those
|
|
3
|
+
* hours on the passport"). A model used through OpenCode, Goose, Hermes or OpenClaw is already read with that client's
|
|
4
|
+
* session (session-databases.mjs). Used DIRECTLY, a local model leaves its chats in two stores:
|
|
5
|
+
*
|
|
6
|
+
* · the Ollama app (ollama/ollama app/store/database.go and internal/onboarding/app_state.go, read 2026-11-09): one SQLite
|
|
7
|
+
* file, `db.sqlite` under ~/Library/Application Support/Ollama (macOS) or %LOCALAPPDATA%\Ollama (Windows); Linux has no
|
|
8
|
+
* desktop app. `chats` (one per conversation) and `messages` (role, model_name, created_at and updated_at as Go writes a
|
|
9
|
+
* time). It keeps NO token counts: the lines carry none, never an estimate from the text.
|
|
10
|
+
* · Open WebUI (open-webui/open-webui backend/open_webui/models/chats.py, chat_messages.py and env.py): `webui.db` under its
|
|
11
|
+
* DATA_DIR. Since the `chat_message` table, one row per message with role, model_id, created_at (seconds) and a `usage`
|
|
12
|
+
* JSON normalised to input_tokens / output_tokens (Ollama's prompt_eval_count / eval_count and OpenAI's names read as
|
|
13
|
+
* fallbacks, as Open WebUI's own reader does); before it, the messages inside `chat.chat` under history.messages.
|
|
14
|
+
* Open WebUI is a server for several accounts: a database that holds more than one account is NOT read (whose chats
|
|
15
|
+
* they are cannot be told from here), and the counter says so.
|
|
16
|
+
*
|
|
17
|
+
* Each query selects roles, clocks, model ids and token counts and NO text column: never a title, a message, its thinking,
|
|
18
|
+
* a tool call's arguments or result, a file, a URL or a prompt (scripts/test-local-model-readers.mjs holds every query to
|
|
19
|
+
* that and plants text that must appear nowhere). Read through node:sqlite, read-only; a store that is missing is skipped,
|
|
20
|
+
* one that is present and cannot be read (locked, damaged, another schema) is named by `stores`, never a crash.
|
|
21
|
+
*
|
|
22
|
+
* NOT READ: Ollama's server log (~/.ollama/logs/server.log). Its request lines carry a time, a status and a latency, no
|
|
23
|
+
* model and no conversation, and every request a client above already measures appears there too (docs/OPEN.md §0p).
|
|
24
|
+
* NOT VERIFIED on a real install here: the paths and schemas are read from the two projects' source; the tests run on
|
|
25
|
+
* fixtures of that shape.
|
|
26
|
+
*/
|
|
27
|
+
import { createRequire } from "node:module";
|
|
28
|
+
import { readdirSync, statSync } from "node:fs";
|
|
29
|
+
import { homedir, platform } from "node:os";
|
|
30
|
+
import { join } from "node:path";
|
|
31
|
+
import { cleanModel } from "./transcript-readers.mjs";
|
|
32
|
+
|
|
33
|
+
let sqlite;
|
|
34
|
+
/** The database read-only, or the reason it is not: `missing` (no file), `unreadable` (present, not openable). */
|
|
35
|
+
function openStore(file) {
|
|
36
|
+
try { if (!statSync(file).isFile()) return { why: "missing" }; } catch { return { why: "missing" }; }
|
|
37
|
+
if (sqlite === undefined) {
|
|
38
|
+
const warn = process.emitWarning; // node:sqlite says it is experimental on some versions: not the person's business in a hook
|
|
39
|
+
try { process.emitWarning = () => {}; sqlite = createRequire(import.meta.url)("node:sqlite"); } catch { sqlite = null; } finally { process.emitWarning = warn; }
|
|
40
|
+
}
|
|
41
|
+
if (!sqlite) return { why: "no_sqlite" };
|
|
42
|
+
try { return { db: new sqlite.DatabaseSync(file, { readOnly: true, timeout: 250 }) }; } catch { return { why: "unreadable" }; }
|
|
43
|
+
}
|
|
44
|
+
const splitSession = (pseudo) => { const at = pseudo.lastIndexOf("#"); return { file: pseudo.slice(pseudo.indexOf(":") + 1, at), id: pseudo.slice(at + 1) }; };
|
|
45
|
+
const SESSION_ID = /^[A-Za-z0-9_.:-]{1,120}$/;
|
|
46
|
+
const hasTable = (db, name) => Boolean(db.prepare("select 1 from sqlite_master where type = 'table' and name = ?").get(name));
|
|
47
|
+
/** A clock as SQLite holds it, as milliseconds: Go's text time through julianday inside SQLite, epoch seconds or ms as they are. */
|
|
48
|
+
const CLOCK = (column) => `case when typeof(${column}) in ('integer', 'real') then ${column} else (julianday(${column}) - 2440587.5) * 86400000.0 end`;
|
|
49
|
+
const msOf = (value) => { const n = Number(value); return value === null || !Number.isFinite(n) || n <= 0 ? null : Math.round(n > 1e11 ? n : n * 1000); };
|
|
50
|
+
const isoOf = (value) => { const ms = msOf(value); return ms === null ? null : new Date(ms).toISOString(); };
|
|
51
|
+
const count = (value) => (value === null || value === undefined || !Number.isFinite(Number(value)) || Number(value) < 0 ? null : Math.round(Number(value)));
|
|
52
|
+
const user = (timestamp) => ({ type: "user", timestamp, message: { content: [{ type: "text" }] } });
|
|
53
|
+
const toolResult = (timestamp) => ({ type: "user", timestamp, message: { content: [{ type: "tool_result" }] } });
|
|
54
|
+
|
|
55
|
+
// ── ollama app session reader ──
|
|
56
|
+
export function ollamaHomes(given) {
|
|
57
|
+
if (given) return [given.replace(/^~(?=\/|$)/, homedir())];
|
|
58
|
+
if (platform() === "darwin") return [join(homedir(), "Library", "Application Support", "Ollama")];
|
|
59
|
+
if (platform() === "win32" && process.env.LOCALAPPDATA) return [join(process.env.LOCALAPPDATA, "Ollama")];
|
|
60
|
+
return [];
|
|
61
|
+
}
|
|
62
|
+
const OLLAMA_SESSIONS = `select c.id as id, max(${CLOCK("coalesce(m.updated_at, m.created_at)")}) as last from chats c join messages m on m.chat_id = c.id group by c.id order by c.id`;
|
|
63
|
+
export function* ollamaSessions(homes) {
|
|
64
|
+
for (const home of homes) {
|
|
65
|
+
const file = join(home, "db.sqlite"), { db } = openStore(file);
|
|
66
|
+
if (!db) continue;
|
|
67
|
+
try {
|
|
68
|
+
for (const row of db.prepare(OLLAMA_SESSIONS).all()) if (SESSION_ID.test(String(row.id))) yield { sessionId: String(row.id), file: `ollama:${file}#${row.id}`, cwd: null, writtenAt: msOf(row.last) ?? 0 };
|
|
69
|
+
} catch { /* locked or another schema: named by ollamaStores */ } finally { db.close(); }
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
/** One chat → lines in Claude Code's shape: the person's turns, the model's answers at the moment each was finished, tool results. No text, no tokens (none kept). */
|
|
73
|
+
export function ollamaLines(pseudo) {
|
|
74
|
+
const { file, id } = splitSession(pseudo), { db } = openStore(file);
|
|
75
|
+
if (!db) return null;
|
|
76
|
+
try {
|
|
77
|
+
const rows = db.prepare(`select role, ${CLOCK("created_at")} as asked, ${CLOCK("coalesce(updated_at, created_at)")} as done, model_name as model from messages where chat_id = ? order by created_at, id`).all(id);
|
|
78
|
+
const lines = [{ type: "meta", steered: "desk" }]; // the desktop app, at the computer
|
|
79
|
+
for (const row of rows) {
|
|
80
|
+
if (row.role === "user") { const at = isoOf(row.asked); if (at) lines.push(user(at)); continue; }
|
|
81
|
+
if (row.role === "tool") { const at = isoOf(row.asked); if (at) lines.push(toolResult(at)); continue; }
|
|
82
|
+
if (row.role !== "assistant") continue;
|
|
83
|
+
const at = isoOf(row.done); if (at) lines.push({ type: "assistant", timestamp: at, message: { model: cleanModel(row.model), content: [] } });
|
|
84
|
+
}
|
|
85
|
+
return lines;
|
|
86
|
+
} catch { return null; } finally { db.close(); }
|
|
87
|
+
}
|
|
88
|
+
export function ollamaStores(homes) {
|
|
89
|
+
return homes.map((home) => {
|
|
90
|
+
const opened = openStore(join(home, "db.sqlite"));
|
|
91
|
+
if (!opened.db) return opened.why === "missing" ? null : { client: "ollama", state: opened.why };
|
|
92
|
+
try { return hasTable(opened.db, "chats") && hasTable(opened.db, "messages") ? { client: "ollama", state: "read", chats: Number(opened.db.prepare("select count(*) as n from chats").get().n) || 0 } : { client: "ollama", state: "unknown_schema" }; }
|
|
93
|
+
catch { return { client: "ollama", state: "unreadable" }; } finally { opened.db.close(); }
|
|
94
|
+
}).filter(Boolean);
|
|
95
|
+
}
|
|
96
|
+
// ── end ollama app session reader ──
|
|
97
|
+
|
|
98
|
+
// ── open-webui session reader ──
|
|
99
|
+
/** Where Open WebUI keeps webui.db: DATA_DIR, and the package's own data folder in a uv tool or pipx install (`open_webui/data`). */
|
|
100
|
+
export function openWebuiHomes(given) {
|
|
101
|
+
if (given) return [given.replace(/^~(?=\/|$)/, homedir())];
|
|
102
|
+
const homes = process.env.DATA_DIR ? [process.env.DATA_DIR] : [];
|
|
103
|
+
for (const venv of [join(homedir(), ".local", "share", "uv", "tools", "open-webui"), join(homedir(), ".local", "pipx", "venvs", "open-webui"), join(homedir(), ".local", "share", "pipx", "venvs", "open-webui")]) {
|
|
104
|
+
let pythons = []; try { pythons = readdirSync(join(venv, "lib")).filter((name) => /^python3\.\d+$/.test(name)).sort(); } catch { continue; }
|
|
105
|
+
for (const python of pythons) homes.push(join(venv, "lib", python, "site-packages", "open_webui", "data"));
|
|
106
|
+
}
|
|
107
|
+
return homes;
|
|
108
|
+
}
|
|
109
|
+
const accountsOf = (db) => (hasTable(db, "user") ? Number(db.prepare('select count(*) as n from "user"').get().n) || 0 : 0);
|
|
110
|
+
const USAGE = (...keys) => `case when json_valid(usage) then ${keys.length > 1 ? `coalesce(${keys.map((k) => `json_extract(usage, '$.${k}')`).join(", ")})` : `json_extract(usage, '$.${keys[0]}')`} end`;
|
|
111
|
+
const HISTORY = (key) => `json_extract(m.value, '$.${key}')`;
|
|
112
|
+
export function* openWebuiSessions(homes) {
|
|
113
|
+
for (const home of homes) {
|
|
114
|
+
const file = join(home, "webui.db"), { db } = openStore(file);
|
|
115
|
+
if (!db) continue;
|
|
116
|
+
try {
|
|
117
|
+
if (accountsOf(db) > 1) continue; // several accounts: whose chat is whose is not this computer's to say
|
|
118
|
+
const rows = hasTable(db, "chat_message") ? db.prepare("select chat_id as id, max(created_at) as last from chat_message group by chat_id order by chat_id").all() : db.prepare("select id, updated_at as last from chat order by id").all();
|
|
119
|
+
for (const row of rows) if (SESSION_ID.test(String(row.id))) yield { sessionId: String(row.id), file: `open-webui:${file}#${row.id}`, cwd: null, writtenAt: msOf(row.last) ?? 0 };
|
|
120
|
+
} catch { /* locked or another schema: named by openWebuiStores */ } finally { db.close(); }
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
/** One chat → lines: every message of every branch at its own clock (a regenerated answer was produced, and waited for), the model, the tokens Open WebUI kept. */
|
|
124
|
+
export function openWebuiLines(pseudo) {
|
|
125
|
+
const { file, id } = splitSession(pseudo), { db } = openStore(file);
|
|
126
|
+
if (!db) return null;
|
|
127
|
+
try {
|
|
128
|
+
if (accountsOf(db) > 1) return [];
|
|
129
|
+
const rows = hasTable(db, "chat_message")
|
|
130
|
+
? db.prepare(`select role, created_at as at, model_id as model, ${USAGE("input_tokens", "prompt_tokens", "prompt_eval_count")} as input, ${USAGE("output_tokens", "completion_tokens", "eval_count")} as output, ${USAGE("cache_read_input_tokens")} as cache_read
|
|
131
|
+
from chat_message where chat_id = ? order by created_at, id`).all(id)
|
|
132
|
+
: db.prepare(`select ${HISTORY("role")} as role, ${HISTORY("timestamp")} as at, ${HISTORY("model")} as model,
|
|
133
|
+
coalesce(${HISTORY("usage.input_tokens")}, ${HISTORY("usage.prompt_tokens")}, ${HISTORY("usage.prompt_eval_count")}, ${HISTORY("info.prompt_eval_count")}) as input,
|
|
134
|
+
coalesce(${HISTORY("usage.output_tokens")}, ${HISTORY("usage.completion_tokens")}, ${HISTORY("usage.eval_count")}, ${HISTORY("info.eval_count")}) as output, ${HISTORY("usage.cache_read_input_tokens")} as cache_read
|
|
135
|
+
from chat c, json_each(c.chat, '$.history.messages') m where c.id = ? and json_valid(c.chat) order by ${HISTORY("timestamp")}`).all(id);
|
|
136
|
+
const lines = [{ type: "meta" }]; // a browser on this computer or on a phone in the same network look alike here: not said
|
|
137
|
+
for (const row of rows) {
|
|
138
|
+
const at = isoOf(row.at); if (!at) continue;
|
|
139
|
+
if (row.role === "user") { lines.push(user(at)); continue; }
|
|
140
|
+
if (row.role !== "assistant") continue;
|
|
141
|
+
const input = count(row.input), output = count(row.output), cacheRead = count(row.cache_read);
|
|
142
|
+
const usage = input !== null || output !== null ? { usage: { input_tokens: Math.max(0, (input ?? 0) - (cacheRead ?? 0)), output_tokens: output ?? 0, cache_read_input_tokens: cacheRead ?? 0, cache_creation_input_tokens: 0 } } : {};
|
|
143
|
+
lines.push({ type: "assistant", timestamp: at, message: { model: cleanModel(row.model), ...usage, content: [] } });
|
|
144
|
+
}
|
|
145
|
+
return lines;
|
|
146
|
+
} catch { return null; } finally { db.close(); }
|
|
147
|
+
}
|
|
148
|
+
export function openWebuiStores(homes) {
|
|
149
|
+
return homes.map((home) => {
|
|
150
|
+
const opened = openStore(join(home, "webui.db"));
|
|
151
|
+
if (!opened.db) return opened.why === "missing" ? null : { client: "open-webui", state: opened.why };
|
|
152
|
+
try {
|
|
153
|
+
if (!hasTable(opened.db, "chat")) return { client: "open-webui", state: "unknown_schema" };
|
|
154
|
+
if (accountsOf(opened.db) > 1) return { client: "open-webui", state: "several_accounts" };
|
|
155
|
+
return { client: "open-webui", state: "read", chats: Number(opened.db.prepare("select count(*) as n from chat").get().n) || 0 };
|
|
156
|
+
} catch { return { client: "open-webui", state: "unreadable" }; } finally { opened.db.close(); }
|
|
157
|
+
}).filter(Boolean);
|
|
158
|
+
}
|
|
159
|
+
// ── end open-webui session reader ──
|
|
160
|
+
|
|
161
|
+
/** The registry entries session-databases.mjs takes in: the same shape as its own clients, and a store report beside. */
|
|
162
|
+
export const LOCAL_MODEL_CLIENTS = {
|
|
163
|
+
ollama: { homes: ollamaHomes, sessions: ollamaSessions, lines: ollamaLines, stores: ollamaStores },
|
|
164
|
+
"open-webui": { homes: openWebuiHomes, sessions: openWebuiSessions, lines: openWebuiLines, stores: openWebuiStores },
|
|
165
|
+
};
|
package/worktrust.mjs
CHANGED
|
@@ -78,7 +78,7 @@ const command = args.includes("--help") ? "help" : args.includes("--version") ?
|
|
|
78
78
|
const flag = (name) => { const at = args.indexOf(`--${name}`); return at >= 0 ? args[at + 1] : undefined; };
|
|
79
79
|
const has = (name) => args.includes(`--${name}`);
|
|
80
80
|
/** This CLI's version, said to the door so the app can tell which computer runs an old one (check-cli-package holds it equal to package.json). */
|
|
81
|
-
const CLI_VERSION = "0.11.
|
|
81
|
+
const CLI_VERSION = "0.11.4";
|
|
82
82
|
/**
|
|
83
83
|
* HOW THIS CLI MEASURES, AS A NUMBER OF ITS OWN (0.10.31; owner, 2026-10-28: 0.10.30 offered a re-measure it had no reason
|
|
84
84
|
* to offer). Raised ONLY when what is measured changes: the timeline, the seconds, the tokens, the steering, the session
|
|
@@ -98,21 +98,25 @@ const CLI_VERSION = "0.11.2";
|
|
|
98
98
|
* came with 0.10.31): `update` offers the re-measure once, its day digests change with the rules, so the re-measure sends
|
|
99
99
|
* every day again; WorkTrust replaces only the lines of the two buckets (other apps, app not recorded) that name no app
|
|
100
100
|
* (20261031100200) and carries every other line as it is: no figure moves, the Other apps hours move to their app's row.
|
|
101
|
+
* 4 RAISES IT AGAIN (owner, 2026-11-09): two new READERS, the Ollama app's and Open WebUI's chats (session-local-models.mjs),
|
|
102
|
+
* so a computer with either has days no earlier rules measured; `update` offers the re-measure once and it sends them. Its
|
|
103
|
+
* first CLI version is the release's (core MEASURE_RULES_SINCE and 20261110110200 name 0.11.4; the release keeps the three equal).
|
|
101
104
|
*/
|
|
102
|
-
const MEASURE_RULES =
|
|
105
|
+
const MEASURE_RULES = 4;
|
|
103
106
|
/** What each measure-rules version changed, in the words the re-measure offer says (one entry per raise, never rewritten). */
|
|
104
107
|
const MEASURE_CHANGES = {
|
|
105
108
|
1: ["each answer's tokens counted once", "nothing lost at midnight", "when each stretch began", "how you steered the agent", "what the seconds were", "more AI apps", "how each session was started"],
|
|
106
109
|
2: ["which subagents were active at once, and how their failed steps were recovered", "whether each agent call completed", "who wrote each turn of a run no person started"],
|
|
107
110
|
3: ["Gemini CLI's sessions", "which AI app each earlier line came from (Copilot in VS Code, Gemini CLI and the other apps get their own rows)"],
|
|
111
|
+
4: ["the Ollama app's and Open WebUI's chats"],
|
|
108
112
|
};
|
|
109
113
|
const ORIGIN = (flag("origin") ?? process.env.WORKTRUST_ORIGIN ?? "https://app.worktrust.io").replace(/\/$/, "");
|
|
110
114
|
const MCP = flag("url") ?? process.env.WORKTRUST_MCP_URL ?? `${ORIGIN}/api/mcp`;
|
|
111
115
|
const HOME_DIR = join(homedir(), ".worktrust");
|
|
112
116
|
const HERE = dirname(fileURLToPath(import.meta.url));
|
|
113
|
-
const SCRIPTS = ["credential-store.mjs", "remote-protocol.mjs", "remote-store.mjs", "remote-policy.mjs", "remote-journal.mjs", "remote-steered.mjs", "remote-inventory.mjs", "remote-claude-events.mjs", "remote-claude-progress.mjs", "remote-attachments.mjs", "remote-preview.mjs", "remote-coalesce.mjs", "remote-steering.mjs", "remote-codex-events.mjs", "remote-adapter-codex.mjs", "remote-adapter-terminal.mjs", "remote-terminal-sessions.mjs", "remote-terminal-cli.mjs", "remote-screen-states.mjs", "remote-screen-approvals.mjs", "remote-screen-push.mjs", "remote-cdp.mjs", "remote-live-preview.mjs", "remote-projects.mjs", "remote-pipeline-config.mjs", "remote-pipeline-parsers.mjs", "remote-pipeline.mjs", "remote-releases.mjs", "remote-release-plans.mjs", "remote-adapter-claude-code.mjs", "remote-approval-bridge.mjs", "remote-approvals.mjs", "remote-sessions.mjs", "remote-session-list.mjs", "remote-changes.mjs", "remote-endorse.mjs", "remote-daemon.mjs", "remote-transport.mjs", "remote-run.mjs", "remote-service.mjs", "remote-pairing.mjs", "remote-qr.mjs", "remote-cli.mjs", "credential-vault.mjs", "credential-vault-scripts.mjs", "history-outbox.mjs", "setup-mcp.mjs", "log-session.mjs", "count-behaviour.mjs", "transcript-readers.mjs", "session-databases.mjs", "config-edits.mjs", "stretch-evidence.mjs", "chat-exports.mjs", "export-facts.mjs", "stack-rules.mjs", "runtime-install.mjs", "orchestration-contract.mjs", "orchestration-evidence.mjs", "orchestration-report.mjs", "claude-mod.mjs", "package-integrity.mjs", "worktrust-launch.mjs", "commit-rules.mjs", "git-commits.mjs", "self-update.mjs", "history-progress.mjs"];
|
|
117
|
+
const SCRIPTS = ["credential-store.mjs", "remote-protocol.mjs", "remote-store.mjs", "remote-policy.mjs", "remote-journal.mjs", "remote-steered.mjs", "remote-inventory.mjs", "remote-claude-events.mjs", "remote-claude-progress.mjs", "remote-attachments.mjs", "remote-preview.mjs", "remote-coalesce.mjs", "remote-steering.mjs", "remote-codex-events.mjs", "remote-adapter-codex.mjs", "remote-opencode-events.mjs", "remote-adapter-opencode.mjs", "remote-opencode-session.mjs", "remote-adapter-terminal.mjs", "remote-terminal-sessions.mjs", "remote-terminal-cli.mjs", "remote-screen-states.mjs", "remote-screen-approvals.mjs", "remote-screen-push.mjs", "remote-cdp.mjs", "remote-live-preview.mjs", "remote-projects.mjs", "remote-pipeline-config.mjs", "remote-pipeline-parsers.mjs", "remote-pipeline.mjs", "remote-releases.mjs", "remote-release-plans.mjs", "remote-adapter-claude-code.mjs", "remote-approval-bridge.mjs", "remote-approvals.mjs", "remote-sessions.mjs", "remote-session-list.mjs", "remote-changes.mjs", "remote-endorse.mjs", "remote-daemon.mjs", "remote-transport.mjs", "remote-run.mjs", "remote-service.mjs", "remote-pairing.mjs", "remote-qr.mjs", "remote-cli.mjs", "remote-agent-switch.mjs", "credential-vault.mjs", "credential-vault-scripts.mjs", "history-outbox.mjs", "setup-mcp.mjs", "log-session.mjs", "count-behaviour.mjs", "transcript-readers.mjs", "session-databases.mjs", "session-local-models.mjs", "config-edits.mjs", "stretch-evidence.mjs", "chat-exports.mjs", "export-facts.mjs", "stack-rules.mjs", "runtime-install.mjs", "orchestration-contract.mjs", "orchestration-evidence.mjs", "orchestration-report.mjs", "claude-mod.mjs", "package-integrity.mjs", "worktrust-launch.mjs", "project-modes.mjs", "commit-rules.mjs", "git-commits.mjs", "self-update.mjs", "history-progress.mjs"];
|
|
114
118
|
/** The modules the scripts import by name from beside them; a download keeps that name. */
|
|
115
|
-
const IMPORTED = new Set(["transcript-readers.mjs", "session-databases.mjs", "config-edits.mjs", "stretch-evidence.mjs", "chat-exports.mjs", "export-facts.mjs", "stack-rules.mjs", "runtime-install.mjs", "orchestration-contract.mjs", "orchestration-evidence.mjs", "orchestration-report.mjs", "commit-rules.mjs", "git-commits.mjs"]);
|
|
119
|
+
const IMPORTED = new Set(["project-modes.mjs", "transcript-readers.mjs", "session-databases.mjs", "session-local-models.mjs", "config-edits.mjs", "stretch-evidence.mjs", "chat-exports.mjs", "export-facts.mjs", "stack-rules.mjs", "runtime-install.mjs", "orchestration-contract.mjs", "orchestration-evidence.mjs", "orchestration-report.mjs", "commit-rules.mjs", "git-commits.mjs"]);
|
|
116
120
|
const downloaded = (name) => (IMPORTED.has(name) ? name : `${name}.download.mjs`);
|
|
117
121
|
const BUNDLED = SCRIPTS.every((name) => existsSync(join(HERE, name)));
|
|
118
122
|
const PLACEHOLDER = `wt_${"0".repeat(43)}`;
|
|
@@ -363,6 +367,8 @@ function saveStableEntry() {
|
|
|
363
367
|
* The OS wrapping key is never written into an AI app or the encrypted credential file.
|
|
364
368
|
*/
|
|
365
369
|
const { createCredentialStore } = await import("./credential-store.mjs").catch(() => ({}));
|
|
370
|
+
// A PROJECT'S MODE (2026-11-09, docs/CONFIDENTIAL-WORK.md): `worktrust project` writes it, the bridge honours it for an AI app's own calls.
|
|
371
|
+
const { sealToolCall, projectCommand } = await import("./project-modes.mjs").catch(() => ({}));
|
|
366
372
|
const keyStore = createCredentialStore?.(KEY_FILE);
|
|
367
373
|
async function protectKey() {
|
|
368
374
|
say(" Protect the WorkTrust token and signing key with this OS account's credential vault.");
|
|
@@ -589,7 +595,7 @@ async function bridge() {
|
|
|
589
595
|
const answer = (id, message) => process.stdout.write(`${JSON.stringify({ jsonrpc: "2.0", id, error: { code: -32603, message } })}\n`);
|
|
590
596
|
let session = null;
|
|
591
597
|
let agent = "worktrust-bridge";
|
|
592
|
-
for await (
|
|
598
|
+
for await (let line of lines({ input: process.stdin })) {
|
|
593
599
|
if (!line.trim()) continue;
|
|
594
600
|
let message;
|
|
595
601
|
try { message = JSON.parse(line); } catch { continue; }
|
|
@@ -599,6 +605,11 @@ async function bridge() {
|
|
|
599
605
|
catch { key = null; if (message.id !== undefined) answer(message.id, "WorkTrust credential storage is unavailable. Unlock your OS vault and retry; no request was sent."); continue; }
|
|
600
606
|
if (!key) { if (message.id !== undefined) answer(message.id, "WorkTrust is not connected on this computer: run `npx worktrust connect`."); continue; }
|
|
601
607
|
if (measurePaused()) { if (message.id !== undefined) answer(message.id, "WorkTrust is paused on this computer by its owner (Sources): nothing is sent until it is turned on again."); continue; }
|
|
608
|
+
// EXCLUDED AND CONFIDENTIAL PROJECTS (2026-11-09): an AI app's log_work or import_history is decided here, before it leaves.
|
|
609
|
+
if (!sealToolCall) { if (message.id !== undefined) answer(message.id, "This WorkTrust package is incomplete (project-modes.mjs): nothing was sent. Run `npx worktrust update`."); continue; }
|
|
610
|
+
const sealed = sealToolCall(message, process.cwd());
|
|
611
|
+
if (sealed.answer) { process.stdout.write(`${JSON.stringify(sealed.answer)}\n`); continue; }
|
|
612
|
+
if (sealed.forward !== message) line = JSON.stringify(sealed.forward);
|
|
602
613
|
try {
|
|
603
614
|
const response = await fetch(key.url, { method: "POST", headers: { "content-type": "application/json", accept: "application/json, text/event-stream", authorization: `Bearer ${key.token}`, "user-agent": agent, ...(session ? { "mcp-session-id": session } : {}), ...proof(key.device, key.url, line) }, body: line });
|
|
604
615
|
session = response.headers.get("mcp-session-id") ?? session;
|
|
@@ -844,6 +855,9 @@ async function offerHistory(paths, token, devicePem, url = MCP, rebuild = false,
|
|
|
844
855
|
let found = null;
|
|
845
856
|
try { found = JSON.parse(counted.out.trim().split("\n").pop()); } catch { /* no line: nothing to offer */ }
|
|
846
857
|
say();
|
|
858
|
+
// THE LOCAL MODELS' STORES (2026-11-09): each one found is named, read with its chats or not read with why; an absent one is not.
|
|
859
|
+
const WHY = { several_accounts: "it holds more than one account, so whose chats they are cannot be told", unreadable: "it could not be opened (locked by its app, or damaged)", unknown_schema: "its layout is not one WorkTrust knows", no_sqlite: "this Node has no SQLite (Node 22.5 or newer reads it)" };
|
|
860
|
+
for (const store of found?.stores ?? []) say(` ${{ ollama: "Ollama (app)", "open-webui": "Open WebUI" }[store.client] ?? store.client}: ${store.state === "read" ? `${store.chats} chats read` : `found, not read: ${WHY[store.state] ?? store.state}`}`);
|
|
847
861
|
if (!found?.sessions) { historyDone(true); say(rebuild ? " Your AI apps hold no earlier sessions on this computer to re-measure." : " Your AI apps hold no earlier sessions on this computer to send."); return; }
|
|
848
862
|
say(` This computer holds ${found.sessions} earlier sessions of your AI apps · ${found.days} days · ${found.first} … ${found.last}. WorkTrust measures the hours when they arrive.`);
|
|
849
863
|
// REBUILD (owner, 2026-10-07): the plan per AI app, in days and hours, and what it replaces, before the one question. Enter is No.
|
|
@@ -1656,6 +1670,8 @@ function help() {
|
|
|
1656
1670
|
say(" days this computer's own sessions lack, reconstructed, never verified hours (asks first)");
|
|
1657
1671
|
say(" worktrust disconnect take WorkTrust out of every AI app here (asks first)");
|
|
1658
1672
|
say(" worktrust status what is coupled here");
|
|
1673
|
+
say(" worktrust project a folder's mode: exclude (nothing read), confidential (hours and tokens count, no name,");
|
|
1674
|
+
say(" branch, path or commit sent) or normal; `project list` shows them (default folder: here)");
|
|
1659
1675
|
say(" worktrust remote steer this computer's agents from your phone: enable, pair (a QR), status, pause, resume,");
|
|
1660
1676
|
say(" disable, phones, projects, run. Opt-in, its own key, never counted as your AI Hours");
|
|
1661
1677
|
say(" worktrust mcp off hours only: the WorkTrust door out of every AI app here, nothing of it in your sessions;");
|
|
@@ -1694,7 +1710,9 @@ const agentShell = AGENT_ENV.find((name) => process.env[name] && process.env[nam
|
|
|
1694
1710
|
const doorSwitch = command === "mcp" && ["off", "on"].includes(args[args.indexOf("mcp") + 1]);
|
|
1695
1711
|
// Remote control (2026-11-07) is the person's act at the keyboard: an agent cannot enable, pair, extend or run its own leash; `remote status` only reads.
|
|
1696
1712
|
const remoteAct = command === "remote" && args[args.indexOf("remote") + 1] !== "status";
|
|
1697
|
-
|
|
1713
|
+
// A project's mode is the person's (2026-11-09): an agent could otherwise set a confidential folder back to normal; `project list` only reads.
|
|
1714
|
+
const projectAct = command === "project" && ![undefined, "list"].includes(args[args.indexOf("project") + 1]);
|
|
1715
|
+
if (agentShell && (PERSON_ONLY.has(command) || doorSwitch || remoteAct || projectAct)) {
|
|
1698
1716
|
say();
|
|
1699
1717
|
say(` worktrust${command === "default" ? "" : ` ${command}`} is run by the person, in their own terminal, never by an AI agent for them (this shell is an agent's: ${agentShell}).`);
|
|
1700
1718
|
say(" Nothing was read, sent or changed. See AGENTS.md in the package: https://www.npmjs.com/package/worktrust");
|
|
@@ -1724,7 +1742,7 @@ async function relayToNewest() {
|
|
|
1724
1742
|
}
|
|
1725
1743
|
if (await relayToNewest()) return;
|
|
1726
1744
|
|
|
1727
|
-
if (!["version", "help", "preserve"].includes(command)) {
|
|
1745
|
+
if (!["version", "help", "preserve", "project"].includes(command)) {
|
|
1728
1746
|
try { keyStore.load(); }
|
|
1729
1747
|
catch { fail("The local WorkTrust key file is unsafe or damaged, or the OS vault is locked or unavailable. Upload stopped. Unlock your OS vault and retry. Do not delete the key file or reset the keychain."); }
|
|
1730
1748
|
}
|
|
@@ -1749,6 +1767,7 @@ else if (command === "codex") await offerCodex();
|
|
|
1749
1767
|
else if (command === "antigravity") await offerAntigravity();
|
|
1750
1768
|
else if (command === "disconnect") await disconnect();
|
|
1751
1769
|
else if (command === "status") await status();
|
|
1770
|
+
else if (command === "project") { if (!projectCommand) fail("worktrust project needs the complete WorkTrust package. Nothing was changed."); projectCommand(args.slice(args.indexOf("project") + 1).filter((arg) => !arg.startsWith("--")), { say, fail }); }
|
|
1752
1771
|
else if (command === "remote") await (await import("./remote-cli.mjs")).remoteCommand(args.slice(args.indexOf("remote") + 1).filter((a, i, all) => !a.startsWith("--") && !(i > 0 && ["--gateway", "--origin"].includes(all[i - 1]))), { say, fail, ask, has, flag, origin: ORIGIN, os: OS, openBrowser, prepare: async () => { await prepareBundledRuntime(); return { node: NODE, nodeArgs: [...NODE_FLAGS, ...NODE_ARGS], entry: STABLE }; } });
|
|
1753
1772
|
else if (command === "preserve") await preserve();
|
|
1754
1773
|
else if (command === "mod") await mod();
|