@rubytech/create-maxy-code 0.1.468 → 0.1.470

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.
Files changed (41) hide show
  1. package/dist/index.js +40 -0
  2. package/package.json +1 -1
  3. package/payload/platform/config/brand.json +1 -0
  4. package/payload/platform/lib/storage-broker/dist/__tests__/cf-exec.test.js +12 -2
  5. package/payload/platform/lib/storage-broker/dist/__tests__/cf-exec.test.js.map +1 -1
  6. package/payload/platform/lib/storage-broker/dist/cf-exec.d.ts +9 -1
  7. package/payload/platform/lib/storage-broker/dist/cf-exec.d.ts.map +1 -1
  8. package/payload/platform/lib/storage-broker/dist/cf-exec.js +10 -3
  9. package/payload/platform/lib/storage-broker/dist/cf-exec.js.map +1 -1
  10. package/payload/platform/lib/storage-broker/src/__tests__/cf-exec.test.ts +26 -3
  11. package/payload/platform/lib/storage-broker/src/cf-exec.ts +16 -3
  12. package/payload/platform/plugins/.claude-plugin/marketplace.json +5 -0
  13. package/payload/platform/plugins/admin/hooks/lib/maxy-mcp-plugins.txt +1 -0
  14. package/payload/platform/plugins/admin/skills/platform-architecture/SKILL.md +106 -1
  15. package/payload/platform/plugins/docs/references/admin-ui.md +32 -0
  16. package/payload/platform/plugins/docs/references/google-guide.md +68 -0
  17. package/payload/platform/plugins/google/.claude-plugin/plugin.json +21 -0
  18. package/payload/platform/plugins/google/PLUGIN.md +104 -0
  19. package/payload/platform/plugins/google/lib/mcp-spawn-tee/index.js +193 -0
  20. package/payload/platform/plugins/google/lib/mcp-spawn-tee/package.json +3 -0
  21. package/payload/platform/plugins/google/mcp/package.json +20 -0
  22. package/payload/platform/plugins/google/references/auth.md +43 -24
  23. package/payload/platform/services/claude-session-manager/dist/account-title-stores.d.ts +17 -4
  24. package/payload/platform/services/claude-session-manager/dist/account-title-stores.d.ts.map +1 -1
  25. package/payload/platform/services/claude-session-manager/dist/account-title-stores.js +50 -13
  26. package/payload/platform/services/claude-session-manager/dist/account-title-stores.js.map +1 -1
  27. package/payload/platform/services/claude-session-manager/dist/canonical-tool-names.generated.d.ts.map +1 -1
  28. package/payload/platform/services/claude-session-manager/dist/canonical-tool-names.generated.js +12 -0
  29. package/payload/platform/services/claude-session-manager/dist/canonical-tool-names.generated.js.map +1 -1
  30. package/payload/platform/services/claude-session-manager/dist/fs-watcher.d.ts +7 -0
  31. package/payload/platform/services/claude-session-manager/dist/fs-watcher.d.ts.map +1 -1
  32. package/payload/platform/services/claude-session-manager/dist/fs-watcher.js +8 -0
  33. package/payload/platform/services/claude-session-manager/dist/fs-watcher.js.map +1 -1
  34. package/payload/platform/services/claude-session-manager/dist/http-server.js +8 -8
  35. package/payload/platform/services/claude-session-manager/dist/http-server.js.map +1 -1
  36. package/payload/platform/templates/specialists/agents/personal-assistant.md +1 -1
  37. package/payload/server/{chunk-FOYHK255.js → chunk-56WJMBQQ.js} +3 -3
  38. package/payload/server/{chunk-POBXIHOF.js → chunk-JRIBGO45.js} +15 -1
  39. package/payload/server/maxy-edge.js +1 -1
  40. package/payload/server/server.js +643 -379
  41. package/payload/server/{src-52M7SECF.js → src-JYPKMWJR.js} +1 -1
@@ -485,6 +485,38 @@ or mis-named icon asset shows `icons-present<3`, and a dropped head injection
485
485
  shows `manifest-linked<3`. The graph, data, and browser shells are intentionally
486
486
  non-installable.
487
487
 
