@workpowers/speckle 0.3.1 → 0.4.0
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 +26 -1
- package/bin/speckle-mcp.mjs +1 -1
- package/dist/cli.js +6 -0
- package/dist/headers.d.ts +1 -1
- package/dist/headers.js +1 -1
- package/dist/index.js +7 -1
- package/dist/proxy.d.ts +2 -1
- package/dist/proxy.js +16 -2
- package/dist/workflow-client.d.ts +18 -0
- package/dist/workflow-client.js +43 -0
- package/dist/workflow-command.d.ts +2 -0
- package/dist/workflow-command.js +41 -0
- package/dist/workflow-contract.d.ts +301 -0
- package/dist/workflow-contract.js +84 -0
- package/dist/workflow-files.d.ts +32 -0
- package/dist/workflow-files.js +147 -0
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -47,6 +47,30 @@ The router boots into one of two shapes depending on what it can see:
|
|
|
47
47
|
as Claude Desktop). Discovery tools are registered instead, so the agent can
|
|
48
48
|
find its way to a project first.
|
|
49
49
|
|
|
50
|
+
## Keep workflow guidance current
|
|
51
|
+
|
|
52
|
+
The router observes dedicated local Speckle guidance on each tool call and
|
|
53
|
+
surfaces process revisions during an open session. Fetch `speckle_get_workflow`
|
|
54
|
+
before planning/resuming. The guide and the small repository bootstrap have
|
|
55
|
+
independent revisions; local file observations are attributed to the router,
|
|
56
|
+
never presented as independent server verification.
|
|
57
|
+
|
|
58
|
+
From a repository with a `.speckle` marker and the router environment configured:
|
|
59
|
+
|
|
60
|
+
```sh
|
|
61
|
+
npx -y @workpowers/speckle workflow # preview only
|
|
62
|
+
npx -y @workpowers/speckle workflow --apply # dedicated bootstrap + local receipt
|
|
63
|
+
npx -y @workpowers/speckle workflow --apply --cache # also retain an offline planning cache
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Review the diff and reference `SPECKLE.md` from `AGENTS.md` or `CLAUDE.md`.
|
|
67
|
+
Reconcile old copied Speckle guidance while preserving project-specific rules.
|
|
68
|
+
Keep `.speckle-workflow.json` local (for example via Git's local exclude file).
|
|
69
|
+
The command refuses edited/unowned files and symlinks. No commits are made.
|
|
70
|
+
Unavailable live guidance is reported explicitly with any valid cache's revision
|
|
71
|
+
and age; a cache is never called current. Server releases carry new guidance;
|
|
72
|
+
restart the router after updating the router package itself.
|
|
73
|
+
|
|
50
74
|
## Diagnosing
|
|
51
75
|
|
|
52
76
|
```bash
|
|
@@ -74,7 +98,8 @@ your key somewhere it does not belong.
|
|
|
74
98
|
|
|
75
99
|
Published from `plugins/speckle-mcp` in the Speckle monorepo by
|
|
76
100
|
`.github/workflows/publish-router.yml`, which fires when this package's
|
|
77
|
-
`version` field changes on `main`.
|
|
101
|
+
`version` field changes on `main`. It publishes over npm's OIDC trusted
|
|
102
|
+
publishing, so no npm token is stored anywhere in the repository.
|
|
78
103
|
|
|
79
104
|
## License
|
|
80
105
|
|
package/bin/speckle-mcp.mjs
CHANGED
|
@@ -11,7 +11,7 @@ const args = process.argv.slice(2);
|
|
|
11
11
|
const sub = args[0];
|
|
12
12
|
|
|
13
13
|
const isCliSubcommand =
|
|
14
|
-
sub === "init" || sub === "doctor" || sub === "help" || sub === "--help" || sub === "-h";
|
|
14
|
+
sub === "init" || sub === "doctor" || sub === "workflow" || sub === "help" || sub === "--help" || sub === "-h";
|
|
15
15
|
|
|
16
16
|
if (isCliSubcommand) {
|
|
17
17
|
runCli(args).catch((err) => {
|
package/dist/cli.js
CHANGED
|
@@ -16,9 +16,12 @@ import { renderSpeckleMarker } from "./marker.js";
|
|
|
16
16
|
import { resolveWorkspace } from "./workspace.js";
|
|
17
17
|
import { loadRouterConfig, resolveSpeckleHost } from "./config.js";
|
|
18
18
|
import { SpeckleRouterError } from "./errors.js";
|
|
19
|
+
import { runWorkflowCommand } from "./workflow-command.js";
|
|
19
20
|
export async function runCli(args) {
|
|
20
21
|
const [cmd, ...rest] = args;
|
|
21
22
|
switch (cmd) {
|
|
23
|
+
case "workflow":
|
|
24
|
+
return runWorkflowCommand(rest);
|
|
22
25
|
case "init":
|
|
23
26
|
return runInit(rest);
|
|
24
27
|
case "doctor":
|
|
@@ -138,6 +141,9 @@ function printHelp() {
|
|
|
138
141
|
" --url <speckle_url> Optional Speckle host URL when not using the default.",
|
|
139
142
|
" --force Overwrite an existing .speckle file.",
|
|
140
143
|
" speckle-mcp doctor Diagnose local config and marker state (no network).",
|
|
144
|
+
" speckle-mcp workflow Fetch live guidance and preview dedicated local files.",
|
|
145
|
+
" --apply Apply after ownership checks; review the Git diff.",
|
|
146
|
+
" --cache Also keep planning guidance for explicit offline fallback.",
|
|
141
147
|
" speckle-mcp help Show this message.",
|
|
142
148
|
"",
|
|
143
149
|
"Environment:",
|
package/dist/headers.d.ts
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
*/
|
|
14
14
|
import type { ResolvedWorkspace } from "./workspace.js";
|
|
15
15
|
export declare const ROUTER_CLIENT_NAME = "@workpowers/speckle";
|
|
16
|
-
export declare const ROUTER_CLIENT_VERSION = "0.
|
|
16
|
+
export declare const ROUTER_CLIENT_VERSION = "0.4.0";
|
|
17
17
|
export interface RouterRequestHeaders {
|
|
18
18
|
Authorization: string;
|
|
19
19
|
"X-Speckle-Client": string;
|
package/dist/headers.js
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* the server then exposes a project-agnostic discovery toolset.
|
|
13
13
|
*/
|
|
14
14
|
export const ROUTER_CLIENT_NAME = "@workpowers/speckle";
|
|
15
|
-
export const ROUTER_CLIENT_VERSION = "0.
|
|
15
|
+
export const ROUTER_CLIENT_VERSION = "0.4.0";
|
|
16
16
|
export function buildRouterHeaders(args) {
|
|
17
17
|
const { apiKey, workspace, fallbackProjectId } = args;
|
|
18
18
|
const headers = {
|
package/dist/index.js
CHANGED
|
@@ -31,6 +31,8 @@ import { resolveWorkspace } from "./workspace.js";
|
|
|
31
31
|
import { buildRouterHeaders, ROUTER_CLIENT_NAME, ROUTER_CLIENT_VERSION } from "./headers.js";
|
|
32
32
|
import { mirrorServerOptions, wireProxyHandlers } from "./proxy.js";
|
|
33
33
|
import { SpeckleRouterError } from "./errors.js";
|
|
34
|
+
import path from "node:path";
|
|
35
|
+
import { createWorkflowClient } from "./workflow-client.js";
|
|
34
36
|
export async function startRouter() {
|
|
35
37
|
const config = loadRouterConfig();
|
|
36
38
|
let workspace;
|
|
@@ -68,7 +70,11 @@ export async function startRouter() {
|
|
|
68
70
|
await upstream.connect(httpTransport);
|
|
69
71
|
const capabilities = upstream.getServerCapabilities() ?? {};
|
|
70
72
|
const downstream = new Server({ name: ROUTER_CLIENT_NAME, version: ROUTER_CLIENT_VERSION }, mirrorServerOptions(upstream, capabilities));
|
|
71
|
-
wireProxyHandlers(downstream, upstream, capabilities
|
|
73
|
+
wireProxyHandlers(downstream, upstream, capabilities, createWorkflowClient({
|
|
74
|
+
root: workspace ? path.dirname(workspace.markerPath) : undefined,
|
|
75
|
+
workspaceId: workspace?.workspaceRootHash,
|
|
76
|
+
host: host.hostUrl,
|
|
77
|
+
}));
|
|
72
78
|
const stdio = new StdioServerTransport();
|
|
73
79
|
await downstream.connect(stdio);
|
|
74
80
|
// Forward shutdown so the upstream socket is closed when the agent disconnects.
|
package/dist/proxy.d.ts
CHANGED
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
*/
|
|
14
14
|
import type { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
15
15
|
import type { Server, ServerOptions } from "@modelcontextprotocol/sdk/server/index.js";
|
|
16
|
+
import type { createWorkflowClient } from "./workflow-client.js";
|
|
16
17
|
import { type ServerCapabilities } from "@modelcontextprotocol/sdk/types.js";
|
|
17
18
|
/**
|
|
18
19
|
* The options the router's downstream Server must be built with to look like
|
|
@@ -32,5 +33,5 @@ import { type ServerCapabilities } from "@modelcontextprotocol/sdk/types.js";
|
|
|
32
33
|
* passing `undefined` — the SDK stores what it is handed.
|
|
33
34
|
*/
|
|
34
35
|
export declare function mirrorServerOptions(client: Client, capabilities: ServerCapabilities): ServerOptions;
|
|
35
|
-
export declare function wireProxyHandlers(server: Server, client: Client, capabilities: ServerCapabilities): void;
|
|
36
|
+
export declare function wireProxyHandlers(server: Server, client: Client, capabilities: ServerCapabilities, workflow?: ReturnType<typeof createWorkflowClient>): void;
|
|
36
37
|
//# sourceMappingURL=proxy.d.ts.map
|
package/dist/proxy.js
CHANGED
|
@@ -33,7 +33,7 @@ export function mirrorServerOptions(client, capabilities) {
|
|
|
33
33
|
const instructions = client.getInstructions();
|
|
34
34
|
return { capabilities, ...(instructions === undefined ? {} : { instructions }) };
|
|
35
35
|
}
|
|
36
|
-
export function wireProxyHandlers(server, client, capabilities) {
|
|
36
|
+
export function wireProxyHandlers(server, client, capabilities, workflow) {
|
|
37
37
|
// Ping is always available — agents use it to keep the link alive.
|
|
38
38
|
server.setRequestHandler(PingRequestSchema, async () => {
|
|
39
39
|
await client.ping();
|
|
@@ -44,7 +44,21 @@ export function wireProxyHandlers(server, client, capabilities) {
|
|
|
44
44
|
return await client.listTools(req.params);
|
|
45
45
|
});
|
|
46
46
|
server.setRequestHandler(CallToolRequestSchema, async (req) => {
|
|
47
|
-
|
|
47
|
+
try {
|
|
48
|
+
const result = await client.callTool(workflow?.prepare(req.params) ?? req.params);
|
|
49
|
+
workflow?.received(req.params, result);
|
|
50
|
+
const fallback = result.isError ? workflow?.fallback(req.params) : undefined;
|
|
51
|
+
if (fallback && Array.isArray(result.content)) {
|
|
52
|
+
return { ...result, content: [...result.content, ...fallback.content] };
|
|
53
|
+
}
|
|
54
|
+
return result;
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
const fallback = workflow?.fallback(req.params);
|
|
58
|
+
if (fallback)
|
|
59
|
+
return fallback;
|
|
60
|
+
throw error;
|
|
61
|
+
}
|
|
48
62
|
});
|
|
49
63
|
}
|
|
50
64
|
if (capabilities.prompts !== undefined) {
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { CallToolRequest } from "@modelcontextprotocol/sdk/types.js";
|
|
2
|
+
export declare function createWorkflowClient(options: {
|
|
3
|
+
root?: string;
|
|
4
|
+
workspaceId?: string;
|
|
5
|
+
host: string;
|
|
6
|
+
}): {
|
|
7
|
+
prepare(params: CallToolRequest["params"]): CallToolRequest["params"];
|
|
8
|
+
received(params: CallToolRequest["params"], result: unknown): void;
|
|
9
|
+
fallback(params: CallToolRequest["params"]): {
|
|
10
|
+
isError: boolean;
|
|
11
|
+
content: {
|
|
12
|
+
type: "text";
|
|
13
|
+
text: string;
|
|
14
|
+
}[];
|
|
15
|
+
} | undefined;
|
|
16
|
+
};
|
|
17
|
+
export declare function isWorkflowFetch(params: CallToolRequest["params"]): boolean;
|
|
18
|
+
//# sourceMappingURL=workflow-client.d.ts.map
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/** Per-router-session metadata. Re-read checkout evidence on every call; never equate notice delivery with adoption. */
|
|
2
|
+
import { randomUUID } from "node:crypto";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { WORKFLOW_META, publicationSchema } from "./workflow-contract.js";
|
|
5
|
+
import { observeWorkflowFiles, cachedWorkflowFallback } from "./workflow-files.js";
|
|
6
|
+
const responseMeta = z.object({
|
|
7
|
+
notice_id: z.string(), notice_delivered: z.boolean(), fetched_revision: z.string().optional(),
|
|
8
|
+
});
|
|
9
|
+
export function createWorkflowClient(options) {
|
|
10
|
+
const clientId = randomUUID();
|
|
11
|
+
let seenNotice;
|
|
12
|
+
let fetchedRevision;
|
|
13
|
+
return {
|
|
14
|
+
prepare(params) {
|
|
15
|
+
return { ...params, _meta: { ...params._meta, [WORKFLOW_META]: {
|
|
16
|
+
client_id: clientId, workspace_id: options.workspaceId ?? `rootless:${clientId}`,
|
|
17
|
+
seen_notice: seenNotice, fetched_revision: fetchedRevision,
|
|
18
|
+
...(options.root ? { evidence: observeWorkflowFiles(options.root, options.host) } : {}),
|
|
19
|
+
} } };
|
|
20
|
+
},
|
|
21
|
+
received(params, result) {
|
|
22
|
+
const r = result;
|
|
23
|
+
const meta = responseMeta.safeParse(r._meta?.[WORKFLOW_META]);
|
|
24
|
+
if (meta.success && meta.data.notice_delivered)
|
|
25
|
+
seenNotice = meta.data.notice_id;
|
|
26
|
+
// Only a successful explicit retrieval supplies session knowledge. Never an ordinary notice.
|
|
27
|
+
if (isWorkflowFetch(params) && !r.isError) {
|
|
28
|
+
const publication = publicationSchema.safeParse(r.structuredContent);
|
|
29
|
+
if (publication.success)
|
|
30
|
+
fetchedRevision = publication.data.planning.revision;
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
fallback(params) {
|
|
34
|
+
return isWorkflowFetch(params) ? { isError: true,
|
|
35
|
+
content: [{ type: "text", text: cachedWorkflowFallback(options.root, options.host) }] } : undefined;
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
export function isWorkflowFetch(params) {
|
|
40
|
+
return params.name === "speckle_get_workflow" || (params.name === "speckle_toolbox" &&
|
|
41
|
+
params.arguments?.tool === "speckle_get_workflow" && params.arguments.arguments !== undefined);
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=workflow-client.js.map
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/** Explicit workflow preview/apply command; reads only from the authenticated, configured Speckle host. */
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
4
|
+
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
5
|
+
import { loadRouterConfig, resolveSpeckleHost } from "./config.js";
|
|
6
|
+
import { resolveWorkspace } from "./workspace.js";
|
|
7
|
+
import { buildRouterHeaders, ROUTER_CLIENT_NAME, ROUTER_CLIENT_VERSION } from "./headers.js";
|
|
8
|
+
import { publicationSchema } from "./workflow-contract.js";
|
|
9
|
+
import { applyWorkflowFiles, cachedWorkflowFallback } from "./workflow-files.js";
|
|
10
|
+
export async function runWorkflowCommand(args) {
|
|
11
|
+
if (args.some((arg) => arg !== "--apply" && arg !== "--cache")) {
|
|
12
|
+
throw new Error("Usage: speckle-mcp workflow [--apply] [--cache]");
|
|
13
|
+
}
|
|
14
|
+
const config = loadRouterConfig();
|
|
15
|
+
const workspace = resolveWorkspace({ cwd: config.cwd, allowRepoMismatch: config.allowRepoMismatch });
|
|
16
|
+
const root = path.dirname(workspace.markerPath);
|
|
17
|
+
const host = resolveSpeckleHost(config, workspace.marker.marker.speckleUrl).hostUrl;
|
|
18
|
+
const client = new Client({ name: ROUTER_CLIENT_NAME, version: ROUTER_CLIENT_VERSION }, { capabilities: {} });
|
|
19
|
+
let publication;
|
|
20
|
+
try {
|
|
21
|
+
await client.connect(new StreamableHTTPClientTransport(new URL(`${host}/mcp`), {
|
|
22
|
+
requestInit: { headers: { ...buildRouterHeaders({ apiKey: config.apiKey, workspace }) } },
|
|
23
|
+
}));
|
|
24
|
+
const result = await client.callTool({ name: "speckle_get_workflow", arguments: { workflow: "planning" } }, undefined, { timeout: 15_000 });
|
|
25
|
+
if (result.isError)
|
|
26
|
+
throw new Error("Workflow tool refused retrieval");
|
|
27
|
+
publication = publicationSchema.parse(result.structuredContent);
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
process.stderr.write(cachedWorkflowFallback(root, host) + "\n");
|
|
31
|
+
throw new Error("Live workflow retrieval failed; no files were written. Retry against a server supporting speckle_get_workflow.");
|
|
32
|
+
}
|
|
33
|
+
finally {
|
|
34
|
+
await client.close().catch(() => undefined);
|
|
35
|
+
}
|
|
36
|
+
const result = applyWorkflowFiles(root, host, publication, {
|
|
37
|
+
apply: args.includes("--apply"), cache: args.includes("--cache"),
|
|
38
|
+
});
|
|
39
|
+
process.stdout.write(JSON.stringify(result, null, 2) + "\n");
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=workflow-command.js.map
|
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const WORKFLOW_META = "ai.workpowers.speckle/workflow";
|
|
3
|
+
export declare const BOOTSTRAP_FILE = "SPECKLE.md";
|
|
4
|
+
export declare const WORKFLOW_CACHE_FILE = ".speckle-workflow.json";
|
|
5
|
+
export declare const hashContent: (content: string) => string;
|
|
6
|
+
export declare const artifactSchema: z.ZodEffects<z.ZodObject<{
|
|
7
|
+
revision: z.ZodString;
|
|
8
|
+
content: z.ZodString;
|
|
9
|
+
summary: z.ZodString;
|
|
10
|
+
}, "strip", z.ZodTypeAny, {
|
|
11
|
+
revision: string;
|
|
12
|
+
content: string;
|
|
13
|
+
summary: string;
|
|
14
|
+
}, {
|
|
15
|
+
revision: string;
|
|
16
|
+
content: string;
|
|
17
|
+
summary: string;
|
|
18
|
+
}>, {
|
|
19
|
+
revision: string;
|
|
20
|
+
content: string;
|
|
21
|
+
summary: string;
|
|
22
|
+
}, {
|
|
23
|
+
revision: string;
|
|
24
|
+
content: string;
|
|
25
|
+
summary: string;
|
|
26
|
+
}>;
|
|
27
|
+
export declare const publicationSchema: z.ZodObject<{
|
|
28
|
+
protocol_version: z.ZodLiteral<1>;
|
|
29
|
+
planning: z.ZodEffects<z.ZodObject<{
|
|
30
|
+
revision: z.ZodString;
|
|
31
|
+
content: z.ZodString;
|
|
32
|
+
summary: z.ZodString;
|
|
33
|
+
}, "strip", z.ZodTypeAny, {
|
|
34
|
+
revision: string;
|
|
35
|
+
content: string;
|
|
36
|
+
summary: string;
|
|
37
|
+
}, {
|
|
38
|
+
revision: string;
|
|
39
|
+
content: string;
|
|
40
|
+
summary: string;
|
|
41
|
+
}>, {
|
|
42
|
+
revision: string;
|
|
43
|
+
content: string;
|
|
44
|
+
summary: string;
|
|
45
|
+
}, {
|
|
46
|
+
revision: string;
|
|
47
|
+
content: string;
|
|
48
|
+
summary: string;
|
|
49
|
+
}>;
|
|
50
|
+
bootstrap: z.ZodEffects<z.ZodObject<{
|
|
51
|
+
revision: z.ZodString;
|
|
52
|
+
content: z.ZodString;
|
|
53
|
+
summary: z.ZodString;
|
|
54
|
+
}, "strip", z.ZodTypeAny, {
|
|
55
|
+
revision: string;
|
|
56
|
+
content: string;
|
|
57
|
+
summary: string;
|
|
58
|
+
}, {
|
|
59
|
+
revision: string;
|
|
60
|
+
content: string;
|
|
61
|
+
summary: string;
|
|
62
|
+
}>, {
|
|
63
|
+
revision: string;
|
|
64
|
+
content: string;
|
|
65
|
+
summary: string;
|
|
66
|
+
}, {
|
|
67
|
+
revision: string;
|
|
68
|
+
content: string;
|
|
69
|
+
summary: string;
|
|
70
|
+
}>;
|
|
71
|
+
}, "strip", z.ZodTypeAny, {
|
|
72
|
+
protocol_version: 1;
|
|
73
|
+
planning: {
|
|
74
|
+
revision: string;
|
|
75
|
+
content: string;
|
|
76
|
+
summary: string;
|
|
77
|
+
};
|
|
78
|
+
bootstrap: {
|
|
79
|
+
revision: string;
|
|
80
|
+
content: string;
|
|
81
|
+
summary: string;
|
|
82
|
+
};
|
|
83
|
+
}, {
|
|
84
|
+
protocol_version: 1;
|
|
85
|
+
planning: {
|
|
86
|
+
revision: string;
|
|
87
|
+
content: string;
|
|
88
|
+
summary: string;
|
|
89
|
+
};
|
|
90
|
+
bootstrap: {
|
|
91
|
+
revision: string;
|
|
92
|
+
content: string;
|
|
93
|
+
summary: string;
|
|
94
|
+
};
|
|
95
|
+
}>;
|
|
96
|
+
export type WorkflowPublication = z.infer<typeof publicationSchema>;
|
|
97
|
+
declare const observation: z.ZodObject<{
|
|
98
|
+
state: z.ZodEnum<["observed", "missing", "unreadable"]>;
|
|
99
|
+
hash: z.ZodOptional<z.ZodString>;
|
|
100
|
+
baseline_hash: z.ZodOptional<z.ZodString>;
|
|
101
|
+
}, "strip", z.ZodTypeAny, {
|
|
102
|
+
state: "missing" | "observed" | "unreadable";
|
|
103
|
+
hash?: string | undefined;
|
|
104
|
+
baseline_hash?: string | undefined;
|
|
105
|
+
}, {
|
|
106
|
+
state: "missing" | "observed" | "unreadable";
|
|
107
|
+
hash?: string | undefined;
|
|
108
|
+
baseline_hash?: string | undefined;
|
|
109
|
+
}>;
|
|
110
|
+
export declare const workflowContextSchema: z.ZodObject<{
|
|
111
|
+
client_id: z.ZodOptional<z.ZodString>;
|
|
112
|
+
workspace_id: z.ZodOptional<z.ZodString>;
|
|
113
|
+
fetched_revision: z.ZodOptional<z.ZodString>;
|
|
114
|
+
seen_notice: z.ZodOptional<z.ZodString>;
|
|
115
|
+
evidence: z.ZodOptional<z.ZodObject<{
|
|
116
|
+
source: z.ZodEnum<["router", "agent"]>;
|
|
117
|
+
bootstrap: z.ZodObject<{
|
|
118
|
+
state: z.ZodEnum<["observed", "missing", "unreadable"]>;
|
|
119
|
+
hash: z.ZodOptional<z.ZodString>;
|
|
120
|
+
baseline_hash: z.ZodOptional<z.ZodString>;
|
|
121
|
+
}, "strip", z.ZodTypeAny, {
|
|
122
|
+
state: "missing" | "observed" | "unreadable";
|
|
123
|
+
hash?: string | undefined;
|
|
124
|
+
baseline_hash?: string | undefined;
|
|
125
|
+
}, {
|
|
126
|
+
state: "missing" | "observed" | "unreadable";
|
|
127
|
+
hash?: string | undefined;
|
|
128
|
+
baseline_hash?: string | undefined;
|
|
129
|
+
}>;
|
|
130
|
+
planning_cache: z.ZodOptional<z.ZodObject<{
|
|
131
|
+
state: z.ZodEnum<["observed", "missing", "unreadable"]>;
|
|
132
|
+
hash: z.ZodOptional<z.ZodString>;
|
|
133
|
+
baseline_hash: z.ZodOptional<z.ZodString>;
|
|
134
|
+
}, "strip", z.ZodTypeAny, {
|
|
135
|
+
state: "missing" | "observed" | "unreadable";
|
|
136
|
+
hash?: string | undefined;
|
|
137
|
+
baseline_hash?: string | undefined;
|
|
138
|
+
}, {
|
|
139
|
+
state: "missing" | "observed" | "unreadable";
|
|
140
|
+
hash?: string | undefined;
|
|
141
|
+
baseline_hash?: string | undefined;
|
|
142
|
+
}>>;
|
|
143
|
+
}, "strip", z.ZodTypeAny, {
|
|
144
|
+
bootstrap: {
|
|
145
|
+
state: "missing" | "observed" | "unreadable";
|
|
146
|
+
hash?: string | undefined;
|
|
147
|
+
baseline_hash?: string | undefined;
|
|
148
|
+
};
|
|
149
|
+
source: "router" | "agent";
|
|
150
|
+
planning_cache?: {
|
|
151
|
+
state: "missing" | "observed" | "unreadable";
|
|
152
|
+
hash?: string | undefined;
|
|
153
|
+
baseline_hash?: string | undefined;
|
|
154
|
+
} | undefined;
|
|
155
|
+
}, {
|
|
156
|
+
bootstrap: {
|
|
157
|
+
state: "missing" | "observed" | "unreadable";
|
|
158
|
+
hash?: string | undefined;
|
|
159
|
+
baseline_hash?: string | undefined;
|
|
160
|
+
};
|
|
161
|
+
source: "router" | "agent";
|
|
162
|
+
planning_cache?: {
|
|
163
|
+
state: "missing" | "observed" | "unreadable";
|
|
164
|
+
hash?: string | undefined;
|
|
165
|
+
baseline_hash?: string | undefined;
|
|
166
|
+
} | undefined;
|
|
167
|
+
}>>;
|
|
168
|
+
}, "strip", z.ZodTypeAny, {
|
|
169
|
+
client_id?: string | undefined;
|
|
170
|
+
workspace_id?: string | undefined;
|
|
171
|
+
fetched_revision?: string | undefined;
|
|
172
|
+
seen_notice?: string | undefined;
|
|
173
|
+
evidence?: {
|
|
174
|
+
bootstrap: {
|
|
175
|
+
state: "missing" | "observed" | "unreadable";
|
|
176
|
+
hash?: string | undefined;
|
|
177
|
+
baseline_hash?: string | undefined;
|
|
178
|
+
};
|
|
179
|
+
source: "router" | "agent";
|
|
180
|
+
planning_cache?: {
|
|
181
|
+
state: "missing" | "observed" | "unreadable";
|
|
182
|
+
hash?: string | undefined;
|
|
183
|
+
baseline_hash?: string | undefined;
|
|
184
|
+
} | undefined;
|
|
185
|
+
} | undefined;
|
|
186
|
+
}, {
|
|
187
|
+
client_id?: string | undefined;
|
|
188
|
+
workspace_id?: string | undefined;
|
|
189
|
+
fetched_revision?: string | undefined;
|
|
190
|
+
seen_notice?: string | undefined;
|
|
191
|
+
evidence?: {
|
|
192
|
+
bootstrap: {
|
|
193
|
+
state: "missing" | "observed" | "unreadable";
|
|
194
|
+
hash?: string | undefined;
|
|
195
|
+
baseline_hash?: string | undefined;
|
|
196
|
+
};
|
|
197
|
+
source: "router" | "agent";
|
|
198
|
+
planning_cache?: {
|
|
199
|
+
state: "missing" | "observed" | "unreadable";
|
|
200
|
+
hash?: string | undefined;
|
|
201
|
+
baseline_hash?: string | undefined;
|
|
202
|
+
} | undefined;
|
|
203
|
+
} | undefined;
|
|
204
|
+
}>;
|
|
205
|
+
export type WorkflowContext = z.infer<typeof workflowContextSchema>;
|
|
206
|
+
export type FileObservation = z.infer<typeof observation>;
|
|
207
|
+
export declare const cacheSchema: z.ZodObject<{
|
|
208
|
+
protocol_version: z.ZodLiteral<1>;
|
|
209
|
+
host: z.ZodString;
|
|
210
|
+
fetched_at: z.ZodString;
|
|
211
|
+
bootstrap: z.ZodEffects<z.ZodObject<{
|
|
212
|
+
revision: z.ZodString;
|
|
213
|
+
content: z.ZodString;
|
|
214
|
+
summary: z.ZodString;
|
|
215
|
+
}, "strip", z.ZodTypeAny, {
|
|
216
|
+
revision: string;
|
|
217
|
+
content: string;
|
|
218
|
+
summary: string;
|
|
219
|
+
}, {
|
|
220
|
+
revision: string;
|
|
221
|
+
content: string;
|
|
222
|
+
summary: string;
|
|
223
|
+
}>, {
|
|
224
|
+
revision: string;
|
|
225
|
+
content: string;
|
|
226
|
+
summary: string;
|
|
227
|
+
}, {
|
|
228
|
+
revision: string;
|
|
229
|
+
content: string;
|
|
230
|
+
summary: string;
|
|
231
|
+
}>;
|
|
232
|
+
planning: z.ZodOptional<z.ZodEffects<z.ZodObject<{
|
|
233
|
+
revision: z.ZodString;
|
|
234
|
+
content: z.ZodString;
|
|
235
|
+
summary: z.ZodString;
|
|
236
|
+
}, "strip", z.ZodTypeAny, {
|
|
237
|
+
revision: string;
|
|
238
|
+
content: string;
|
|
239
|
+
summary: string;
|
|
240
|
+
}, {
|
|
241
|
+
revision: string;
|
|
242
|
+
content: string;
|
|
243
|
+
summary: string;
|
|
244
|
+
}>, {
|
|
245
|
+
revision: string;
|
|
246
|
+
content: string;
|
|
247
|
+
summary: string;
|
|
248
|
+
}, {
|
|
249
|
+
revision: string;
|
|
250
|
+
content: string;
|
|
251
|
+
summary: string;
|
|
252
|
+
}>>;
|
|
253
|
+
}, "strip", z.ZodTypeAny, {
|
|
254
|
+
protocol_version: 1;
|
|
255
|
+
bootstrap: {
|
|
256
|
+
revision: string;
|
|
257
|
+
content: string;
|
|
258
|
+
summary: string;
|
|
259
|
+
};
|
|
260
|
+
host: string;
|
|
261
|
+
fetched_at: string;
|
|
262
|
+
planning?: {
|
|
263
|
+
revision: string;
|
|
264
|
+
content: string;
|
|
265
|
+
summary: string;
|
|
266
|
+
} | undefined;
|
|
267
|
+
}, {
|
|
268
|
+
protocol_version: 1;
|
|
269
|
+
bootstrap: {
|
|
270
|
+
revision: string;
|
|
271
|
+
content: string;
|
|
272
|
+
summary: string;
|
|
273
|
+
};
|
|
274
|
+
host: string;
|
|
275
|
+
fetched_at: string;
|
|
276
|
+
planning?: {
|
|
277
|
+
revision: string;
|
|
278
|
+
content: string;
|
|
279
|
+
summary: string;
|
|
280
|
+
} | undefined;
|
|
281
|
+
}>;
|
|
282
|
+
export type WorkflowCache = z.infer<typeof cacheSchema>;
|
|
283
|
+
/** Match only bytes actually reported for this checkout, never a revision marker alone. */
|
|
284
|
+
export declare function compareObservation(observed: FileObservation | undefined, revision: string): "missing" | "unknown" | "matches_published" | "unrecognized" | "outdated" | "modified";
|
|
285
|
+
export declare function workflowStatus(publication: WorkflowPublication, context?: WorkflowContext): {
|
|
286
|
+
notice_id: string;
|
|
287
|
+
notify: boolean;
|
|
288
|
+
protocol_version: 1;
|
|
289
|
+
planning_revision: string;
|
|
290
|
+
bootstrap_revision: string;
|
|
291
|
+
session: string;
|
|
292
|
+
checkout: {
|
|
293
|
+
workspace_id: string | null;
|
|
294
|
+
evidence_source: string;
|
|
295
|
+
server_verified: boolean;
|
|
296
|
+
bootstrap: string;
|
|
297
|
+
planning_cache: string;
|
|
298
|
+
};
|
|
299
|
+
};
|
|
300
|
+
export {};
|
|
301
|
+
//# sourceMappingURL=workflow-contract.d.ts.map
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/** Shared, versioned wire contract for live guidance. Client evidence is never authentication. */
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
export const WORKFLOW_META = "ai.workpowers.speckle/workflow";
|
|
5
|
+
export const BOOTSTRAP_FILE = "SPECKLE.md";
|
|
6
|
+
export const WORKFLOW_CACHE_FILE = ".speckle-workflow.json";
|
|
7
|
+
export const hashContent = (content) => `sha256:${createHash("sha256").update(content, "utf8").digest("hex")}`;
|
|
8
|
+
const hash = z.string().regex(/^sha256:[a-f0-9]{64}$/);
|
|
9
|
+
const identity = z.string().min(1).max(160);
|
|
10
|
+
export const artifactSchema = z.object({
|
|
11
|
+
revision: hash,
|
|
12
|
+
content: z.string().min(1).max(64_000),
|
|
13
|
+
summary: z.string().min(1).max(500),
|
|
14
|
+
}).refine((a) => hashContent(a.content) === a.revision, "Content does not match its revision");
|
|
15
|
+
export const publicationSchema = z.object({
|
|
16
|
+
protocol_version: z.literal(1),
|
|
17
|
+
planning: artifactSchema,
|
|
18
|
+
bootstrap: artifactSchema,
|
|
19
|
+
});
|
|
20
|
+
const observation = z.object({
|
|
21
|
+
state: z.enum(["observed", "missing", "unreadable"]),
|
|
22
|
+
hash: hash.optional(),
|
|
23
|
+
baseline_hash: hash.optional(),
|
|
24
|
+
});
|
|
25
|
+
export const workflowContextSchema = z.object({
|
|
26
|
+
client_id: identity.optional(),
|
|
27
|
+
workspace_id: identity.optional(),
|
|
28
|
+
fetched_revision: hash.optional(),
|
|
29
|
+
seen_notice: hash.optional(),
|
|
30
|
+
evidence: z.object({
|
|
31
|
+
source: z.enum(["router", "agent"]),
|
|
32
|
+
bootstrap: observation,
|
|
33
|
+
planning_cache: observation.optional(),
|
|
34
|
+
}).optional(),
|
|
35
|
+
});
|
|
36
|
+
export const cacheSchema = z.object({
|
|
37
|
+
protocol_version: z.literal(1),
|
|
38
|
+
host: z.string().url(),
|
|
39
|
+
fetched_at: z.string().datetime(),
|
|
40
|
+
bootstrap: artifactSchema,
|
|
41
|
+
planning: artifactSchema.optional(),
|
|
42
|
+
});
|
|
43
|
+
/** Match only bytes actually reported for this checkout, never a revision marker alone. */
|
|
44
|
+
export function compareObservation(observed, revision) {
|
|
45
|
+
if (!observed || observed.state === "unreadable")
|
|
46
|
+
return "unknown";
|
|
47
|
+
if (observed.state === "missing")
|
|
48
|
+
return "missing";
|
|
49
|
+
if (!observed.hash)
|
|
50
|
+
return "unknown";
|
|
51
|
+
if (observed.hash === revision)
|
|
52
|
+
return "matches_published";
|
|
53
|
+
if (!observed.baseline_hash)
|
|
54
|
+
return "unrecognized";
|
|
55
|
+
return observed.hash === observed.baseline_hash ? "outdated" : "modified";
|
|
56
|
+
}
|
|
57
|
+
export function workflowStatus(publication, context = {}) {
|
|
58
|
+
// Evidence without checkout scope must not be applied to the current checkout.
|
|
59
|
+
const evidence = context.workspace_id ? context.evidence : undefined;
|
|
60
|
+
const status = {
|
|
61
|
+
protocol_version: 1,
|
|
62
|
+
planning_revision: publication.planning.revision,
|
|
63
|
+
bootstrap_revision: publication.bootstrap.revision,
|
|
64
|
+
session: context.fetched_revision === publication.planning.revision ? "fetched" :
|
|
65
|
+
context.fetched_revision ? "outdated" : "unknown",
|
|
66
|
+
checkout: {
|
|
67
|
+
workspace_id: context.workspace_id ?? null,
|
|
68
|
+
evidence_source: evidence?.source ?? "none",
|
|
69
|
+
server_verified: false,
|
|
70
|
+
bootstrap: compareObservation(evidence?.bootstrap, publication.bootstrap.revision),
|
|
71
|
+
planning_cache: compareObservation(evidence?.planning_cache, publication.planning.revision),
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
const noticeId = hashContent(JSON.stringify({ status, client_id: context.client_id ?? null }));
|
|
75
|
+
const needsNotice = status.session !== "fetched" || status.checkout.bootstrap !== "matches_published" ||
|
|
76
|
+
!["unknown", "missing", "matches_published"].includes(status.checkout.planning_cache);
|
|
77
|
+
return {
|
|
78
|
+
...status,
|
|
79
|
+
notice_id: noticeId,
|
|
80
|
+
// Receipt means delivered, not read, applied or approved. No cross-client cache.
|
|
81
|
+
notify: needsNotice && !(context.client_id && context.workspace_id && context.seen_notice === noticeId),
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=workflow-contract.js.map
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { type WorkflowCache, type WorkflowPublication } from "./workflow-contract.js";
|
|
2
|
+
/** Fixed filenames, regular files only. Do not follow an instruction/cache symlink. */
|
|
3
|
+
export declare function readManagedFile(file: string): string | undefined;
|
|
4
|
+
export declare function readWorkflowCache(root: string, host: string): WorkflowCache | undefined;
|
|
5
|
+
export declare function observeWorkflowFiles(root: string, host: string): {
|
|
6
|
+
source: "router";
|
|
7
|
+
bootstrap: {
|
|
8
|
+
state: "missing" | "observed" | "unreadable";
|
|
9
|
+
hash?: string | undefined;
|
|
10
|
+
baseline_hash?: string | undefined;
|
|
11
|
+
};
|
|
12
|
+
planning_cache: {
|
|
13
|
+
state: "missing" | "observed" | "unreadable";
|
|
14
|
+
hash?: string | undefined;
|
|
15
|
+
baseline_hash?: string | undefined;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
/** Refuse modified/unowned files before writing either artifact. Recheck before each rename. */
|
|
19
|
+
export declare function applyWorkflowFiles(root: string, host: string, input: WorkflowPublication, options?: {
|
|
20
|
+
apply?: boolean;
|
|
21
|
+
cache?: boolean;
|
|
22
|
+
replace?: (file: string, content: string, expected: string | undefined) => void;
|
|
23
|
+
}): {
|
|
24
|
+
applied: boolean;
|
|
25
|
+
files: {
|
|
26
|
+
path: string;
|
|
27
|
+
content: string;
|
|
28
|
+
}[];
|
|
29
|
+
next_step: string;
|
|
30
|
+
};
|
|
31
|
+
export declare function cachedWorkflowFallback(root: string | undefined, host: string): string;
|
|
32
|
+
//# sourceMappingURL=workflow-files.d.ts.map
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
/** Bounded local observations and explicit, conflict-preserving application of dedicated workflow files. */
|
|
2
|
+
import { constants, openSync, fstatSync, readSync, closeSync, lstatSync, writeFileSync, renameSync, unlinkSync } from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { randomUUID } from "node:crypto";
|
|
5
|
+
import { BOOTSTRAP_FILE, WORKFLOW_CACHE_FILE, hashContent, cacheSchema, publicationSchema } from "./workflow-contract.js";
|
|
6
|
+
const MAX_FILE_BYTES = 256_000;
|
|
7
|
+
/** Fixed filenames, regular files only. Do not follow an instruction/cache symlink. */
|
|
8
|
+
export function readManagedFile(file) {
|
|
9
|
+
let fd;
|
|
10
|
+
try {
|
|
11
|
+
fd = openSync(file, constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK);
|
|
12
|
+
}
|
|
13
|
+
catch (error) {
|
|
14
|
+
if (error.code === "ENOENT")
|
|
15
|
+
return undefined;
|
|
16
|
+
throw error;
|
|
17
|
+
}
|
|
18
|
+
try {
|
|
19
|
+
const stat = fstatSync(fd);
|
|
20
|
+
if (!stat.isFile() || stat.size > MAX_FILE_BYTES)
|
|
21
|
+
throw new Error("Managed workflow file is not a bounded regular file");
|
|
22
|
+
// Bound the read as well as the initial stat in case a file grows concurrently.
|
|
23
|
+
const buffer = Buffer.alloc(MAX_FILE_BYTES + 1);
|
|
24
|
+
let size = 0;
|
|
25
|
+
while (size < buffer.length) {
|
|
26
|
+
const count = readSync(fd, buffer, size, buffer.length - size, null);
|
|
27
|
+
if (count === 0)
|
|
28
|
+
break;
|
|
29
|
+
size += count;
|
|
30
|
+
}
|
|
31
|
+
if (size > MAX_FILE_BYTES)
|
|
32
|
+
throw new Error("Managed workflow file grew beyond the size limit");
|
|
33
|
+
return buffer.toString("utf8", 0, size);
|
|
34
|
+
}
|
|
35
|
+
finally {
|
|
36
|
+
closeSync(fd);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
export function readWorkflowCache(root, host) {
|
|
40
|
+
const raw = readManagedFile(path.join(root, WORKFLOW_CACHE_FILE));
|
|
41
|
+
if (raw === undefined)
|
|
42
|
+
return undefined;
|
|
43
|
+
const cache = cacheSchema.parse(JSON.parse(raw));
|
|
44
|
+
if (cache.host !== host)
|
|
45
|
+
throw new Error("Workflow receipt belongs to another Speckle host");
|
|
46
|
+
if (Date.parse(cache.fetched_at) > Date.now() + 60_000)
|
|
47
|
+
throw new Error("Workflow receipt has a future timestamp");
|
|
48
|
+
return cache;
|
|
49
|
+
}
|
|
50
|
+
export function observeWorkflowFiles(root, host) {
|
|
51
|
+
let cache;
|
|
52
|
+
let cacheUnreadable = false;
|
|
53
|
+
try {
|
|
54
|
+
cache = readWorkflowCache(root, host);
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
cacheUnreadable = true;
|
|
58
|
+
}
|
|
59
|
+
let bootstrap;
|
|
60
|
+
try {
|
|
61
|
+
const content = readManagedFile(path.join(root, BOOTSTRAP_FILE));
|
|
62
|
+
bootstrap = content === undefined ? { state: "missing" } : {
|
|
63
|
+
state: "observed", hash: hashContent(content), baseline_hash: cache?.bootstrap.revision,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
bootstrap = { state: "unreadable" };
|
|
68
|
+
}
|
|
69
|
+
const planning_cache = cacheUnreadable ? { state: "unreadable" } : cache?.planning ? {
|
|
70
|
+
state: "observed", hash: hashContent(cache.planning.content), baseline_hash: cache.planning.revision,
|
|
71
|
+
} : { state: "missing" };
|
|
72
|
+
return { source: "router", bootstrap, planning_cache };
|
|
73
|
+
}
|
|
74
|
+
/** Refuse modified/unowned files before writing either artifact. Recheck before each rename. */
|
|
75
|
+
export function applyWorkflowFiles(root, host, input, options = {}) {
|
|
76
|
+
const publication = publicationSchema.parse(input);
|
|
77
|
+
const bootstrapPath = path.join(root, BOOTSTRAP_FILE);
|
|
78
|
+
const cachePath = path.join(root, WORKFLOW_CACHE_FILE);
|
|
79
|
+
const previousBootstrap = readManagedFile(bootstrapPath);
|
|
80
|
+
const previousReceipt = readManagedFile(cachePath);
|
|
81
|
+
const previousCache = readWorkflowCache(root, host);
|
|
82
|
+
if (previousBootstrap !== undefined && previousBootstrap !== publication.bootstrap.content &&
|
|
83
|
+
hashContent(previousBootstrap) !== previousCache?.bootstrap.revision) {
|
|
84
|
+
throw new Error("SPECKLE.md is edited or unowned. Reconcile it manually; no files were written.");
|
|
85
|
+
}
|
|
86
|
+
const receipt = {
|
|
87
|
+
protocol_version: 1, host, fetched_at: new Date().toISOString(), bootstrap: publication.bootstrap,
|
|
88
|
+
// Once opted into caching, refresh it on subsequent apply operations as well.
|
|
89
|
+
...((options.cache || previousCache?.planning) ? { planning: publication.planning } : {}),
|
|
90
|
+
};
|
|
91
|
+
const files = [{ path: BOOTSTRAP_FILE, content: publication.bootstrap.content },
|
|
92
|
+
{ path: WORKFLOW_CACHE_FILE, content: JSON.stringify(receipt, null, 2) + "\n" }];
|
|
93
|
+
if (options.apply) {
|
|
94
|
+
const replace = options.replace ?? replaceManagedFile;
|
|
95
|
+
replace(bootstrapPath, files[0].content, previousBootstrap);
|
|
96
|
+
if (readManagedFile(bootstrapPath) !== files[0].content)
|
|
97
|
+
throw new Error("Bootstrap verification failed; receipt not advanced");
|
|
98
|
+
// The receipt advances only after verifying the installed bootstrap bytes.
|
|
99
|
+
replace(cachePath, files[1].content, previousReceipt);
|
|
100
|
+
if (readManagedFile(cachePath) !== files[1].content || readManagedFile(bootstrapPath) !== files[0].content) {
|
|
101
|
+
throw new Error("Workflow application did not verify; re-read files before retrying");
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return { applied: Boolean(options.apply), files,
|
|
105
|
+
next_step: "Review the diff. Add a reference to SPECKLE.md in AGENTS.md/CLAUDE.md after reconciling old Speckle guidance; preserve project conventions. Keep .speckle-workflow.json local (a receipt/optional cache), not a copied planning manual." };
|
|
106
|
+
}
|
|
107
|
+
function replaceManagedFile(file, content, expected) {
|
|
108
|
+
if (readManagedFile(file) !== expected)
|
|
109
|
+
throw new Error("Workflow file changed since preview; retry after reviewing it");
|
|
110
|
+
if (expected === content)
|
|
111
|
+
return;
|
|
112
|
+
const temp = `${file}.${randomUUID()}.tmp`;
|
|
113
|
+
try {
|
|
114
|
+
writeFileSync(temp, content, { flag: "wx", mode: 0o600 });
|
|
115
|
+
if (readManagedFile(file) !== expected)
|
|
116
|
+
throw new Error("Workflow file changed during update; preserved it");
|
|
117
|
+
// lstat refuses a dangling link (readManagedFile otherwise reports ENOENT).
|
|
118
|
+
try {
|
|
119
|
+
if (lstatSync(file).isSymbolicLink())
|
|
120
|
+
throw new Error("Refusing a workflow symlink");
|
|
121
|
+
}
|
|
122
|
+
catch (error) {
|
|
123
|
+
if (error.code !== "ENOENT")
|
|
124
|
+
throw error;
|
|
125
|
+
}
|
|
126
|
+
renameSync(temp, file);
|
|
127
|
+
}
|
|
128
|
+
finally {
|
|
129
|
+
try {
|
|
130
|
+
unlinkSync(temp);
|
|
131
|
+
}
|
|
132
|
+
catch { /* rename already consumed it */ }
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
export function cachedWorkflowFallback(root, host) {
|
|
136
|
+
try {
|
|
137
|
+
const cache = root ? readWorkflowCache(root, host) : undefined;
|
|
138
|
+
if (!cache?.planning)
|
|
139
|
+
return "Live Speckle guidance unavailable; no valid planning cache. Freshness unknown. Retry live retrieval; preserve existing gates.";
|
|
140
|
+
const age = Math.max(0, Math.floor((Date.now() - Date.parse(cache.fetched_at)) / 1000));
|
|
141
|
+
return `Live Speckle guidance unavailable. CACHED planning ${cache.planning.revision}, fetched ${cache.fetched_at} (${age}s ago). Current revision is UNKNOWN. Existing gates still apply.\n\n${cache.planning.content}`;
|
|
142
|
+
}
|
|
143
|
+
catch {
|
|
144
|
+
return "Live Speckle guidance unavailable; local receipt/cache is unreadable, corrupt or from another host. Freshness unknown; retry live retrieval.";
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
//# sourceMappingURL=workflow-files.js.map
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@workpowers/speckle",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Local MCP router for Speckle — resolves project context from a committed .speckle marker and forwards calls to the remote Speckle MCP endpoint.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
8
8
|
"bin": {
|
|
9
|
-
"speckle-mcp": "
|
|
9
|
+
"speckle-mcp": "bin/speckle-mcp.mjs"
|
|
10
10
|
},
|
|
11
11
|
"files": [
|
|
12
12
|
"bin",
|
|
@@ -20,7 +20,8 @@
|
|
|
20
20
|
"test": "vitest run"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@modelcontextprotocol/sdk": "^1.27.1"
|
|
23
|
+
"@modelcontextprotocol/sdk": "^1.27.1",
|
|
24
|
+
"zod": "^3.25.76"
|
|
24
25
|
},
|
|
25
26
|
"devDependencies": {
|
|
26
27
|
"@types/node": "^22.10.5",
|