truthspine 0.0.0-stage → 0.2.2
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 +201 -0
- package/README.md +80 -2
- package/bin/truthspine-mcp.mjs +40 -0
- package/lib/claude-lifecycle-contract.cjs +79 -0
- package/lib/installed-mcp-launcher.cjs +963 -0
- package/lib/package.json +3 -0
- package/package.json +58 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction, and
|
|
10
|
+
distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,81 @@
|
|
|
1
|
-
#
|
|
1
|
+
# TruthSpine MCP connector (npm)
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/truthspine) [](https://www.npmjs.com/package/truthspine) [](LICENSE)
|
|
4
|
+
|
|
5
|
+
The free MCP connector for TruthSpine, the local-first project-truth app for AI agents.
|
|
6
|
+
|
|
7
|
+
Stop re-explaining your project to every new AI chat. It works on your computer, with no cloud account and nothing extra to install.
|
|
8
|
+
|
|
9
|
+
One checked record of what was decided, what was done, what failed and what comes next. Every connected chat checks your project before it answers, so you never re-explain it. Your project stays on your computer.
|
|
10
|
+
|
|
11
|
+
This is the free connector. It needs the TruthSpine desktop app installed on the same computer: the [Microsoft Store](https://apps.microsoft.com/detail/9pbn25k75vdj) on Windows, the [Mac App Store](https://apps.apple.com/app/id6794478470) on macOS, or the AppImage from [truthspine.app](https://truthspine.app/download) on Linux.
|
|
12
|
+
|
|
13
|
+
## See it
|
|
14
|
+
|
|
15
|
+

|
|
16
|
+
|
|
17
|
+
*Codex in VS Code. Real recording, waits shortened.*
|
|
18
|
+
|
|
19
|
+

|
|
20
|
+
|
|
21
|
+

|
|
22
|
+
|
|
23
|
+

|
|
24
|
+
|
|
25
|
+
## Setup
|
|
26
|
+
|
|
27
|
+
1. Install and open the TruthSpine app, and connect your project folder in it.
|
|
28
|
+
2. Add an MCP server to your tool that runs `npx -y @timeprooflabs/truthspine-mcp --host <tool>`, started in your project folder (or add `--project <folder>`). Use your tool's name for `<tool>`. Without `--host` the connection is labelled as an agent on this computer.
|
|
29
|
+
3. In a chat, say "Connect TruthSpine".
|
|
30
|
+
|
|
31
|
+
Names for `--host`:
|
|
32
|
+
|
|
33
|
+
- Claude Desktop: `claude-desktop`
|
|
34
|
+
- Claude Code: `claude-code`
|
|
35
|
+
- Codex: `codex-cli`
|
|
36
|
+
- Cursor: `cursor`
|
|
37
|
+
- VS Code: `vscode`
|
|
38
|
+
- GitHub Copilot in VS Code: `github-copilot-vscode`
|
|
39
|
+
- Cline: `cline`
|
|
40
|
+
- Windsurf / Devin: `windsurf-devin`
|
|
41
|
+
- OpenCode: `opencode`
|
|
42
|
+
- LM Studio: `lm-studio`
|
|
43
|
+
- Kiro: `kiro`
|
|
44
|
+
- Google Antigravity: `antigravity`
|
|
45
|
+
- JetBrains IDEs: `jetbrains`
|
|
46
|
+
- Zed: `zed`
|
|
47
|
+
- Hermes Agent: `hermes-agent`
|
|
48
|
+
- OpenClaw: `openclaw`
|
|
49
|
+
- GitHub Copilot CLI: `copilot-cli`
|
|
50
|
+
- Droid: `droid`
|
|
51
|
+
- Pi: `pi`
|
|
52
|
+
- Gemini CLI: `gemini-cli`
|
|
53
|
+
|
|
54
|
+
The TruthSpine app can also write these settings for you: open Connections and choose your tool.
|
|
55
|
+
|
|
56
|
+
## Tools
|
|
57
|
+
|
|
58
|
+
- `attach`: Attach this chat to the project's TruthSpine record and receive the current brief: decisions, completed work, evidence and next steps.
|
|
59
|
+
- `consult`: Ask what is true about the project, what was decided and why, or what to do next. Read only.
|
|
60
|
+
- `record`: Save a decision, finished work, a failure or the next step to the project's record on this computer.
|
|
61
|
+
- `history`: Read what was saved recently, or confirm that a save was recorded. Read only.
|
|
62
|
+
|
|
63
|
+
## Licence
|
|
64
|
+
|
|
65
|
+
This connector is open source (Apache License 2.0). It needs the TruthSpine app, which you get separately.
|
|
66
|
+
The connector needs no license of its own.
|
|
67
|
+
On Windows, get the TruthSpine app from the Microsoft Store.
|
|
68
|
+
On Mac, get the TruthSpine app from the App Store.
|
|
69
|
+
On Linux, get the TruthSpine AppImage from truthspine.app.
|
|
70
|
+
|
|
71
|
+
## Privacy Policy
|
|
72
|
+
|
|
73
|
+
Full policy: https://truthspine.app/privacy
|
|
74
|
+
|
|
75
|
+
- **What is collected:** this connector collects nothing itself. It starts the TruthSpine app installed on your computer and passes your agent's requests to it.
|
|
76
|
+
- **Use and storage:** the TruthSpine app keeps your project record (decisions, completed work, evidence references and next steps) in its data folder on your computer. Project files are read on your computer and are not uploaded by TruthSpine.
|
|
77
|
+
- **Third-party sharing:** none by this connector. What your agent shows or sends to its own AI provider is governed by that provider. The app contacts TimeProofLabs only for licence checks and, if you agree to it, anonymous usage counts. Purchases go through Microsoft, Apple or Stripe. Optional features you turn on, such as remote access or GitHub projects, connect only to accounts you choose.
|
|
78
|
+
- **Retention:** the record stays on your computer until you delete the project or the app's data; you can download or delete it at any time from the app.
|
|
79
|
+
- **Contact:** support@truthspine.app
|
|
80
|
+
|
|
81
|
+
Support: https://truthspine.app/support
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import launcher from "../lib/installed-mcp-launcher.cjs";
|
|
4
|
+
import contract from "../lib/claude-lifecycle-contract.cjs";
|
|
5
|
+
|
|
6
|
+
const args = process.argv.slice(2);
|
|
7
|
+
const option = (name) => { const index = args.indexOf(name); return index >= 0 && typeof args[index + 1] === "string" ? args[index + 1] : null; };
|
|
8
|
+
if (args.includes("--help") || args.includes("-h")) {
|
|
9
|
+
process.stdout.write("truthspine-mcp [--host <tool>] [--project <folder>]\nStarts the TruthSpine connector for the TruthSpine app installed on this computer.\n");
|
|
10
|
+
process.exit(0);
|
|
11
|
+
}
|
|
12
|
+
const configuredRoot = String(option("--project") ?? process.env.TRUTHSPINE_PROJECT_ROOT ?? "").trim();
|
|
13
|
+
const host = String(option("--host") ?? process.env.TRUTHSPINE_HOST_ID ?? "computer-agent").trim().toLowerCase();
|
|
14
|
+
const controller = new AbortController();
|
|
15
|
+
let connection;
|
|
16
|
+
let startupStage = "workspace-binding";
|
|
17
|
+
const stop = () => { controller.abort(); connection?.stop(1); };
|
|
18
|
+
process.once("SIGINT", stop); process.once("SIGTERM", stop);
|
|
19
|
+
try {
|
|
20
|
+
const unresolved = /\$\{[^}]+\}|%[A-Za-z_][A-Za-z0-9_]*%|\$env:[A-Za-z_][A-Za-z0-9_]*/i.test(configuredRoot);
|
|
21
|
+
process.env.TRUTHSPINE_PROJECT_ROOT = launcher.resolveBoundedHostWorkspace({ cwd: unresolved ? process.cwd() : configuredRoot || process.cwd(), homeDir: os.homedir() }).projectRoot;
|
|
22
|
+
process.env.TRUTHSPINE_LOCK_PROJECT_ROOT = "1";
|
|
23
|
+
process.env.TRUTHSPINE_HOST_ID = host;
|
|
24
|
+
process.env.TRUTHSPINE_LAUNCHER_HOST_ID = host;
|
|
25
|
+
delete process.env.NODE_OPTIONS; delete process.env.NODE_PATH;
|
|
26
|
+
startupStage = "installed-runtime-start";
|
|
27
|
+
process.env.TRUTHSPINE_RUNTIME_REGISTRATION_PATH = contract.defaultRuntimeRegistrationPath();
|
|
28
|
+
connection = await launcher.startInstalledMcpLauncherWithRecovery({ signal: controller.signal });
|
|
29
|
+
if (!connection?.inPlace) { const result = await connection.closed; process.exitCode = result.code; }
|
|
30
|
+
} catch (error) {
|
|
31
|
+
const guidance = startupStage === "workspace-binding"
|
|
32
|
+
? "Start it inside your project folder or pass --project <folder>. Licensing has not been checked; do not sign in or purchase to resolve this."
|
|
33
|
+
: "Install and open the TruthSpine app, connect this project in it, and check --host names your tool. This startup error alone does not establish a licensing failure.";
|
|
34
|
+
const said = (value, most) => String(value ?? "").replace(/[\u0000-\u001f\u007f]+/g, " ").replace(/(?:[A-Za-z]:)?[\\/][^\s'"`]+/g, "[path]").trim().slice(0, most);
|
|
35
|
+
const where = String(error?.stack ?? "").split("\n").slice(1).map(frame => /at (?:async )?([\w.$<>]+) \(.*?([\w.-]+):(\d+):\d+\)$/.exec(frame.trim())).filter(Boolean).slice(0, 3).map(([, name, file, line]) => `${name} ${file}:${line}`).join(" < ");
|
|
36
|
+
const words = /purchase is not affected/i.test(String(error?.message ?? "")) ? "" : said(error?.message ?? error, 400);
|
|
37
|
+
const cause = [said(error?.code, 80), words, where && `at ${where}`].filter(Boolean).join(": ");
|
|
38
|
+
process.stderr.write(`TruthSpine startup failed at ${startupStage}. ${guidance}${cause ? ` Cause: ${cause}` : ""}\n`);
|
|
39
|
+
process.exitCode = 1;
|
|
40
|
+
} finally { process.removeListener("SIGINT", stop); process.removeListener("SIGTERM", stop); }
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const crypto = require("node:crypto");
|
|
3
|
+
const launcher = require("./installed-mcp-launcher.cjs");
|
|
4
|
+
|
|
5
|
+
const fail = () => { throw new Error("TruthSpine could not bind this Claude session to its workspace. No automatic attachment was confirmed."); };
|
|
6
|
+
// Only the host lifecycle envelope is consumed. transcript_path is never read;
|
|
7
|
+
// permission_mode is never treated as a TruthSpine permission grant.
|
|
8
|
+
function buildClaudeSessionStartRequest(input, { homeDir, platform = process.platform } = {}) {
|
|
9
|
+
if (typeof input !== "string" || Buffer.byteLength(input) > 65536) fail();
|
|
10
|
+
let event;
|
|
11
|
+
try { event = JSON.parse(input); } catch { fail(); }
|
|
12
|
+
if (!event || typeof event !== "object" || Array.isArray(event)
|
|
13
|
+
|| event.hook_event_name !== "SessionStart"
|
|
14
|
+
|| !["startup", "resume", "clear", "compact"].includes(event.source)
|
|
15
|
+
|| typeof event.session_id !== "string" || !event.session_id.trim()
|
|
16
|
+
|| event.session_id.length > 2048 || /[\u0000-\u001f\u007f]/.test(event.session_id)) fail();
|
|
17
|
+
const { projectRoot } = launcher.resolveBoundedHostWorkspace({ cwd: event.cwd, homeDir, platform });
|
|
18
|
+
return Object.freeze({
|
|
19
|
+
tool: "onboard_chat",
|
|
20
|
+
// Host/workspace are fixed by the transport, not overridable tool selectors.
|
|
21
|
+
// Older catalogs reject identityMode before tools/call, preventing silent
|
|
22
|
+
// fallback to the old per-attachment/title-derived chat identity.
|
|
23
|
+
arguments: Object.freeze({ hostChatId: event.session_id, identityMode: "host-thread" }),
|
|
24
|
+
projectRoot,
|
|
25
|
+
sessionIdHash: crypto.createHash("sha256").update(event.session_id).digest("hex")
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function formatClaudeSessionStartResult(request, result) {
|
|
30
|
+
const metrics = result?.metrics;
|
|
31
|
+
if (!request || request.tool !== "onboard_chat"
|
|
32
|
+
|| result?.project?.projectRoot !== request.projectRoot
|
|
33
|
+
|| result?.binding?.hostSurface !== "claude-code"
|
|
34
|
+
|| result?.binding?.hostChatIdHash !== request.sessionIdHash
|
|
35
|
+
|| metrics?.hostSurface !== "claude-code"
|
|
36
|
+
|| typeof metrics?.label !== "string" || !/^[a-z0-9][a-z0-9_-]{0,255}$/.test(metrics.label)
|
|
37
|
+
|| metrics.runId !== metrics.label || metrics.sourceRef !== metrics.label
|
|
38
|
+
|| !/^[a-f0-9]{32}$/.test(metrics.chatSessionFingerprint || "")) fail();
|
|
39
|
+
const identity = [
|
|
40
|
+
"TruthSpine has returned this session's workspace-bound attachment identity.",
|
|
41
|
+
`For an explicit Attach TruthSpine request in this same host session/workspace, call attach with these exact arguments: ${JSON.stringify(request.arguments)}. Never replace them with an empty object or a guessed title/ID.`,
|
|
42
|
+
"Consult answer_guard before project-dependent answers and actions. Save meaningful work with record; do not copy another chat's identity.",
|
|
43
|
+
"These identifiers provide attribution, not owner authorization or proof that reported work is correct."
|
|
44
|
+
].join("\n");
|
|
45
|
+
return { hookSpecificOutput: { hookEventName: "SessionStart", additionalContext: withProjectPacket(identity, result?.packet?.text) } };
|
|
46
|
+
}
|
|
47
|
+
// The session starts with the project itself (B2, Brain 2026-11-01: "every new session starts already knowing my project"
|
|
48
|
+
// was true nowhere, since the hook gave only the identity): the connect reply's packet follows the identity lines. Claude
|
|
49
|
+
// Code keeps a hook's text to 10,000 characters and shows only a short preview of anything longer, so the whole text stays
|
|
50
|
+
// under HOOK_CONTEXT_LIMIT, the packet cut at a whole line with a pointer to the rest.
|
|
51
|
+
const HOOK_CONTEXT_LIMIT = 9500;
|
|
52
|
+
function withProjectPacket(identity, packet) {
|
|
53
|
+
const text = typeof packet === "string" ? packet.replace(/[\u0000-\u0008\u000b-\u001f\u007f]/g, "").trim() : "";
|
|
54
|
+
if (!text) return identity;
|
|
55
|
+
const head = `${identity}\n\nThis project, as TruthSpine keeps it now:\n`;
|
|
56
|
+
const rest = "\n(Shortened here; consult answer_guard for the rest.)";
|
|
57
|
+
if (head.length + text.length <= HOOK_CONTEXT_LIMIT) return head + text;
|
|
58
|
+
let kept = "";
|
|
59
|
+
for (const line of text.split("\n")) {
|
|
60
|
+
if (head.length + kept.length + line.length + 1 + rest.length > HOOK_CONTEXT_LIMIT) break;
|
|
61
|
+
kept += `${kept ? "\n" : ""}${line}`;
|
|
62
|
+
}
|
|
63
|
+
return kept ? head + kept + rest : identity;
|
|
64
|
+
}
|
|
65
|
+
// Where the installed app records itself (the same place the app writes it). Used when a
|
|
66
|
+
// public connector carries no machine-specific path; an explicit setting still wins.
|
|
67
|
+
function defaultRuntimeRegistrationPath({ platform = process.platform, env = process.env,
|
|
68
|
+
homeDir = require("node:os").homedir() } = {}) {
|
|
69
|
+
const path = require("node:path");
|
|
70
|
+
const configured = String(env.TRUTHSPINE_RUNTIME_REGISTRATION_PATH || "").trim();
|
|
71
|
+
if (configured) return configured;
|
|
72
|
+
// Windows: ~\.truthspine\app, never AppData, which a Store app sees only in its private copy (shared-registration-path.js).
|
|
73
|
+
if (platform === "win32") return path.win32.join(homeDir, ".truthspine", "app", "runtime.json");
|
|
74
|
+
const home = homeDir.replace(/\\/g, "/");
|
|
75
|
+
if (platform === "darwin") return path.posix.join(home, "Library", "Application Support", "TruthSpine", "runtime.json");
|
|
76
|
+
return path.posix.join(env.XDG_CONFIG_HOME || path.posix.join(home, ".config"), "TruthSpine", "runtime.json");
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
module.exports = { buildClaudeSessionStartRequest, formatClaudeSessionStartResult, defaultRuntimeRegistrationPath };
|