488
+ ## WhatsApp socket resolution
489
+
490
+ Every route that needs a live WhatsApp socket resolves it through
491
+ `resolveSocket` in
492
+ [`app/lib/whatsapp/manager.ts`](../../../ui/app/lib/whatsapp/manager.ts),
493
+ never through the raw `getSocket` primitive it is built on. `getSocket` is
494
+ an exact-key lookup, and a connection is keyed by its credential dirname
495
+ (often a legacy `default`) while callers frequently hold the platform
496
+ account UUID. A raw lookup therefore returns `null` for a socket that is
497
+ alive under the other key.
498
+
499
+ `resolveSocket` accepts either key and splits that `null` into the two
500
+ failures that demand **opposite** operator advice:
501
+
502
+ | Reason | What it means | Correct advice |
503
+ |---|---|---|
504
+ | `key-miss` | No connection is registered under this id. The socket is likely alive under a different key. | Fix the account keying. **Never advise re-pairing** — that would re-pair a healthy socket. |
505
+ | `disconnected` | The connection exists and its transport is genuinely down. | Transport-down; reconnecting is appropriate. |
506
+
507
+ The reason label, the `presentKeys` rendering, and both operator-facing
508
+ messages have one definition, in
509
+ [`app/lib/whatsapp/socket-resolution-error.ts`](../../../ui/app/lib/whatsapp/socket-resolution-error.ts).
510
+ Callers keep their own log shape, HTTP status, and throw-vs-return
511
+ handling, but never hand-write the message strings — a copied key-miss
512
+ message is how the "do not advise re-pairing" instruction drifts out of
513
+ one branch unnoticed.
514
+
515
+ Two callers predate the shared formatter and still carry their own
516
+ equivalent wording: the reader reply path and the `/send-admin` route.
517
+ Consolidating them is tracked separately; do not copy their strings into
518
+ new callers.
519
+
488
520
  ## Related references
489
521
 
490
522
  - [`platform.md`](platform.md) — UI layout, session reconcile model,
