@listeningkit/log 0.1.2 → 0.1.3

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/AGENTS.md CHANGED
@@ -1296,6 +1296,25 @@ facts, not suggestions. Newest at the bottom. Never delete one without matt.
1296
1296
  its own. The hook's account line shows the open session (pid, since,
1297
1297
  calls). `LOG_TWITTER_HOST=inline` runs the old way, for tests only.
1298
1298
 
1299
+ 106. 2026-11-01 · matt: "when doing stuff like changing the code or
1300
+ anything, ensure that there hasn't been any changes to it locally, like
1301
+ to the engine ... you're not allowed hand-rolled commands, it always has
1302
+ to be through the MCP basically". Two things, enforced by the hooks:
1303
+ - **Through the MCP only.** Every log action an agent takes goes through
1304
+ the log MCP tools (`mcp__log__…`), never a hand-run `log …` or `bun
1305
+ bin/log.ts …` from a shell. The PreToolUse hook (`liveLogs`,
1306
+ `handRunDenial` in `src/agentHooks/liveLog`) refuses one and names the
1307
+ MCP instead. Only the terminal-only prompts (`TERMINAL_ONLY`: launch,
1308
+ login, mcp, chat pin, cookies save, messenger pin) are run in a
1309
+ terminal, by matt. A stale MCP server is said to matt (restart the
1310
+ app), never worked around.
1311
+ - **Local changes first.** Before changing code, check what is already
1312
+ changed and uncommitted in the checkout. The engines hook says it
1313
+ loudly at session start and whenever it changes (`>>> UNCOMMITTED
1314
+ LOCAL CHANGES`, `localChangesLine` in `src/mcp/freshness`): read each
1315
+ one's diff, and never overwrite, revert, stage, publish or ship
1316
+ someone else's uncommitted work without matt.
1317
+
1299
1318
  ## Checks
1300
1319
 
1301
1320
  - Run `bun run check` before pushing: no comments (rule 70), naming gate, `tsc --noEmit`, `bun test`.
@@ -8,7 +8,7 @@ sequenceDiagram
8
8
  Agent->>Hook: SessionStart
9
9
  Note over Hook: where every open browser is, the moment a session starts or comes back from compaction
10
10
  Note over Hook: ~/.logCli/runs over 2 GB or the disk nearly full: said with `log runs prune` before AdsPower refuses to start
11
- Note over Hook: which commands run on the direct-API engine (from DIRECT_ROUTES) and each account's session state and governor use, so a session coming back from compaction knows the engines#59; and, loudly, when the log MCP server runs older code than the checkout
11
+ Note over Hook: which commands run on the direct-API engine (from DIRECT_ROUTES) and each account's session state and governor use, so a session coming back from compaction knows the engines#59; and, loudly, when the log MCP server runs older code than the checkout, and which code files have uncommitted local changes (rule 106)
12
12
  Note over Hook: the knowledge base is there and how to search it and save to it, with how many chunks Redis holds, so a session looks things up before it guesses (rule 93)
13
13
  Note over Hook: anyone who wrote to a signed-in account's inbox since the last look (every platform's inbox, incl. X Chat, read in the background every 4 to 8 minutes), said loudly so a reply is never missed#59; and, from each X account's local inbox store with no network, who wrote last and is waiting on a reply
14
14
  matt->>Agent: a prompt
@@ -19,7 +19,7 @@ sequenceDiagram
19
19
  Note over Hook: the same inbox check with each of matt's prompts: a poll starts when one is due, and new messages from the last poll are put in front of the agent
20
20
  loop each tool call
21
21
  Agent->>Hook: PreToolUse
22
- Note over Hook: a log-cli run that would hide its lines (piped through tail or head) is refused before it starts#59; a long one off a Monitor is told to start one (rule 26)
22
+ Note over Hook: a log-cli run that would hide its lines (piped through tail or head) is refused before it starts#59; a long one off a Monitor is told to start one (rule 26)#59; any log action run by hand from a shell is refused and pointed at its MCP tool (rule 106)
23
23
  alt a log run piped through tail/head
24
24
  Hook-->>Agent: refused (exit 2), run it live
25
25
  else
