phaedo-mcp 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +301 -0
- package/agreement.js +95 -0
- package/build-package.mjs +22 -0
- package/cache.js +76 -0
- package/consult-core.js +439 -0
- package/consult-policies.sample.json +36 -0
- package/consult-policy.js +136 -0
- package/consult.js +118 -0
- package/errors.js +23 -0
- package/fingerprint-source.js +71 -0
- package/hooks/session-start.mjs +48 -0
- package/install.mjs +368 -0
- package/installers/linux/install-phaedo-mcp.sh +32 -0
- package/installers/macos/Install Phaedo MCP.command +37 -0
- package/installers/windows/Install Phaedo MCP.bat +39 -0
- package/lib/node-vault.js +34 -0
- package/lib/phaedo-crypto.js +36 -0
- package/package.json +49 -0
- package/pair.js +29 -0
- package/pairing.js +184 -0
- package/pairing.sample.json +8 -0
- package/phone-source.js +141 -0
- package/policy-editor.html +146 -0
- package/projection.js +115 -0
- package/pull.js +26 -0
- package/receipts.js +211 -0
- package/sample-fingerprint.json +107 -0
- package/server.js +262 -0
- package/server.json +19 -0
- package/vendor/context-block.js +599 -0
- package/vendor/envelope.js +130 -0
- package/vendor/identity.js +122 -0
- package/vendor/kdf.js +114 -0
- package/vendor/protocol.js +56 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright 2026 Randy Shelton
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
# Phaedo MCP server — Phase 1 (push injection)
|
|
2
|
+
|
|
3
|
+
A local [MCP](https://modelcontextprotocol.io) server that exposes your Phaedo
|
|
4
|
+
cognitive-fingerprint **projection** to any MCP client (Claude Desktop, Claude
|
|
5
|
+
Code, Cursor, agent frameworks) — so the assistant responds in your style
|
|
6
|
+
without the Chrome extension. One integration, every MCP client.
|
|
7
|
+
|
|
8
|
+
Implements `docs/protocol/mcp-binding.md` §3.1:
|
|
9
|
+
|
|
10
|
+
| Surface | Name | Returns |
|
|
11
|
+
|---|---|---|
|
|
12
|
+
| tool | `phaedo_request_injection` | §9.2 request → §9.3 Injection Response |
|
|
13
|
+
| resource | `phaedo://fingerprint/projection` | default projection (all layers, standard) |
|
|
14
|
+
| prompt | `phaedo` | one-click `/phaedo` — inserts the projection as a message |
|
|
15
|
+
| tool | `phaedo_consult` | §10.2 request → §10.3 Consultation **signal** (never layer content) |
|
|
16
|
+
| tool | `phaedo_check_authorization` | deterministic-only pre-flight: does a standing authorization (§10.5) already decide this action? (no inference) |
|
|
17
|
+
|
|
18
|
+
The projection is rendered by the **same** `context-block.js` the extension
|
|
19
|
+
injects, so MCP injection is byte-identical to web injection.
|
|
20
|
+
|
|
21
|
+
## Status
|
|
22
|
+
|
|
23
|
+
- **Phase 1a (this cut):** reads the fingerprint from a local JSON file (see
|
|
24
|
+
*Fingerprint source*). Lets injection work in a real client today, no crypto.
|
|
25
|
+
- **Phase 1b-i (done):** the spec-faithful key boundary — authorize → pull
|
|
26
|
+
`/v1/profile` → unwrap the §7.2 envelope from the paired phone, reusing the
|
|
27
|
+
repo crypto modules (`protocol/envelope/kdf/identity.js`) in node. The
|
|
28
|
+
decrypted fingerprint stays in memory (never written to disk). Auto-selected
|
|
29
|
+
when a pairing record is configured (see *Fingerprint source*). Plan +
|
|
30
|
+
decisions: `../docs/roadmap/mcp-1b-plan.md`.
|
|
31
|
+
- **Phase 1b-iii (done):** **encrypted at-rest cache** — a successful phone pull
|
|
32
|
+
caches the fingerprint as ciphertext under a server-held key; when the phone is
|
|
33
|
+
unreachable the server serves that cache, so it works **phone-absent**
|
|
34
|
+
(frictionless default; mirrors the extension's Option C — defense-in-depth, NOT
|
|
35
|
+
phone-gated). State dir defaults to `~/.phaedo-mcp/` (override `PHAEDO_MCP_STATE_DIR`);
|
|
36
|
+
holds a `0600` key file + ciphertext-only cache. **Revocation is honored:** if
|
|
37
|
+
the phone *rejects* this client (revoked / invalid credentials → 4xx), the cache
|
|
38
|
+
is purged and the pull fails — a revoked agent can't keep serving a cached copy.
|
|
39
|
+
The cache only covers the phone being genuinely *unreachable* (network/timeout).
|
|
40
|
+
v1 caveat: the raw key is on disk (weaker than the extension's non-extractable
|
|
41
|
+
key) — OS-keychain is a hardening follow-up.
|
|
42
|
+
- **Per-agent revocable pairing (built, device-verify pending):** the server
|
|
43
|
+
pairs **itself** with the phone as its own SAS-approved, **revocable** client —
|
|
44
|
+
`npm run pair` (LAN auto-discovery or relay typed-code, mirroring the
|
|
45
|
+
extension). Needs the phone's multi-client support (spec §8.4 **v0.1.6**) + the
|
|
46
|
+
phone **Agents/revoke** screen. Obviates hand-copying the pairing record. Plan:
|
|
47
|
+
`../docs/roadmap/mcp-revocable-approval-plan.md`. Phone-gated unlock stays a
|
|
48
|
+
deferred enterprise mode behind a config flag.
|
|
49
|
+
|
|
50
|
+
**Injection-only.** MCP never returns the conversation, so there is **no
|
|
51
|
+
capture** here (binding §5) — your fingerprint does not learn from MCP sessions.
|
|
52
|
+
Local **stdio** only; **standard** mode only (enhanced-privacy/Stained-Glass and
|
|
53
|
+
remote HTTP/SSE are out of this cut).
|
|
54
|
+
|
|
55
|
+
## Install & test
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
cd mcp
|
|
59
|
+
npm install
|
|
60
|
+
npm run smoke # 1a: unit + live stdio integration (23 checks)
|
|
61
|
+
npm run smoke:phone # 1b-i: mock-phone authorize→pull→decrypt→project (12 checks)
|
|
62
|
+
npm run smoke:cache # 1b-iii: encrypted at-rest cache + phone-absent fallback (11 checks)
|
|
63
|
+
npm run smoke:pair # P3: self-pairing crypto vs a mock phone (pair_key + SAS match)
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Pair with the phone
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
cd mcp
|
|
70
|
+
npm run pair
|
|
71
|
+
```
|
|
72
|
+
The server generates its own long-term identity (`identity.json`, `0600`,
|
|
73
|
+
gitignored) and pairs with the phone vault as a distinct client named **"Phaedo
|
|
74
|
+
MCP Server"**:
|
|
75
|
+
- **Same Wi-Fi:** it finds the phone automatically — approve "Phaedo MCP Server"
|
|
76
|
+
on the phone and confirm the SAS matches what the terminal prints.
|
|
77
|
+
- **Off-network:** it prints an `XXXX-XXXX` code; on the phone tap **Pair with
|
|
78
|
+
code**, type it, then confirm the SAS.
|
|
79
|
+
|
|
80
|
+
On success it writes `pairing.json` and pulls your fingerprint autonomously
|
|
81
|
+
thereafter. Revoke anytime from the phone's **Agents** screen.
|
|
82
|
+
|
|
83
|
+
## Fingerprint source
|
|
84
|
+
|
|
85
|
+
`loadFingerprint()` auto-selects, so `server.js`/`projection.js` never change:
|
|
86
|
+
|
|
87
|
+
**Phase 1b — phone (preferred).** If a pairing record is configured, the server
|
|
88
|
+
pulls the live fingerprint from the paired phone over the encrypted boundary.
|
|
89
|
+
A record is found via `PHAEDO_PAIRING` (path) or `mcp/pairing.json`. Run
|
|
90
|
+
**`npm run pair`** (see *Pair with the phone*) to create it — the server pairs
|
|
91
|
+
itself with the phone as its own revocable client. `pairing.json` holds
|
|
92
|
+
`pair_key` (a long-term secret) and is **gitignored**. The phone app must be
|
|
93
|
+
foregrounded/reachable at the configured `endpoint`. *(You can still hand-copy
|
|
94
|
+
`pairing.sample.json` → `pairing.json` from the extension's `phaedo_local_pairing`
|
|
95
|
+
if you prefer.)*
|
|
96
|
+
|
|
97
|
+
**Phase 1a — local JSON (fallback / demo).** With no pairing record, reads a
|
|
98
|
+
**vault payload** from `PHAEDO_FINGERPRINT`, then `mcp/fingerprint.json`, then
|
|
99
|
+
the shipped `mcp/sample-fingerprint.json` (so it runs out of the box):
|
|
100
|
+
```json
|
|
101
|
+
{
|
|
102
|
+
"phaedo_fingerprint": { "layers": { ... }, "fingerprint_id": "...", "persona_strength": 0.6 },
|
|
103
|
+
"phaedo_behavioral_signals": { ... },
|
|
104
|
+
"phaedo_linguistic_profile": { "messageCount": 64, ... },
|
|
105
|
+
"phaedo_session_metrics": { "sessionCount": 6, ... }
|
|
106
|
+
}
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## One-click install (recommended)
|
|
110
|
+
|
|
111
|
+
The installer finds the MCP clients you already have (Claude Desktop, Cursor,
|
|
112
|
+
Claude Code), adds Phaedo to each — preserving your other servers, backing the
|
|
113
|
+
file up first — and then runs the one-time phone pairing.
|
|
114
|
+
|
|
115
|
+
- **macOS:** double-click **`installers/macos/Install Phaedo MCP.command`**.
|
|
116
|
+
- **Windows:** double-click **`installers/windows/Install Phaedo MCP.bat`**.
|
|
117
|
+
- **Linux:** `bash installers/linux/install-phaedo-mcp.sh`.
|
|
118
|
+
|
|
119
|
+
(The launcher installs dependencies the first time, then runs the installer.)
|
|
120
|
+
|
|
121
|
+
Prefer the terminal? From this folder:
|
|
122
|
+
```bash
|
|
123
|
+
npm install
|
|
124
|
+
npm run setup # configure detected clients
|
|
125
|
+
npm run setup:pair # configure, then pair with the phone
|
|
126
|
+
npm run unsetup # remove Phaedo from every client
|
|
127
|
+
node install.mjs --dry-run # preview, write nothing
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
Each client entry runs the server with the **absolute path to your node binary**
|
|
131
|
+
(not bare `node`) — a GUI-launched app like Claude Desktop often has no `node` on
|
|
132
|
+
its PATH. After installing, **restart any client that was already open**, then
|
|
133
|
+
call the `phaedo_request_injection` tool (or read the
|
|
134
|
+
`phaedo://fingerprint/projection` resource) at the start of a chat.
|
|
135
|
+
|
|
136
|
+
> One remaining prerequisite: Node.js (from [nodejs.org](https://nodejs.org)). A
|
|
137
|
+
> signed native installer that bundles the runtime — true zero-prerequisite,
|
|
138
|
+
> one-double-click — is the packaging follow-up (see
|
|
139
|
+
> `../docs/roadmap/mcp-desktop-installer.md`).
|
|
140
|
+
|
|
141
|
+
## Inject at session start (manual → automatic)
|
|
142
|
+
|
|
143
|
+
MCP is pull-based — a server can't push a system prompt into every new session the
|
|
144
|
+
way the browser extension owns the input box. So injection ranges from one-click to
|
|
145
|
+
fully automatic depending on the client:
|
|
146
|
+
|
|
147
|
+
- **Any client — `/phaedo` (one click).** The server exposes a **prompt** named
|
|
148
|
+
`phaedo`. Claude Desktop / Claude Code surface it as a slash command — run
|
|
149
|
+
`/phaedo` at the start of a chat and it inserts your projection. One keystroke,
|
|
150
|
+
no typing.
|
|
151
|
+
- **Claude Code — automatic (a hook).** Run `npm run setup:code-hook` (or
|
|
152
|
+
`node install.mjs --code-hook`). It adds a **SessionStart hook** to
|
|
153
|
+
`~/.claude/settings.json` that runs `hooks/session-start.mjs` and injects your
|
|
154
|
+
projection at the start of **every** Claude Code session — no command, no tool
|
|
155
|
+
call. Fail-safe: if the fingerprint can't be loaded it emits nothing and never
|
|
156
|
+
blocks the session. Remove it with `npm run unsetup`.
|
|
157
|
+
- **Claude Desktop — near-automatic (a Project instruction).** Desktop has no hook
|
|
158
|
+
surface, but in a **Project** you can make Claude call the tool itself every time.
|
|
159
|
+
Paste into the Project's custom instructions:
|
|
160
|
+
> At the start of every conversation, call the `phaedo_request_injection` tool and
|
|
161
|
+
> treat the returned `projection` as authoritative on how I think and want
|
|
162
|
+
> responses formatted. Don't announce that you did it.
|
|
163
|
+
|
|
164
|
+
Every chat in that project then injects automatically.
|
|
165
|
+
|
|
166
|
+
## Consult at decision points (`phaedo_consult`, §10)
|
|
167
|
+
|
|
168
|
+
Beyond injecting style, an agent can **ask the fingerprint how the user's pattern
|
|
169
|
+
bears on a decision** — without ingesting the fingerprint. `phaedo_consult` takes a
|
|
170
|
+
§10.2 request and returns a §10.3 **signal**, never layer content (§10.4 boundary):
|
|
171
|
+
|
|
172
|
+
```jsonc
|
|
173
|
+
// request (tool arguments)
|
|
174
|
+
{ "consultation_type": "action_approval",
|
|
175
|
+
"action_descriptor": { "domain": "financial", "reversible": false, "magnitude": "high",
|
|
176
|
+
"summary": "Approve $12k vendor payment outside terms." },
|
|
177
|
+
"context": { "evidence_provided": ["invoice", "po_match"] } }
|
|
178
|
+
|
|
179
|
+
// response
|
|
180
|
+
{ "signal": "escalate", "confidence": 0.81,
|
|
181
|
+
"rationale_hint": "On irreversible, high-magnitude actions in the financial domain, the subject favors caution and human review.",
|
|
182
|
+
"deference_level": "high" }
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
- `consultation_type`: `action_approval` · `domain_risk_check` · `escalation_default` · `voice_draft`.
|
|
186
|
+
- `signal`: `proceed` · `proceed_with_note` · `clarify` · `escalate` · `decline` · `insufficient_signal` (abstain — the fingerprint has no coverage for this action; fall back to your own default).
|
|
187
|
+
- `deference_level` (`high`/`medium`/`low`) = how strongly to weight it; sparse data → `low`.
|
|
188
|
+
|
|
189
|
+
### Fast pre-flight (`phaedo_check_authorization`, §10.5)
|
|
190
|
+
|
|
191
|
+
Before paying for a full consult, an agent can ask whether one of your **standing
|
|
192
|
+
authorizations** already decides the action — a **deterministic-only** check (no
|
|
193
|
+
inference, no model):
|
|
194
|
+
|
|
195
|
+
```jsonc
|
|
196
|
+
// request: { "action_descriptor": { "domain": "financial", "reversible": false, "amount": 12000 } }
|
|
197
|
+
// matched: { "authorization_matched": true, "signal": "escalate", "rule_id": "irreversible-spend-over-5k-escalate",
|
|
198
|
+
// "rationale_hint": "Per your standing rule: Any irreversible spend over $5,000 goes to me…" }
|
|
199
|
+
// no match: { "authorization_matched": false, "signal": null, "rule_id": null,
|
|
200
|
+
// "rationale_hint": "No standing authorization matches this action; run phaedo_consult…" }
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
A match is your pre-decision (confidence 1.0, deference high). On no match, fall back to
|
|
204
|
+
`phaedo_consult` or your own default. Same §10.4 boundary — only the rule's decision crosses.
|
|
205
|
+
|
|
206
|
+
### Receipts (§10.6) — your on-device audit trail
|
|
207
|
+
|
|
208
|
+
Every resolved consultation (abstains included, plus matched pre-flights) writes one
|
|
209
|
+
**encrypted, append-only receipt** to `~/.phaedo-mcp/receipts.enc` — which agent asked
|
|
210
|
+
what, and what your oracle answered. Receipts **never leave the device**; the store is
|
|
211
|
+
ciphertext under its own derived key (`phaedo:receipts:enc:v0.1`), capped (default
|
|
212
|
+
5,000, oldest evicted; `PHAEDO_RECEIPTS_CAP` to change). Only one field is ever mutable
|
|
213
|
+
after write: `user_action` (what you actually did — feeds future agreement tracking).
|
|
214
|
+
Quick readout on your own machine:
|
|
215
|
+
|
|
216
|
+
```bash
|
|
217
|
+
cd mcp && npm run receipts # decrypts locally, lists the last 50 (with a short id per line)
|
|
218
|
+
node receipts.js mark <id|prefix|latest> approved # record what YOU did → approved | rejected | modified | unknown
|
|
219
|
+
npm run agreement # per-domain agreement rate (oracle vs your actual decisions)
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
`user_action` is **subject-authored**: set it from what *you* decided, not from whether an
|
|
223
|
+
agent proceeded. Until receipts carry one, `npm run agreement` shows `—`
|
|
224
|
+
(no data ≠ 0%); each one you mark makes the rate live. Metric definition:
|
|
225
|
+
`../docs/architecture/agreement-metric.md`.
|
|
226
|
+
|
|
227
|
+
**Two resolvers, both local.** The default is a **deterministic rule engine** —
|
|
228
|
+
resilient cue extraction (reads §4.2 signals, then keyword-scans the relevant
|
|
229
|
+
layers' interview text), relevance-scoped per consultation type, with
|
|
230
|
+
confidence/deference grounded in real cue coverage. Nothing leaves the device;
|
|
231
|
+
always available.
|
|
232
|
+
|
|
233
|
+
**Model judge (richest context — ON by default, local).** The judge reasons over
|
|
234
|
+
the *full projection* via a **local** Ollama / OpenAI-compatible endpoint and
|
|
235
|
+
returns a §10.3 signal. Any failure/timeout/parse error **falls back to the rule
|
|
236
|
+
engine**, so the model can only improve on, never break, the floor (and a missing
|
|
237
|
+
model never breaks consultation). The §10.4 boundary is enforced on parse.
|
|
238
|
+
|
|
239
|
+
The **installer turns this on automatically**: it probes local Ollama and writes
|
|
240
|
+
`PHAEDO_CONSULT_MODEL` into each client's server entry (picking an installed general
|
|
241
|
+
model, else defaulting to `llama3.1:8b`). Toggle it at install time:
|
|
242
|
+
|
|
243
|
+
```bash
|
|
244
|
+
npm run setup # model judge ON (auto-detect Ollama)
|
|
245
|
+
node install.mjs --consult-model qwen2.5:7b # pin a specific model
|
|
246
|
+
node install.mjs --consult-url http://localhost:11434 # custom endpoint
|
|
247
|
+
node install.mjs --no-model-judge # rule engine only
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
Use a **general** chat model (NOT the extraction fine-tune). To run it: `ollama
|
|
251
|
+
pull llama3.1:8b`. Raw env (if configuring a client by hand):
|
|
252
|
+
`PHAEDO_CONSULT_MODEL`, `PHAEDO_CONSULT_MODEL_URL`, `PHAEDO_CONSULT_API_KEY`
|
|
253
|
+
(OpenAI-compatible endpoints only).
|
|
254
|
+
|
|
255
|
+
`voice_draft` always redirects to the injection projection (generation is out of
|
|
256
|
+
scope). A retrieval/scoping reranker is the next upgrade (`../docs/roadmap/mcp-server.md`).
|
|
257
|
+
|
|
258
|
+
### Deference policies (guardrails that make delegation safe)
|
|
259
|
+
|
|
260
|
+
The user can author **standing rules** that *override* the inferred signal —
|
|
261
|
+
per-domain / magnitude / reversibility (spec §10.5). e.g. "always escalate
|
|
262
|
+
irreversible spend/legal", "auto-proceed low-stakes reversible writing".
|
|
263
|
+
|
|
264
|
+
**Author them in the browser:** open **`policy-editor.html`** (double-click — it's
|
|
265
|
+
self-contained), build rules with the form, and **Download / Copy** the result to
|
|
266
|
+
**`mcp/consult-policies.json`**. The server **auto-reads that file** — no env, just
|
|
267
|
+
restart the client. (Override the path with `PHAEDO_CONSULT_POLICIES`; see
|
|
268
|
+
`consult-policies.sample.json`.) Portable alternative: put the rules in the vault
|
|
269
|
+
under `phaedo_consult_policies` so they travel with you (in-app authoring is a
|
|
270
|
+
follow-up).
|
|
271
|
+
|
|
272
|
+
`effect`: `escalate`/`require_human` · `decline` · `autoproceed` (all at `deference:
|
|
273
|
+
high`) · `bias_cautious`/`bias_bold` (nudge one step). The matched rule's `note`
|
|
274
|
+
becomes the `rationale_hint` ("Per your standing rule: …"), so the agent sees why.
|
|
275
|
+
Policies never apply to `voice_draft` and never widen the §10.4 boundary.
|
|
276
|
+
|
|
277
|
+
## Connect a client manually (advanced)
|
|
278
|
+
|
|
279
|
+
The installer writes exactly this. The minimal **paired** entry needs no `env` —
|
|
280
|
+
`pairing.json` next to `server.js` drives the source automatically.
|
|
281
|
+
|
|
282
|
+
**Claude Desktop** — add to `claude_desktop_config.json`:
|
|
283
|
+
```json
|
|
284
|
+
{
|
|
285
|
+
"mcpServers": {
|
|
286
|
+
"phaedo": {
|
|
287
|
+
"command": "/absolute/path/to/node",
|
|
288
|
+
"args": ["/Users/galavoxx/phaedo/mcp/server.js"]
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
```
|
|
293
|
+
For the Phase-1a demo (no phone), add
|
|
294
|
+
`"env": { "PHAEDO_FINGERPRINT": "/absolute/path/to/your/fingerprint.json" }`.
|
|
295
|
+
Restart Claude Desktop, then call `phaedo_request_injection` at the start of a
|
|
296
|
+
chat and prepend the returned `projection`.
|
|
297
|
+
|
|
298
|
+
**Claude Code** — `.mcp.json` in a project, or:
|
|
299
|
+
```bash
|
|
300
|
+
claude mcp add phaedo -- /absolute/path/to/node /Users/galavoxx/phaedo/mcp/server.js
|
|
301
|
+
```
|
package/agreement.js
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
// Phaedo — agreement tracking FOUNDATION (build brief M5).
|
|
2
|
+
//
|
|
3
|
+
// Given the §10.6 receipt store, compute the per-domain AGREEMENT RATE: how often
|
|
4
|
+
// the oracle's decisive signal matched what the subject actually did
|
|
5
|
+
// (`user_action`), over a sliding time window. This is the minimal data layer for
|
|
6
|
+
// the delegation gradient and the seed of the native persona benchmark
|
|
7
|
+
// (docs/architecture/agreement-metric.md).
|
|
8
|
+
//
|
|
9
|
+
// PURE: (receipts, opts) -> report. No I/O, no globals, no side effects — the
|
|
10
|
+
// same discipline as consult-core.js. Reading the store happens in the caller
|
|
11
|
+
// (CLI below / harness); receipts are data here.
|
|
12
|
+
//
|
|
13
|
+
// DELIBERATELY NOT WIRED to deference_level. Closing the loop (high agreement →
|
|
14
|
+
// auto-raise deference) is a product decision for a later session, not an
|
|
15
|
+
// engineering default (brief M5 step 2). Dev-only readout: `npm run agreement`.
|
|
16
|
+
//
|
|
17
|
+
// Metric definition v0 (full rationale in docs/architecture/agreement-metric.md):
|
|
18
|
+
// - Only receipts with a known user_action count (`approved|rejected|modified`;
|
|
19
|
+
// `unknown`/null are recorded but excluded from the rate).
|
|
20
|
+
// - Only DECISIVE signals are scored: proceed / proceed_with_note / decline.
|
|
21
|
+
// escalate, clarify, and insufficient_signal hand the decision to a human or
|
|
22
|
+
// defer — they make no outcome prediction, so "agreement" is undefined for
|
|
23
|
+
// them; they are counted separately as non_directional.
|
|
24
|
+
// - Agreement: proceed|proceed_with_note ↔ approved; decline ↔ rejected.
|
|
25
|
+
// `modified` counts as DISAGREEMENT for every decisive signal (the subject
|
|
26
|
+
// did not accept the action as-judged). Conservative on purpose: it
|
|
27
|
+
// understates agreement rather than overstating delegation safety.
|
|
28
|
+
// - Domain key: action_descriptor.domain, lowercased; null → "(none)".
|
|
29
|
+
|
|
30
|
+
export const DECISIVE = ['proceed', 'proceed_with_note', 'decline'];
|
|
31
|
+
export const DEFAULT_WINDOW_DAYS = 30;
|
|
32
|
+
|
|
33
|
+
function agrees(signal, userAction) {
|
|
34
|
+
if (userAction === 'approved') return signal === 'proceed' || signal === 'proceed_with_note';
|
|
35
|
+
if (userAction === 'rejected') return signal === 'decline';
|
|
36
|
+
return false; // 'modified' — the action was not accepted as-judged
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// (receipts, { windowDays, now }) -> {
|
|
40
|
+
// window: { days, since, now, total_receipts, in_window },
|
|
41
|
+
// overall: { scored, agreements, disagreements, rate, non_directional, awaiting_user_action },
|
|
42
|
+
// domains: { [domain]: same-shape-as-overall },
|
|
43
|
+
// }
|
|
44
|
+
// `rate` is null when nothing was scored (no data ≠ 0% agreement).
|
|
45
|
+
export function computeAgreement(receipts, { windowDays = DEFAULT_WINDOW_DAYS, now = Date.now() } = {}) {
|
|
46
|
+
const since = now - windowDays * 24 * 60 * 60 * 1000;
|
|
47
|
+
const bucket = () => ({ scored: 0, agreements: 0, disagreements: 0, rate: null, non_directional: 0, awaiting_user_action: 0 });
|
|
48
|
+
const overall = bucket();
|
|
49
|
+
const domains = {};
|
|
50
|
+
let inWindow = 0;
|
|
51
|
+
|
|
52
|
+
for (const r of Array.isArray(receipts) ? receipts : []) {
|
|
53
|
+
const t = Date.parse(r?.created_at);
|
|
54
|
+
if (!Number.isFinite(t) || t < since || t > now) continue;
|
|
55
|
+
inWindow++;
|
|
56
|
+
const domain = (r.request?.action_descriptor?.domain || '(none)').toLowerCase();
|
|
57
|
+
const d = (domains[domain] ||= bucket());
|
|
58
|
+
const signal = r.response?.signal;
|
|
59
|
+
const action = r.user_action;
|
|
60
|
+
|
|
61
|
+
for (const b of [overall, d]) {
|
|
62
|
+
if (!DECISIVE.includes(signal)) { b.non_directional++; continue; }
|
|
63
|
+
if (action == null || action === 'unknown') { b.awaiting_user_action++; continue; }
|
|
64
|
+
b.scored++;
|
|
65
|
+
if (agrees(signal, action)) b.agreements++; else b.disagreements++;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
for (const b of [overall, ...Object.values(domains)]) {
|
|
70
|
+
if (b.scored > 0) b.rate = Math.round((b.agreements / b.scored) * 1000) / 1000;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return {
|
|
74
|
+
window: { days: windowDays, since: new Date(since).toISOString(), now: new Date(now).toISOString(), total_receipts: Array.isArray(receipts) ? receipts.length : 0, in_window: inWindow },
|
|
75
|
+
overall,
|
|
76
|
+
domains,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// ── Dev CLI: `node agreement.js` / `npm run agreement` — local readout only ───
|
|
81
|
+
// Decrypts the local receipt store with the local key; nothing leaves the device.
|
|
82
|
+
// NOT product UX and NOT fed back into deference (see header).
|
|
83
|
+
if (process.argv[1] && process.argv[1].endsWith('agreement.js')) {
|
|
84
|
+
const days = Number(process.argv[2]) || DEFAULT_WINDOW_DAYS;
|
|
85
|
+
Promise.all([import('./receipts.js'), import('./cache.js')]).then(async ([{ readReceipts }, { defaultStateDir }]) => {
|
|
86
|
+
const report = computeAgreement(await readReceipts(defaultStateDir()), { windowDays: days });
|
|
87
|
+
const { overall: o, window: w } = report;
|
|
88
|
+
console.log(`Agreement over the last ${w.days}d — ${w.in_window}/${w.total_receipts} receipts in window\n`);
|
|
89
|
+
const line = (label, b) =>
|
|
90
|
+
console.log(`${label.padEnd(22)} rate ${b.rate === null ? ' — ' : (b.rate * 100).toFixed(1) + '%'} (${b.agreements}✓ ${b.disagreements}✗ of ${b.scored} scored · ${b.non_directional} non-directional · ${b.awaiting_user_action} awaiting user_action)`);
|
|
91
|
+
line('OVERALL', o);
|
|
92
|
+
for (const [dom, b] of Object.entries(report.domains).sort()) line(` ${dom}`, b);
|
|
93
|
+
if (o.scored === 0) console.log('\nNo scored receipts yet — set user_action on receipts as you accept/reject agent actions.');
|
|
94
|
+
}).catch((e) => { console.error(`agreement: ${e.message}`); process.exit(1); });
|
|
95
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Make the npm package self-contained. The MCP server reaches two sets of files at
|
|
3
|
+
// the repo root (one source of truth, shared with the extension): the injection
|
|
4
|
+
// renderer (context-block.js, via projection.js) and the classic crypto modules
|
|
5
|
+
// (protocol/envelope/kdf/identity.js, via lib/phaedo-crypto.js). The published
|
|
6
|
+
// package ships only mcp/, so this copies those root modules into mcp/vendor/;
|
|
7
|
+
// projection.js and lib/phaedo-crypto.js prefer the vendored copies when present
|
|
8
|
+
// and fall back to the repo root in dev. Runs as `prepack` (npm pack / publish)
|
|
9
|
+
// and `npm run build`. Idempotent; mcp/vendor/ is gitignored (a build artifact).
|
|
10
|
+
|
|
11
|
+
import { copyFileSync, mkdirSync } from 'fs';
|
|
12
|
+
import { dirname, join, resolve } from 'path';
|
|
13
|
+
import { fileURLToPath } from 'url';
|
|
14
|
+
|
|
15
|
+
const HERE = dirname(fileURLToPath(import.meta.url));
|
|
16
|
+
const ROOT = resolve(HERE, '..');
|
|
17
|
+
const VENDOR = join(HERE, 'vendor');
|
|
18
|
+
const FILES = ['context-block.js', 'protocol.js', 'envelope.js', 'kdf.js', 'identity.js'];
|
|
19
|
+
|
|
20
|
+
mkdirSync(VENDOR, { recursive: true });
|
|
21
|
+
for (const f of FILES) copyFileSync(resolve(ROOT, f), join(VENDOR, f));
|
|
22
|
+
process.stdout.write(`[phaedo-mcp] bundled ${FILES.length} root modules → mcp/vendor/\n`);
|