@foundocs/foundocs-setup 0.4.0 → 0.4.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 +6 -0
- package/dist/bridge.mjs +37 -13
- package/package.json +2 -2
- package/src/bridge.mjs +30 -13
- package/src/cli.mjs +1 -1
- package/src/global.mjs +97 -19
- package/templates/workspace-skill.md +5 -3
package/README.md
CHANGED
|
@@ -162,6 +162,12 @@ The bundled Foundocs skill uses live tool discovery for `set_content_status` (at
|
|
|
162
162
|
|
|
163
163
|
Manual identified targets execute on explicit request. Dreaming never archives automatically: the 168-hour/four-negative-evaluation threshold selects review candidates, current bodies and beneficial uses must also be assessed, and only specific current human approval applies a proposal. Content-grounded low future reuse value is also a reason to propose archiving unnecessary knowledge, even if it is factually correct and has no retrieval history; rare but useful rules, decision context and recovery lessons remain protected. Documents gain archive proposals only. See the [Dreaming protocol](skills/foundocs/references/dreaming.md) and [evaluation cases](eval/README.md). Test new installs and skill updates in isolated fixtures; do not overwrite a developer's edited installed skills.
|
|
164
164
|
|
|
165
|
+
### Upgrade an existing global installation
|
|
166
|
+
|
|
167
|
+
Run `npx --yes @foundocs/foundocs-setup@latest workspace update --client codex` (or `--client claude`) and reopen the host. If you registered with a custom storage directory, pass the same `--storage` path. This refreshes the host configuration and skills using the existing workspace registrations and credentials.
|
|
168
|
+
|
|
169
|
+
Ordinary chats in unlinked folders have no Foundocs tools or automatic knowledge or episode capture. You can still explicitly ask to create or link a Foundocs project there. In a linked folder the global bridge serves only that folder’s workspace and project. Reopen the chat after linking if the host cached the empty tool list.
|
|
170
|
+
|
|
165
171
|
## Source and releases
|
|
166
172
|
|
|
167
173
|
This repository contains the installer, bundled agent skills, templates and tests for `@foundocs/foundocs-setup`. The Foundocs application and server are maintained separately. Use this repository for installer changes and releases.
|
package/dist/bridge.mjs
CHANGED
|
@@ -36831,7 +36831,7 @@ function requestError(error2, name) {
|
|
|
36831
36831
|
{ code, retryable, ...tool ? { tool } : {}, ...httpStatus !== void 0 ? { httpStatus } : {}, ...remoteCode !== void 0 ? { remoteCode } : {} }
|
|
36832
36832
|
);
|
|
36833
36833
|
}
|
|
36834
|
-
async function runBridge({ credentialPath, projectId, workspaceId, mcpUrl: endpoint, root, client, automaticFactory, automaticBase }) {
|
|
36834
|
+
async function runBridge({ credentialPath, projectId, workspaceId, mcpUrl: endpoint, root, client, automaticFactory, automaticBase, folderProject }) {
|
|
36835
36835
|
let automatic, automaticSupported = false, recovered = false;
|
|
36836
36836
|
let remote, local, checkpointRoute = "remote", checkpointWasLocal = false;
|
|
36837
36837
|
let argumentDefaults, inventoryRequest;
|
|
@@ -36895,16 +36895,31 @@ async function runBridge({ credentialPath, projectId, workspaceId, mcpUrl: endpo
|
|
|
36895
36895
|
try {
|
|
36896
36896
|
const url2 = new URL(endpoint);
|
|
36897
36897
|
if (url2.protocol !== "https:" && !(url2.protocol === "http:" && ["localhost", "127.0.0.1", "[::1]"].includes(url2.hostname)) || url2.username || url2.password || url2.search || url2.hash) throw new Error();
|
|
36898
|
-
const
|
|
36899
|
-
|
|
36900
|
-
|
|
36901
|
-
|
|
36902
|
-
|
|
36903
|
-
|
|
36904
|
-
|
|
36898
|
+
const connectRemote = async () => {
|
|
36899
|
+
const key = await readCredential(credentialPath, projectId, workspaceId);
|
|
36900
|
+
const next = new Client({ name: "foundocs-local-auth", version: "0.2.0" }, { listMaxPages: 20 });
|
|
36901
|
+
const transport = new StreamableHTTPClientTransport(url2, {
|
|
36902
|
+
requestInit: { headers: { Authorization: `Bearer ${key}` } },
|
|
36903
|
+
fetch: (target, init) => {
|
|
36904
|
+
if (new URL(typeof target === "string" || target instanceof URL ? target : target.url).origin !== url2.origin) throw new Error("Origin changed");
|
|
36905
|
+
return fetch(target, { ...init, redirect: "error", signal: init?.signal ? AbortSignal.any([init.signal, AbortSignal.timeout(2e4)]) : AbortSignal.timeout(2e4) });
|
|
36906
|
+
}
|
|
36907
|
+
});
|
|
36908
|
+
try {
|
|
36909
|
+
await next.connect(transport, { timeout: 2e4 });
|
|
36910
|
+
} catch (error2) {
|
|
36911
|
+
await next.close().catch(() => {
|
|
36912
|
+
});
|
|
36913
|
+
throw error2;
|
|
36905
36914
|
}
|
|
36906
|
-
|
|
36907
|
-
|
|
36915
|
+
remote = next;
|
|
36916
|
+
remote.onerror = () => process.stderr.write("Foundocs remote MCP transport error.\n");
|
|
36917
|
+
};
|
|
36918
|
+
let connecting;
|
|
36919
|
+
const ensureConnected = () => remote || (connecting ??= connectRemote().finally(() => {
|
|
36920
|
+
connecting = void 0;
|
|
36921
|
+
}));
|
|
36922
|
+
if (!folderProject) await ensureConnected();
|
|
36908
36923
|
if (automaticFactory && automaticBase) automatic = new AutomaticMeasurement({
|
|
36909
36924
|
projectId,
|
|
36910
36925
|
factory: automaticFactory,
|
|
@@ -36922,9 +36937,13 @@ async function runBridge({ credentialPath, projectId, workspaceId, mcpUrl: endpo
|
|
|
36922
36937
|
return body.data;
|
|
36923
36938
|
}
|
|
36924
36939
|
});
|
|
36925
|
-
local = new Server({ name: "foundocs", version: "0.2.0" }, { capabilities: { tools: {} }, instructions: remote
|
|
36940
|
+
local = new Server({ name: "foundocs", version: "0.2.0" }, { capabilities: { tools: {} }, instructions: remote?.getInstructions() });
|
|
36926
36941
|
local.setRequestHandler("tools/list", async () => {
|
|
36927
36942
|
try {
|
|
36943
|
+
if (folderProject) {
|
|
36944
|
+
if (!await folderProject(local)) return { tools: [] };
|
|
36945
|
+
await ensureConnected();
|
|
36946
|
+
}
|
|
36928
36947
|
const tools = await refreshToolInventory();
|
|
36929
36948
|
const collision = tools.some((tool) => tool.name === checkpointTool.name);
|
|
36930
36949
|
const supported = !!root && ["codex", "claude"].includes(client) && tools.some((tool) => tool.name === "capture_episode") && !collision;
|
|
@@ -36938,6 +36957,12 @@ async function runBridge({ credentialPath, projectId, workspaceId, mcpUrl: endpo
|
|
|
36938
36957
|
});
|
|
36939
36958
|
local.setRequestHandler("tools/call", async (request) => {
|
|
36940
36959
|
if (!/^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(request.params.arguments?.project_id)) throw new ProtocolError3(ProtocolErrorCode2.InvalidParams, "Read and pass the explicit project_id from the governing foundocs.json.");
|
|
36960
|
+
if (folderProject) {
|
|
36961
|
+
if (await folderProject(local) !== request.params.arguments.project_id) {
|
|
36962
|
+
throw new ProtocolError3(ProtocolErrorCode2.InvalidParams, "No matching Foundocs binding in this folder.");
|
|
36963
|
+
}
|
|
36964
|
+
await ensureConnected();
|
|
36965
|
+
}
|
|
36941
36966
|
if (checkpointRoute !== "remote" && request.params.name === checkpointTool.name) {
|
|
36942
36967
|
const args = request.params.arguments;
|
|
36943
36968
|
if (args.project_id !== projectId) throw new ProtocolError3(ProtocolErrorCode2.InvalidParams, "Local checkpoint project differs from this installation.");
|
|
@@ -36960,7 +36985,7 @@ async function runBridge({ credentialPath, projectId, workspaceId, mcpUrl: endpo
|
|
|
36960
36985
|
if (args?.view !== "index") delete defaults.includeRetrievalContext;
|
|
36961
36986
|
const params = Object.keys(defaults).length > 0 ? { ...request.params, arguments: { ...defaults, ...args } } : request.params;
|
|
36962
36987
|
if (automaticSupported) return await automatic.call(params);
|
|
36963
|
-
if (args && ["effectTask", "effectTaskId", "effectTaskComplete"].some((
|
|
36988
|
+
if (args && ["effectTask", "effectTaskId", "effectTaskComplete"].some((key) => Object.hasOwn(args, key))) {
|
|
36964
36989
|
throw new ProtocolError3(ProtocolErrorCode2.InvalidParams, "Automatic measurement metadata requires the current installer and server.");
|
|
36965
36990
|
}
|
|
36966
36991
|
return await remote.callTool(params);
|
|
@@ -36969,7 +36994,6 @@ async function runBridge({ credentialPath, projectId, workspaceId, mcpUrl: endpo
|
|
|
36969
36994
|
}
|
|
36970
36995
|
});
|
|
36971
36996
|
local.onerror = () => process.stderr.write("Foundocs local MCP transport error.\n");
|
|
36972
|
-
remote.onerror = () => process.stderr.write("Foundocs remote MCP transport error.\n");
|
|
36973
36997
|
process.stdin.on("end", () => {
|
|
36974
36998
|
void close();
|
|
36975
36999
|
});
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@foundocs/foundocs-setup",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "Repeatable project setup and agent skills for the Foundocs remote MCP server",
|
|
5
5
|
"foundocsRelease": {
|
|
6
|
-
"summary": "
|
|
6
|
+
"summary": "Keep global Foundocs tools and capture inactive in unlinked folders."
|
|
7
7
|
},
|
|
8
8
|
"type": "module",
|
|
9
9
|
"bin": {
|
package/src/bridge.mjs
CHANGED
|
@@ -64,7 +64,7 @@ function requestError(error, name) {
|
|
|
64
64
|
{ code, retryable, ...(tool ? { tool } : {}), ...(httpStatus !== undefined ? { httpStatus } : {}), ...(remoteCode !== undefined ? { remoteCode } : {}) });
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
export async function runBridge({ credentialPath, projectId, workspaceId, mcpUrl: endpoint, root, client, automaticFactory, automaticBase }) {
|
|
67
|
+
export async function runBridge({ credentialPath, projectId, workspaceId, mcpUrl: endpoint, root, client, automaticFactory, automaticBase, folderProject }) {
|
|
68
68
|
let automatic, automaticSupported = false, recovered = false;
|
|
69
69
|
let remote, local, checkpointRoute = 'remote', checkpointWasLocal = false;
|
|
70
70
|
let argumentDefaults, inventoryRequest;
|
|
@@ -116,16 +116,24 @@ function refreshToolInventory() {
|
|
|
116
116
|
try {
|
|
117
117
|
const url = new URL(endpoint);
|
|
118
118
|
if ((url.protocol !== 'https:' && !(url.protocol === 'http:' && ['localhost', '127.0.0.1', '[::1]'].includes(url.hostname))) || url.username || url.password || url.search || url.hash) throw new Error();
|
|
119
|
-
const
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
119
|
+
const connectRemote = async () => {
|
|
120
|
+
const key = await readCredential(credentialPath, projectId, workspaceId);
|
|
121
|
+
const next = new Client({ name: 'foundocs-local-auth', version: '0.2.0' }, { listMaxPages: 20 });
|
|
122
|
+
const transport = new StreamableHTTPClientTransport(url, {
|
|
123
|
+
requestInit: { headers: { Authorization: `Bearer ${key}` } },
|
|
124
|
+
fetch: (target, init) => {
|
|
125
|
+
if (new URL(typeof target === 'string' || target instanceof URL ? target : target.url).origin !== url.origin) throw new Error('Origin changed');
|
|
126
|
+
return fetch(target, { ...init, redirect: 'error', signal: init?.signal ? AbortSignal.any([init.signal, AbortSignal.timeout(20000)]) : AbortSignal.timeout(20000) });
|
|
127
|
+
},
|
|
128
|
+
});
|
|
129
|
+
try { await next.connect(transport, { timeout: 20000 }); }
|
|
130
|
+
catch (error) { await next.close().catch(() => {}); throw error; }
|
|
131
|
+
remote = next;
|
|
132
|
+
remote.onerror = () => process.stderr.write('Foundocs remote MCP transport error.\n');
|
|
133
|
+
};
|
|
134
|
+
let connecting;
|
|
135
|
+
const ensureConnected = () => remote || (connecting ??= connectRemote().finally(() => { connecting = undefined; }));
|
|
136
|
+
if (!folderProject) await ensureConnected();
|
|
129
137
|
if (automaticFactory && automaticBase) automatic = new AutomaticMeasurement({ projectId,
|
|
130
138
|
factory: automaticFactory, store: automaticStore(automaticBase), warn: message => process.stderr.write(message + '\n'),
|
|
131
139
|
remote: async (name, args, raw = false) => {
|
|
@@ -136,9 +144,13 @@ try {
|
|
|
136
144
|
return body.data;
|
|
137
145
|
},
|
|
138
146
|
});
|
|
139
|
-
local = new Server({ name: 'foundocs', version: '0.2.0' }, { capabilities: { tools: {} }, instructions: remote
|
|
147
|
+
local = new Server({ name: 'foundocs', version: '0.2.0' }, { capabilities: { tools: {} }, instructions: remote?.getInstructions() });
|
|
140
148
|
local.setRequestHandler('tools/list', async () => {
|
|
141
149
|
try {
|
|
150
|
+
if (folderProject) {
|
|
151
|
+
if (!await folderProject(local)) return { tools: [] };
|
|
152
|
+
await ensureConnected();
|
|
153
|
+
}
|
|
142
154
|
// The SDK collects all pages before we consider adding a local name.
|
|
143
155
|
const tools = await refreshToolInventory();
|
|
144
156
|
const collision = tools.some(tool => tool.name === checkpointTool.name);
|
|
@@ -152,6 +164,12 @@ try {
|
|
|
152
164
|
});
|
|
153
165
|
local.setRequestHandler('tools/call', async (request) => {
|
|
154
166
|
if (!/^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(request.params.arguments?.project_id)) throw new ProtocolError(ProtocolErrorCode.InvalidParams, 'Read and pass the explicit project_id from the governing foundocs.json.');
|
|
167
|
+
if (folderProject) {
|
|
168
|
+
if (await folderProject(local) !== request.params.arguments.project_id) {
|
|
169
|
+
throw new ProtocolError(ProtocolErrorCode.InvalidParams, 'No matching Foundocs binding in this folder.');
|
|
170
|
+
}
|
|
171
|
+
await ensureConnected();
|
|
172
|
+
}
|
|
155
173
|
if (checkpointRoute !== 'remote' && request.params.name === checkpointTool.name) {
|
|
156
174
|
const args = request.params.arguments;
|
|
157
175
|
if (args.project_id !== projectId) throw new ProtocolError(ProtocolErrorCode.InvalidParams, 'Local checkpoint project differs from this installation.');
|
|
@@ -181,7 +199,6 @@ try {
|
|
|
181
199
|
catch (error) { throw requestError(error, request.params.name); }
|
|
182
200
|
});
|
|
183
201
|
local.onerror = () => process.stderr.write('Foundocs local MCP transport error.\n');
|
|
184
|
-
remote.onerror = () => process.stderr.write('Foundocs remote MCP transport error.\n');
|
|
185
202
|
process.stdin.on('end', () => { void close(); });
|
|
186
203
|
for (const signal of ['SIGINT', 'SIGTERM']) process.on(signal, () => { void close().finally(() => process.exit(0)); });
|
|
187
204
|
await local.connect(new StdioServerTransport());
|
package/src/cli.mjs
CHANGED
|
@@ -4,7 +4,7 @@ import { install, doctor, rollback, updateInstallation, migrate, upgradeRuntime,
|
|
|
4
4
|
const [command, ...args] = process.argv.slice(2);
|
|
5
5
|
try {
|
|
6
6
|
if (command === '--help' || command === '-h') {
|
|
7
|
-
process.stdout.write('foundocs-setup install --root ABSOLUTE_PATH < private-input.json\nfoundocs-setup doctor --root ABSOLUTE_PATH\nfoundocs-setup update --root ABSOLUTE_PATH\nfoundocs-setup update-skills --root ABSOLUTE_PATH (alias for update)\nfoundocs-setup rollback --root ABSOLUTE_PATH\nfoundocs-setup migrate --root ABSOLUTE_PATH\nfoundocs-setup upgrade-runtime --root ABSOLUTE_PATH\nfoundocs-setup mcp --project-id UUID\nfoundocs-setup measure prepare|run|flush|configure|status --root ABSOLUTE_PATH < private-task.json\nfoundocs-setup install-global < private-input.json\nfoundocs-setup project create|link --client CLIENT --root ABSOLUTE_PATH [--workspace NAME_OR_ID] [--name NAME | --id UUID] [--replace OLD_UUID]\nfoundocs-setup workspace list|default --client CLIENT [--workspace NAME_OR_ID]\nInstall reads the one-time code from private stdin only. Never put credentials in argv or shell command text.\n');
|
|
7
|
+
process.stdout.write('foundocs-setup install --root ABSOLUTE_PATH < private-input.json\nfoundocs-setup doctor --root ABSOLUTE_PATH\nfoundocs-setup update --root ABSOLUTE_PATH\nfoundocs-setup update-skills --root ABSOLUTE_PATH (alias for update)\nfoundocs-setup rollback --root ABSOLUTE_PATH\nfoundocs-setup migrate --root ABSOLUTE_PATH\nfoundocs-setup upgrade-runtime --root ABSOLUTE_PATH\nfoundocs-setup mcp --project-id UUID\nfoundocs-setup measure prepare|run|flush|configure|status --root ABSOLUTE_PATH < private-task.json\nfoundocs-setup install-global < private-input.json\nfoundocs-setup project create|link --client CLIENT --root ABSOLUTE_PATH [--workspace NAME_OR_ID] [--name NAME | --id UUID] [--replace OLD_UUID]\nfoundocs-setup workspace list|default|update --client CLIENT [--workspace NAME_OR_ID]\nInstall reads the one-time code from private stdin only. Never put credentials in argv or shell command text.\n');
|
|
8
8
|
} else if (['install-global', 'project', 'workspace', 'mcp-global'].includes(command)) {
|
|
9
9
|
const { globalCommand } = await import('./global.mjs');
|
|
10
10
|
const result = await globalCommand(command, args);
|
package/src/global.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { execFile } from 'node:child_process';
|
|
2
2
|
import { createHash, randomUUID } from 'node:crypto';
|
|
3
3
|
import { lstat, mkdir, readFile, unlink } from 'node:fs/promises';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
4
5
|
import { homedir } from 'node:os';
|
|
5
6
|
import { basename, dirname, isAbsolute, join, relative, sep } from 'node:path';
|
|
6
7
|
import { isDeepStrictEqual, parseArgs, promisify } from 'node:util';
|
|
@@ -72,35 +73,81 @@ async function prepareHost(input, dir) {
|
|
|
72
73
|
const args = ['--yes', '@foundocs/foundocs-setup@' + version, 'mcp-global', '--client', client, '--workspace', workspaceId, '--storage', dirname(dir)];
|
|
73
74
|
const configPath = client === 'codex' ? join(configHome, 'config.toml') : process.env.CLAUDE_CONFIG_DIR ? join(configHome, '.claude.json') : join(home, '.claude.json');
|
|
74
75
|
const current = await textFile(configPath);
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
|
|
76
|
+
const parseHost = text => client === 'codex' ? parseToml(text ?? '') : JSON.parse(text ?? '{}');
|
|
77
|
+
const entry = config => (client === 'codex' ? config.mcp_servers : config.mcpServers)?.[name];
|
|
78
|
+
const expected = parseHost(current);
|
|
79
|
+
const configured = entry(expected);
|
|
80
|
+
let updatedConfig;
|
|
81
|
+
if (configured) {
|
|
82
|
+
const oldPackage = configured.args?.[1];
|
|
83
|
+
const oldArgs = [...args];
|
|
84
|
+
oldArgs[1] = oldPackage;
|
|
85
|
+
if (configured.command !== 'npx' || !/^@foundocs\/foundocs-setup@\d+\.\d+\.\d+$/.test(oldPackage) ||
|
|
86
|
+
!isDeepStrictEqual(configured.args, oldArgs) || Object.keys(configured).some(key => !['command', 'args', 'type'].includes(key)) ||
|
|
87
|
+
(configured.type && configured.type !== 'stdio')) fail('Conflicting user MCP entry: ' + name);
|
|
88
|
+
if (oldPackage !== args[1]) {
|
|
89
|
+
// Keep comments, unrelated entries and formatting intact in either host format.
|
|
90
|
+
configured.args = args;
|
|
91
|
+
for (let i = current.indexOf(oldPackage); i >= 0; i = current.indexOf(oldPackage, i + oldPackage.length)) {
|
|
92
|
+
const candidate = current.slice(0, i) + args[1] + current.slice(i + oldPackage.length);
|
|
93
|
+
if (isDeepStrictEqual(parseHost(candidate), expected)) { updatedConfig = candidate; break; }
|
|
94
|
+
}
|
|
95
|
+
if (!updatedConfig) fail('Cannot safely update the MCP entry: ' + name);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
78
98
|
await execute(client, ['--version'], { cwd: dir, timeout: 15000 });
|
|
79
99
|
const skillRoot = join(configHome, 'skills', 'foundocs-workspace');
|
|
100
|
+
const guideRoot = join(dir, 'guides', version, client);
|
|
101
|
+
const skillPath = join(skillRoot, 'SKILL.md');
|
|
102
|
+
const receipt = join(dir, client + '-workspace-skill.sha256');
|
|
80
103
|
const source = await readFile(new URL('../templates/workspace-skill.md', import.meta.url), 'utf8');
|
|
81
|
-
const
|
|
104
|
+
const storageArg = JSON.stringify(dirname(dir));
|
|
105
|
+
const bootstrap = source.replaceAll('{{CLIENT}}', client).replaceAll('{{VERSION}}', version)
|
|
106
|
+
.replaceAll('{{STORAGE}}', storageArg).replaceAll('{{GUIDES}}', JSON.stringify(guideRoot));
|
|
107
|
+
await safeParent(dirname(configHome), skillPath);
|
|
108
|
+
const before = await textFile(skillPath);
|
|
109
|
+
// 0.4.0 predates receipts. Recognize only its exact template for this client and storage.
|
|
110
|
+
const legacyHash = client === 'codex' ? 'caeed0744464166dd0772882e965fd9b9464c06d160ffa9f002e5385276f5f91' : 'cccf248e38dbea2d0328dc29c403ef2baba3816250a58894f64754c92f621083';
|
|
111
|
+
if (before !== null && before !== bootstrap && digest(before) !== (await textFile(receipt))?.trim() &&
|
|
112
|
+
digest(before.replace(storageArg, '{{STORAGE}}')) !== legacyHash) fail('Global workspace skill has local edits: ' + skillPath);
|
|
113
|
+
const guides = [];
|
|
114
|
+
const legacySkills = [];
|
|
82
115
|
for (const asset of skillAssets(client)) {
|
|
83
116
|
const name = asset.name.split('/skills/')[1];
|
|
117
|
+
const path = join(guideRoot, name);
|
|
118
|
+
await safeParent(dir, path);
|
|
84
119
|
const content = name === 'foundocs/references/configuration.md'
|
|
85
|
-
? await readFile(new URL('../templates/workspace-configuration.md', import.meta.url), 'utf8')
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
changes.push({ path, content: file.content });
|
|
120
|
+
? await readFile(new URL('../templates/workspace-configuration.md', import.meta.url), 'utf8') : asset.content;
|
|
121
|
+
const existing = await textFile(path);
|
|
122
|
+
if (existing === null) guides.push({ path, content });
|
|
123
|
+
else if (existing !== content) fail('Global guide has local edits: ' + path);
|
|
124
|
+
if (name.endsWith('/SKILL.md')) {
|
|
125
|
+
const legacy = join(skillRoot, name);
|
|
126
|
+
await safeParent(dirname(configHome), legacy);
|
|
127
|
+
const descriptor = await textFile(legacy);
|
|
128
|
+
if (descriptor !== null && descriptor !== content) fail('Global skill has local edits: ' + legacy);
|
|
129
|
+
if (descriptor !== null) legacySkills.push({ path: legacy, content });
|
|
130
|
+
}
|
|
97
131
|
}
|
|
98
132
|
return async () => {
|
|
99
|
-
for (const { path, content } of
|
|
133
|
+
for (const { path, content } of guides) {
|
|
100
134
|
await mkdir(dirname(path), { recursive: true, mode: 0o700 });
|
|
101
|
-
if (await textFile(path) !== null) fail('Global skill changed during installation.');
|
|
102
135
|
await atomicWrite(path, content);
|
|
103
136
|
}
|
|
137
|
+
if (before !== bootstrap) {
|
|
138
|
+
if (await textFile(skillPath) !== before) fail('Workspace skill changed during installation.');
|
|
139
|
+
await mkdir(skillRoot, { recursive: true, mode: 0o700 });
|
|
140
|
+
await atomicWrite(skillPath, bootstrap);
|
|
141
|
+
}
|
|
142
|
+
await atomicWrite(receipt, digest(bootstrap) + '\n');
|
|
143
|
+
for (const { path, content } of legacySkills) {
|
|
144
|
+
if (await textFile(path) !== content) fail('Global skill changed during migration: ' + path);
|
|
145
|
+
await unlink(path);
|
|
146
|
+
}
|
|
147
|
+
if (updatedConfig) {
|
|
148
|
+
if (await textFile(configPath) !== current) fail('Client configuration changed. Retry the update.');
|
|
149
|
+
await atomicWrite(configPath, updatedConfig, (await lstat(configPath)).mode & 0o777);
|
|
150
|
+
}
|
|
104
151
|
if (!configured) {
|
|
105
152
|
if (await textFile(configPath) !== current) fail('Client configuration changed. Rerun the same installation.');
|
|
106
153
|
const command = client === 'codex' ? ['mcp', 'add', name, '--', 'npx', ...args] :
|
|
@@ -129,6 +176,10 @@ export async function installGlobal(input, options = {}) {
|
|
|
129
176
|
if (catalog.workspace?.id !== ws.id) fail('Workspace identity mismatch.');
|
|
130
177
|
ws.name = catalog.workspace.name;
|
|
131
178
|
await finishHost();
|
|
179
|
+
for (const other of registry.workspaces.filter(item => item.id !== ws.id)) {
|
|
180
|
+
const update = await (options.prepareHost ?? prepareHost)({ client: input.client, workspaceId: other.id }, dir);
|
|
181
|
+
await update();
|
|
182
|
+
}
|
|
132
183
|
registry.workspaces = [...registry.workspaces.filter(item => item.id !== ws.id), ws];
|
|
133
184
|
await atomicWrite(path, json(registry));
|
|
134
185
|
return { status: 'workspace_registered', workspace: catalog.workspace, server: serverName(ws.id), next: 'Reload the client, open your project folder and ask Foundocs to create or link its project.' };
|
|
@@ -203,6 +254,23 @@ export async function bindProject(action, args, options = {}) {
|
|
|
203
254
|
});
|
|
204
255
|
}
|
|
205
256
|
|
|
257
|
+
// Respect the host's selected folder. A default workspace is never a document binding.
|
|
258
|
+
async function folderProject(server, workspaceId) {
|
|
259
|
+
try {
|
|
260
|
+
let folder = process.cwd();
|
|
261
|
+
if (server.getClientCapabilities()?.roots) {
|
|
262
|
+
const { roots } = await server.listRoots({}, { timeout: 3000 });
|
|
263
|
+
if (roots.length !== 1) return null;
|
|
264
|
+
folder = fileURLToPath(roots[0].uri);
|
|
265
|
+
}
|
|
266
|
+
let root = folder;
|
|
267
|
+
try { root = (await execute('git', ['-C', folder, 'rev-parse', '--show-toplevel'], { timeout: 3000 })).stdout.trim(); }
|
|
268
|
+
catch { /* Plain folders are bound at the selected directory. */ }
|
|
269
|
+
const binding = await readJson(join(root, 'foundocs.json'));
|
|
270
|
+
return binding?.workspace_id === workspaceId && uuid.test(binding.project_id) ? binding.project_id : null;
|
|
271
|
+
} catch { return null; }
|
|
272
|
+
}
|
|
273
|
+
|
|
206
274
|
export async function globalCommand(command, argv) {
|
|
207
275
|
if (command === 'install-global') {
|
|
208
276
|
if (argv.length || process.stdin.isTTY) fail('Provide the installation JSON on private stdin.');
|
|
@@ -219,6 +287,16 @@ export async function globalCommand(command, argv) {
|
|
|
219
287
|
await privateDirectory(dir);
|
|
220
288
|
const registry = await readJson(path);
|
|
221
289
|
if (command === 'workspace' && action === 'list') return { defaultId: registry?.defaultId, workspaces: (registry?.workspaces ?? []).map(({ id, name }) => ({ id, name, server: serverName(id) })) };
|
|
290
|
+
if (command === 'workspace' && action === 'update') {
|
|
291
|
+
return withLock(dir, async () => {
|
|
292
|
+
const registered = (await readJson(path))?.workspaces ?? [];
|
|
293
|
+
for (const ws of registered) {
|
|
294
|
+
const update = await prepareHost({ client: values.client, workspaceId: ws.id }, dir);
|
|
295
|
+
await update();
|
|
296
|
+
}
|
|
297
|
+
return { status: 'updated', workspaces: registered.length, version };
|
|
298
|
+
});
|
|
299
|
+
}
|
|
222
300
|
if (command === 'workspace' && action === 'default') {
|
|
223
301
|
if (!values.workspace) fail('Choose --workspace NAME_OR_ID.');
|
|
224
302
|
return withLock(dir, async () => {
|
|
@@ -232,5 +310,5 @@ export async function globalCommand(command, argv) {
|
|
|
232
310
|
if (command !== 'mcp-global' || !uuid.test(values.workspace)) fail('Unknown workspace operation.');
|
|
233
311
|
const ws = selectWorkspace(registry, values.workspace);
|
|
234
312
|
const { runBridge } = await import('./bridge.mjs');
|
|
235
|
-
await runBridge({ credentialPath: keyPath(dir, values.client, ws), projectId: null, workspaceId: ws.id, mcpUrl: ws.mcpUrl });
|
|
313
|
+
await runBridge({ credentialPath: keyPath(dir, values.client, ws), projectId: null, workspaceId: ws.id, mcpUrl: ws.mcpUrl, folderProject: server => folderProject(server, ws.id) });
|
|
236
314
|
}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: foundocs-workspace
|
|
3
|
-
description:
|
|
3
|
+
description: Use when the user explicitly asks to create or link a Foundocs project or manage a Foundocs workspace. For ordinary work, use only when the current project context already identifies a Foundocs binding. An unlinked folder needs no Foundocs lookup, capture, or setup prompt.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# Foundocs workspace
|
|
7
7
|
|
|
8
|
+
For ordinary chat or coding, stay silent when the governing folder has no valid `foundocs.json`. Do not search the filesystem for a binding during unrelated chat, call Foundocs tools, list workspaces, load the guides, ask for configuration, or suggest installing it. A registered global workspace alone never activates document lookup or capture. Explicit Foundocs creation and linking requests below work from an unlinked folder.
|
|
9
|
+
|
|
8
10
|
Use the selected {{CLIENT}} installation. Run the pinned CLI as an argument array with prefix `npx --yes @foundocs/foundocs-setup@{{VERSION}}`. Append `--client {{CLIENT}}` and the two arguments `--storage` and {{STORAGE}} to the commands below. Treat names and folder paths as literal arguments.
|
|
9
11
|
|
|
10
12
|
- On an explicit request to create a project, run `project create --root ABSOLUTE_PROJECT_ROOT`. Use the current governing project root. The folder name is the default. Pass `--name NAME` when requested.
|
|
@@ -12,6 +14,6 @@ Use the selected {{CLIENT}} installation. Run the pinned CLI as an argument arra
|
|
|
12
14
|
- On a switch confirmation show both targets and wait for the user's decision. Once confirmed, repeat the same command with `--replace OLD_PROJECT_ID`. Retry interrupted creation with the same root and name.
|
|
13
15
|
- `workspace list` shows registered workspaces. Use `workspace default --workspace ID_OR_NAME` only when asked to change the default.
|
|
14
16
|
- A `project_installation` result means the folder has a separate project-scoped install. Show the previous project and requested target. Only after explicit approval to remove that installation, run its existing `rollback --root ABSOLUTE_PROJECT_ROOT` workflow. Proceed with the requested global link when rollback succeeds and the folder is clear. If rollback reports conflicts or restores an older binding, preserve it and report the conflict.
|
|
15
|
-
- After binding, use the MCP server named in the CLI result. Call `get_project_context` for the exact project ID and report the workspace and project names. If the
|
|
17
|
+
- After binding, use the MCP server named in the CLI result. Call `get_project_context` for the exact project ID and report the workspace and project names. If the host cached an empty tool list before binding, reopen the chat in the linked folder; distinguish a saved folder binding from host verification.
|
|
16
18
|
- For ordinary Foundocs work, use the exact governing project’s `foundocs.json`. A global binding contains `workspace_id` and `project_id`. Use this workspace's MCP server (use the server name returned by `workspace list` for that exact workspace ID). Use the project’s existing instructions and MCP connection when it has its own installation. Never guess a binding in an unlinked folder.
|
|
17
|
-
- Once bound,
|
|
19
|
+
- Once bound, read the appropriate guide under {{GUIDES}}: `foundocs/SKILL.md`, `foundocs-capture-knowledge/SKILL.md`, or `foundocs-capture-episode/SKILL.md` for the requested activity. For a global binding the explicit workspace and project in the governing folder are the configuration. Global setup installs no project-scoped update or checkpoint hooks. The private bootstrap CLI handles workspace registration and linking before any project is selected.
|