@@ -0,0 +1,68 @@
1
+ # Google Calendar
2
+
3
+ Live Google Calendar for one account: read the user's real events, and create,
4
+ update, cancel, respond to and check availability against them. Eleven tools,
5
+ admin agent only.
6
+
7
+ There is deliberately no Gmail surface here. Mail runs on the `email` plugin's
8
+ IMAP/SMTP path, and Gmail's read/modify scopes are *restricted*, which would
9
+ force Google's annual third-party security assessment. Calendar is only a
10
+ *sensitive* scope, so it needs the lighter brand verification.
11
+
12
+ ## Connecting an account
13
+
14
+ `google-account-register` returns a consent URL. Relay it to the user: they open
15
+ it on any device, sign in, and approve. Google redirects to this install's
16
+ public host at `/api/google/oauth/callback`, which exchanges the code and stores
17
+ encrypted tokens. `google-account-register-poll` then reports the outcome.
18
+
19
+ The register tool does not block and does not wait. A second register while one
20
+ is already live is refused rather than overwriting it; that refusal names how
21
+ long the live one has been pending.
22
+
23
+ One account can connect several Google accounts. Every operational tool takes an
24
+ optional `account` (the email address). Omit it when there is one; with two or
25
+ more, omitting it returns a refusal listing them.
26
+
27
+ ## Reading and controlling
28
+
29
+ - `google-calendar-list` — events in the next `rangeDays` days (default 7).
30
+ Recurring series are expanded into instances, so this returns what the user
31
+ actually sees in their calendar.
32
+ - `google-calendar-event` — one event by id.
33
+ - `google-calendar-create` — times are RFC3339 (`2026-07-20T09:00:00Z`) unless
34
+ `allDay` is true, in which case they are plain dates (`2026-07-20`).
35
+ - `google-calendar-update` — changes only the fields you name. Omitted fields
36
+ are left alone, so an update never blanks something by accident.
37
+ - `google-calendar-cancel` — deletes the event and notifies attendees.
38
+ - `google-calendar-respond` — accept, decline or tentatively accept an
39
+ invitation. Every other attendee's response is preserved.
40
+ - `google-calendar-freebusy` — busy blocks between two times. Free time is the
41
+ complement, which you work out.
42
+
43
+ ## Checking health
44
+
45
+ `google-account-list` answers "is anything connected?" from local stores with no
46
+ network call. Read each entry's `status` — a count alone is not "connected", and
47
+ an unreadable store still counts. `google-account-info` gives one account's auth
48
+ state, including whether its access token is near expiry and which scopes were
49
+ granted.
50
+
51
+ ## When something is wrong
52
+
53
+ **"GOOGLE_CLIENT_ID is not configured"** — this brand has no Google vendor app
54
+ yet. Nothing the operator does on the device fixes it; the brand needs its own
55
+ Google Cloud OAuth client. See `platform/plugins/google/references/auth.md`.
56
+
57
+ **A 403 naming insufficient scope** — the connected account approved something
58
+ narrower than the full calendar scope. Re-run `google-account-register` so they
59
+ re-consent.
60
+
61
+ **The user re-consents every week** — the brand's Google app is still in
62
+ Testing, where Google caps refresh tokens at seven days and limits the app to
63
+ 100 named test users. Completing brand verification removes both. This is a
64
+ property of the vendor app, not a fault in the connection.
65
+
66
+ **A registration never completes** — the consent URL was opened but not
67
+ approved, or the callback could not be reached. `google-account-register-poll`
68
+ reports `expired` once the pending entry outlives Google's code lifetime.
@@ -0,0 +1,21 @@
1
+ {
2
+ "name": "google",
3
+ "description": "Live Google Calendar for one account via the Google Calendar API v3 — read plus control. Per-account OAuth authorization-code + PKCE; the consent URL is minted by the plugin and the code is exchanged by platform/ui, which holds the house-only client secret. One account can connect several Google accounts; every operational tool takes an optional account selector (the email address) and refuses ambiguously when two or more are connected and none is named. There is deliberately no Gmail surface — mail runs on the `email` plugin's IMAP/SMTP path, and Gmail's restricted scopes would force Google's annual third-party security assessment, whereas Calendar is only a sensitive scope. Tools — google-account-register / google-account-register-poll: connect a Google Calendar (returns a consent URL, then reports the outcome from local state); google-calendar-list: events in the next rangeDays days, recurring series expanded; google-calendar-event: one event by id; google-calendar-create / google-calendar-update / google-calendar-cancel: control events, attendees notified, update changes only the fields named; google-calendar-respond: accept, decline or tentatively accept an invitation, leaving other attendees' responses untouched; google-calendar-freebusy: busy blocks for this or named calendars; google-account-info: auth state for one connected Google account; google-account-list: every connected Google account with its own status.",
4
+ "version": "0.1.0",
5
+ "author": {
6
+ "name": "Rubytech LLC"
7
+ },
8
+ "mcpServers": {
9
+ "google": {
10
+ "type": "stdio",
11
+ "command": "node",
12
+ "args": [
13
+ "${CLAUDE_PLUGIN_ROOT}/lib/mcp-spawn-tee/index.js",
14
+ "${CLAUDE_PLUGIN_ROOT}/mcp/dist/index.js"
15
+ ],
16
+ "env": {
17
+ "MCP_SPAWN_TEE_NAME": "google"
18
+ }
19
+ }
20
+ }
21
+ }
@@ -0,0 +1,104 @@
1
+ ---
2
+ name: google
3
+ description: Live Google Calendar for one account via the Google Calendar API v3 — read plus control. Per-account OAuth authorization-code + PKCE; the consent URL is minted by the plugin and the code is exchanged by platform/ui, which holds the house-only client secret. One account can connect several Google accounts; every operational tool takes an optional account selector (the email address) and refuses ambiguously when two or more are connected and none is named. There is deliberately no Gmail surface — mail runs on the `email` plugin's IMAP/SMTP path, and Gmail's restricted scopes would force Google's annual third-party security assessment, whereas Calendar is only a sensitive scope. Tools — google-account-register / google-account-register-poll: connect a Google Calendar (returns a consent URL, then reports the outcome from local state); google-calendar-list: events in the next rangeDays days, recurring series expanded; google-calendar-event: one event by id; google-calendar-create / google-calendar-update / google-calendar-cancel: control events, attendees notified, update changes only the fields named; google-calendar-respond: accept, decline or tentatively accept an invitation, leaving other attendees' responses untouched; google-calendar-freebusy: busy blocks for this or named calendars; google-account-info: auth state for one connected Google account; google-account-list: every connected Google account with its own status.
4
+ tools:
5
+ - name: google-account-register
6
+ publicAllowlist: false
7
+ adminAllowlist: false
8
+ - name: google-account-register-poll
9
+ publicAllowlist: false
10
+ adminAllowlist: false
11
+ - name: google-calendar-list
12
+ publicAllowlist: false
13
+ adminAllowlist: false
14
+ - name: google-calendar-event
15
+ publicAllowlist: false
16
+ adminAllowlist: false
17
+ - name: google-calendar-create
18
+ publicAllowlist: false
19
+ adminAllowlist: false
20
+ - name: google-calendar-update
21
+ publicAllowlist: false
22
+ adminAllowlist: false
23
+ - name: google-calendar-cancel
24
+ publicAllowlist: false
25
+ adminAllowlist: false
26
+ - name: google-calendar-respond
27
+ publicAllowlist: false
28
+ adminAllowlist: false
29
+ - name: google-calendar-freebusy
30
+ publicAllowlist: false
31
+ adminAllowlist: false
32
+ - name: google-account-info
33
+ publicAllowlist: false
34
+ adminAllowlist: false
35
+ - name: google-account-list
36
+ publicAllowlist: false
37
+ adminAllowlist: false
38
+ mcp:
39
+ command: node
40
+ args:
41
+ - ${PLATFORM_ROOT}/lib/mcp-spawn-tee/dist/index.js
42
+ - ${PLATFORM_ROOT}/plugins/google/mcp/dist/index.js
43
+ env:
44
+ MCP_SPAWN_TEE_NAME: google
45
+ LOG_DIR: ${LOG_DIR}
46
+ PLATFORM_ROOT: ${PLATFORM_ROOT}
47
+ ACCOUNT_ID: ${ACCOUNT_ID}
48
+ SESSION_ID: ${SESSION_ID}
49
+ GOOGLE_CLIENT_ID: ${GOOGLE_CLIENT_ID}
50
+ GOOGLE_PUBLIC_BASE: ${GOOGLE_PUBLIC_BASE}
51
+ MAXY_UI_INTERNAL_PORT: ${MAXY_UI_INTERNAL_PORT}
52
+ mcp-manifest: auto
53
+ ---
54
+
55
+ # Google Calendar
56
+
57
+ Per-account live Google Calendar. Read the user's real events, and create,
58
+ update, cancel, respond to and check availability against them.
59
+
60
+ ## Why this exists
61
+
62
+ A client sub-account cannot hold a claude.ai connector: connectors are
63
+ authorised per client and visible only to the admin/claude.ai session, and the
64
+ install holds one house Google identity that cannot represent each client's
65
+ separate calendar. Before this plugin the only live-calendar path was that
66
+ house-admin-only connector, so a client asking "what is on my calendar?" was
67
+ dead-ended. See `references/auth.md`.
68
+
69
+ ## Auth
70
+
71
+ Authorization-code + PKCE, not device-code. Google's device flow serves a fixed
72
+ scope allowlist that excludes Calendar, and the out-of-band paste-a-code flow
73
+ has been blocked since 31 January 2023, so consent must land on a real redirect.
74
+
75
+ `google-account-register` mints the PKCE pair and a `state` nonce, persists them
76
+ single-slot per account, and returns a consent URL. The user opens it on any
77
+ device and approves. Google redirects to `/api/google/oauth/callback` on this
78
+ install's public host, which verifies `state`, exchanges the code, resolves the
79
+ account's email from its primary calendar, and writes encrypted tokens.
80
+ `google-account-register-poll` then reports the outcome from local state.
81
+
82
+ The client secret never enters this MCP process. A Web-application client must
83
+ present it to refresh, so refresh is delegated to `platform/ui`, which holds it
84
+ at `${PLATFORM_ROOT}/config/google-house.env`.
85
+
86
+ ## Scope
87
+
88
+ One scope: `https://www.googleapis.com/auth/calendar`. The account's email is
89
+ read from `GET /calendars/primary` (whose id is the address) rather than by
90
+ requesting `openid`/`email`/`profile`, so consent stays minimal.
91
+
92
+ ## Configuration
93
+
94
+ | Variable | Source | Effect when unset |
95
+ |---|---|---|
96
+ | `GOOGLE_CLIENT_ID` | `brand.json#googleClientId` | Plugin inert; register refuses with an actionable message |
97
+ | `GOOGLE_PUBLIC_BASE` | install's public host origin | Register refuses; the redirect cannot be built |
98
+ | `MAXY_ADMIN_BASE` | loopback `platform/ui` base | Defaults to `http://127.0.0.1:19301` |
99
+
100
+ ## Out of scope
101
+
102
+ Gmail (stays on IMAP/SMTP), Contacts, Drive/Docs, push notification channels,
103
+ recurring-series per-occurrence editing, and auto-sync with the internal
104
+ `scheduling` plugin.
@@ -0,0 +1,193 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ /**
4
+ * MCP spawn-tee — in-process stderr capture + lifecycle observability.
5
+ *
6
+ * Claude Code spawns each MCP server itself; the platform never holds a
7
+ * ChildProcess handle. This shim sits between Claude Code and the real MCP
8
+ * server: Claude Code runs `node <this> <real-entry>`, and the shim runs the
9
+ * real entry IN ITS OWN PROCESS via dynamic import() — one node runtime, not
10
+ * two. Before importing, it replaces process.stderr.write with a tee so every
11
+ * stderr byte the server writes is mirrored to the log sinks; stdin and stdout
12
+ * (the JSON-RPC channel) are never touched.
13
+ *
14
+ * Claude Code CLI → shim (this file) = node running <real-entry> in-process
15
+ * stdin/stdout : untouched (JSON-RPC channel)
16
+ * stderr : process.stderr.write teed → raw sink + passthrough
17
+ *
18
+ * Destinations:
19
+ * - `${LOG_DIR}/mcp-<name>-<SESSION_ID>.log` — raw stderr + lifecycle lines.
20
+ * The sole raw sink. Task 1721 retired the per-date twin: its date was
21
+ * pinned at spawn, no reader ever parsed it, and a since-removed stderr
22
+ * tee wrote the same file, so every line landed twice.
23
+ * - `${LOG_DIR}/mcp-<name>-nosession.log` — the same, for a spawn with
24
+ * no SESSION_ID (enumeration). One fixed file per server.
25
+ * - `server.log` via the loopback log-ingest route — best-effort mirror of
26
+ * the [mcp-helper] lifecycle lines.
27
+ *
28
+ * Lifecycle lines, correlation key `session=<id8> server=<name>` — unchanged:
29
+ * [mcp-helper] op=spawn ... pid= entry=
30
+ * [mcp-helper] op=boot ... head=<first stderr bytes>
31
+ * [mcp-helper] op=exit ... code= signal= lifetimeMs= stderr-tail=
32
+ *
33
+ * Process model (Task 989): the shim IS the server's process. op=exit fires
34
+ * from process.on("exit"), so it covers a normal exit, a non-zero exit, an
35
+ * uncaught throw (code 1), and a catchable-signal exit (SIGTERM/SIGINT/SIGHUP,
36
+ * whose handlers record the signal name). An external SIGKILL is uncatchable
37
+ * and leaves no op=exit line — the per-session stderr tail already on disk and
38
+ * Claude Code's own transport-drop are the evidence for that death mode.
39
+ *
40
+ * The shim never writes to fd 1 (stdout) — that is the JSON-RPC channel.
41
+ */
42
+ Object.defineProperty(exports, "__esModule", { value: true });
43
+ const node_fs_1 = require("node:fs");
44
+ const node_path_1 = require("node:path");
45
+ const node_url_1 = require("node:url");
46
+ const SERVER_NAME = process.env.MCP_SPAWN_TEE_NAME ?? "unknown";
47
+ const LOG_DIR = process.env.LOG_DIR;
48
+ const SESSION_ID = process.env.SESSION_ID;
49
+ const PLATFORM_PORT = process.env.PLATFORM_PORT;
50
+ const ENTRY = process.argv[2];
51
+ const SESSION_ID8 = SESSION_ID ? SESSION_ID.slice(0, 8) : "—";
52
+ const spawnStamp = Date.now();
53
+ // The one raw sink (Task 1721). A sessionless spawn (rc-daemon stamps
54
+ // SESSION_ID='' — rc-daemon.ts:513 — while still stamping LOG_DIR) shares one
55
+ // fixed file per server rather than a date-named one: the date was never read
56
+ // by any reader and named a process lifetime, not a day. Interleaved spawns in
57
+ // the nosession file are separated by the [mcp-helper] op=spawn pid= lines.
58
+ const rawSinkPath = LOG_DIR
59
+ ? (0, node_path_1.resolve)(LOG_DIR, SESSION_ID ? `mcp-${SERVER_NAME}-${SESSION_ID}.log` : `mcp-${SERVER_NAME}-nosession.log`)
60
+ : undefined;
61
+ // Rolling tail of entry stderr for op=exit. Capped so a chatty server cannot
62
+ // grow the buffer without bound.
63
+ const TAIL_CAP = 2048;
64
+ let stderrTail = "";
65
+ let bootEmitted = false;
66
+ let exitEmitted = false;
67
+ let exitSignal;
68
+ // The real stderr writer, captured before the tee replaces it. Lifecycle lines
69
+ // and stderr passthrough both go through this so they are never re-teed into
70
+ // the raw sink nor recursed back into the patched writer.
71
+ const rawStderrWrite = process.stderr.write.bind(process.stderr);
72
+ // LOG_DIR is created once, lazily, on the first successful append — not per
73
+ // chunk. teeWrite runs on the server's own stderr hot path now, so a per-call
74
+ // mkdirSync would be two syscalls per log line for nothing.
75
+ let logDirReady = false;
76
+ function appendSafe(path, data) {
77
+ if (!path || !LOG_DIR)
78
+ return;
79
+ try {
80
+ if (!logDirReady) {
81
+ (0, node_fs_1.mkdirSync)(LOG_DIR, { recursive: true });
82
+ logDirReady = true;
83
+ }
84
+ (0, node_fs_1.appendFileSync)(path, data);
85
+ }
86
+ catch {
87
+ /* unwritable destination — never mask primary output */
88
+ }
89
+ }
90
+ // Best-effort mirror of a lifecycle line to server.log via the loopback
91
+ // log-ingest route. Fire-and-forget: the per-session file is authoritative, so
92
+ // a dropped POST loses nothing. On the "exit" event the loop is stopping, so
93
+ // the op=exit mirror may not flush — the per-session line, written sync, holds.
94
+ function postToServerLog(suffix, level) {
95
+ if (!PLATFORM_PORT)
96
+ return;
97
+ try {
98
+ const ctrl = new AbortController();
99
+ const t = setTimeout(() => ctrl.abort(), 500);
100
+ t.unref?.(); // never let the abort timer keep the shim's event loop alive
101
+ void fetch(`http://127.0.0.1:${PLATFORM_PORT}/api/admin/log-ingest`, {
102
+ method: "POST",
103
+ headers: { "content-type": "application/json" },
104
+ body: JSON.stringify({ tag: "mcp-helper", level, line: suffix }),
105
+ signal: ctrl.signal,
106
+ }).then(() => clearTimeout(t)).catch(() => clearTimeout(t));
107
+ }
108
+ catch {
109
+ /* fetch threw synchronously — best-effort only */
110
+ }
111
+ }
112
+ // Emit one [mcp-helper] lifecycle line: authoritative per-session file (sync,
113
+ // survives process.exit), the shim's own stderr via the RAW writer (journald /
114
+ // Claude Code visibility, never re-teed), and a best-effort server.log mirror.
115
+ // `suffix` is the line body after the tag and carries no newline (the
116
+ // log-ingest route rejects newlines).
117
+ function emitLifecycle(suffix, level) {
118
+ const line = `[mcp-helper] ${suffix}\n`;
119
+ appendSafe(rawSinkPath, line);
120
+ try {
121
+ rawStderrWrite(line);
122
+ }
123
+ catch { /* stderr closed */ }
124
+ postToServerLog(suffix, level);
125
+ }
126
+ if (!ENTRY) {
127
+ emitLifecycle(`op=error session=${SESSION_ID8} server=${SERVER_NAME} reason="no entry given (argv[2] missing)"`, "error");
128
+ process.exit(2);
129
+ }
130
+ // Replace process.stderr.write with a tee: mirror every server stderr byte to
131
+ // the raw sink, keep a rolling tail for op=exit, emit
132
+ // op=boot on the first bytes, then pass the write through to the real stderr.
133
+ const teeWrite = ((...args) => {
134
+ const chunk = args[0];
135
+ appendSafe(rawSinkPath, chunk); // raw sink (Task 1721)
136
+ const text = typeof chunk === "string" ? chunk : Buffer.from(chunk).toString("utf8");
137
+ stderrTail = (stderrTail + text).slice(-TAIL_CAP);
138
+ if (!bootEmitted) {
139
+ bootEmitted = true;
140
+ const head = text.split("\n")[0].slice(0, 200);
141
+ emitLifecycle(`op=boot session=${SESSION_ID8} server=${SERVER_NAME} head=${JSON.stringify(head)}`, "info");
142
+ }
143
+ return rawStderrWrite(...args); // passthrough
144
+ });
145
+ process.stderr.write = teeWrite;
146
+ // Catchable-signal handling. The shim drives the exit ONLY when it is the sole
147
+ // listener for the signal — i.e. the imported entry installed no handler of its
148
+ // own. In that case it records the signal (so op=exit carries signal=<sig>) and
149
+ // exits with 128+signum, mirroring the prior wrapper's exit-status convention.
150
+ //
151
+ // When the entry DID install a handler, the shim defers entirely and records
152
+ // nothing: the entry's handler decides the exit code, and op=exit reflects that
153
+ // exit verbatim. This matches the prior two-process model, where a child that
154
+ // caught the signal and exited cleanly was observed as code=0 signal=— (a clean
155
+ // self-exit), not as a signal death. Setting exitSignal here unconditionally
156
+ // would mislabel every graceful signal-driven shutdown as a signal kill.
157
+ function onSignal(sig, code) {
158
+ return () => {
159
+ if (process.listenerCount(sig) === 1) {
160
+ exitSignal = sig;
161
+ process.exit(code);
162
+ }
163
+ };
164
+ }
165
+ process.on("SIGTERM", onSignal("SIGTERM", 143));
166
+ process.on("SIGINT", onSignal("SIGINT", 130));
167
+ process.on("SIGHUP", onSignal("SIGHUP", 129));
168
+ // op=exit, emitted once from the process "exit" event. Sync-only — the loop is
169
+ // stopping. When a catchable signal caused the exit, report code=— signal=<sig>
170
+ // to match the prior wrapper's format; otherwise code=<exit code> signal=—.
171
+ process.on("exit", (code) => {
172
+ if (exitEmitted)
173
+ return;
174
+ exitEmitted = true;
175
+ const lifetimeMs = Date.now() - spawnStamp;
176
+ const tail = stderrTail.slice(-200);
177
+ const codeField = exitSignal ? "—" : String(code);
178
+ const level = exitSignal || code !== 0 ? "error" : "info";
179
+ emitLifecycle(`op=exit session=${SESSION_ID8} server=${SERVER_NAME} pid=${process.pid} ` +
180
+ `code=${codeField} signal=${exitSignal ?? "—"} lifetimeMs=${lifetimeMs} stderr-tail=${JSON.stringify(tail)}`, level);
181
+ });
182
+ emitLifecycle(`op=spawn session=${SESSION_ID8} server=${SERVER_NAME} pid=${process.pid} entry=${ENTRY}`, "info");
183
+ // Run the real MCP server in THIS process. Dynamic import() (not top-level
184
+ // await — this file compiles to CommonJS) loads the ESM entry; a load-time
185
+ // failure mirrors the old child spawn-error path (op=error, exit 127). The
186
+ // op=exit handler is suppressed on this path so op=error stays the sole record.
187
+ import((0, node_url_1.pathToFileURL)(ENTRY).href).catch((err) => {
188
+ const msg = err instanceof Error ? err.message : String(err);
189
+ exitEmitted = true;
190
+ emitLifecycle(`op=error session=${SESSION_ID8} server=${SERVER_NAME} reason=${JSON.stringify(`import error: ${msg}`)}`, "error");
191
+ process.exit(127);
192
+ });
193
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }
@@ -0,0 +1,20 @@
1
+ {
2
+ "name": "@maxy/google",
3
+ "version": "0.1.0",
4
+ "private": true,
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "scripts": {
8
+ "build": "tsc",
9
+ "test": "node --test dist/__tests__/*.test.js",
10
+ "start": "node dist/index.js"
11
+ },
12
+ "dependencies": {
13
+ "@modelcontextprotocol/sdk": "^1.12.1",
14
+ "zod": "^3.24.0"
15
+ },
16
+ "devDependencies": {
17
+ "@types/node": "^22.0.0",
18
+ "typescript": "^5.7.0"
19
+ }
20
+ }
@@ -16,8 +16,8 @@ outcome (values themselves deliberately not recorded):
16
16
  The 604799 figure is the concrete argument for completing brand verification: in Testing,
