@tangenta/claude-code 0.19.0 → 0.20.1

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.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tangenta",
3
- "version": "0.19.0",
3
+ "version": "0.20.1",
4
4
  "description": "Attaches Claude Code to a Tangenta issue: the issue page shows the session's plan and activity, and people on it can message, answer and stop Claude.",
5
5
  "author": { "name": "Tangenta" },
6
6
  "keywords": ["tangenta", "issues", "agents"],
package/.mcp.json CHANGED
@@ -4,7 +4,17 @@
4
4
  "type": "stdio",
5
5
  "command": "node",
6
6
  "args": ["${CLAUDE_PLUGIN_ROOT}/scripts/mcp-proxy.mjs"],
7
- "env": { "TANGENTA_PLUGIN_API_URL": "${user_config.api_url}" }
7
+ "env": {
8
+ "TANGENTA_PLUGIN_API_URL": "${user_config.api_url}"
9
+ }
10
+ },
11
+ "agent": {
12
+ "type": "stdio",
13
+ "command": "node",
14
+ "args": ["${CLAUDE_PLUGIN_ROOT}/scripts/agent-mcp.mjs"],
15
+ "env": {
16
+ "TANGENTA_PLUGIN_API_URL": "${user_config.api_url}"
17
+ }
8
18
  }
9
19
  }
10
20
  }
package/README.md CHANGED
@@ -25,4 +25,26 @@ Claude Code from). The hosted Tangenta needs no setting.
25
25
  Then open an issue in Tangenta, start an agent session and send the prompt it gives you to
26
26
  Claude Code. See `docs/AGENTS.md` in the Tangenta repository for the trust rules and the limits.
27
27
 
28
+ ## Connect as an agent
29
+
30
+ The plugin also connects Claude Code to Tangenta as an agent: a member of the workspace with its
31
+ own API key and access. Add the agent in Tangenta (Settings > Agents) and copy its one-time
32
+ setup prompt into Claude Code. The prompt installs this plugin and runs `/tangenta:setup` with
33
+ the setup token, which works once within an hour.
34
+
35
+ A second local MCP server, `agent`, keeps the agent's key on your machine and never shows it. Its
36
+ tools:
37
+
38
+ - `connect_agent` exchanges the setup token (and, for a self-hosted instance, the API address)
39
+ for the agent's key.
40
+ - `agent_status` tells which agent, workspace and access Claude Code is connected as, and whether
41
+ Tangenta still accepts the key.
42
+ - `renew_agent_key` swaps the key for a new one with the same access. The old key stops working
43
+ 5 minutes later.
44
+
45
+ Slash commands:
46
+
47
+ - `/tangenta:setup <setup token> [API address]` calls `connect_agent`, then `agent_status`.
48
+ - `/tangenta:renew` calls `renew_agent_key`, then `agent_status`.
49
+
28
50
  MIT licensed.