@@ -120,6 +120,7 @@ Its rules are matt's, in AGENTS.md (read the resource log://agents; the newest r
120
120
  31. LinkedIn is reached only through vendor/openLinkedinApi's one curl_cffi Session pinned to Chrome (`IMPERSONATE`), never plain `requests`, and every call goes through the account's governor; a LinkedIn account writes at most 10 times a day (rule 102).
121
121
  32. More than one send on an account goes through the queue (`twitterQueueBuild`, plan, run), whose random times space them like a person; never a hand-rolled loop of sends and never helpers reading or sending on the same account in parallel. The X engine takes one call per account at a time (`engine.lock`, `accountBusy` after 15 min), spaces each 4 to 11 s after the last, and keeps the transaction key for 3 hours instead of loading x.com before every call (rule 104).
122
122
  33. One X session per account, always: every X call (CLI, MCP, hooks, queue, X Chat watch) goes through that account's one engine host (`python/twitterApi/host.py`), which holds one twikit client, one connection and one transaction key, as X's own web app holds one page. A second session can't start (`host.lock`); if the host can't be reached the call is refused loudly (`xSessionHostDown`) and nothing is sent. Never open another session or hand-roll a script to get around it. The hook's account line shows the open session (rule 105).
123
+ 34. Every log action goes through these MCP tools, never a hand-run `log …` or `bun bin/log.ts …` from a shell (the shell hook refuses one); only the terminal-only prompts are run in a terminal, by matt. Before changing log-cli code, read what is already changed and uncommitted (the hook says it loudly: `>>> UNCOMMITTED LOCAL CHANGES`) and never overwrite, revert, stage, publish or ship someone else's uncommitted work without matt (rule 106).
123
124
  A refusal names its error code and what to do (`errors` tool). Each tool's description ends with the AGENTS.md rules it falls under.
124
125
 
125
126
  ## Which guide for which work
@@ -469,3 +470,5 @@ From AGENTS.md (`log://agents`). The newest rules are at the bottom of AGENTS.md
469
470
  **Rule 104.** 2026-11-01 · matt: "the timing stuff there i saw you hand rolled the outbound stuff when it should be queued and it has to have random intervals, but the bundle itself actually reveals more information". On 2026-11-01 matthewsoldit got a soft block, then X's 226 ("looks automated") on a reply. The live log showed 8 thread reads fired in 0.2 s by two parallel helpers while sends went out from a hand-written loop, and every `log twitter` call was a fresh client that loaded x.com's home page and its signer before acting, so a 3-line dm was 3 cold starts in 9 s. X's own web client (`sign.o` in its x-web bundle, read 2026-11-01) loads the page once and signs every call from it. From now on: more than one send goes through the queue (`log twitter queue build|plan|run`, random times), never a hand-rolled loop and never helpers reading or sending on one account in parallel. The X engine takes one call per account at a time (`engine.lock`, refused with `accountBusy` after 15 min), waits 4 to 11 s after the last call, and keeps the transaction key in `clientTransaction.json` for 3 hours (`python/twitterApi/engine.py`, `vendor/twikit` `ClientTransaction.state` and `restore`).
470
471
 
471
472
  **Rule 105.** 2026-11-01 · matt: "we cannot be opening multiple sessions there, that defeats the core purpose of what we use this tool for ... it should always be one, and then it needs to loudly create issues". An X account has one session, always. Every X call (CLI, MCP, hooks, the queue, the X Chat watch) goes through the account's one engine host (`python/twitterApi/host.py`, started on the first call, closed after 30 idle minutes or when the engine code changes): one twikit client, one connection, one cookie jar and one transaction key, the way X's own web app keeps one page and signs every call from it (x-web `startup-dynamic`, read with rea 2026-11-01). A second host can't start (`host.lock`); a call that can't reach the host is refused with `xSessionHostDown` and sends nothing, never falls back to a session of its own. The hook's account line shows the open session (pid, since, calls). `LOG_TWITTER_HOST=inline` runs the old way, for tests only.
