Repository navigation
Expand file tree
/
Copy pathconfig.ts
More file actions
284 lines (249 loc) · 10.7 KB
/
Copy pathconfig.ts
File metadata and controls
284 lines (249 loc) · 10.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
import { randomUUID } from "node:crypto";
import path from "node:path";
import {
DEFAULT_MODEL_ID,
DEFAULT_THINKING_LEVEL,
} from "@tangent/shared/contracts.ts";
import { nestedRoots } from "./memory/paths.ts";
function readAbsoluteUrl(name: string, fallback: string): string {
const value = process.env[name] ?? fallback;
try {
new URL(value);
} catch {
throw new Error(`${name} must be an absolute URL`);
}
return value;
}
/** Port the dev server listens on. Vite proxies /api and /socket.io here. */
export const PORT = Number(process.env.PORT ?? 8787);
/**
* Root directory that holds every session's scoped folder. Each session gets
* its own subdirectory (`SESSIONS_ROOT/<id>`) which a Pi worker will run in.
* Gitignored by default. Always absolute, so path-containment checks against a
* session root compare like with like.
*/
export const SESSIONS_ROOT = path.resolve(
process.env.SESSIONS_ROOT ?? path.join(process.cwd(), ".sessions"),
);
/**
* SQLite database file backing session, asset, and agent-roster metadata.
* Chat history is not stored here; it lives as per-conversation JSONL files
* inside each session's folder. Defaults to a `tangent.db` alongside the
* session folders so a single persistent volume covers everything.
*/
export const SESSIONS_DB =
process.env.SESSIONS_DB ?? path.join(SESSIONS_ROOT, "tangent.db");
/**
* Root directory backing the agent bundle marketplace. Each saved bundle gets
* its own subdirectory (`AGENT_BUNDLES_ROOT/<id>`) holding the original ZIP,
* extracted metadata, and icon. Gitignored by default.
*/
export const AGENT_BUNDLES_ROOT =
process.env.AGENT_BUNDLES_ROOT ??
path.resolve(process.cwd(), ".agent-bundles");
/**
* Root directory holding server-managed shared folders — the cross-session
* "project" folders a session mounts into its root by symlink. Each folder gets
* its own subdirectory (`SHARED_ROOT/<id>`) that any number of sessions may link
* to, so edits in one session are visible to the others. Gitignored by default.
*/
export const SHARED_ROOT = path.resolve(
process.env.SHARED_ROOT ?? path.join(process.cwd(), ".shared"),
);
/**
* Root directory holding each pi-memory store's qmd index and collection config,
* kept out of the store itself so agents that can write a shared folder can't
* plant qmd `update:` hooks or repoint the collection. Must not be named `.qmd`:
* qmd adopts any `.qmd/index.yml` above its working directory. Gitignored by
* default.
*/
export const QMD_STATE_ROOT = path.resolve(
process.env.QMD_STATE_ROOT ?? path.join(process.cwd(), ".qmd-state"),
);
/**
* Root directory holding each bundle's knowledge base (`<root>/<manifestId>/`),
* shared by every session created from that bundle. Never mounted into a
* session: the server is its only writer. Gitignored by default.
*/
export const BUNDLE_MEMORY_ROOT = path.resolve(
process.env.BUNDLE_MEMORY_ROOT ?? path.join(process.cwd(), ".bundle-memory"),
);
// Agents write the session and shared trees, and qmd state is keyed by which
// root a store sits under, so these must stay disjoint.
const nested = nestedRoots({
SESSIONS_ROOT,
SHARED_ROOT,
QMD_STATE_ROOT,
BUNDLE_MEMORY_ROOT,
});
if (nested) {
throw new Error(
`${nested[0]} and ${nested[1]} must not be the same directory or nested inside each other`,
);
}
/**
* Name of the per-session subdirectory whose contents are served over HTTP as
* artifacts (images, generated HTML pages, reports). Agents write user-facing
* outputs here and reference them by this relative path; the file API only
* exposes paths inside this folder.
*/
export const ARTIFACTS_DIRNAME = "artifacts";
/**
* Name of the per-session subdirectory that holds files a human uploads into
* the session via the chat composer. Files land here so the Pi worker (running
* with its cwd set to the session root) can read them by their relative path,
* and the file API can serve them back to the chat UI.
*/
export const UPLOADS_DIRNAME = "uploads";
/** Upper bound on a `file` host-resource's decoded content, enforced at the boundary. */
export const MAX_FILE_RESOURCE_BYTES = 1024 * 1024; // 1 MiB
/**
* Max size of a JSON request body on `/api`. Sized to admit a `file`
* host-resource at its {@link MAX_FILE_RESOURCE_BYTES} cap even after JSON
* string-escaping inflates it (a byte needing `\uXXXX` costs six), plus slack
* for the surrounding envelope. Raises the ceiling for every `/api` route, not
* just the resource routes — the accepted tradeoff for a single body parser.
*/
export const MAX_JSON_BODY_BYTES = 8 * 1024 * 1024; // 8 MiB
/**
* Root directory holding the agents' global memory: long-lived facts that apply
* across every session. It is injected (read-only context) into each session at
* spawn and is only mutated on an explicit user request. Gitignored by default.
*/
export const GLOBAL_MEMORY_DIR =
process.env.GLOBAL_MEMORY_DIR ?? path.resolve(process.cwd(), ".memory");
/**
* Canonical, agent-writable global memory file inside {@link GLOBAL_MEMORY_DIR}.
* A snapshot of its contents is also copied into each session root under the
* same basename so the agent can read it with its own file tools.
*/
export const GLOBAL_MEMORY_FILENAME = "GLOBAL_MEMORY.md";
/**
* Canonical, agent-writable per-session memory file, kept at the session root.
* Seeded from a bundle's `memory/MEMORY.md` when present; otherwise Prime
* creates it on its first `remember`.
*/
export const SESSION_MEMORY_FILENAME = "MEMORY.md";
/**
* Executable used to spawn the Pi coding agent. Overridable so the binary can
* be pinned in environments where `pi` is not on PATH.
*/
export const PI_BIN = process.env.PI_BIN ?? "pi";
/**
* Base URL of the LLM proxy the bundled proxy-provider extension points Pi at.
* Override in deployments to target the proxy available in that environment.
* Mirrored here for logging; the extension reads it directly.
*/
export const PI_PROXY_URL = readAbsoluteUrl(
"PI_PROXY_URL",
"https://proxy.example.com",
);
/**
* Provider/model Pi is pinned to when spawned. In the container there is no
* `~/.pi/agent/settings.json`, so these are passed explicitly to match the
* shared default.
*/
const [DEFAULT_PROVIDER, DEFAULT_MODEL] = DEFAULT_MODEL_ID.split("/");
export const PI_PROVIDER = process.env.PI_PROVIDER ?? DEFAULT_PROVIDER;
export const PI_MODEL = process.env.PI_MODEL ?? DEFAULT_MODEL;
/**
* Default thinking depth Pi is spawned with via `--thinking` when an agent has
* no explicit selection. One of Pi's levels: off, minimal, low, medium, high,
* xhigh, max. Overridable per environment and per agent at runtime.
*/
export const PI_THINKING = process.env.PI_THINKING ?? DEFAULT_THINKING_LEVEL;
/**
* When enabled, the Pi manager emits verbose logs including raw stdout RPC
* lines. Lifecycle logs are always emitted regardless of this flag. Defaults to
* true for now (set PI_DEBUG=0/false/no to silence the verbose stream).
*/
export const PI_DEBUG = !/^(0|false|no)$/i.test(process.env.PI_DEBUG ?? "");
/**
* Base URL the orchestrator extension (running inside each Pi process) uses to
* reach this server's internal agent API. Defaults to loopback on {@link PORT}.
*/
export const INTERNAL_URL =
process.env.TANGENT_INTERNAL_URL ?? `http://127.0.0.1:${PORT}`;
/**
* Shared secret the orchestrator extension must present (as a bearer token) to
* call the internal agent API. Generated per server start unless pinned via env
* so arbitrary local processes can't drive a session's agents.
*/
export const INTERNAL_TOKEN =
process.env.TANGENT_INTERNAL_TOKEN ?? randomUUID();
/**
* Public base URL at which this server is reachable by an external MCP client
* (the gateway dials in over this). The server cannot self-discover it, so it
* is supplied per environment: a tunnel URL in local dev, the reverse-proxy URL
* in a real instance. Empty by default, which disables issuing relay channels
* until set. No trailing slash.
*/
export const PUBLIC_URL = (process.env.TANGENT_PUBLIC_URL ?? "").replace(
/\/+$/,
"",
);
/**
* Shared secret a remote environment must present (in the Socket.IO handshake
* `auth`) to connect to the remote sub-agent gateway. Empty by default, which
* disables remote sub-agent hosting until an environment supplies a token so a
* stray connection can never drive a session's agents.
*/
export const REMOTE_ENV_TOKEN = process.env.REMOTE_ENV_TOKEN ?? "";
/**
* HMAC key used to mint and verify scoped `/remote-env` tokens for embed hosts.
* Generated per server start unless pinned via env. Independent of
* {@link REMOTE_ENV_TOKEN} (the optional server-to-server shared secret) and of
* {@link INTERNAL_TOKEN} (which Pi children inherit).
*/
export const REMOTE_ENV_SIGNING_SECRET =
process.env.REMOTE_ENV_SIGNING_SECRET ?? randomUUID();
/**
* Secret Tangent presents (as a bearer token) to an attached A2A agent. Unlike
* the other connector secrets this one travels outbound, so an empty value is
* not a lockout: a peer that asks for no credential is still reachable.
*/
export const A2A_TOKEN = process.env.A2A_TOKEN ?? "";
/**
* Name of the cookie holding the Oktasso JWT that `GET /api/me` reads to resolve
* the current user. Empty by default so the route is effectively disabled until
* an environment supplies the cookie name (the local `dev` script sets it).
*/
export const AUTH_JWT_TOKEN_COOKIE_NAME =
process.env.AUTH_JWT_TOKEN_COOKIE_NAME ?? "";
/**
* Name of a request header carrying the same JWT, for deployments behind a
* proxy that forwards it as a header but drops cookies. Empty disables it.
*/
export const AUTH_JWT_TOKEN_HEADER_NAME = (
process.env.AUTH_JWT_TOKEN_HEADER_NAME ?? ""
).toLowerCase();
/**
* Origins allowed to embed the UI cross-origin (the host pages running
* `@tangent/embed-react`). Comma-separated; drives both the `/api` CORS headers
* and the Socket.IO handshake allowlist. Empty by default so a same-origin
* deployment grants no cross-origin trust.
*/
export const EMBED_ALLOWED_ORIGINS = (process.env.EMBED_ALLOWED_ORIGINS ?? "")
.split(",")
.map((origin) => origin.trim())
.filter(Boolean);
/**
* Emails (lowercased) of the admins who manage bundle editors and edit global
* memory. Comma-separated. Empty by default, which turns the role gate off so
* every caller may upload/delete bundles and edit global memory.
*/
export const ADMIN_EMAILS: ReadonlySet<string> = new Set(
(process.env.ADMIN_EMAILS ?? "")
.split(",")
.map((email) => email.trim().toLowerCase())
.filter(Boolean),
);
/**
* Base URL of the Tangle API reached by the bundle-UI/agent egress allowlist.
* The OpenAPI doc declares no `servers`, so this is supplied per environment.
* Only the origin is used when matching egress destinations.
*/
export const TANGLE_API_URL = readAbsoluteUrl(
"TANGLE_API_URL",
"https://api.example.com",
);