teamshare-bridge 0.1.0 → 0.2.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.
- package/README.md +2 -2
- package/dist/bridge/daemon.js +252 -14
- package/dist/bridge/daemon.js.map +1 -1
- package/dist/bridge/index.js +10 -0
- package/dist/bridge/index.js.map +1 -1
- package/dist/bridge/local-server.d.ts +6 -1
- package/dist/bridge/local-server.js +24 -0
- package/dist/bridge/local-server.js.map +1 -1
- package/dist/bridge/protocol.js +33 -4
- package/dist/bridge/protocol.js.map +1 -1
- package/dist/bridge/spawn.d.ts +30 -4
- package/dist/bridge/spawn.js +93 -29
- package/dist/bridge/spawn.js.map +1 -1
- package/dist/cli/index.js +1103 -65
- package/dist/cli/index.js.map +1 -1
- package/dist/lib/api.d.ts +205 -6
- package/dist/lib/api.js +147 -5
- package/dist/lib/api.js.map +1 -1
- package/dist/lib/chat-reply.d.ts +22 -2
- package/dist/lib/chat-reply.js +139 -67
- package/dist/lib/chat-reply.js.map +1 -1
- package/dist/lib/config.d.ts +103 -0
- package/dist/lib/config.js +273 -0
- package/dist/lib/config.js.map +1 -1
- package/dist/lib/doc-reply.d.ts +11 -0
- package/dist/lib/doc-reply.js +18 -34
- package/dist/lib/doc-reply.js.map +1 -1
- package/dist/lib/harness.d.ts +38 -0
- package/dist/lib/harness.js +140 -0
- package/dist/lib/harness.js.map +1 -0
- package/dist/lib/llm.d.ts +30 -2
- package/dist/lib/llm.js +284 -30
- package/dist/lib/llm.js.map +1 -1
- package/dist/lib/lock.d.ts +1 -1
- package/dist/lib/models.d.ts +11 -0
- package/dist/lib/models.js +30 -1
- package/dist/lib/models.js.map +1 -1
- package/dist/lib/orchestrator/client.d.ts +27 -0
- package/dist/lib/orchestrator/client.js +136 -0
- package/dist/lib/orchestrator/client.js.map +1 -0
- package/dist/lib/orchestrator/index.d.ts +5 -0
- package/dist/lib/orchestrator/index.js +17 -0
- package/dist/lib/orchestrator/index.js.map +1 -0
- package/dist/lib/orchestrator/runner.d.ts +18 -0
- package/dist/lib/orchestrator/runner.js +177 -0
- package/dist/lib/orchestrator/runner.js.map +1 -0
- package/dist/lib/orchestrator/worktree.d.ts +43 -0
- package/dist/lib/orchestrator/worktree.js +243 -0
- package/dist/lib/orchestrator/worktree.js.map +1 -0
- package/dist/lib/session-stream.d.ts +1 -1
- package/dist/lib/skills.d.ts +21 -0
- package/dist/lib/skills.js +80 -0
- package/dist/lib/skills.js.map +1 -0
- package/dist/lib/usage.d.ts +52 -0
- package/dist/lib/usage.js +69 -0
- package/dist/lib/usage.js.map +1 -0
- package/package.json +3 -1
- package/skills/teamshare-auth-rbac/SKILL.md +79 -0
- package/skills/teamshare-cdd/SKILL.md +145 -0
- package/skills/teamshare-modularity/SKILL.md +92 -0
- package/tools/usage_report.py +223 -0
package/dist/lib/config.d.ts
CHANGED
|
@@ -3,6 +3,20 @@ export declare const BRIDGE_CANDIDATE_PORTS: readonly [48231, 48242, 48253, 4826
|
|
|
3
3
|
export interface AgentConfig {
|
|
4
4
|
agentId: string;
|
|
5
5
|
apiKey: string;
|
|
6
|
+
/**
|
|
7
|
+
* Optional per-agent LLM provider key (e.g. an opencode-go API key) that
|
|
8
|
+
* OVERRIDES the global `opencodeKey`. Agents use this instead of the
|
|
9
|
+
* user's default opencode credentials so agent usage never bills the
|
|
10
|
+
* user's personal account.
|
|
11
|
+
*/
|
|
12
|
+
opencodeKey?: string;
|
|
13
|
+
}
|
|
14
|
+
/** Project -> local folder mapping (the "project guard", IMP-6xx). */
|
|
15
|
+
export interface ProjectLink {
|
|
16
|
+
/** Canonical absolute path the agent may work inside. */
|
|
17
|
+
path: string;
|
|
18
|
+
/** Strict mode (default true): unlinked projects are hard-blocked. */
|
|
19
|
+
guard?: boolean;
|
|
6
20
|
}
|
|
7
21
|
export interface BridgeConfig {
|
|
8
22
|
agents: AgentConfig[];
|
|
@@ -15,6 +29,21 @@ export interface BridgeConfig {
|
|
|
15
29
|
wakeRules: {
|
|
16
30
|
priorities: string[];
|
|
17
31
|
} | null;
|
|
32
|
+
projects: Record<string, ProjectLink>;
|
|
33
|
+
/**
|
|
34
|
+
* Default LLM provider key for agents (e.g. an opencode-go API key).
|
|
35
|
+
* Agents run the harness with this key via OPENCODE_API_KEY so their
|
|
36
|
+
* usage never touches the user's default opencode credentials. A
|
|
37
|
+
* per-agent `opencodeKey` overrides it. NEVER logged.
|
|
38
|
+
*/
|
|
39
|
+
opencodeKey?: string;
|
|
40
|
+
/**
|
|
41
|
+
* DeepSeek API key for chat replies (the lightweight chat model).
|
|
42
|
+
* Chat replies always use this key with deepseek:deepseek-chat at low
|
|
43
|
+
* settings, regardless of the agent's task model. Falls back to
|
|
44
|
+
* LLM_API_KEY / CHAT_LLM_API_KEY env vars.
|
|
45
|
+
*/
|
|
46
|
+
chatKey?: string;
|
|
18
47
|
}
|
|
19
48
|
export declare function configPath(): string;
|
|
20
49
|
export declare function defaultConfig(): BridgeConfig;
|
|
@@ -22,4 +51,78 @@ export declare function loadConfig(): BridgeConfig;
|
|
|
22
51
|
export declare function saveConfig(config: BridgeConfig): void;
|
|
23
52
|
/** Adds/updates an agent key entry (used by `connect` and `add-agent`). */
|
|
24
53
|
export declare function upsertAgent(agentId: string, apiKey: string): BridgeConfig;
|
|
54
|
+
export type PreflightResult = {
|
|
55
|
+
ok: true;
|
|
56
|
+
canonical: string;
|
|
57
|
+
} | {
|
|
58
|
+
ok: false;
|
|
59
|
+
reason: string;
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Preflight a folder before linking it (the permission gate, IMP-6xx):
|
|
63
|
+
* must exist, be a directory, be readable AND writable by this user, and
|
|
64
|
+
* must not be a network location (UNC or mapped drive), OneDrive, or
|
|
65
|
+
* outside the user profile. The link command IS the permission grant - the
|
|
66
|
+
* agent never runs anywhere but linked folders.
|
|
67
|
+
*/
|
|
68
|
+
export declare function preflightFolder(rawPath: string): PreflightResult;
|
|
69
|
+
/** Links a project to a local folder (guard on by default). Returns the result. */
|
|
70
|
+
export declare function linkProject(projectId: string, path: string, guard?: boolean): PreflightResult & {
|
|
71
|
+
config?: BridgeConfig;
|
|
72
|
+
};
|
|
73
|
+
/** Removes a project link. */
|
|
74
|
+
export declare function unlinkProject(projectId: string): BridgeConfig;
|
|
75
|
+
/**
|
|
76
|
+
* Working folder for a project, or null when it is not linked (hard block -
|
|
77
|
+
* the caller must refuse the session and explain how to link it).
|
|
78
|
+
*/
|
|
79
|
+
export declare function projectCwd(projectId: string): string | null;
|
|
80
|
+
/** The exact command shown when a project is not linked (guard message). */
|
|
81
|
+
export declare function linkHint(projectId: string): string;
|
|
82
|
+
/**
|
|
83
|
+
* Sets the agent LLM provider key. Without `agentId` it is the GLOBAL
|
|
84
|
+
* default for every agent; with `agentId` it overrides that agent only.
|
|
85
|
+
* `null` clears it (global null falls back to the user's own credentials).
|
|
86
|
+
*/
|
|
87
|
+
export declare function setOpenCodeKey(key: string | null, agentId?: string): BridgeConfig;
|
|
88
|
+
/**
|
|
89
|
+
* Resolves the LLM provider key for an agent: per-agent override >
|
|
90
|
+
* global default > an already-set OPENCODE_API_KEY env (leave untouched) >
|
|
91
|
+
* none (opencode falls back to the user's auth.json). The key itself is
|
|
92
|
+
* NEVER logged - callers only ever log which source won.
|
|
93
|
+
*/
|
|
94
|
+
export declare function agentOpenCodeKey(agentId: string): string | null;
|
|
95
|
+
/**
|
|
96
|
+
* Sets the chat model API key (DeepSeek key for chat replies). Stored in
|
|
97
|
+
* config.json as `chatKey`. `null` clears it. Chat always uses this key
|
|
98
|
+
* with deepseek:deepseek-chat at low settings, regardless of agent model.
|
|
99
|
+
*/
|
|
100
|
+
export declare function setChatKey(key: string | null): BridgeConfig;
|
|
101
|
+
/**
|
|
102
|
+
* Resolves the chat model API key: config chatKey > CHAT_LLM_API_KEY env >
|
|
103
|
+
* LLM_API_KEY env > none.
|
|
104
|
+
*/
|
|
105
|
+
export declare function chatKey(): string | null;
|
|
25
106
|
export declare function msg(err: unknown): string;
|
|
107
|
+
/**
|
|
108
|
+
* Wires the TeamShare MCP server into opencode's config. Idempotent —
|
|
109
|
+
* skips if already wired. The entry is:
|
|
110
|
+
* mcp.teamshare = { type: "remote", url: "https://teamshare-backend.onrender.com/mcp",
|
|
111
|
+
* headers: { "X-Api-Key": "<key>" } }
|
|
112
|
+
*
|
|
113
|
+
* Returns true if wired, false if already present.
|
|
114
|
+
*/
|
|
115
|
+
export declare function wireOpencodeMcp(apiKey: string): boolean;
|
|
116
|
+
/**
|
|
117
|
+
* Removes the TeamShare MCP entry from opencode's config.
|
|
118
|
+
* Returns true if removed, false if not present.
|
|
119
|
+
*/
|
|
120
|
+
export declare function unwireOpencodeMcp(): boolean;
|
|
121
|
+
/**
|
|
122
|
+
* Returns the current MCP wiring status for opencode.
|
|
123
|
+
*/
|
|
124
|
+
export declare function mcpStatus(): {
|
|
125
|
+
wired: boolean;
|
|
126
|
+
configPath: string | null;
|
|
127
|
+
entry?: unknown;
|
|
128
|
+
};
|
package/dist/lib/config.js
CHANGED
|
@@ -6,13 +6,27 @@ exports.defaultConfig = defaultConfig;
|
|
|
6
6
|
exports.loadConfig = loadConfig;
|
|
7
7
|
exports.saveConfig = saveConfig;
|
|
8
8
|
exports.upsertAgent = upsertAgent;
|
|
9
|
+
exports.preflightFolder = preflightFolder;
|
|
10
|
+
exports.linkProject = linkProject;
|
|
11
|
+
exports.unlinkProject = unlinkProject;
|
|
12
|
+
exports.projectCwd = projectCwd;
|
|
13
|
+
exports.linkHint = linkHint;
|
|
14
|
+
exports.setOpenCodeKey = setOpenCodeKey;
|
|
15
|
+
exports.agentOpenCodeKey = agentOpenCodeKey;
|
|
16
|
+
exports.setChatKey = setChatKey;
|
|
17
|
+
exports.chatKey = chatKey;
|
|
9
18
|
exports.msg = msg;
|
|
19
|
+
exports.wireOpencodeMcp = wireOpencodeMcp;
|
|
20
|
+
exports.unwireOpencodeMcp = unwireOpencodeMcp;
|
|
21
|
+
exports.mcpStatus = mcpStatus;
|
|
10
22
|
/**
|
|
11
23
|
* teamshare-bridge config: ~/.teamshare/config.json
|
|
12
24
|
*/
|
|
13
25
|
const node_fs_1 = require("node:fs");
|
|
14
26
|
const node_os_1 = require("node:os");
|
|
15
27
|
const node_path_1 = require("node:path");
|
|
28
|
+
const node_child_process_1 = require("node:child_process");
|
|
29
|
+
const api_1 = require("./api");
|
|
16
30
|
/** Ports the website probes to detect the bridge (contract section 5). */
|
|
17
31
|
exports.BRIDGE_CANDIDATE_PORTS = [
|
|
18
32
|
48231, 48242, 48253, 48264, 48275, 48286, 48297,
|
|
@@ -30,6 +44,7 @@ function defaultConfig() {
|
|
|
30
44
|
harness: 'auto',
|
|
31
45
|
quietHours: null,
|
|
32
46
|
wakeRules: null,
|
|
47
|
+
projects: {},
|
|
33
48
|
};
|
|
34
49
|
}
|
|
35
50
|
function loadConfig() {
|
|
@@ -45,6 +60,15 @@ function loadConfig() {
|
|
|
45
60
|
harness: raw.harness ?? def.harness,
|
|
46
61
|
quietHours: raw.quietHours ?? null,
|
|
47
62
|
wakeRules: raw.wakeRules ?? null,
|
|
63
|
+
projects: raw.projects && typeof raw.projects === 'object'
|
|
64
|
+
? raw.projects
|
|
65
|
+
: {},
|
|
66
|
+
opencodeKey: typeof raw.opencodeKey === 'string' && raw.opencodeKey.length > 0
|
|
67
|
+
? raw.opencodeKey
|
|
68
|
+
: undefined,
|
|
69
|
+
chatKey: typeof raw.chatKey === 'string' && raw.chatKey.length > 0
|
|
70
|
+
? raw.chatKey
|
|
71
|
+
: undefined,
|
|
48
72
|
};
|
|
49
73
|
}
|
|
50
74
|
}
|
|
@@ -75,7 +99,256 @@ function upsertAgent(agentId, apiKey) {
|
|
|
75
99
|
saveConfig(config);
|
|
76
100
|
return config;
|
|
77
101
|
}
|
|
102
|
+
/**
|
|
103
|
+
* Preflight a folder before linking it (the permission gate, IMP-6xx):
|
|
104
|
+
* must exist, be a directory, be readable AND writable by this user, and
|
|
105
|
+
* must not be a network location (UNC or mapped drive), OneDrive, or
|
|
106
|
+
* outside the user profile. The link command IS the permission grant - the
|
|
107
|
+
* agent never runs anywhere but linked folders.
|
|
108
|
+
*/
|
|
109
|
+
function preflightFolder(rawPath) {
|
|
110
|
+
const abs = (0, node_path_1.resolve)(rawPath.trim().replace(/^"|"$/g, ''));
|
|
111
|
+
try {
|
|
112
|
+
if (!(0, node_fs_1.existsSync)(abs))
|
|
113
|
+
return { ok: false, reason: `Folder does not exist: ${abs}` };
|
|
114
|
+
if (!(0, node_fs_1.statSync)(abs).isDirectory()) {
|
|
115
|
+
return { ok: false, reason: `Not a folder: ${abs}` };
|
|
116
|
+
}
|
|
117
|
+
(0, node_fs_1.accessSync)(abs, node_fs_1.constants.R_OK | node_fs_1.constants.W_OK);
|
|
118
|
+
}
|
|
119
|
+
catch (err) {
|
|
120
|
+
return { ok: false, reason: `Cannot read+write ${abs} with the current user: ${msg(err)}` };
|
|
121
|
+
}
|
|
122
|
+
if (/^(\\\\|\/\/)/.test(abs)) {
|
|
123
|
+
return { ok: false, reason: `Network (UNC) paths are blocked: ${abs}` };
|
|
124
|
+
}
|
|
125
|
+
const home = (0, node_os_1.homedir)();
|
|
126
|
+
const homeLower = home.toLowerCase();
|
|
127
|
+
const absLower = abs.toLowerCase();
|
|
128
|
+
const oneDrivePrefixes = [
|
|
129
|
+
process.env.OneDrive,
|
|
130
|
+
process.env.OneDriveConsumer,
|
|
131
|
+
(0, node_path_1.join)(home, 'OneDrive'),
|
|
132
|
+
(0, node_path_1.join)(home, 'OneDrive - '),
|
|
133
|
+
]
|
|
134
|
+
.filter((p) => !!p)
|
|
135
|
+
.map((p) => p.toLowerCase());
|
|
136
|
+
if (oneDrivePrefixes.some((prefix) => absLower.startsWith(prefix))) {
|
|
137
|
+
return { ok: false, reason: `OneDrive-synced folders are blocked (sync/encryption pitfalls): ${abs}` };
|
|
138
|
+
}
|
|
139
|
+
if (process.platform === 'win32') {
|
|
140
|
+
const mapped = mappedNetworkDrives();
|
|
141
|
+
const drive = abs.split(node_path_1.sep)[0]?.toUpperCase();
|
|
142
|
+
if (drive && mapped.has(drive)) {
|
|
143
|
+
return { ok: false, reason: `Network drive ${drive}:\\ is blocked (mapped to ${mapped.get(drive)}): ${abs}` };
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
if (!absLower.startsWith(homeLower + node_path_1.sep) && absLower !== homeLower) {
|
|
147
|
+
return {
|
|
148
|
+
ok: false,
|
|
149
|
+
reason: `Outside the user profile is blocked (${abs}). ` +
|
|
150
|
+
`Link folders under ${home} - the agent runs with your own user permissions only.`,
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
return { ok: true, canonical: abs };
|
|
154
|
+
}
|
|
155
|
+
/** Mapped network drive letters (Windows `net use`), e.g. { Z: -> \\server\share }. */
|
|
156
|
+
function mappedNetworkDrives() {
|
|
157
|
+
const map = new Map();
|
|
158
|
+
try {
|
|
159
|
+
const res = (0, node_child_process_1.spawnSync)('net', ['use'], { encoding: 'utf8', windowsHide: true });
|
|
160
|
+
if (res.status !== 0 || !res.stdout)
|
|
161
|
+
return map;
|
|
162
|
+
for (const line of res.stdout.split(/\r?\n/)) {
|
|
163
|
+
const match = line.match(/^\s*([A-Z]):\s+(\\\\[^\s]+)/i);
|
|
164
|
+
if (match)
|
|
165
|
+
map.set(match[1].toUpperCase(), match[2]);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
catch {
|
|
169
|
+
/* best-effort - unknown drives are treated as local */
|
|
170
|
+
}
|
|
171
|
+
return map;
|
|
172
|
+
}
|
|
173
|
+
/** Links a project to a local folder (guard on by default). Returns the result. */
|
|
174
|
+
function linkProject(projectId, path, guard = true) {
|
|
175
|
+
const preflight = preflightFolder(path);
|
|
176
|
+
if (!preflight.ok)
|
|
177
|
+
return preflight;
|
|
178
|
+
const config = loadConfig();
|
|
179
|
+
config.projects[projectId] = { path: preflight.canonical, guard };
|
|
180
|
+
saveConfig(config);
|
|
181
|
+
return { ...preflight, config };
|
|
182
|
+
}
|
|
183
|
+
/** Removes a project link. */
|
|
184
|
+
function unlinkProject(projectId) {
|
|
185
|
+
const config = loadConfig();
|
|
186
|
+
delete config.projects[projectId];
|
|
187
|
+
saveConfig(config);
|
|
188
|
+
return config;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Working folder for a project, or null when it is not linked (hard block -
|
|
192
|
+
* the caller must refuse the session and explain how to link it).
|
|
193
|
+
*/
|
|
194
|
+
function projectCwd(projectId) {
|
|
195
|
+
const link = loadConfig().projects[projectId];
|
|
196
|
+
if (!link?.path)
|
|
197
|
+
return null;
|
|
198
|
+
try {
|
|
199
|
+
if (!(0, node_fs_1.existsSync)(link.path) || !(0, node_fs_1.statSync)(link.path).isDirectory()) {
|
|
200
|
+
console.warn(`[config] linked folder missing for project ${projectId}: ${link.path}`);
|
|
201
|
+
return null;
|
|
202
|
+
}
|
|
203
|
+
(0, node_fs_1.accessSync)(link.path, node_fs_1.constants.R_OK | node_fs_1.constants.W_OK);
|
|
204
|
+
}
|
|
205
|
+
catch {
|
|
206
|
+
return null;
|
|
207
|
+
}
|
|
208
|
+
return link.path;
|
|
209
|
+
}
|
|
210
|
+
/** The exact command shown when a project is not linked (guard message). */
|
|
211
|
+
function linkHint(projectId) {
|
|
212
|
+
return (`teamshare-agent link --project ${projectId} --path <folder>` +
|
|
213
|
+
`\n(Link a local folder first - the agent is hard-blocked until then.)`);
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Sets the agent LLM provider key. Without `agentId` it is the GLOBAL
|
|
217
|
+
* default for every agent; with `agentId` it overrides that agent only.
|
|
218
|
+
* `null` clears it (global null falls back to the user's own credentials).
|
|
219
|
+
*/
|
|
220
|
+
function setOpenCodeKey(key, agentId) {
|
|
221
|
+
const config = loadConfig();
|
|
222
|
+
if (agentId) {
|
|
223
|
+
const agent = config.agents.find((a) => a.agentId === agentId);
|
|
224
|
+
if (!agent)
|
|
225
|
+
throw new Error(`agent not configured: ${agentId}`);
|
|
226
|
+
agent.opencodeKey = key ?? undefined;
|
|
227
|
+
}
|
|
228
|
+
else {
|
|
229
|
+
config.opencodeKey = key ?? undefined;
|
|
230
|
+
}
|
|
231
|
+
saveConfig(config);
|
|
232
|
+
return config;
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Resolves the LLM provider key for an agent: per-agent override >
|
|
236
|
+
* global default > an already-set OPENCODE_API_KEY env (leave untouched) >
|
|
237
|
+
* none (opencode falls back to the user's auth.json). The key itself is
|
|
238
|
+
* NEVER logged - callers only ever log which source won.
|
|
239
|
+
*/
|
|
240
|
+
function agentOpenCodeKey(agentId) {
|
|
241
|
+
if (process.env.OPENCODE_API_KEY)
|
|
242
|
+
return null; // env already wins
|
|
243
|
+
const config = loadConfig();
|
|
244
|
+
const agent = config.agents.find((a) => a.agentId === agentId);
|
|
245
|
+
return agent?.opencodeKey ?? config.opencodeKey ?? null;
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Sets the chat model API key (DeepSeek key for chat replies). Stored in
|
|
249
|
+
* config.json as `chatKey`. `null` clears it. Chat always uses this key
|
|
250
|
+
* with deepseek:deepseek-chat at low settings, regardless of agent model.
|
|
251
|
+
*/
|
|
252
|
+
function setChatKey(key) {
|
|
253
|
+
const config = loadConfig();
|
|
254
|
+
config.chatKey = key ?? undefined;
|
|
255
|
+
saveConfig(config);
|
|
256
|
+
return config;
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Resolves the chat model API key: config chatKey > CHAT_LLM_API_KEY env >
|
|
260
|
+
* LLM_API_KEY env > none.
|
|
261
|
+
*/
|
|
262
|
+
function chatKey() {
|
|
263
|
+
const config = loadConfig();
|
|
264
|
+
return config.chatKey ?? process.env.CHAT_LLM_API_KEY ?? process.env.LLM_API_KEY ?? null;
|
|
265
|
+
}
|
|
78
266
|
function msg(err) {
|
|
79
267
|
return err instanceof Error ? err.message : String(err);
|
|
80
268
|
}
|
|
269
|
+
// ── opencode MCP wiring ─────────────────────────────────────────────────────
|
|
270
|
+
const OPENCODE_CONFIG_DIR = (0, node_path_1.join)((0, node_os_1.homedir)(), '.config', 'opencode');
|
|
271
|
+
const OPENCODE_CONFIG_JSONC = (0, node_path_1.join)(OPENCODE_CONFIG_DIR, 'opencode.jsonc');
|
|
272
|
+
const OPENCODE_CONFIG_JSON = (0, node_path_1.join)(OPENCODE_CONFIG_DIR, 'opencode.json');
|
|
273
|
+
const TEAMSHARE_MCP_KEY = 'teamshare';
|
|
274
|
+
function opencodeConfigPath() {
|
|
275
|
+
if ((0, node_fs_1.existsSync)(OPENCODE_CONFIG_JSONC))
|
|
276
|
+
return OPENCODE_CONFIG_JSONC;
|
|
277
|
+
if ((0, node_fs_1.existsSync)(OPENCODE_CONFIG_JSON))
|
|
278
|
+
return OPENCODE_CONFIG_JSON;
|
|
279
|
+
return null;
|
|
280
|
+
}
|
|
281
|
+
/** Strip single-line // comments from JSONC before parsing. */
|
|
282
|
+
function stripJsoncComments(text) {
|
|
283
|
+
return text.replace(/^[ \t]*\/\/.*$/gm, '');
|
|
284
|
+
}
|
|
285
|
+
function readOpencodeConfig() {
|
|
286
|
+
const path = opencodeConfigPath();
|
|
287
|
+
if (!path)
|
|
288
|
+
return null;
|
|
289
|
+
try {
|
|
290
|
+
const raw = (0, node_fs_1.readFileSync)(path, 'utf8');
|
|
291
|
+
return JSON.parse(stripJsoncComments(raw));
|
|
292
|
+
}
|
|
293
|
+
catch {
|
|
294
|
+
return null;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
function writeOpencodeConfig(config) {
|
|
298
|
+
const path = opencodeConfigPath() ?? OPENCODE_CONFIG_JSON;
|
|
299
|
+
const dir = (0, node_path_1.join)(path, '..');
|
|
300
|
+
if (!(0, node_fs_1.existsSync)(dir))
|
|
301
|
+
(0, node_fs_1.mkdirSync)(dir, { recursive: true });
|
|
302
|
+
(0, node_fs_1.writeFileSync)(path, JSON.stringify(config, null, 2) + '\n', 'utf8');
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Wires the TeamShare MCP server into opencode's config. Idempotent —
|
|
306
|
+
* skips if already wired. The entry is:
|
|
307
|
+
* mcp.teamshare = { type: "remote", url: "https://teamshare-backend.onrender.com/mcp",
|
|
308
|
+
* headers: { "X-Api-Key": "<key>" } }
|
|
309
|
+
*
|
|
310
|
+
* Returns true if wired, false if already present.
|
|
311
|
+
*/
|
|
312
|
+
function wireOpencodeMcp(apiKey) {
|
|
313
|
+
const config = readOpencodeConfig() ?? {};
|
|
314
|
+
const mcp = (typeof config.mcp === 'object' && config.mcp !== null
|
|
315
|
+
? config.mcp
|
|
316
|
+
: {});
|
|
317
|
+
if (TEAMSHARE_MCP_KEY in mcp)
|
|
318
|
+
return false; // already wired
|
|
319
|
+
mcp[TEAMSHARE_MCP_KEY] = {
|
|
320
|
+
type: 'remote',
|
|
321
|
+
url: `${api_1.DEFAULT_API_URL}/mcp`,
|
|
322
|
+
headers: { 'X-Api-Key': apiKey },
|
|
323
|
+
};
|
|
324
|
+
config.mcp = mcp;
|
|
325
|
+
writeOpencodeConfig(config);
|
|
326
|
+
return true;
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* Removes the TeamShare MCP entry from opencode's config.
|
|
330
|
+
* Returns true if removed, false if not present.
|
|
331
|
+
*/
|
|
332
|
+
function unwireOpencodeMcp() {
|
|
333
|
+
const config = readOpencodeConfig();
|
|
334
|
+
if (!config)
|
|
335
|
+
return false;
|
|
336
|
+
const mcp = config.mcp;
|
|
337
|
+
if (!mcp || !(TEAMSHARE_MCP_KEY in mcp))
|
|
338
|
+
return false;
|
|
339
|
+
delete mcp[TEAMSHARE_MCP_KEY];
|
|
340
|
+
config.mcp = mcp;
|
|
341
|
+
writeOpencodeConfig(config);
|
|
342
|
+
return true;
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* Returns the current MCP wiring status for opencode.
|
|
346
|
+
*/
|
|
347
|
+
function mcpStatus() {
|
|
348
|
+
const path = opencodeConfigPath();
|
|
349
|
+
const config = readOpencodeConfig();
|
|
350
|
+
const mcp = config && typeof config.mcp === 'object' ? config.mcp : undefined;
|
|
351
|
+
const entry = mcp?.[TEAMSHARE_MCP_KEY];
|
|
352
|
+
return { wired: !!entry, configPath: path, entry };
|
|
353
|
+
}
|
|
81
354
|
//# sourceMappingURL=config.js.map
|
package/dist/lib/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/lib/config.ts"],"names":[],"mappings":";;;AA4BA,gCAEC;AAED,sCAYC;AAED,gCAwBC;AAED,gCAOC;AAGD,kCAOC;AAED,kBAEC;AA7FD;;GAEG;AACH,qCAA6E;AAC7E,qCAAkC;AAClC,yCAAiC;AAEjC,0EAA0E;AAC7D,QAAA,sBAAsB,GAAG;IACpC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK;CACvC,CAAC;AAeX,MAAM,UAAU,GAAG,IAAA,gBAAI,EAAC,IAAA,iBAAO,GAAE,EAAE,YAAY,CAAC,CAAC;AACjD,MAAM,WAAW,GAAG,IAAA,gBAAI,EAAC,UAAU,EAAE,aAAa,CAAC,CAAC;AAEpD,SAAgB,UAAU;IACxB,OAAO,WAAW,CAAC;AACrB,CAAC;AAED,SAAgB,aAAa;IAC3B,MAAM,IAAI,GACR,8BAAsB,CACpB,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,8BAAsB,CAAC,MAAM,CAAC,CAC1D,CAAC;IACJ,OAAO;QACL,MAAM,EAAE,EAAE;QACV,IAAI,EAAE,IAAI;QACV,OAAO,EAAE,MAAM;QACf,UAAU,EAAE,IAAI;QAChB,SAAS,EAAE,IAAI;KAChB,CAAC;AACJ,CAAC;AAED,SAAgB,UAAU;IACxB,IAAI,CAAC;QACH,IAAI,IAAA,oBAAU,EAAC,WAAW,CAAC,EAAE,CAAC;YAC5B,MAAM,GA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AAmB,CAAC,MAAM,CAAC,CAAC;IAC5B,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;GAGG;AACH,SAAgB,iBAAiB;IAC/B,MAAM,MAAM,GAAG,kBAAkB,EAAE,CAAC;IACpC,IAAI,CAAC,MAAM;QAAE,OAAO,KAAK,CAAC;IAC1B,MAAM,GAAG,GAAG,MAAM,CAAC,GAA0C,CAAC;IAC9D,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC,iBAAiB,IAAI,GAAG,CAAC;QAAE,OAAO,KAAK,CAAC;IACtD,OAAO,GAAG,CAAC,iBAAiB,CAAC,CAAC;IAC9B,MAAM,CAAC,GAAG,GAAG,GAAG,CAAC;IACjB,mBAAmB,CAAC,MAAM,CAAC,CAAC;IAC5B,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;GAEG;AACH,SAAgB,SAAS;IACvB,MAAM,IAAI,GAAG,kBAAkB,EAAE,CAAC;IAClC,MAAM,MAAM,GAAG,kBAAkB,EAAE,CAAC;IACpC,MAAM,GAAG,GAAG,MAAM,IAAI,OAAO,MAAM,CAAC,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAE,MAAM,CAAC,GAA+B,CAAC,CAAC,CAAC,SAAS,CAAC;IAC3G,MAAM,KAAK,GAAG,GAAG,EAAE,CAAC,iBAAiB,CAAC,CAAC;IACvC,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;AACrD,CAAC"}
|
package/dist/lib/doc-reply.d.ts
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Phase F document assistant (`teamshare-agent doc`): reads a document's
|
|
3
|
+
* extracted text (Word/PPT/Excel/PDF) plus its comment thread, and replies
|
|
4
|
+
* to every comment that @mentions the agent. The reply quotes the relevant
|
|
5
|
+
* context - the document text is included in the prompt so the model can
|
|
6
|
+
* answer questions about the document content.
|
|
7
|
+
*/
|
|
1
8
|
import { TeamshareApi } from './api';
|
|
2
9
|
export interface DocReplyOptions {
|
|
3
10
|
harness: 'auto' | 'opencode' | 'claude' | 'none';
|
|
@@ -11,6 +18,10 @@ export interface DocReplyOptions {
|
|
|
11
18
|
};
|
|
12
19
|
/** Debug/testing switch (TS_CHAT_ECHO=1): post canned acknowledgments. */
|
|
13
20
|
echo?: boolean;
|
|
21
|
+
/** Document being assisted - recorded as the session title for spend attribution. */
|
|
22
|
+
documentId?: string;
|
|
23
|
+
/** API client carrying the session agent's key (used to pin the harness MCP identity). */
|
|
24
|
+
api?: import('./api').TeamshareApi;
|
|
14
25
|
}
|
|
15
26
|
/**
|
|
16
27
|
* Runs the document reply loop: fetch the document + extract, find comments
|
package/dist/lib/doc-reply.js
CHANGED
|
@@ -1,52 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.runDocReply = runDocReply;
|
|
4
|
-
|
|
5
|
-
* Phase F document assistant (`teamshare-agent doc`): reads a document's
|
|
6
|
-
* extracted text (Word/PPT/Excel/PDF) plus its comment thread, and replies
|
|
7
|
-
* to every comment that @mentions the agent. The reply quotes the relevant
|
|
8
|
-
* context - the document text is included in the prompt so the model can
|
|
9
|
-
* answer questions about the document content.
|
|
10
|
-
*/
|
|
11
|
-
const node_child_process_1 = require("node:child_process");
|
|
4
|
+
const harness_1 = require("./harness");
|
|
12
5
|
const llm_1 = require("./llm");
|
|
13
6
|
const MAX_TARGETS = 10;
|
|
14
7
|
const CONTEXT_WINDOW = 10;
|
|
15
8
|
const MAX_DOC_CHARS = 60_000;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
(0, node_child_process_1.execFileSync)(bin, ['--version'], { stdio: 'ignore' });
|
|
19
|
-
return true;
|
|
20
|
-
}
|
|
21
|
-
catch {
|
|
22
|
-
return false;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
9
|
+
/** Harness prompts go through argv (Windows limit: 32,767 chars) - keep headroom. */
|
|
10
|
+
const HARNESS_MAX_DOC_CHARS = 24_000;
|
|
25
11
|
function generateReply(agentName, target, prompt, opts) {
|
|
26
12
|
if (opts.echo) {
|
|
27
13
|
return Promise.resolve(`@${target.author?.name ?? 'there'} — this is an automated acknowledgment from ${agentName}. I read the document and I'm on it.`);
|
|
28
14
|
}
|
|
29
15
|
if (opts.selfMode || opts.harness === 'none') {
|
|
30
16
|
if (!opts.llm?.apiKey) {
|
|
31
|
-
throw new Error('--self / --harness none requires
|
|
17
|
+
throw new Error('--self / --harness none requires a provider API key (set it on the agent in TeamShare, or LLM_API_KEY / CHAT_LLM_API_KEY env)');
|
|
32
18
|
}
|
|
33
19
|
return (0, llm_1.complete)(prompt, opts.llm);
|
|
34
20
|
}
|
|
35
|
-
if (opts.harness === 'opencode' || (opts.harness === 'auto' && hasBin('opencode'))) {
|
|
36
|
-
return Promise.resolve((0,
|
|
37
|
-
encoding: 'utf8',
|
|
38
|
-
maxBuffer: 2 * 1024 * 1024,
|
|
39
|
-
}).trim());
|
|
21
|
+
if (opts.harness === 'opencode' || (opts.harness === 'auto' && (0, harness_1.hasBin)('opencode'))) {
|
|
22
|
+
return Promise.resolve((0, harness_1.runHarness)('opencode', ['run', '--title', `TeamShare doc ${opts.documentId}`, prompt], { opencodeAgentKey: opts.api?.apiKey, opencodeMcpUrl: opts.api?.baseUrl }));
|
|
40
23
|
}
|
|
41
|
-
if (opts.harness === 'claude' || (opts.harness === 'auto' && hasBin('claude'))) {
|
|
42
|
-
return Promise.resolve((0,
|
|
43
|
-
encoding: 'utf8',
|
|
44
|
-
maxBuffer: 2 * 1024 * 1024,
|
|
45
|
-
}).trim());
|
|
24
|
+
if (opts.harness === 'claude' || (opts.harness === 'auto' && (0, harness_1.hasBin)('claude'))) {
|
|
25
|
+
return Promise.resolve((0, harness_1.runHarness)('claude', ['-p', prompt]));
|
|
46
26
|
}
|
|
47
|
-
throw new Error('No harness found (install opencode or claude, or use --self with
|
|
27
|
+
throw new Error('No harness found (install opencode or claude, or use --self with a provider API key)');
|
|
48
28
|
}
|
|
49
|
-
function docPrompt(agentName, docName, docText, target, context) {
|
|
29
|
+
function docPrompt(agentName, docName, docText, target, context, maxChars) {
|
|
50
30
|
const thread = context
|
|
51
31
|
.map((c) => `[${c.createdAt}] ${c.author?.name ?? '?'}: ${c.body}`)
|
|
52
32
|
.join('\n');
|
|
@@ -54,8 +34,8 @@ function docPrompt(agentName, docName, docText, target, context) {
|
|
|
54
34
|
`You are ${agentName}, a TeamShare document assistant. The document "${docName}" contains:`,
|
|
55
35
|
'',
|
|
56
36
|
'--- DOCUMENT CONTENT ---',
|
|
57
|
-
docText.slice(0,
|
|
58
|
-
docText.length >
|
|
37
|
+
docText.slice(0, maxChars),
|
|
38
|
+
docText.length > maxChars ? '\n…[truncated]' : '',
|
|
59
39
|
'--- END DOCUMENT CONTENT ---',
|
|
60
40
|
'',
|
|
61
41
|
'The document comment thread looks like this:',
|
|
@@ -93,11 +73,15 @@ async function runDocReply(api, agentId, documentId, mentionToken, opts) {
|
|
|
93
73
|
if (!targets.length)
|
|
94
74
|
return { replied: 0, skipped: 0 };
|
|
95
75
|
let replied = 0;
|
|
76
|
+
const usesHarness = !opts.echo &&
|
|
77
|
+
!opts.selfMode &&
|
|
78
|
+
opts.harness !== 'none' &&
|
|
79
|
+
(opts.harness !== 'auto' || (0, harness_1.hasBin)('opencode') || (0, harness_1.hasBin)('claude'));
|
|
96
80
|
for (const target of targets.slice(0, MAX_TARGETS)) {
|
|
97
81
|
const targetIndex = rows.findIndex((r) => r.id === target.id);
|
|
98
82
|
const context = rows.slice(Math.max(0, targetIndex - CONTEXT_WINDOW), targetIndex + 1);
|
|
99
|
-
const prompt = docPrompt(selfName, doc.name, docText, target, context);
|
|
100
|
-
const reply = await generateReply(selfName, target, prompt, opts);
|
|
83
|
+
const prompt = docPrompt(selfName, doc.name, docText, target, context, usesHarness ? HARNESS_MAX_DOC_CHARS : MAX_DOC_CHARS);
|
|
84
|
+
const reply = await generateReply(selfName, target, prompt, { ...opts, documentId, api });
|
|
101
85
|
if (!reply)
|
|
102
86
|
continue;
|
|
103
87
|
await api.addComment({ documentId, body: reply });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"doc-reply.js","sourceRoot":"","sources":["../../src/lib/doc-reply.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"doc-reply.js","sourceRoot":"","sources":["../../src/lib/doc-reply.ts"],"names":[],"mappings":";;AAyGA,kCAmDC;AApJD,uCAA+C;AAC/C,+BAAiC;AAcjC,MAAM,WAAW,GAAG,EAAE,CAAC;AACvB,MAAM,cAAc,GAAG,EAAE,CAAC;AAC1B,MAAM,aAAa,GAAG,MAAM,CAAC;AAC7B,qFAAqF;AACrF,MAAM,qBAAqB,GAAG,MAAM,CAAC;AASrC,SAAS,aAAa,CACpB,SAAiB,EACjB,MAAkB,EAClB,MAAc,EACd,IAAqB;IAErB,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;QACd,OAAO,OAAO,CAAC,OAAO,CACpB,IAAI,MAAM,CAAC,MAAM,EAAE,IAAI,IAAI,OAAO,+CAA+C,SAAS,sCAAsC,CACjI,CAAC;IACJ,CAAC;IACD,IAAI,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,OAAO,KAAK,MAAM,EAAE,CAAC;QAC7C,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,CAAC;YACtB,MAAM,IAAI,KAAK,CAAC,+HAA+H,CAAC,CAAC;QACnJ,CAAC;QACD,OAAO,IAAA,cAAQ,EAAC,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;IACpC,CAAC;IACD,IAAI,IAAI,CAAC,OAAO,KAAK,UAAU,IAAI,CAAC,IAAI,CAAC,OAAO,KAAK,MAAM,IAAI,IAAA,gBAAM,EAAC,UAAU,CAAC,CAAC,EAAE,CAAC;QACnF,OAAO,OAAO,CAAC,OAAO,CACpB,IAAA,oBAAU,EACR,U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AAE,UAAU,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;QAClD,OAAO,IAAI,CAAC,CAAC;IACf,CAAC;IACD,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,MAAM,GAAG,OAAO,EAAE,CAAC;AACxD,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export interface HarnessRunOptions {
|
|
2
|
+
maxBuffer?: number;
|
|
3
|
+
/**
|
|
4
|
+
* Agent API key injected into a per-session opencode config so the
|
|
5
|
+
* teamshare MCP server authenticates as THIS agent (never the global
|
|
6
|
+
* config's key - shared keys made agents act as each other).
|
|
7
|
+
*/
|
|
8
|
+
opencodeAgentKey?: string;
|
|
9
|
+
/** TeamShare API base URL for the MCP override (default: hosted API). */
|
|
10
|
+
opencodeMcpUrl?: string;
|
|
11
|
+
}
|
|
12
|
+
export interface ResolvedBin {
|
|
13
|
+
file: string;
|
|
14
|
+
args?: string[];
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Resolves a PATH command to something Node can spawn without a shell.
|
|
18
|
+
* Windows npm shims (opencode.cmd / opencode.ps1, claude.cmd) cannot be
|
|
19
|
+
* spawned directly (ENOENT) and shell-joining truncates multi-line args at
|
|
20
|
+
* the first newline - so the shim's real target (opencode.exe or a JS entry
|
|
21
|
+
* run via node) is extracted from the shim file instead.
|
|
22
|
+
*/
|
|
23
|
+
export declare function resolveBin(bin: string): ResolvedBin | null;
|
|
24
|
+
/**
|
|
25
|
+
* Writes a throwaway opencode config that overrides the teamshare MCP
|
|
26
|
+
* server's API key for this run (project/`OPENCODE_CONFIG` scope wins over
|
|
27
|
+
* the user's global config). Returns the config file path + cleanup.
|
|
28
|
+
*/
|
|
29
|
+
export declare function writeOpencodeMcpConfig(agentKey: string, apiBaseUrl: string): {
|
|
30
|
+
file: string;
|
|
31
|
+
cleanup: () => void;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Runs a harness binary non-interactively and returns its stdout.
|
|
35
|
+
* Spawned without a shell so multi-line prompts survive intact.
|
|
36
|
+
*/
|
|
37
|
+
export declare function runHarness(cmd: string, args: string[], opts?: HarnessRunOptions): string;
|
|
38
|
+
export declare function hasBin(bin: string): boolean;
|