473
+
474
+ **Rule 106.** 2026-11-01 · matt: "when doing stuff like changing the code or anything, ensure that there hasn't been any changes to it locally, like to the engine ... you're not allowed hand-rolled commands, it always has to be through the MCP basically". Two things, enforced by the hooks: - **Through the MCP only.** Every log action an agent takes goes through the log MCP tools (`mcp__log__…`), never a hand-run `log …` or `bun bin/log.ts …` from a shell. The PreToolUse hook (`liveLogs`, `handRunDenial` in `src/agentHooks/liveLog`) refuses one and names the MCP instead. Only the terminal-only prompts (`TERMINAL_ONLY`: launch, login, mcp, chat pin, cookies save, messenger pin) are run in a terminal, by matt. A stale MCP server is said to matt (restart the app), never worked around. - **Local changes first.** Before changing code, check what is already changed and uncommitted in the checkout. The engines hook says it loudly at session start and whenever it changes (`>>> UNCOMMITTED LOCAL CHANGES`, `localChangesLine` in `src/mcp/freshness`): read each one's diff, and never overwrite, revert, stage, publish or ship someone else's uncommitted work without matt.
package/docs/reference.md CHANGED
@@ -595,13 +595,13 @@ One list (`src/agentHooks/registry`) writes Claude Code's `.claude/settings.json
595
595
  | UserPromptSubmit | every turn | [`scripts/hooks/pageState.ts`](../scripts/hooks/pageState.ts) | where every open browser is, with each of matt's prompts |
596
596
  | SessionStart | `startup\|resume\|clear\|compact` | [`scripts/hooks/storage.ts`](../scripts/hooks/storage.ts) | ~/.logCli/runs over 2 GB or the disk nearly full: said with `log runs prune` before AdsPower refuses to start |
597
597
  | UserPromptSubmit | every turn | [`scripts/hooks/storage.ts`](../scripts/hooks/storage.ts) | the same storage check with each of matt's prompts (measured at most every 15 minutes) |
598
- | SessionStart | `startup\|resume\|clear\|compact` | [`scripts/hooks/engines.ts`](../scripts/hooks/engines.ts) | which commands run on the direct-API engine (from DIRECT_ROUTES) and each account's session state and governor use, so a session coming back from compaction knows the engines; and, loudly, when the log MCP server runs older code than the checkout |
598
+ | SessionStart | `startup\|resume\|clear\|compact` | [`scripts/hooks/engines.ts`](../scripts/hooks/engines.ts) | which commands run on the direct-API engine (from DIRECT_ROUTES) and each account's session state and governor use, so a session coming back from compaction knows the engines; and, loudly, when the log MCP server runs older code than the checkout, and which code files have uncommitted local changes (rule 106) |
599
599
  | UserPromptSubmit | every turn | [`scripts/hooks/engines.ts`](../scripts/hooks/engines.ts) | the same engine line with matt's prompt, only when an account's session state, its governor use or the MCP server's freshness changed |
600
600
  | SessionStart | `startup\|resume\|clear\|compact` | [`scripts/hooks/knowledge.ts`](../scripts/hooks/knowledge.ts) | the knowledge base is there and how to search it and save to it, with how many chunks Redis holds, so a session looks things up before it guesses (rule 93) |
601
601
  | SessionStart | `startup\|resume\|clear\|compact` | [`scripts/hooks/inbox.ts`](../scripts/hooks/inbox.ts) | anyone who wrote to a signed-in account's inbox since the last look (every platform's inbox, incl. X Chat, read in the background every 4 to 8 minutes), said loudly so a reply is never missed; and, from each X account's local inbox store with no network, who wrote last and is waiting on a reply |
602
602
  | UserPromptSubmit | every turn | [`scripts/hooks/inbox.ts`](../scripts/hooks/inbox.ts) | the same inbox check with each of matt's prompts: a poll starts when one is due, and new messages from the last poll are put in front of the agent |
603
603
  | PostToolUse | `Bash\|PowerShell\|Monitor\|mcp__log__.*` | [`scripts/hooks/inbox.ts`](../scripts/hooks/inbox.ts) | the same inbox check after a log tool or shell call, so a reply that lands mid-task is said at once |
604
- | PreToolUse | `Bash\|PowerShell\|Monitor` | [`scripts/hooks/liveLogs.ts`](../scripts/hooks/liveLogs.ts) | a log-cli run that would hide its lines (piped through tail or head) is refused before it starts; a long one off a Monitor is told to start one (rule 26) |
604
+ | PreToolUse | `Bash\|PowerShell\|Monitor` | [`scripts/hooks/liveLogs.ts`](../scripts/hooks/liveLogs.ts) | a log-cli run that would hide its lines (piped through tail or head) is refused before it starts; a long one off a Monitor is told to start one (rule 26); any log action run by hand from a shell is refused and pointed at its MCP tool (rule 106) |
605
605
  | PostToolUse | `Bash\|PowerShell\|Monitor\|mcp__log__.*` | [`scripts/hooks/pageState.ts`](../scripts/hooks/pageState.ts) | a browser landed on a known state (checkpoint, captcha, prompt) or a step failed: its resolver, at once |