@@ -0,0 +1,6 @@
1
+ ---
2
+ description: Renew the Tangenta agent's API key (the old key stops working 5 minutes later)
3
+ ---
4
+
5
+ Call the tool `renew_agent_key` of the Tangenta plugin's `agent` MCP server, then `agent_status`
6
+ of the same server, and tell me what they answered. Never ask for, print or store the key.
@@ -0,0 +1,10 @@
1
+ ---
2
+ description: Connect Claude Code to Tangenta as an agent, with the one-time setup token of its setup prompt
3
+ argument-hint: <setup token> [API address]
4
+ ---
5
+
6
+ Connect this Claude Code to Tangenta as the agent the setup token was made for: call the tool
7
+ `connect_agent` of the Tangenta plugin's `agent` MCP server with `setupToken` set to the first
8
+ word of "$ARGUMENTS" and, when there is a second word, `apiUrl` set to it. Never write the token
9
+ or a key to a file, a command or the chat. Then call `agent_status` of the same server and tell
10
+ me what it answered. If `connect_agent` isn't listed yet, ask me to restart Claude Code first.
@@ -0,0 +1,214 @@
1
+ /**
2
+ * The plugin's `agent` MCP server (stdio): Claude Code works in Tangenta as one agent member with
3
+ * the agent's own API key (lib/agent.mjs). Its own tools connect (`connect_agent`, with the setup
4
+ * token of the agent's setup prompt), check (`agent_status`) and renew (`renew_agent_key`) that
5
+ * key; once connected, every Tangenta MCP tool is listed and forwarded to `<api>/mcp` with the key,
6
+ * read from the state file on every call, so a renewal takes effect at once. After connecting it
7
+ * tells Claude Code the tool list changed.
8
+ */
9
+ import { ConfigError } from "./config.mjs";
10
+ import {
11
+ AgentError,
12
+ NOT_CONNECTED,
13
+ connectAgent,
14
+ readCredentials,
15
+ redact,
16
+ renewAgentKey,
17
+ } from "./agent.mjs";
18
+ import { TangentaError, rpc } from "./tangenta.mjs";
19
+
20
+ const VERSIONS = ["2025-11-25", "2025-06-18", "2025-03-26"];
21
+ const CALL_TIMEOUT_MS = 30_000;
22
+ const LIST_TIMEOUT_MS = 10_000;
23
+
24
+ export const AGENT_TOOLS = [
25
+ {
26
+ name: "connect_agent",
27
+ title: "Connect as the Tangenta agent",
28
+ description:
29
+ "Exchanges the one-time setup token from an agent's Tangenta setup prompt for the " +
30
+ "agent's own API key, which the plugin keeps; the key is never shown. The token works " +
31
+ "once, within an hour.",
32
+ inputSchema: {
33
+ type: "object",
34
+ properties: {
35
+ setupToken: { type: "string", description: "The setup token, tng_stp_..." },
36
+ apiUrl: { type: "string", description: "The API address the setup prompt names." },
37
+ },
38
+ required: ["setupToken"],
39
+ additionalProperties: false,
40
+ },
41
+ annotations: { readOnlyHint: false, destructiveHint: false },
42
+ },
43
+ {
44
+ name: "agent_status",
45
+ title: "Tangenta agent status",
46
+ description:
47
+ "Which Tangenta agent, workspace and access Claude Code is connected as, and whether " +
48
+ "Tangenta still accepts its key.",
49
+ inputSchema: { type: "object", properties: {}, additionalProperties: false },
50
+ annotations: { readOnlyHint: true },
51
+ },
52
+ {
53
+ name: "renew_agent_key",
54
+ title: "Renew the Tangenta agent key",
55
+ description:
56
+ "Swaps the agent's API key for a new one with the same access; the old key stops working " +
57
+ "5 minutes later.",
58
+ inputSchema: { type: "object", properties: {}, additionalProperties: false },
59
+ annotations: { readOnlyHint: false, destructiveHint: false },
60
+ },
61
+ ];
62
+
63
+ const LOCAL_NAMES = new Set(AGENT_TOOLS.map((tool) => tool.name));
64
+
65
+ function result(id, value) {
66
+ return { jsonrpc: "2.0", id, result: value };
67
+ }
68
+
69
+ function failure(id, code, message) {
70
+ return { jsonrpc: "2.0", id, error: { code, message: redact(message) } };
71
+ }
72
+
73
+ function text(message, isError = false) {
74
+ const content = [{ type: "text", text: redact(message) }];
75
+ return isError ? { content, isError: true } : { content };
76
+ }
77
+
78
+ function initialize(params) {
79
+ const requested = params?.protocolVersion;
80
+ return {
81
+ protocolVersion: VERSIONS.includes(requested) ? requested : VERSIONS[0],
82
+ capabilities: { tools: { listChanged: true } },
83
+ serverInfo: { name: "tangenta-agent", title: "Tangenta agent", version: "0.20.1" },
84
+ instructions:
85
+ "Tangenta's tools, as the agent member this Claude Code is connected as. Connect with " +
86
+ "connect_agent and the setup token of the agent's setup prompt; check with agent_status.",
87
+ };
88
+ }
89
+
90
+ async function remote(credentials, method, params, timeoutMs, deps) {
91
+ const message = { jsonrpc: "2.0", id: 1, method, params };
92
+ return rpc({
93
+ apiUrl: credentials.apiUrl,
94
+ token: credentials.apiKey,
95
+ message,
96
+ timeoutMs,
97
+ fetchImpl: deps.fetchImpl,
98
+ });
99
+ }
100
+
101
+ /** The remote tools, or none when not connected or Tangenta can't be reached. */
102
+ async function remoteTools(env, deps) {
103
+ const credentials = readCredentials(env);
104
+ if (!credentials) return [];
105
+ try {
106
+ const answer = await remote(credentials, "tools/list", {}, LIST_TIMEOUT_MS, deps);
107
+ const tools = answer?.result?.tools;
108
+ return Array.isArray(tools) ? tools.filter((tool) => !LOCAL_NAMES.has(tool?.name)) : [];
109
+ } catch {
110
+ return [];
111
+ }
112
+ }
113
+
114
+ function unauthorizedText() {
115
+ return (
116
+ "Tangenta no longer accepts the agent's key: it was revoked, renewed more than 5 minutes " +
117
+ "ago elsewhere, or the agent was removed. Ask an admin for a new setup prompt from the " +
118
+ "agent's page."
119
+ );
120
+ }
121
+
122
+ async function status(env, deps) {
123
+ const credentials = readCredentials(env);
124
+ if (!credentials) return text(NOT_CONNECTED, true);
125
+ const agent = credentials.agent?.name ?? "the agent";
126
+ const workspace = credentials.workspace?.name ?? "its workspace";
127
+ const intro =
128
+ `Connected as ${agent} in ${workspace} at ${credentials.apiUrl}, ${credentials.access} ` +
129
+ `access, key ending ${credentials.keySuffix}.`;
130
+ try {
131
+ const answer = await remote(credentials, "tools/list", {}, LIST_TIMEOUT_MS, deps);
132
+ const count = answer?.result?.tools?.length ?? 0;
133
+ return text(`${intro} Tangenta accepts the key and offers ${count} tools.`);
134
+ } catch (error) {
135
+ if (error instanceof TangentaError && error.kind === "unauthorized") {
136
+ return text(`${intro} ${unauthorizedText()}`, true);
137
+ }
138
+ return text(`${intro} ${error.message}`, true);
139
+ }
140
+ }
141
+
142
+ async function forward(id, name, args, env, deps) {
143
+ const credentials = readCredentials(env);
144
+ if (!credentials) return result(id, text(NOT_CONNECTED, true));
145
+ let answer;
146
+ try {
147
+ answer = await remote(
148
+ credentials,
149
+ "tools/call",
150
+ { name, arguments: args },
151
+ CALL_TIMEOUT_MS,
152
+ deps,
153
+ );
154
+ } catch (error) {
155
+ if (!(error instanceof TangentaError)) throw error;
156
+ const message = error.kind === "unauthorized" ? unauthorizedText() : error.message;
157
+ return result(id, text(message, true));
158
+ }
159
+ if (answer?.error) return failure(id, answer.error.code ?? -32_603, String(answer.error.message));
160
+ return result(id, answer?.result ?? text("Tangenta's answer had no result.", true));
161
+ }
162
+
163
+ async function callLocal(id, name, args, env, deps) {
164
+ try {
165
+ if (name === "connect_agent") {
166
+ const message = await connectAgent(env, args, deps);
167
+ deps.notify?.({ jsonrpc: "2.0", method: "notifications/tools/list_changed" });
168
+ return result(id, text(message));
169
+ }
170
+ if (name === "renew_agent_key") return result(id, text(await renewAgentKey(env, deps)));
171
+ return result(id, await status(env, deps));
172
+ } catch (error) {
173
+ if (error instanceof AgentError || error instanceof ConfigError) {
174
+ return result(id, text(error.message, true));
175
+ }
176
+ throw error;
177
+ }
178
+ }
179
+
180
+ /**
181
+ * Answers one JSON-RPC message, or null for a notification or a response. `deps.env`,
182
+ * `deps.fetchImpl` and `deps.notify` (sends a notification to Claude Code) replace the process
183
+ * environment, fetch and stdout in tests.
184
+ */
185
+ export async function handleAgentMessage(message, deps = {}) {
186
+ const env = deps.env ?? process.env;
187
+ if (!message || message.jsonrpc !== "2.0" || typeof message.method !== "string") {
188
+ if (message && message.jsonrpc === "2.0" && ("result" in message || "error" in message)) {
189
+ return null;
190
+ }
191
+ return failure(message?.id ?? null, -32_600, "Invalid request.");
192
+ }
193
+ if (!("id" in message)) return null;
194
+ const { id, method } = message;
195
+ const params = message.params ?? {};
196
+ switch (method) {
197
+ case "initialize":
198
+ return result(id, initialize(params));
199
+ case "ping":
200
+ return result(id, {});
201
+ case "tools/list":
202
+ return result(id, { tools: [...AGENT_TOOLS, ...(await remoteTools(env, deps))] });
203
+ case "tools/call": {
204
+ const args = params.arguments ?? {};
205
+ if (typeof params.name !== "string" || typeof args !== "object" || Array.isArray(args)) {
206
+ return failure(id, -32_602, "A tool call needs a name and an arguments object.");
207
+ }
208
+ if (LOCAL_NAMES.has(params.name)) return callLocal(id, params.name, args, env, deps);
209
+ return forward(id, params.name, args, env, deps);
210
+ }
211
+ default:
212
+ return failure(id, -32_601, "Method not found.");
213
+ }
214
+ }
package/lib/agent.mjs ADDED
@@ -0,0 +1,202 @@
1
+ /**
2
+ * The agent's own API key: Claude Code connects to Tangenta as one agent member. A one-time setup
3
+ * token (`tng_stp_`, from the agent's setup prompt) is exchanged once at
4
+ * `POST <api>/agents/setup/exchange` for the agent's API key (`tng_api_`), and
5
+ * `POST <api>/agents/keys/renew` swaps that key for a new one (the old key works 5 more minutes).
6
+ *
7
+ * The key lives in `<state root>/agent/credentials.json`: the directory 0700, the file 0600,
8
+ * written atomically; a state root inside the project is refused, so the key never lands in a
9
+ * repository. Nothing here prints, logs or answers the key or the token: answers name the last 4
10
+ * characters only.
11
+ */
12
+ import {
13
+ chmodSync,
14
+ closeSync,
15
+ mkdirSync,
16
+ openSync,
17
+ readFileSync,
18
+ realpathSync,
19
+ renameSync,
20
+ writeSync,
21
+ } from "node:fs";
22
+ import { join } from "node:path";
23
+
24
+ import { attachApiUrl, projectDir, stateRoot, stateRootInsideProject } from "./config.mjs";
25
+
26
+ /** The agent API key and setup token forms; answers and errors never carry either. */
27
+ export const AGENT_SECRET_PATTERN = /tng_(?:api|stp)_[A-Za-z0-9_-]{20,}/g;
28
+
29
+ const SETUP_TOKEN = /^tng_stp_[A-Za-z0-9_-]{43}$/;
30
+ const REQUEST_TIMEOUT_MS = 15_000;
31
+
32
+ export class AgentError extends Error {}
33
+
34
+ /** `text` with every agent key and setup token replaced. */
35
+ export function redact(text) {
36
+ return String(text).replaceAll(AGENT_SECRET_PATTERN, "[kept by the Tangenta plugin]");
37
+ }
38
+
39
+ function realPath(path) {
40
+ try {
41
+ return realpathSync(path);
42
+ } catch {
43
+ return path;
44
+ }
45
+ }
46
+
47
+ /** Where the agent's credentials are kept, outside the project. */
48
+ export function credentialsPath(env) {
49
+ const root = realPath(stateRoot(env));
50
+ if (stateRootInsideProject(env, projectDir(env, null))) {
51
+ throw new AgentError(
52
+ "The Tangenta plugin's state directory is inside the project, where the agent's key could " +
53
+ "end up in the repository. Point TANGENTA_PLUGIN_STATE_DIR somewhere else.",
54
+ );
55
+ }
56
+ return join(root, "agent", "credentials.json");
57
+ }
58
+
59
+ /** The stored credentials (`apiUrl`, `apiKey`, `keySuffix`, `access`, `agent`, `workspace`). */
60
+ export function readCredentials(env) {
61
+ let text;
62
+ try {
63
+ text = readFileSync(credentialsPath(env), "utf8");
64
+ } catch (error) {
65
+ if (error instanceof AgentError) throw error;
66
+ return null;
67
+ }
68
+ try {
69
+ const credentials = JSON.parse(text);
70
+ return typeof credentials?.apiKey === "string" && typeof credentials?.apiUrl === "string"
71
+ ? credentials
72
+ : null;
73
+ } catch {
74
+ return null;
75
+ }
76
+ }
77
+
78
+ /** Replaces the stored credentials, atomically and readable by this user only. */
79
+ export function writeCredentials(env, credentials) {
80
+ const path = credentialsPath(env);
81
+ const directory = join(path, "..");
82
+ mkdirSync(directory, { recursive: true, mode: 0o700 });
83
+ chmodSync(directory, 0o700);
84
+ const temporary = `${path}.${process.pid}.${Date.now()}.tmp`;
85
+ const descriptor = openSync(temporary, "wx", 0o600);
86
+ try {
87
+ writeSync(descriptor, JSON.stringify(credentials));
88
+ } finally {
89
+ closeSync(descriptor);
90
+ }
91
+ renameSync(temporary, path);
92
+ chmodSync(path, 0o600);
93
+ }
94
+
95
+ /** POSTs `body` as JSON and answers the parsed answer; failures name no secret. */
96
+ async function post({ url, body, apiKey, fetchImpl = fetch }) {
97
+ const headers = { "content-type": "application/json", accept: "application/json" };
98
+ if (apiKey) headers.authorization = `Bearer ${apiKey}`;
99
+ let response;
100
+ try {
101
+ response = await fetchImpl(url, {
102
+ method: "POST",
103
+ redirect: "manual",
104
+ headers,
105
+ body: JSON.stringify(body),
106
+ signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS),
107
+ });
108
+ } catch (error) {
109
+ const reason = error?.name === "TimeoutError" ? "didn't answer in time" : "can't be reached";
110
+ throw new AgentError(`Tangenta at ${new URL(url).origin} ${reason}.`);
111
+ }
112
+ let answer = null;
113
+ try {
114
+ answer = await response.json();
115
+ } catch {
116
+ answer = null;
117
+ }
118
+ if (!response.ok) {
119
+ const message = answer?.errors?.[0]?.message ?? `Tangenta answered HTTP ${response.status}.`;
120
+ throw new AgentError(redact(message));
121
+ }
122
+ return answer ?? {};
123
+ }
124
+
125
+ function describe(credentials) {
126
+ const agent = credentials.agent?.name ?? "the agent";
127
+ const handle = credentials.agent?.handle ? ` (@${credentials.agent.handle})` : "";
128
+ const workspace = credentials.workspace?.name ? ` in ${credentials.workspace.name}` : "";
129
+ return (
130
+ `${agent}${handle}${workspace} at ${credentials.apiUrl}, ${credentials.access} access, ` +
131
+ `key ending ${credentials.keySuffix}`
132
+ );
133
+ }
134
+
135
+ /**
136
+ * Exchanges `setupToken` at `apiUrl` (checked like an attach line's address: https, and the
137
+ * configured address wins) and stores the key. Answers a sentence without the key.
138
+ */
139
+ export async function connectAgent(env, { setupToken, apiUrl }, deps = {}) {
140
+ const token = typeof setupToken === "string" ? setupToken.trim() : "";
141
+ if (!SETUP_TOKEN.test(token)) {
142
+ throw new AgentError(
143
+ "That isn't a Tangenta setup token (tng_stp_...). Copy it from the setup prompt.",
144
+ );
145
+ }
146
+ const address = attachApiUrl(env, typeof apiUrl === "string" && apiUrl.trim() ? apiUrl : null);
147
+ const answer = await post({
148
+ url: `${address}/agents/setup/exchange`,
149
+ body: { setupToken: token },
150
+ fetchImpl: deps.fetchImpl,
151
+ });
152
+ if (typeof answer.apiKey !== "string") throw new AgentError("Tangenta's answer had no key.");
153
+ const credentials = {
154
+ apiUrl: address,
155
+ apiKey: answer.apiKey,
156
+ keySuffix: answer.keySuffix ?? answer.apiKey.slice(-4),
157
+ access: answer.access,
158
+ agent: answer.agent ?? null,
159
+ workspace: answer.workspace ?? null,
160
+ connectedAt: new Date().toISOString(),
161
+ };
162
+ writeCredentials(env, credentials);
163
+ return `Connected as ${describe(credentials)}. The key is kept by the plugin.`;
164
+ }
165
+
166
+ /**
167
+ * Renews the stored key: Tangenta answers a new key for the same agent and access, and the old
168
+ * one stops working a few minutes later. Answers a sentence without either key.
169
+ */
170
+ export async function renewAgentKey(env, deps = {}) {
171
+ const credentials = readCredentials(env);
172
+ if (!credentials) throw new AgentError(NOT_CONNECTED);
173
+ const answer = await post({
174
+ url: `${credentials.apiUrl}/agents/keys/renew`,
175
+ body: {},
176
+ apiKey: credentials.apiKey,
177
+ fetchImpl: deps.fetchImpl,
178
+ });
179
+ if (typeof answer.apiKey !== "string") throw new AgentError("Tangenta's answer had no key.");
180
+ const renewed = {
181
+ ...credentials,
182
+ apiKey: answer.apiKey,
183
+ keySuffix: answer.keySuffix ?? answer.apiKey.slice(-4),
184
+ access: answer.access ?? credentials.access,
185
+ renewedAt: new Date().toISOString(),
186
+ };
187
+ writeCredentials(env, renewed);
188
+ const ends = answer.previousKeyExpiresAt
189
+ ? ` The old key stops at ${answer.previousKeyExpiresAt}.`
190
+ : "";
191
+ return `Renewed the key of ${describe(renewed)}.${ends}`;
192
+ }
193
+
194
+ export const NOT_CONNECTED =
195
+ "Claude Code isn't connected to Tangenta as an agent. Paste the agent's setup prompt from its " +
196
+ "page in Tangenta, or run /tangenta:setup with its setup token.";
197
+
198
+ /** The stored connection as a sentence, without the key; null when there is none. */
199
+ export function connectionSummary(env) {
200
+ const credentials = readCredentials(env);
201
+ return credentials ? describe(credentials) : null;
202
+ }
package/lib/config.mjs CHANGED
@@ -14,8 +14,9 @@
14
14
  * TANGENTA_QUESTION_WAIT_SECONDS how long the Stop hook waits for the answer to a question