17
17
  every connected account silently re-consents weekly. Verification removes it.
18
18
 
19
- Phases 1–2 may now proceed against the flow below, with one caveat: the client-secret
20
- storage location is an **open Phase 1 decision** (see "Open Phase 1 decision" below).
19
+ Phases 1–2 may now proceed against the flow below. Client-secret storage is decided:
20
+ house-only at `${PLATFORM_ROOT}/config/google-house.env` (see below).
21
21
 
22
22
  ## Original spike verdict (documentation-backed, now confirmed)
23
23
 
@@ -203,32 +203,51 @@ on that brand, exactly as `outlookClientId` does. The client id ships as the bra
203
203
  `GOOGLE_CLIENT_ID` and inherited down the spawn chain (manager unit env → PTY → MCP child).
204
204
 
205
205
  Divergence from Outlook: the recommended Web-application flow (Option B) also needs a
206
- **client secret**, and where that secret lives is an **open Phase 1 decision**, not a
207
- settled one. A brand that ships `googleClientId` empty has the plugin inert with an
206
+ **client secret**, which lives house-only at `${PLATFORM_ROOT}/config/google-house.env`
207
+ (decided; see below). A brand that ships `googleClientId` empty has the plugin inert with an
208
208
  actionable signal (`clientIdConfigured=false`), register refuses, and no operator action