606
606
  | Stop | every turn | [`scripts/hooks/pageState.ts`](../scripts/hooks/pageState.ts) | the turn does not end while a browser sits on a state log-cli can resolve (rule 54) |
607
607
 
@@ -620,7 +620,7 @@ sequenceDiagram
620
620
  Agent->>Hook: SessionStart
621
621
  Note over Hook: where every open browser is, the moment a session starts or comes back from compaction
622
622
  Note over Hook: ~/.logCli/runs over 2 GB or the disk nearly full: said with `log runs prune` before AdsPower refuses to start
623
- Note over Hook: which commands run on the direct-API engine (from DIRECT_ROUTES) and each account's session state and governor use, so a session coming back from compaction knows the engines#59; and, loudly, when the log MCP server runs older code than the checkout
623
+ Note over Hook: which commands run on the direct-API engine (from DIRECT_ROUTES) and each account's session state and governor use, so a session coming back from compaction knows the engines#59; and, loudly, when the log MCP server runs older code than the checkout, and which code files have uncommitted local changes (rule 106)
624
624
  Note over Hook: the knowledge base is there and how to search it and save to it, with how many chunks Redis holds, so a session looks things up before it guesses (rule 93)
625
625
  Note over Hook: anyone who wrote to a signed-in account's inbox since the last look (every platform's inbox, incl. X Chat, read in the background every 4 to 8 minutes), said loudly so a reply is never missed#59; and, from each X account's local inbox store with no network, who wrote last and is waiting on a reply
626
626
  matt->>Agent: a prompt
@@ -631,7 +631,7 @@ sequenceDiagram
631
631
  Note over Hook: the same inbox check with each of matt's prompts: a poll starts when one is due, and new messages from the last poll are put in front of the agent
632
632
  loop each tool call
633
633
  Agent->>Hook: PreToolUse
634
- Note over Hook: a log-cli run that would hide its lines (piped through tail or head) is refused before it starts#59; a long one off a Monitor is told to start one (rule 26)
634
+ Note over Hook: a log-cli run that would hide its lines (piped through tail or head) is refused before it starts#59; a long one off a Monitor is told to start one (rule 26)#59; any log action run by hand from a shell is refused and pointed at its MCP tool (rule 106)
635
635
  alt a log run piped through tail/head
636
636
  Hook-->>Agent: refused (exit 2), run it live
637
637
  else
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@listeningkit/log",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "ListeningKit's go-to-market tool, open-sourced: one CLI and MCP server that runs your accounts on X, Reddit, Facebook and Discord, self-hosted.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -2,7 +2,7 @@
2
2
  import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs'
3
3
  import { join } from 'node:path'
4
4
  import { engineContext, fbkStateRoot } from '../../src/directApi/engine/index'
5
- import { staleServerLine } from '../../src/mcp/freshness/index'
5
+ import { localChangesLine, staleServerLine } from '../../src/mcp/freshness/index'
6
6
 
7
7
  const raw = await Bun.stdin.text().catch(() => '')
8
8
  let event = 'UserPromptSubmit'
@@ -10,8 +10,8 @@ try {
10
10
  event = (JSON.parse(raw || '{}') as { hook_event_name?: string }).hook_event_name ?? event
11
11
  } catch {}
12
12
 
13
- const stale = staleServerLine(join(import.meta.dir, '..', '..'))
14
- const text = [stale, engineContext()].filter(Boolean).join('\n')
13
+ const repo = join(import.meta.dir, '..', '..')
14
+ const text = [staleServerLine(repo), localChangesLine(repo), engineContext()].filter(Boolean).join('\n')
15
15
  const root = fbkStateRoot()
16
16
  const last = join(root, '.lastHook')
17
17
  const changed = !existsSync(last) || readFileSync(last, 'utf8') !== text
@@ -1,16 +1,18 @@
1
1
  import { isPlatform } from "../../cli/runner/helpers/platforms.ts";