15
15
  * TANGENTA_EMIT_ACTIONS 0 turns off reporting each tool call as an action
16
16
  */
17
+ import { existsSync, realpathSync } from "node:fs";
17
18
  import { homedir } from "node:os";
18
- import { join, resolve } from "node:path";
19
+ import { isAbsolute, join, relative, resolve } from "node:path";
19
20
 
20
21
  /** The least time between two input checks after tool calls, unless the environment says. */
21
22
  export const DEFAULT_POLL_INTERVAL_MS = 5_000;
@@ -177,6 +178,28 @@ export function projectDir(env, hookInput) {
177
178
  return resolve(process.cwd());
178
179
  }
179
180
 
181
+ function realPath(path) {
182
+ try {
183
+ return realpathSync(path);
184
+ } catch {
185
+ return path;
186
+ }
187
+ }
188
+
189
+ /**
190
+ * Whether the state root lies inside the project, where a key or session token could end up
191
+ * in a repository. The user's home directory as the project is exempt, since every default
192
+ * state root is under it, unless the home directory is itself a git repository (a dotfiles
193
+ * checkout), where a key could still be committed.
194
+ */
195
+ export function stateRootInsideProject(env, project) {
196
+ const projectPath = realPath(project);
197
+ const home = realPath(present(env.HOME) ? env.HOME : homedir());
198
+ if (projectPath === home && !existsSync(join(home, ".git"))) return false;
199
+ const path = relative(projectPath, realPath(stateRoot(env)));
200
+ return path === "" || (!path.startsWith("..") && !isAbsolute(path));
201
+ }
202
+
180
203
  function integer(value, fallback, { min, max }) {
181
204
  const parsed = Number.parseInt(value ?? "", 10);
182
205
  if (Number.isNaN(parsed)) return fallback;
package/lib/proxy.mjs CHANGED
@@ -124,7 +124,7 @@ function initialize(params) {
124
124
  return {
125
125
  protocolVersion: VERSIONS.includes(requested) ? requested : VERSIONS[0],
126
126
  capabilities: { tools: { listChanged: false } },
127
- serverInfo: { name: `tangenta-${PROXY_SERVER}`, title: "Tangenta session", version: "0.19.0" },
127
+ serverInfo: { name: `tangenta-${PROXY_SERVER}`, title: "Tangenta session", version: "0.20.1" },
128
128
  instructions:
129
129
  "Tools of the Tangenta session this project is attached to: report activity and the " +
130
130
  "plan to the issue page, ask the starter a question, and end the session.",
package/lib/store.mjs CHANGED
@@ -18,9 +18,9 @@ import {
18
18
  statSync,
19
19
  writeSync,
20
20
  } from "node:fs";
21
- import { isAbsolute, join, relative } from "node:path";
21
+ import { join } from "node:path";
22
22
 
23
- import { stateRoot } from "./config.mjs";
23
+ import { stateRoot, stateRootInsideProject } from "./config.mjs";
24
24
 
25
25
  const LOCK_WAIT_MS = 8_000;
26
26
  const LOCK_STALE_MS = 20_000;
@@ -36,16 +36,11 @@ function realPath(path) {
36
36
  }
37
37
  }
38
38
 
39
- function inside(parent, child) {
40
- const path = relative(parent, child);
41
- return path === "" || (!path.startsWith("..") && !isAbsolute(path));
42
- }
43
-
44
39
  /** The store of `project` under the state root that `env` names. */
45
40
  export function openStore(env, project) {
46
41
  const root = realPath(stateRoot(env));
47
42
  const projectPath = realPath(project);
48
- if (inside(projectPath, root)) {
43
+ if (stateRootInsideProject(env, projectPath)) {
49
44
  throw new StoreError(
50
45
  "The Tangenta plugin's state directory is inside the project, where the session token " +
51
46
  "could end up in the repository. Point TANGENTA_PLUGIN_STATE_DIR somewhere else.",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tangenta/claude-code",
3
- "version": "0.19.0",
3
+ "version": "0.20.1",
4
4
  "type": "module",
5
5
  "description": "The Tangenta plugin for Claude Code: hooks and a local MCP server that attach a Claude Code session to a Tangenta issue. No dependencies.",
6
6
  "keywords": [
@@ -14,6 +14,7 @@
14
14
  "license": "MIT",
15
15
  "files": [
16
16
  ".claude-plugin",
17
+ "commands",
17
18
  "hooks",
18
19
  "lib",
19
20
  "scripts",
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * The Tangenta plugin's `agent` MCP server over stdio: one JSON-RPC message per line in, one per
4
+ * line out (see lib/agent-proxy.mjs). Every line it writes has agent keys and setup tokens
5
+ * replaced, so neither reaches Claude.
6
+ */
7
+ import { createInterface } from "node:readline";
8
+
9
+ import { redact } from "../lib/agent.mjs";
10
+ import { handleAgentMessage } from "../lib/agent-proxy.mjs";
11
+
12
+ function send(message) {
13
+ process.stdout.write(`${redact(JSON.stringify(message))}\n`);
14
+ }
15
+
16
+ const lines = createInterface({ input: process.stdin, crlfDelay: Infinity });
17
+
18
+ for await (const line of lines) {
19
+ if (!line.trim()) continue;
20
+ let message;
21
+ try {
22
+ message = JSON.parse(line);
23
+ } catch {
24
+ send({ jsonrpc: "2.0", id: null, error: { code: -32_700, message: "Parse error." } });
25
+ continue;
26
+ }
27
+ try {
28
+ const answer = await handleAgentMessage(message, { notify: send });
29
+ if (answer) send(answer);
30
+ } catch (error) {
31
+ const reason = String(error?.message ?? error);
32
+ send({ jsonrpc: "2.0", id: message?.id ?? null, error: { code: -32_603, message: reason } });
33
+ }
34
+ }