209
209
  makes it work until the vendor client exists — mirroring Outlook's inert behaviour.
210
210
 
211
- ### Open Phase 1 decision: there is no brand-level secret store
211
+ ### Client-secret storage: house-only (decided 2026-07-18)
212
212
 
213
213
  An earlier draft of this file said the secret is "held in the brand's secret store, the same
214
- way Cloudflare tokens are held". That was wrong, and Phase 1 must resolve it before the
215
- register path is built. The two stores that actually exist are:
216
-
217
- - **`brands/<brand>/brand.json`** — ships inside the published npm package. It can carry the
218
- client **id** (public, non-secret, exactly like `outlookClientId`) and must never carry a
219
- secret.
220
- - **`~/<brand>-code/data/accounts/<accountId>/secrets`** — where the Cloudflare master token
221
- lives (`platform/plugins/cloudflare/references/api.md`). This is **account-scoped**, one
222
- per install.
223
-
224
- The mismatch: the Google client secret is **per-brand** (one vendor app serves every install
225
- of that brand), but the only real secret store is **per-account**. Outlook never hit this
226
- because its device-code flow is secret-less, so there is no precedent to copy. Phase 1 must
227
- choose and record one of: replicate the brand secret into each install's account-scoped
228
- secrets at provisioning time; introduce a genuine brand-scoped secret store; or drop to
229
- Option A (Desktop client), whose installed-app secret Google documents as non-confidential
230
- and which therefore needs no confidential store at all. Do not assume a brand secret store
231
- exists — nothing implements one today.
214
+ way Cloudflare tokens are held". That was wrong no brand-level secret store exists. The
215
+ decision, mirroring the Cloudflare master token exactly:
216
+
217
+ ```
218
+ ${PLATFORM_ROOT}/config/google-house.env # mode 600, parent 700
219
+ GOOGLE_CLIENT_ID=…
220
+ GOOGLE_CLIENT_SECRET=…
221
+ ```
222
+
223
+ Written once per install by the operator, never echoed, never in a project tree.
224
+ `platform/plugins/cloudflare/references/api.md` already establishes this pattern for
225
+ multi-client installs and names SiteDesk as the case: an account-wide credential inside a
226
+ sub-account's secrets file lets that sub-account reach every other client's resources, so
227
+ the master lives house-only at `${PLATFORM_ROOT}/config/cloudflare-house.env`, "a location
228
+ no sub-account spawn sources". `google-house.env` is that file's twin.
229
+
230
+ Rejected, with reasons:
231
+
232
+ - **`brands/<brand>/brand.json`** ships inside the published npm package. It carries
233
+ `googleClientId` (public, exactly like `outlookClientId`, and the value the inert check
234
+ reads) and never the secret.
235
+ - **`~/<brand>-code/data/accounts/<accountId>/secrets`** is wrong-scoped twice: the secret is
236
+ per-brand not per-account, so replicating it multiplies exposure for no benefit, and on a
237
+ multi-tenant install it drops a brand-wide credential into a client sub-account's own
238
+ directory.
239
+ - **A Desktop-type client** (installed-app secret, documented non-confidential) would remove
240
+ the storage question but forces the loopback redirect and its copy-the-code-off-a-404 flow
241
+ on a phone, and discards the already-provisioned, verified Web-application client.
242
+
243
+ House-only is sufficient here rather than merely tidier, because the token exchange runs in
244
+ the `/api/google/oauth/callback` route inside the always-running `platform/ui` server, which
245
+ is house-scoped. The secret never needs to reach a per-account MCP spawn.
246
+
247
+ **It is a boundary of intent, not of permission.** Every account's session runs as the same
248
+ unix user and the house path is deterministic, so an agent holding `Bash` can read the file
249
+ regardless; OS user separation was costed and declined. Never cite house-only placement as
250
+ proof a sub-account cannot reach the secret.
232
251
 