2
2
  import { LONG_RUNNING } from "../../mcp/server/helpers/toolsFromCommands.ts";
3
+ import { TERMINAL_ONLY } from "../../mcp/server/types.ts";
3
4
 
4
5
  export interface LiveLogVerdict {
5
6
  deny: string | null;
6
7
  context: string | null;
7
8
  }
8
9
 
9
- const FROM_CHECKOUT = /\bbin[\\/]log\.ts["']?\s+([A-Za-z]+)(?:\s+([A-Za-z]+))?/;
10
+ const FROM_CHECKOUT = /^\s*(?:\(\s*)?(?:[A-Za-z_][A-Za-z0-9_]*=\S*\s+)*(?:&\s*)?["']?(?:\S*[\\/])?(?:bun|node|tsx)(?:\.exe)?["']?\s+(?:run\s+)?["']?(?:\S*[\\/])?bin[\\/]log\.ts["']?\s+([A-Za-z]+)(?:\s+([A-Za-z]+))?/;
10
11
  const INSTALLED = /^\s*(?:\(\s*)?(?:[A-Za-z_][A-Za-z0-9_]*=\S*\s+)*(?:\S*[\\/])?log(?:\.exe)?\s+([A-Za-z]+)(?:\s+([A-Za-z]+))?/;
11
12
 
12
13
  export function logCommandOf(command: string): string | null {
13
- const match = FROM_CHECKOUT.exec(command) ?? command.split(/;|&&|\|\||\||\n/).map((part) => INSTALLED.exec(part)).find((m) => m !== null);
14
+ const parts = command.replace(/'[^'\n]*'|"(?:[^"\\\n]|\\.)*"/g, (quoted) => (/\s/.test(quoted) ? "''" : quoted)).split(/;|&&|\|\||\||\n/);
15
+ const match = parts.map((part) => FROM_CHECKOUT.exec(part) ?? INSTALLED.exec(part)).find((m) => m !== null);
14
16
  if (!match) return null;
15
17
  return isPlatform(match[1]) && match[2] ? match[2] : match[1];
16
18
  }
@@ -23,9 +25,16 @@ export function buffersOutput(command: string): boolean {
23
25
  return logPipelines(command).some((p) => /\|\s*(?:tail|head)\b(?![^|]*\s-f\b)/.test(p) || /\|\s*Select-Object\s+-(?:First|Last)\b/i.test(p));
24
26
  }
25
27
 
28
+ export function handRunDenial(name: string): string | null {
29
+ if (name in TERMINAL_ONLY) return null;
30
+ return `log ${name} was run by hand from a shell. Every log action goes through the log MCP tools, never a hand-run \`log …\` or \`bun bin/log.ts …\` command (rule 106: matt, "you're not allowed hand-rolled commands, it always has to be through the MCP"). Call its mcp__log__ tool instead (getGuide names it); if the MCP server is stale, say so to matt rather than working around it. Only the terminal-only prompts (${Object.keys(TERMINAL_ONLY).join(", ")}) are run in a terminal, by matt.`;
31
+ }
32
+
26
33
  export function liveLogVerdict(tool: string, command: string, runInBackground = false): LiveLogVerdict {
27
34
  const name = logCommandOf(command);
28
35
  if (!name) return { deny: null, context: null };
36
+ const handRun = handRunDenial(name);
37
+ if (handRun) return { deny: handRun, context: null };
29
38
  if (buffersOutput(command)) {
30
39
  return {
31
40
  deny: `log ${name} piped through tail/head shows nothing until it ends (rule 26: matt sees every line as it happens). Run it with \`2>&1 | tee <runFolder>/<name>.log\` and no tail/head, under Monitor, or start a Monitor on \`tail -f ~/.logCli/mcp/<day>.log\` (every log run writes there).`,
@@ -20,13 +20,13 @@ export const AGENT_HOOKS: readonly AgentHook[] = [
20
20
  { event: "UserPromptSubmit", script: PAGE_STATE, timeout: 20, why: "where every open browser is, with each of matt's prompts" },
21
21
  { event: "SessionStart", matcher: "startup|resume|clear|compact", script: STORAGE, timeout: 30, why: "~/.logCli/runs over 2 GB or the disk nearly full: said with `log runs prune` before AdsPower refuses to start" },
22
22
  { event: "UserPromptSubmit", script: STORAGE, timeout: 30, why: "the same storage check with each of matt's prompts (measured at most every 15 minutes)" },
23
- { event: "SessionStart", matcher: "startup|resume|clear|compact", script: ENGINES, timeout: 10, why: "which commands run on the direct-API engine (from DIRECT_ROUTES) and each account's session state and governor use, so a session coming back from compaction knows the engines; and, loudly, when the log MCP server runs older code than the checkout" },
23
+ { event: "SessionStart", matcher: "startup|resume|clear|compact", script: ENGINES, timeout: 10, why: "which commands run on the direct-API engine (from DIRECT_ROUTES) and each account's session state and governor use, so a session coming back from compaction knows the engines; and, loudly, when the log MCP server runs older code than the checkout, and which code files have uncommitted local changes (rule 106)" },
24
24
  { event: "UserPromptSubmit", script: ENGINES, timeout: 10, why: "the same engine line with matt's prompt, only when an account's session state, its governor use or the MCP server's freshness changed" },
25
25
  { event: "SessionStart", matcher: "startup|resume|clear|compact", script: KNOWLEDGE, timeout: 10, why: "the knowledge base is there and how to search it and save to it, with how many chunks Redis holds, so a session looks things up before it guesses (rule 93)" },
26
26
  { event: "SessionStart", matcher: "startup|resume|clear|compact", script: INBOX, timeout: 15, why: "anyone who wrote to a signed-in account's inbox since the last look (every platform's inbox, incl. X Chat, read in the background every 4 to 8 minutes), said loudly so a reply is never missed; and, from each X account's local inbox store with no network, who wrote last and is waiting on a reply" },
27
27
  { event: "UserPromptSubmit", script: INBOX, timeout: 15, why: "the same inbox check with each of matt's prompts: a poll starts when one is due, and new messages from the last poll are put in front of the agent" },
28
28
  { event: "PostToolUse", matcher: TOOL_MATCHER, script: INBOX, timeout: 15, why: "the same inbox check after a log tool or shell call, so a reply that lands mid-task is said at once" },
29
- { event: "PreToolUse", matcher: SHELL_MATCHER, script: LIVE_LOGS, timeout: 10, why: "a log-cli run that would hide its lines (piped through tail or head) is refused before it starts; a long one off a Monitor is told to start one (rule 26)" },
29
+ { event: "PreToolUse", matcher: SHELL_MATCHER, script: LIVE_LOGS, timeout: 10, why: "a log-cli run that would hide its lines (piped through tail or head) is refused before it starts; a long one off a Monitor is told to start one (rule 26); any log action run by hand from a shell is refused and pointed at its MCP tool (rule 106)" },
30
30
  { event: "PostToolUse", matcher: TOOL_MATCHER, script: PAGE_STATE, timeout: 20, why: "a browser landed on a known state (checkpoint, captcha, prompt) or a step failed: its resolver, at once" },
31
31
  { event: "Stop", script: PAGE_STATE, timeout: 20, why: "the turn does not end while a browser sits on a state log-cli can resolve (rule 54)" },
32
32
  ];
@@ -163,10 +163,10 @@ function discordContext(messages: readonly InboxMessage[]): string {
163
163
  const { account } = messages[0]
164
164
  return [
165
165
  `>>> NEW DISCORD MESSAGE${messages.length === 1 ? '' : 'S'} (${messages.length}): pushed by Discord's gateway the moment it landed. Tell matt now, with what they said. Then, for each one:`,
166
- ` 1. Read the chat around it: \`log discord read --account ${account} --channel <channel> --limit 20\`.`,
167
- ' 2. Before writing a word, pull how matt really writes in that chat: `log voice --to <who> --with <channel> --context "<what they said>"` (no --text): his latest messages there and his real replies to things like it. Draft from those, in his words and his length, using only facts matt has said, answering what they actually asked. Never from the twitter guide alone.',
168
- ' 3. Gate it against the same chat: `log voice --to <who> --with <channel> --context "<what they said>" --text "<draft>"`. Rewrite until it passes.',
169
- ` 4. Show matt the draft and send only when he says (\`log discord send --account ${account} --channel <channel> --text "<draft>" --approvedBy matt --live\`).`,
166
+ ` 1. Read the chat around it: \`discordRead\` { account: "${account}", channel: "<channel>", limit: "20" }.`,
167
+ ' 2. Before writing a word, pull how matt really writes in that chat: `voice` { to: "<who>", with: "<channel>", context: "<what they said>" } (no text): his latest messages there and his real replies to things like it. Draft from those, in his words and his length, using only facts matt has said, answering what they actually asked. Never from the twitter guide alone.',
168
+ ' 3. Gate it against the same chat: `voice` { to, with, context, text: "<draft>" }. Rewrite until it passes.',
169
+ ` 4. Show matt the draft and send only when he says (\`discordSendLive\` { account: "${account}", channel: "<channel>", text: "<draft>", approvedBy: "matt", confirmLive: true }).`,
170
170
  ...lines,
171
171
  ].join('\n')
172
172
  }
@@ -184,10 +184,10 @@ function twitterContext(messages: readonly InboxMessage[]): string {
184
184
  const { platform, account } = messages[0]
185
185
  return [
186
186
  `>>> NEW MESSAGE${messages.length === 1 ? '' : 'S'} (${messages.length}): someone wrote to an account, pushed by X the moment it landed. Tell matt now, with what they said. Then, for each person:`,
187
- ` 1. Read everything with them, the old DM thread and X Chat merged (one conversation, whichever id a message names): \`log ${platform} dms --account ${account} --with <handle>\`.`,
188
- ' 2. Before writing a word, pull how matt really writes to them: `log voice --to <handle> --with <handle> --context "<what they said>"` (no --text): his messages to them first, then his whole history (every platform). Draft from those, in his words and his length, using only facts matt has said, answering what they actually asked. Never from the twitter guide alone.',
189
- ` 3. Gate it against the same person: \`log voice --to <handle> --with <handle> --context "<what they said>" --text "<draft>"\`. Rewrite until it passes.`,
190
- ` 4. Show matt the draft and send only when he says (\`log ${platform} dm --account ${account} --userId <id> --text "<draft>" --approvedBy matt --live\`).`,
187
+ ` 1. Read everything with them, the old DM thread and X Chat merged (one conversation, whichever id a message names): \`twitterDms\` { account: "${account}", with: "<handle>" }.`,
188
+ ' 2. Before writing a word, pull how matt really writes to them: `voice` { to: "<handle>", with: "<handle>", context: "<what they said>" } (no text): his messages to them first, then his whole history (every platform). Draft from those, in his words and his length, using only facts matt has said, answering what they actually asked. Never from the twitter guide alone.',
189
+ ` 3. Gate it against the same person: \`voice\` { to, with, context, text: "<draft>" }. Rewrite until it passes.`,
190
+ ` 4. Show matt the draft and send only when he says (\`twitterDmLive\` { account: "${account}", userId: "<id>", text: "<draft>", approvedBy: "matt", confirmLive: true }). Every step is the log MCP tool, never a hand-run command (rule 106).`,
191
191
  ...lines,
192
192
  ].join('\n')
193
193
  }
@@ -234,7 +234,7 @@ export function storedInboxContext(accounts: readonly string[], root: string = t
234
234
  parts.push([
235
235
  `X inbox for ${account}, from the local store (synced ${syncedAt.slice(0, 16).replace('T', ' ')} UTC, live pushes added since; nothing was fetched for this): ${total} conversation${total === 1 ? '' : 's'} where they wrote last${total > waiting.length ? `, the newest ${waiting.length}` : ''}:`,
236
236
  ...waiting.map((w) => ` ${w.with} at ${w.at.slice(0, 16).replace('T', ' ')} UTC: "${w.text.replace(/\s+/g, ' ').slice(0, 160)}" (conversation ${w.conversationId})`),
237
- ` \`log twitter dms --account ${account}\` fetches only what is new since then (about 5 s); \`--with <handle>\` reads one person in full.`,
237
+ ` \`twitterDms\` { account: "${account}" } fetches only what is new since then (about 5 s); with: "<handle>" reads one person in full.`,
238
238
  ].join('\n'))
239
239
  }
240
240
  return parts.length ? parts.join('\n\n') : null
@@ -1,3 +1,4 @@
1
+ import { execFileSync } from "node:child_process";
1
2
  import { existsSync, mkdirSync, readdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
2
3
  import { homedir } from "node:os";
3
4
  import { dirname, join } from "node:path";
@@ -48,5 +49,21 @@ export function staleServerLine(root: string, file = serverStampFile()): string
48
49
  if (!alive(started.pid)) return null;
49
50
  const now = codeStamp(root);
50
51
  if (now <= started.stamp) return null;
51
- return `>>> The log MCP server (pid ${started.pid}, started ${started.startedAt.slice(0, 16)}Z) is running older code than the checkout: log-cli changed at ${new Date(now).toISOString().slice(0, 16)}Z. Its tools and their descriptions are stale until it restarts (reconnect the log server with /mcp, or restart Claude). The terminal CLI (log) runs the current code.`;
52
+ return `>>> The log MCP server (pid ${started.pid}, started ${started.startedAt.slice(0, 16)}Z) is running older code than the checkout: log-cli changed at ${new Date(now).toISOString().slice(0, 16)}Z. Its tool descriptions and rules are stale until it restarts: tell matt to restart the Claude app or start a new chat (in a terminal claude, reconnect the log server with /mcp). Its calls still run the checkout's engine. Never work around it with a hand-run \`log …\` command (rule 106).`;
53
+ }
54
+
55
+ const LOCAL_PATHS = ["src", "python", "vendor", "bin", "scripts", "package.json"];
56
+
57
+ export function uncommittedFiles(root: string, run: (args: string[]) => string = (args) => execFileSync("git", args, { cwd: root, encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] })): string[] {
58
+ try {
59
+ return run(["status", "--porcelain", "--", ...LOCAL_PATHS]).split(/\r?\n/).map((l) => l.slice(3).trim()).filter(Boolean);
60
+ } catch {
61
+ return [];
62
+ }
63
+ }
64
+
65
+ export function localChangesLine(root: string, files: string[] = uncommittedFiles(root)): string | null {
66
+ if (files.length === 0) return null;
67
+ const shown = files.slice(0, 12).join(", ") + (files.length > 12 ? ` and ${files.length - 12} more` : "");
68
+ return `>>> UNCOMMITTED LOCAL CHANGES in log-cli's code (${files.length}): ${shown}. They aren't committed, may be someone else's work in progress, and the running engine and MCP already run them. Before changing code, read what each one changed (git diff); never overwrite, revert, stage, publish or ship them as your own without matt (rule 106).`;
52
69
  }
@@ -1,4 +1,4 @@
1
- export const RULES_REVIEWED_THROUGH = 105;
1
+ export const RULES_REVIEWED_THROUGH = 106;
2
2
 
3
3
  export const AGENTS_URI = "log://agents";
4
4
 
@@ -38,6 +38,7 @@ export const CORE_PRINCIPLES = [
38
38
  "31. LinkedIn is reached only through vendor/openLinkedinApi's one curl_cffi Session pinned to Chrome (`IMPERSONATE`), never plain `requests`, and every call goes through the account's governor; a LinkedIn account writes at most 10 times a day (rule 102).",
39
39
  "32. More than one send on an account goes through the queue (`twitterQueueBuild`, plan, run), whose random times space them like a person; never a hand-rolled loop of sends and never helpers reading or sending on the same account in parallel. The X engine takes one call per account at a time (`engine.lock`, `accountBusy` after 15 min), spaces each 4 to 11 s after the last, and keeps the transaction key for 3 hours instead of loading x.com before every call (rule 104).",
40
40
  "33. One X session per account, always: every X call (CLI, MCP, hooks, queue, X Chat watch) goes through that account's one engine host (`python/twitterApi/host.py`), which holds one twikit client, one connection and one transaction key, as X's own web app holds one page. A second session can't start (`host.lock`); if the host can't be reached the call is refused loudly (`xSessionHostDown`) and nothing is sent. Never open another session or hand-roll a script to get around it. The hook's account line shows the open session (rule 105).",
41
+ "34. Every log action goes through these MCP tools, never a hand-run `log …` or `bun bin/log.ts …` from a shell (the shell hook refuses one); only the terminal-only prompts are run in a terminal, by matt. Before changing log-cli code, read what is already changed and uncommitted (the hook says it loudly: `>>> UNCOMMITTED LOCAL CHANGES`) and never overwrite, revert, stage, publish or ship someone else's uncommitted work without matt (rule 106).",
41
42
  "A refusal names its error code and what to do (`errors` tool). Each tool's description ends with the AGENTS.md rules it falls under.",
42
43
  ].join("\n");
43
44