233
252
  ---
234
253
 
@@ -258,7 +277,7 @@ follow-up once the plugin lands (mirroring Outlook 1479/1485).
258
277
  new one."). Capture it at creation into its final destination, or plan to rotate. It is
259
278
  never pasted into a chat transcript, a shell command that lands in history, or the repo.
260
279
  Rotation is free and has no downtime: **Add secret**, store the new one, delete the old.
261
- Where it should finally live is an open Phase 1 decision — see above.
280
+ It lives house-only at `${PLATFORM_ROOT}/config/google-house.env` — see above.
262
281
  - **Option A (fallback):** application type **Desktop app**. Copy the **Client ID**.
263
282
  5. Set `googleClientId` in the brand's `brand.json` and re-bundle:
264
283
  ```jsonc
@@ -1,5 +1,12 @@
1
1
  import type { Logger } from './types.js';
2
2
  import { UserTitleStore } from './user-title-store.js';
3
+ /** The account evidence a session row carries. Structural rather than the full
4
+ * `SessionRow` so the `/spawn` call site, which has a cwd and no row, can
5
+ * satisfy it without synthesising one. */
6
+ export interface TitleStoreRowRef {
7
+ cwd: string | null;
8
+ accountId: string | null;
9
+ }
3
10
  export declare class AccountTitleStores {
4
11
  private readonly accountsRoot;
5
12
  private readonly bootAccountId;
@@ -11,10 +18,16 @@ export declare class AccountTitleStores {
11
18
  /** The per-account store for `accountId`, created and loaded from disk on
12
19
  * first access and cached thereafter. A null `accountId` (unresolvable
13
20
  * session account) falls back to the boot account and is logged. */
14
- forAccount(accountId: string | null): UserTitleStore;
15
- /** The per-account store for the account a session runs under, resolved
16
- * from its spawn `cwd`. Same resolution the delete/list paths use. */
17
- forSessionCwd(cwd: string | null): UserTitleStore;
21
+ forAccount(accountId: string | null, source?: string): UserTitleStore;
22
+ /** The per-account store for the account a session runs under.
23
+ *
24
+ * `cwd` is tried first: for a live row it is read from claude's own PID
25
+ * file and is the standing spawn-directory invariant (Tasks 1315/1322).
26
+ * Once the process exits there is no PID file and no cwd, so the sidecar's
27
+ * `accountId` — which survives the process — is the evidence that remains.
28
+ * Both absent means the sidecar predates Task 983's stamping, and the boot
29
+ * fallback logs it. */
30
+ forSessionRow(row: TitleStoreRowRef | null | undefined): UserTitleStore;
18
31
  /** The boot account's store — used for the manager's boot-ready size log. */
19
32
  bootStore(): UserTitleStore;
20
33
  }
@@ -1 +1 @@
1
- {"version":3,"file":"account-title-stores.d.ts","sourceRoot":"","sources":["../src/account-title-stores.ts"],"names":[],"mappings":"AAqBA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AACxC,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAEtD,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAQ;IACrC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAQ;IACtC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAQ;IAC/B,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAoC;IAEhE;wEACoE;gBACxD,cAAc,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAMlD;;yEAEqE;IACrE,UAAU,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,GAAG,cAAc;IAwBpD;2EACuE;IACvE,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,GAAG,cAAc;IAIjD,6EAA6E;IAC7E,SAAS,IAAI,cAAc;CAG5B"}
1
+ {"version":3,"file":"account-title-stores.d.ts","sourceRoot":"","sources":["../src/account-title-stores.ts"],"names":[],"mappings":"AAsBA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AACxC,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAEtD;;2CAE2C;AAC3C,MAAM,WAAW,gBAAgB;IAC/B,GAAG,EAAE,MAAM,GAAG,IAAI,CAAA;IAClB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAA;CACzB;AAWD,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAQ;IACrC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAQ;IACtC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAQ;IAC/B,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAoC;IAEhE;wEACoE;gBACxD,cAAc,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAMlD;;yEAEqE;IACrE,UAAU,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,EAAE,MAAM,SAAW,GAAG,cAAc;IAwBvE;;;;;;;4BAOwB;IACxB,aAAa,CAAC,GAAG,EAAE,gBAAgB,GAAG,IAAI,GAAG,SAAS,GAAG,cAAc;IAuBvE,6EAA6E;IAC7E,SAAS,IAAI,cAAc;CAG5B"}