deepclause-sdk 0.6.0 → 0.7.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 +57 -0
- package/dist/agent.d.ts +2 -0
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +5 -0
- package/dist/agent.js.map +1 -1
- package/dist/cli/agent-inbox.d.ts +25 -0
- package/dist/cli/agent-inbox.d.ts.map +1 -0
- package/dist/cli/agent-inbox.js +46 -0
- package/dist/cli/agent-inbox.js.map +1 -0
- package/dist/cli/config.d.ts +28 -28
- package/dist/cli/index.d.ts +1 -1
- package/dist/cli/index.js +7 -2
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/repl.d.ts +7 -0
- package/dist/cli/repl.d.ts.map +1 -1
- package/dist/cli/repl.js +181 -13
- package/dist/cli/repl.js.map +1 -1
- package/dist/cli/run.d.ts +1 -0
- package/dist/cli/run.d.ts.map +1 -1
- package/dist/cli/run.js +3 -1
- package/dist/cli/run.js.map +1 -1
- package/dist/cli/serve.d.ts +3 -0
- package/dist/cli/serve.d.ts.map +1 -0
- package/dist/cli/serve.js +131 -0
- package/dist/cli/serve.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/judge/llm.d.ts.map +1 -1
- package/dist/judge/llm.js +9 -4
- package/dist/judge/llm.js.map +1 -1
- package/dist/judge/types.d.ts +10 -0
- package/dist/judge/types.d.ts.map +1 -1
- package/dist/judge/types.js.map +1 -1
- package/dist/prolog-src/deepclause_mi.pl +370 -54
- package/dist/repl/agent-inbox.d.ts +73 -0
- package/dist/repl/agent-inbox.d.ts.map +1 -0
- package/dist/repl/agent-inbox.js +168 -0
- package/dist/repl/agent-inbox.js.map +1 -0
- package/dist/repl/agent.d.ts +14 -1
- package/dist/repl/agent.d.ts.map +1 -1
- package/dist/repl/agent.js +25 -6
- package/dist/repl/agent.js.map +1 -1
- package/dist/repl/backend.d.ts +6 -0
- package/dist/repl/backend.d.ts.map +1 -1
- package/dist/repl/backend.js +17 -2
- package/dist/repl/backend.js.map +1 -1
- package/dist/repl/event-history.d.ts.map +1 -1
- package/dist/repl/event-history.js +3 -0
- package/dist/repl/event-history.js.map +1 -1
- package/dist/repl/harness-tools.d.ts +9 -2
- package/dist/repl/harness-tools.d.ts.map +1 -1
- package/dist/repl/harness-tools.js +38 -14
- package/dist/repl/harness-tools.js.map +1 -1
- package/dist/repl/history.d.ts +14 -3
- package/dist/repl/history.d.ts.map +1 -1
- package/dist/repl/history.js +62 -5
- package/dist/repl/history.js.map +1 -1
- package/dist/repl/index.d.ts +11 -0
- package/dist/repl/index.d.ts.map +1 -1
- package/dist/repl/index.js +6 -2
- package/dist/repl/index.js.map +1 -1
- package/dist/repl/process-backend.d.ts +1 -0
- package/dist/repl/process-backend.d.ts.map +1 -1
- package/dist/repl/process-executor.d.ts +4 -0
- package/dist/repl/process-executor.d.ts.map +1 -1
- package/dist/repl/process-executor.js +36 -1
- package/dist/repl/process-executor.js.map +1 -1
- package/dist/repl/process-worker.d.ts.map +1 -1
- package/dist/repl/process-worker.js +33 -8
- package/dist/repl/process-worker.js.map +1 -1
- package/dist/repl/processes.d.ts +14 -1
- package/dist/repl/processes.d.ts.map +1 -1
- package/dist/repl/processes.js +8 -2
- package/dist/repl/processes.js.map +1 -1
- package/dist/repl/reference.d.ts.map +1 -1
- package/dist/repl/reference.js +4 -3
- package/dist/repl/reference.js.map +1 -1
- package/dist/repl/render.d.ts.map +1 -1
- package/dist/repl/render.js +13 -0
- package/dist/repl/render.js.map +1 -1
- package/dist/repl/session.d.ts +72 -5
- package/dist/repl/session.d.ts.map +1 -1
- package/dist/repl/session.js +595 -42
- package/dist/repl/session.js.map +1 -1
- package/dist/repl/toolset.d.ts +8 -0
- package/dist/repl/toolset.d.ts.map +1 -1
- package/dist/repl/toolset.js +53 -4
- package/dist/repl/toolset.js.map +1 -1
- package/dist/repl/tui/renderer.d.ts.map +1 -1
- package/dist/repl/tui/renderer.js +3 -1
- package/dist/repl/tui/renderer.js.map +1 -1
- package/dist/repl/work-hooks.d.ts +29 -0
- package/dist/repl/work-hooks.d.ts.map +1 -0
- package/dist/repl/work-hooks.js +117 -0
- package/dist/repl/work-hooks.js.map +1 -0
- package/dist/repl/worker-host.d.ts +2 -0
- package/dist/repl/worker-host.d.ts.map +1 -1
- package/dist/repl/worker-host.js +48 -4
- package/dist/repl/worker-host.js.map +1 -1
- package/dist/repl/worker-protocol.d.ts +23 -2
- package/dist/repl/worker-protocol.d.ts.map +1 -1
- package/dist/repl/worker-protocol.js +1 -1
- package/dist/runner.d.ts +2 -2
- package/dist/runner.d.ts.map +1 -1
- package/dist/runner.js +19 -3
- package/dist/runner.js.map +1 -1
- package/dist/runtime-identity.json +6 -6
- package/dist/serve/agent-broadcast.d.ts +29 -0
- package/dist/serve/agent-broadcast.d.ts.map +1 -0
- package/dist/serve/agent-broadcast.js +28 -0
- package/dist/serve/agent-broadcast.js.map +1 -0
- package/dist/serve/agent-preferences.d.ts +16 -0
- package/dist/serve/agent-preferences.d.ts.map +1 -0
- package/dist/serve/agent-preferences.js +42 -0
- package/dist/serve/agent-preferences.js.map +1 -0
- package/dist/serve/api-docs.d.ts +61 -0
- package/dist/serve/api-docs.d.ts.map +1 -0
- package/dist/serve/api-docs.js +122 -0
- package/dist/serve/api-docs.js.map +1 -0
- package/dist/serve/backend.d.ts +12 -0
- package/dist/serve/backend.d.ts.map +1 -0
- package/dist/serve/backend.js +52 -0
- package/dist/serve/backend.js.map +1 -0
- package/dist/serve/capabilities.d.ts +6 -0
- package/dist/serve/capabilities.d.ts.map +1 -0
- package/dist/serve/capabilities.js +21 -0
- package/dist/serve/capabilities.js.map +1 -0
- package/dist/serve/example-agent.d.ts +5 -0
- package/dist/serve/example-agent.d.ts.map +1 -0
- package/dist/serve/example-agent.js +5 -0
- package/dist/serve/example-agent.js.map +1 -0
- package/dist/serve/files.d.ts +55 -0
- package/dist/serve/files.d.ts.map +1 -0
- package/dist/serve/files.js +249 -0
- package/dist/serve/files.js.map +1 -0
- package/dist/serve/harness.d.ts +3 -0
- package/dist/serve/harness.d.ts.map +1 -0
- package/dist/serve/harness.js +53 -0
- package/dist/serve/harness.js.map +1 -0
- package/dist/serve/previews.d.ts +40 -0
- package/dist/serve/previews.d.ts.map +1 -0
- package/dist/serve/previews.js +240 -0
- package/dist/serve/previews.js.map +1 -0
- package/dist/serve/protocol.d.ts +228 -0
- package/dist/serve/protocol.d.ts.map +1 -0
- package/dist/serve/protocol.js +2 -0
- package/dist/serve/protocol.js.map +1 -0
- package/dist/serve/schedules.d.ts +85 -0
- package/dist/serve/schedules.d.ts.map +1 -0
- package/dist/serve/schedules.js +249 -0
- package/dist/serve/schedules.js.map +1 -0
- package/dist/serve/server.d.ts +50 -0
- package/dist/serve/server.d.ts.map +1 -0
- package/dist/serve/server.js +1696 -0
- package/dist/serve/server.js.map +1 -0
- package/dist/serve/session-worker.d.ts +2 -0
- package/dist/serve/session-worker.d.ts.map +1 -0
- package/dist/serve/session-worker.js +291 -0
- package/dist/serve/session-worker.js.map +1 -0
- package/dist/serve/sessions.d.ts +178 -0
- package/dist/serve/sessions.d.ts.map +1 -0
- package/dist/serve/sessions.js +905 -0
- package/dist/serve/sessions.js.map +1 -0
- package/dist/serve/storage.d.ts +41 -0
- package/dist/serve/storage.d.ts.map +1 -0
- package/dist/serve/storage.js +211 -0
- package/dist/serve/storage.js.map +1 -0
- package/dist/serve/ui/api-docs.html +17 -0
- package/dist/serve/ui/api-docs.js +36 -0
- package/dist/serve/ui/app.js +958 -0
- package/dist/serve/ui/authoring.js +92 -0
- package/dist/serve/ui/deepclause-logo.png +0 -0
- package/dist/serve/ui/deepclause-mark.svg +1 -0
- package/dist/serve/ui/diff.js +16 -0
- package/dist/serve/ui/dompurify-LICENSE.txt +202 -0
- package/dist/serve/ui/features.css +15 -0
- package/dist/serve/ui/files.js +13 -0
- package/dist/serve/ui/ibm-plex-mono-latin.woff2 +0 -0
- package/dist/serve/ui/ibmplexmono-OFL.txt +93 -0
- package/dist/serve/ui/icons.js +30 -0
- package/dist/serve/ui/index.html +68 -0
- package/dist/serve/ui/manrope-OFL.txt +93 -0
- package/dist/serve/ui/manrope-latin.woff2 +0 -0
- package/dist/serve/ui/markdown.js +38 -0
- package/dist/serve/ui/marked-LICENSE.txt +44 -0
- package/dist/serve/ui/marked.js +88 -0
- package/dist/serve/ui/purify.js +2454 -0
- package/dist/serve/ui/style.css +249 -0
- package/dist/serve/ui/web-work.css +247 -0
- package/dist/serve/ui/web.css +1848 -0
- package/dist/serve/workflow-bundles.d.ts +8 -0
- package/dist/serve/workflow-bundles.d.ts.map +1 -0
- package/dist/serve/workflow-bundles.js +78 -0
- package/dist/serve/workflow-bundles.js.map +1 -0
- package/dist/serve/workflow-calls.d.ts +6 -0
- package/dist/serve/workflow-calls.d.ts.map +1 -0
- package/dist/serve/workflow-calls.js +13 -0
- package/dist/serve/workflow-calls.js.map +1 -0
- package/dist/serve/workflows.d.ts +93 -0
- package/dist/serve/workflows.d.ts.map +1 -0
- package/dist/serve/workflows.js +219 -0
- package/dist/serve/workflows.js.map +1 -0
- package/dist/system/assets/docs/AGENT_PROMPT.md +6 -6
- package/dist/system/assets/docs/DML_AUTHORING.md +80 -2
- package/dist/system/assets/docs/DML_PROCESSES.md +24 -0
- package/dist/system/assets/docs/DML_REFERENCE.md +98 -10
- package/dist/system/assets/docs/DML_SHELL.md +149 -7
- package/dist/system/assets/docs/DML_TASKS.md +10 -3
- package/dist/system/assets/docs/LOCAL_AGENT_PROMPT.md +6 -6
- package/dist/system/environment.d.ts +5 -1
- package/dist/system/environment.d.ts.map +1 -1
- package/dist/system/environment.js +14 -8
- package/dist/system/environment.js.map +1 -1
- package/dist/system/runtime/agentvm-manager.d.ts +12 -1
- package/dist/system/runtime/agentvm-manager.d.ts.map +1 -1
- package/dist/system/runtime/agentvm-manager.js +136 -20
- package/dist/system/runtime/agentvm-manager.js.map +1 -1
- package/dist/system/runtime/shell-manager.d.ts +3 -0
- package/dist/system/runtime/shell-manager.d.ts.map +1 -1
- package/dist/system/runtime/shell-manager.js +1 -1
- package/dist/system/runtime/shell-manager.js.map +1 -1
- package/dist/system/timezone.d.ts +20 -0
- package/dist/system/timezone.d.ts.map +1 -0
- package/dist/system/timezone.js +37 -0
- package/dist/system/timezone.js.map +1 -0
- package/dist/types.d.ts +37 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/work/index.d.ts +13 -3
- package/dist/work/index.d.ts.map +1 -1
- package/dist/work/index.js +80 -15
- package/dist/work/index.js.map +1 -1
- package/docs/DEEP_RESEARCH_EXAMPLE.md +127 -0
- package/docs/SERVE.md +664 -0
- package/docs/WORK_AGENT_HOOKS_PLAN.md +416 -0
- package/docs/WORK_AGENT_INBOX.md +140 -0
- package/docs/WORK_AGENT_INBOX_PLAN.md +91 -0
- package/docs/WORK_MODE.md +269 -0
- package/package.json +24 -2
- package/sdk-examples/deep-research.dml +144 -0
- package/sdk-examples/deep-research.py +502 -0
- package/sdk-examples/hooked-agent.dml +49 -0
- package/sdk-examples/subagent-inbox.dml +66 -0
- package/src/prolog-src/deepclause_mi.pl +370 -54
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { WorkSpec } from '../work/index.js';
|
|
2
|
+
import type { WorkflowDraft } from './workflows.js';
|
|
3
|
+
export interface DeploymentBundle extends WorkflowDraft {
|
|
4
|
+
format: 'workflow-v1';
|
|
5
|
+
}
|
|
6
|
+
/** Reviewed build provenance, captured once at startup. Never guess a Prolog call graph. */
|
|
7
|
+
export declare function loadDeploymentBundles(workspace: string, file: string | undefined, source: string, spec: WorkSpec, stateDir: string): Promise<Map<string, DeploymentBundle>>;
|
|
8
|
+
//# sourceMappingURL=workflow-bundles.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workflow-bundles.d.ts","sourceRoot":"","sources":["../../src/serve/workflow-bundles.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAC,QAAQ,EAAC,MAAM,kBAAkB,CAAC;AAC/C,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,gBAAgB,CAAC;AAKlD,MAAM,WAAW,gBAAiB,SAAQ,aAAa;IAAE,MAAM,EAAC,aAAa,CAAC;CAAC;AAI/E,4FAA4F;AAC5F,wBAAsB,qBAAqB,CAAC,SAAS,EAAC,MAAM,EAAC,IAAI,EAAC,MAAM,GAAC,SAAS,EAAC,MAAM,EAAC,MAAM,EAAC,IAAI,EAAC,QAAQ,EAAC,QAAQ,EAAC,MAAM,GAAE,OAAO,CAAC,GAAG,CAAC,MAAM,EAAC,gBAAgB,CAAC,CAAC,CAgCpK"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import * as fs from 'node:fs/promises';
|
|
3
|
+
import * as path from 'node:path';
|
|
4
|
+
import { WorkspaceFiles } from './files.js';
|
|
5
|
+
const digest = (bytes) => createHash('sha256').update(bytes).digest('hex');
|
|
6
|
+
const MAX = 1024 * 1024;
|
|
7
|
+
/** Reviewed build provenance, captured once at startup. Never guess a Prolog call graph. */
|
|
8
|
+
export async function loadDeploymentBundles(workspace, file, source, spec, stateDir) {
|
|
9
|
+
const bundles = new Map();
|
|
10
|
+
if (!file)
|
|
11
|
+
return bundles;
|
|
12
|
+
const resolvedFile = path.resolve(workspace, file), extension = path.extname(resolvedFile);
|
|
13
|
+
const filename = resolvedFile.slice(0, extension ? -extension.length : undefined) + '.workflows.json';
|
|
14
|
+
const stat = await fs.lstat(filename).catch(error => { if (error.code === 'ENOENT')
|
|
15
|
+
return; throw error; });
|
|
16
|
+
const files = new WorkspaceFiles(workspace, stateDir), relative = path.relative(workspace, filename).split(path.sep).join('/');
|
|
17
|
+
const pinned = new Map((spec.snapshot?.scripts ?? []).map(script => [script.path, script.sha256]));
|
|
18
|
+
async function capture(link, limit = MAX) {
|
|
19
|
+
if (!link || typeof link.path !== 'string' || !/^[a-f0-9]{64}$/.test(link.sha256) || pinned.get(link.path) !== link.sha256)
|
|
20
|
+
throw new Error('Workflow bundle files must be pinned by the deployment');
|
|
21
|
+
const resolved = await files.resolve(link.path), info = await fs.stat(resolved.target);
|
|
22
|
+
if (info.size > limit)
|
|
23
|
+
throw new Error('Workflow bundle file exceeds limits');
|
|
24
|
+
const bytes = await fs.readFile(resolved.target);
|
|
25
|
+
if (digest(bytes) !== link.sha256)
|
|
26
|
+
throw new Error('Workflow bundle file changed; assemble and explicitly restart before editing');
|
|
27
|
+
return bytes.toString('utf8');
|
|
28
|
+
}
|
|
29
|
+
if (!stat) {
|
|
30
|
+
// A standalone single-workflow file is already an explicit ownership unit.
|
|
31
|
+
// The strict native workflow loader still rejects legacy shell/Agent code.
|
|
32
|
+
if (spec.shell?.kind === 'workflow' && spec.shell.workflows.length === 1 && /(?:^|\n)\s*workflow\s*\(/.test(source) && !/(?:^|\n)\s*shell\s*\(/.test(source)) {
|
|
33
|
+
if ((spec.snapshot?.scripts?.length ?? 0) > 64)
|
|
34
|
+
throw new Error('Workflow bundle asset count exceeds limits');
|
|
35
|
+
const assets = [];
|
|
36
|
+
let size = 0;
|
|
37
|
+
for (const asset of spec.snapshot?.scripts ?? []) {
|
|
38
|
+
const content = await capture(asset, 8 * MAX);
|
|
39
|
+
size += Buffer.byteLength(content);
|
|
40
|
+
if (size > 8 * MAX)
|
|
41
|
+
throw new Error('Workflow bundle assets exceed limits');
|
|
42
|
+
assets.push({ path: asset.path, content });
|
|
43
|
+
}
|
|
44
|
+
bundles.set(spec.shell.workflows[0].name, { format: 'workflow-v1', source, assets, modules: spec.snapshot?.modules });
|
|
45
|
+
}
|
|
46
|
+
return bundles;
|
|
47
|
+
}
|
|
48
|
+
const pinnedManifest = pinned.get(relative);
|
|
49
|
+
if (!pinnedManifest)
|
|
50
|
+
throw new Error('Workflow manifest is not linked by the deployment');
|
|
51
|
+
const text = await capture({ path: relative, sha256: pinnedManifest });
|
|
52
|
+
const manifest = JSON.parse(text);
|
|
53
|
+
if (manifest.v !== 1 || manifest.generatedBy !== 'deepclause-harness' || manifest.harnessSha256 !== digest(source) || !Array.isArray(manifest.workflows) || manifest.workflows.length > 128)
|
|
54
|
+
throw new Error('Invalid or stale workflow bundle manifest');
|
|
55
|
+
for (const entry of manifest.workflows) {
|
|
56
|
+
if (!entry || typeof entry.name !== 'string' || bundles.has(entry.name) || !spec.shell?.workflows.some(flow => flow.name === entry.name) || !Array.isArray(entry.assets) || entry.assets.length > 64 || !Array.isArray(entry.dependency?.exports) || !entry.dependency.exports.length || entry.dependency.exports.length > 128 || new Set(entry.dependency.exports).size !== entry.dependency.exports.length || entry.dependency.exports.some(item => typeof item !== 'string' || !/^bp_[a-zA-Z0-9_]+\/(?:[0-9]|[12][0-9]|3[0-2])$/.test(item) || item === 'bp_workflow_policy/0'))
|
|
57
|
+
throw new Error('Invalid workflow bundle entry');
|
|
58
|
+
const own = await capture(entry.source), support = await capture(entry.dependency), exports = [...entry.dependency.exports, 'bp_workflow_policy/0'].join(',');
|
|
59
|
+
const dependencySource = `:- export([${exports}]).\nbp_workflow_policy :- bp_authorize(workflow,${JSON.stringify(entry.name)}).\n${support}`, hash = digest(dependencySource);
|
|
60
|
+
const modules = [{ id: 'dcmod_workflow_support_' + hash.slice(0, 16), name: 'workflow_support', version: hash, hash, source: dependencySource }];
|
|
61
|
+
const assets = [];
|
|
62
|
+
let size = 0;
|
|
63
|
+
const assetPaths = new Set();
|
|
64
|
+
for (const asset of entry.assets) {
|
|
65
|
+
if (assetPaths.has(asset?.path))
|
|
66
|
+
throw new Error('Duplicate workflow bundle asset');
|
|
67
|
+
assetPaths.add(asset?.path);
|
|
68
|
+
const content = await capture(asset, 8 * MAX);
|
|
69
|
+
size += Buffer.byteLength(content);
|
|
70
|
+
if (size > 8 * MAX)
|
|
71
|
+
throw new Error('Workflow bundle assets exceed limits');
|
|
72
|
+
assets.push({ path: asset.path, content });
|
|
73
|
+
}
|
|
74
|
+
bundles.set(entry.name, { format: 'workflow-v1', source: `:- use_harness(workflow_support,version(${JSON.stringify(hash)}),[${exports}]).\n${own}`, assets, modules });
|
|
75
|
+
}
|
|
76
|
+
return bundles;
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=workflow-bundles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workflow-bundles.js","sourceRoot":"","sources":["../../src/serve/workflow-bundles.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,aAAa,CAAC;AACvC,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACvC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAGlC,OAAO,EAAC,cAAc,EAAC,MAAM,YAAY,CAAC;AAE1C,MAAM,MAAM,GAAC,CAAC,KAAuB,EAAC,EAAE,CAAA,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACzF,MAAM,GAAG,GAAC,IAAI,GAAC,IAAI,CAAC;AAKpB,4FAA4F;AAC5F,MAAM,CAAC,KAAK,UAAU,qBAAqB,CAAC,SAAgB,EAAC,IAAqB,EAAC,MAAa,EAAC,IAAa,EAAC,QAAe;IAC5H,MAAM,OAAO,GAAC,IAAI,GAAG,EAA2B,CAAC;IAAA,IAAG,CAAC,IAAI;QAAC,OAAO,OAAO,CAAC;IACzE,MAAM,YAAY,GAAC,IAAI,CAAC,OAAO,CAAC,SAAS,EAAC,IAAI,CAAC,EAAC,SAAS,GAAC,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;IACrF,MAAM,QAAQ,GAAC,YAAY,CAAC,KAAK,CAAC,CAAC,EAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,GAAC,iBAAiB,CAAC;IACjG,MAAM,IAAI,GAAC,MAAM,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,CA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AU,CAAC;QAC9D,KAAI,MAAM,KAAK,IAAI,KAAK,CAAC,MAAM,EAAC,CAAC;YAAA,IAAG,UAAU,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC;gBAAC,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;YAAA,UAAU,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;YAAA,MAAM,OAAO,GAAC,MAAM,OAAO,CAAC,KAAK,EAAC,CAAC,GAAC,GAAG,CAAC,CAAC;YAAA,IAAI,IAAE,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;YAAA,IAAG,IAAI,GAAC,CAAC,GAAC,GAAG;gBAAC,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAC;YAAA,MAAM,CAAC,IAAI,CAAC,EAAC,IAAI,EAAC,KAAK,CAAC,IAAI,EAAC,OAAO,EAAC,CAAC,CAAC;QAAA,CAAC;QACvU,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,EAAC,EAAC,MAAM,EAAC,aAAa,EAAC,MAAM,EAAC,2CAA2C,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,MAAM,OAAO,QAAQ,GAAG,EAAE,EAAC,MAAM,EAAC,OAAO,EAAC,CAAC,CAAC;IACjK,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { WorkflowCallScope } from './sessions.js';
|
|
2
|
+
export declare const WORKFLOW_CALL_DEPTH = 4;
|
|
3
|
+
export declare const WORKFLOW_CALL_BUDGET = 16;
|
|
4
|
+
/** Shared root-operation budget, but a separate immutable ancestry for each child. */
|
|
5
|
+
export declare function descendWorkflowCall(scope: WorkflowCallScope, key: string): WorkflowCallScope;
|
|
6
|
+
//# sourceMappingURL=workflow-calls.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workflow-calls.d.ts","sourceRoot":"","sources":["../../src/serve/workflow-calls.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAEvD,eAAO,MAAM,mBAAmB,IAAI,CAAC;AACrC,eAAO,MAAM,oBAAoB,KAAK,CAAC;AAEvC,sFAAsF;AACtF,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,iBAAiB,EAAE,GAAG,EAAE,MAAM,GAAG,iBAAiB,CAK5F"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export const WORKFLOW_CALL_DEPTH = 4;
|
|
2
|
+
export const WORKFLOW_CALL_BUDGET = 16;
|
|
3
|
+
/** Shared root-operation budget, but a separate immutable ancestry for each child. */
|
|
4
|
+
export function descendWorkflowCall(scope, key) {
|
|
5
|
+
if (++scope.budget.calls > WORKFLOW_CALL_BUDGET)
|
|
6
|
+
throw new Error(`Workflow call budget exhausted (${WORKFLOW_CALL_BUDGET})`);
|
|
7
|
+
if (scope.ancestors.includes(key))
|
|
8
|
+
throw new Error('Recursive workflow call refused');
|
|
9
|
+
if (scope.ancestors.length >= WORKFLOW_CALL_DEPTH)
|
|
10
|
+
throw new Error(`Workflow call depth limit reached (${WORKFLOW_CALL_DEPTH})`);
|
|
11
|
+
return { budget: scope.budget, ancestors: [...scope.ancestors, key] };
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=workflow-calls.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workflow-calls.js","sourceRoot":"","sources":["../../src/serve/workflow-calls.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC;AACrC,MAAM,CAAC,MAAM,oBAAoB,GAAG,EAAE,CAAC;AAEvC,sFAAsF;AACtF,MAAM,UAAU,mBAAmB,CAAC,KAAwB,EAAE,GAAW;IACvE,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,KAAK,GAAG,oBAAoB;QAAE,MAAM,IAAI,KAAK,CAAC,mCAAmC,oBAAoB,GAAG,CAAC,CAAC;IAC7H,IAAI,KAAK,CAAC,SAAS,CAAC,QAAQ,CAAC,GAAG,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;IACtF,IAAI,KAAK,CAAC,SAAS,CAAC,MAAM,IAAI,mBAAmB;QAAE,MAAM,IAAI,KAAK,CAAC,sCAAsC,mBAAmB,GAAG,CAAC,CAAC;IACjI,OAAO,EAAC,MAAM,EAAC,KAAK,CAAC,MAAM,EAAC,SAAS,EAAC,CAAC,GAAG,KAAK,CAAC,SAAS,EAAC,GAAG,CAAC,EAAC,CAAC;AAClE,CAAC"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import type { WorkSpec, WorkSnapshot } from '../work/index.js';
|
|
2
|
+
import type { ShellWorkflow } from '../types.js';
|
|
3
|
+
export interface WorkflowDraft {
|
|
4
|
+
format?: 'workflow-v1';
|
|
5
|
+
modules?: import('../repl/session.js').HarnessModuleSource[];
|
|
6
|
+
source: string;
|
|
7
|
+
assets: Array<{
|
|
8
|
+
path: string;
|
|
9
|
+
content: string;
|
|
10
|
+
}>;
|
|
11
|
+
authorVersion?: number;
|
|
12
|
+
agentId?: string;
|
|
13
|
+
}
|
|
14
|
+
export interface WorkflowRevision {
|
|
15
|
+
id: string;
|
|
16
|
+
version: number;
|
|
17
|
+
revision: string;
|
|
18
|
+
digest: string;
|
|
19
|
+
createdAt: string;
|
|
20
|
+
entries: ShellWorkflow[];
|
|
21
|
+
snapshot: WorkSnapshot;
|
|
22
|
+
draft: WorkflowDraft;
|
|
23
|
+
}
|
|
24
|
+
export declare const workflowId: (id: string) => string;
|
|
25
|
+
/**
|
|
26
|
+
* Rewrite links to the bundle's own files into the immutable revision copy.
|
|
27
|
+
*
|
|
28
|
+
* Publishing moves assets out of the author's draft into a version directory.
|
|
29
|
+
* A workflow that names one of its own files by its bundle-relative path —
|
|
30
|
+
* `script_file(Name, "scripts/fetch.py")` or `exec(bash(argv:["python3","scripts/fetch.py"]))` —
|
|
31
|
+
* must keep working after that move, so every exact literal equal to a linked
|
|
32
|
+
* asset path is resolved to the published path. Prose and longer strings are
|
|
33
|
+
* untouched: only a literal whose whole value is the asset path is rewritten.
|
|
34
|
+
*/
|
|
35
|
+
export declare function relocateAssetReferences(source: string, assets: ReadonlyArray<{
|
|
36
|
+
path: string;
|
|
37
|
+
published: string;
|
|
38
|
+
}>): string;
|
|
39
|
+
/** Single-host publication index. HEAD is the sole activation point; versions/assets are write-once. */
|
|
40
|
+
export declare class WorkflowCatalog {
|
|
41
|
+
readonly workspace: string;
|
|
42
|
+
readonly directory: string;
|
|
43
|
+
private readonly validate;
|
|
44
|
+
private readonly reserved;
|
|
45
|
+
private heads;
|
|
46
|
+
private tail;
|
|
47
|
+
private deleted;
|
|
48
|
+
private hidden;
|
|
49
|
+
private get registryFile();
|
|
50
|
+
isDeleted(id: string): boolean;
|
|
51
|
+
has(id: string): boolean;
|
|
52
|
+
hiddenDeployment(): string[];
|
|
53
|
+
private saveRegistry;
|
|
54
|
+
/** Tombstone first. Pinned run assets remain private and immutable, never executable via the catalog. */
|
|
55
|
+
remove(id: string): Promise<void>;
|
|
56
|
+
hideDeployment(name: string): Promise<void>;
|
|
57
|
+
constructor(workspace: string, directory: string, validate: (source: string, assets: readonly string[], modules?: WorkflowDraft['modules'], workflowOnly?: boolean) => Promise<WorkSpec>, reserved: string[]);
|
|
58
|
+
list(): {
|
|
59
|
+
id: string;
|
|
60
|
+
version: number;
|
|
61
|
+
revision: string;
|
|
62
|
+
digest: string;
|
|
63
|
+
createdAt: string;
|
|
64
|
+
entries: ShellWorkflow[];
|
|
65
|
+
}[];
|
|
66
|
+
entries(): {
|
|
67
|
+
revision: string;
|
|
68
|
+
workflowId: string;
|
|
69
|
+
version: number;
|
|
70
|
+
editable: boolean;
|
|
71
|
+
description?: string;
|
|
72
|
+
name: string;
|
|
73
|
+
goal: string;
|
|
74
|
+
inputs: import("../types.js").ShellWorkflowArg[];
|
|
75
|
+
outputs: import("../types.js").ShellWorkflowArg[];
|
|
76
|
+
}[];
|
|
77
|
+
current(id: string): WorkflowRevision | undefined;
|
|
78
|
+
versions(id: string): Promise<{
|
|
79
|
+
version: number;
|
|
80
|
+
revision: string;
|
|
81
|
+
createdAt: string;
|
|
82
|
+
entries: string[];
|
|
83
|
+
authorVersion: number | undefined;
|
|
84
|
+
}[]>;
|
|
85
|
+
read(id: string, revision?: string): Promise<WorkflowRevision>;
|
|
86
|
+
private readRevision;
|
|
87
|
+
open(): Promise<void>;
|
|
88
|
+
private checkNames;
|
|
89
|
+
publish(id: string, expected: string | undefined, draft: WorkflowDraft, signal?: AbortSignal): Promise<WorkflowRevision>;
|
|
90
|
+
private publishInner;
|
|
91
|
+
}
|
|
92
|
+
export declare function workflowSeed(name: string): string;
|
|
93
|
+
//# sourceMappingURL=workflows.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workflows.d.ts","sourceRoot":"","sources":["../../src/serve/workflows.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAC/D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEjD,MAAM,WAAW,aAAa;IAC5B,MAAM,CAAC,EAAC,aAAa,CAAC;IACtB,OAAO,CAAC,EAAC,OAAO,oBAAoB,EAAE,mBAAmB,EAAE,CAAC;IAC5D,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACjD,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AACD,MAAM,WAAW,gBAAgB;IAC/B,EAAE,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM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AtDA,MAAM;iBAAW,MAAM;kBAAY,MAAM;gBAAU,MAAM;mBAAa,MAAM;iBACvE,aAAa,EAAE;;IAsDxB,OAAO;;;;;;;;;;;IACP,OAAO,CAAC,EAAE,EAAE,MAAM;IACZ,QAAQ,CAAC,EAAE,EAAE,MAAM;;;;;;;IASnB,IAAI,CAAC,EAAE,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC;YAQtD,YAAY;IAKpB,IAAI;IAmBV,OAAO,CAAC,UAAU;IAQlB,OAAO,CAAC,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,SAAS,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,gBAAgB,CAAC;YAI1G,YAAY;CAuC3B;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,UAGxC"}
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import * as fs from 'node:fs/promises';
|
|
2
|
+
import * as path from 'node:path';
|
|
3
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
4
|
+
import { atomicJson } from './storage.js';
|
|
5
|
+
const hash = (text) => createHash('sha256').update(text).digest('hex');
|
|
6
|
+
export const workflowId = (id) => { if (!/^[a-z][a-z0-9_]{0,63}$/.test(id))
|
|
7
|
+
throw new Error('Workflow ID must be lowercase letters, digits or underscores (max 64)'); return id; };
|
|
8
|
+
const literal = (text) => JSON.stringify(text);
|
|
9
|
+
const assetPattern = (text) => text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
10
|
+
/**
|
|
11
|
+
* Rewrite links to the bundle's own files into the immutable revision copy.
|
|
12
|
+
*
|
|
13
|
+
* Publishing moves assets out of the author's draft into a version directory.
|
|
14
|
+
* A workflow that names one of its own files by its bundle-relative path —
|
|
15
|
+
* `script_file(Name, "scripts/fetch.py")` or `exec(bash(argv:["python3","scripts/fetch.py"]))` —
|
|
16
|
+
* must keep working after that move, so every exact literal equal to a linked
|
|
17
|
+
* asset path is resolved to the published path. Prose and longer strings are
|
|
18
|
+
* untouched: only a literal whose whole value is the asset path is rewritten.
|
|
19
|
+
*/
|
|
20
|
+
export function relocateAssetReferences(source, assets) {
|
|
21
|
+
let out = source;
|
|
22
|
+
for (const asset of assets) {
|
|
23
|
+
for (const value of [asset.path, `./${asset.path}`]) {
|
|
24
|
+
if (!value)
|
|
25
|
+
continue;
|
|
26
|
+
const double = assetPattern(value), single = assetPattern(value.replace(/'/g, "''"));
|
|
27
|
+
const quotedAtom = `'${asset.published.replace(/'/g, "''")}'`;
|
|
28
|
+
out = out.replace(new RegExp(`(script_file\\([^,]+,\\s*)("${double}"|'${single}')(\\s*\\))`, 'g'), (_match, start, _path, end) => start + literal(asset.published) + end);
|
|
29
|
+
out = out.replace(new RegExp(`"${double}"`, 'g'), literal(asset.published));
|
|
30
|
+
out = out.replace(new RegExp(`'${single}'`, 'g'), quotedAtom);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return out;
|
|
34
|
+
}
|
|
35
|
+
/** Single-host publication index. HEAD is the sole activation point; versions/assets are write-once. */
|
|
36
|
+
export class WorkflowCatalog {
|
|
37
|
+
workspace;
|
|
38
|
+
directory;
|
|
39
|
+
validate;
|
|
40
|
+
reserved;
|
|
41
|
+
heads = new Map();
|
|
42
|
+
tail = Promise.resolve();
|
|
43
|
+
deleted = new Set();
|
|
44
|
+
hidden = new Set();
|
|
45
|
+
get registryFile() { return path.join(path.dirname(this.directory), 'workflow-registry.json'); }
|
|
46
|
+
isDeleted(id) { return this.deleted.has(id); }
|
|
47
|
+
has(id) { return this.heads.has(id); }
|
|
48
|
+
hiddenDeployment() { return [...this.hidden]; }
|
|
49
|
+
async saveRegistry(deleted = this.deleted, hidden = this.hidden) { await atomicJson(this.registryFile, { v: 1, deleted: [...deleted], hidden: [...hidden] }); }
|
|
50
|
+
/** Tombstone first. Pinned run assets remain private and immutable, never executable via the catalog. */
|
|
51
|
+
remove(id) {
|
|
52
|
+
workflowId(id);
|
|
53
|
+
const job = this.tail.catch(() => { }).then(async () => { const deleted = new Set(this.deleted).add(id); await this.saveRegistry(deleted); this.deleted = deleted; this.heads.delete(id); await fs.rm(path.join(this.directory, id, 'HEAD.json'), { force: true }); });
|
|
54
|
+
this.tail = job;
|
|
55
|
+
return job;
|
|
56
|
+
}
|
|
57
|
+
hideDeployment(name) {
|
|
58
|
+
if (!this.reserved.includes(name))
|
|
59
|
+
throw new Error('Unknown bundled workflow');
|
|
60
|
+
const job = this.tail.catch(() => { }).then(async () => { const hidden = new Set(this.hidden).add(name); await this.saveRegistry(this.deleted, hidden); this.hidden = hidden; });
|
|
61
|
+
this.tail = job;
|
|
62
|
+
return job;
|
|
63
|
+
}
|
|
64
|
+
constructor(workspace, directory, validate, reserved) {
|
|
65
|
+
this.workspace = workspace;
|
|
66
|
+
this.directory = directory;
|
|
67
|
+
this.validate = validate;
|
|
68
|
+
this.reserved = reserved;
|
|
69
|
+
}
|
|
70
|
+
list() { return [...this.heads.values()].map(({ draft: _draft, snapshot: _snapshot, ...view }) => structuredClone(view)); }
|
|
71
|
+
entries() { return [...this.heads.values()].flatMap(item => item.entries.map(entry => ({ ...entry, revision: item.revision, workflowId: item.id, version: item.version, editable: item.draft.format === 'workflow-v1' }))); }
|
|
72
|
+
current(id) { const value = this.heads.get(workflowId(id)); return value ? structuredClone(value) : undefined; }
|
|
73
|
+
async versions(id) {
|
|
74
|
+
workflowId(id);
|
|
75
|
+
if (!this.heads.has(id))
|
|
76
|
+
throw new Error('Unknown workflow');
|
|
77
|
+
const names = await fs.readdir(path.join(this.directory, id, 'versions'));
|
|
78
|
+
const versions = [];
|
|
79
|
+
for (const revision of names.filter(name => /^[a-f0-9]{32}$/.test(name)).slice(-200)) {
|
|
80
|
+
try {
|
|
81
|
+
const value = await this.readRevision(id, revision);
|
|
82
|
+
versions.push({ version: value.version, revision: value.revision, createdAt: value.createdAt, entries: value.entries.map(entry => entry.name), authorVersion: value.draft.authorVersion });
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
if (error.code !== 'ENOENT')
|
|
86
|
+
throw error;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return versions.sort((a, b) => b.version - a.version);
|
|
90
|
+
}
|
|
91
|
+
async read(id, revision) {
|
|
92
|
+
workflowId(id);
|
|
93
|
+
if (this.deleted.has(id))
|
|
94
|
+
throw new Error('Workflow was deleted');
|
|
95
|
+
const head = this.heads.get(id);
|
|
96
|
+
if (!head)
|
|
97
|
+
throw new Error('Unknown workflow');
|
|
98
|
+
if (!revision || revision === head.revision)
|
|
99
|
+
return structuredClone(head);
|
|
100
|
+
if (!/^[a-f0-9]{32}$/.test(revision))
|
|
101
|
+
throw new Error('Invalid workflow revision');
|
|
102
|
+
return this.readRevision(id, revision);
|
|
103
|
+
}
|
|
104
|
+
async readRevision(id, revision) {
|
|
105
|
+
const value = JSON.parse(await fs.readFile(path.join(this.directory, id, 'versions', revision, 'version.json'), 'utf8'));
|
|
106
|
+
if (value.id !== id || value.revision !== revision || !Array.isArray(value.entries) || !value.snapshot?.source || value.digest !== hash(JSON.stringify(value.draft)))
|
|
107
|
+
throw new Error('Corrupt workflow version');
|
|
108
|
+
return value;
|
|
109
|
+
}
|
|
110
|
+
async open() {
|
|
111
|
+
await fs.mkdir(this.directory, { recursive: true, mode: 0o700 });
|
|
112
|
+
try {
|
|
113
|
+
const registry = JSON.parse(await fs.readFile(this.registryFile, 'utf8'));
|
|
114
|
+
if (registry.v !== 1 || !Array.isArray(registry.deleted) || !Array.isArray(registry.hidden) || registry.deleted.some((id) => typeof id !== 'string' || !/^[a-z][a-z0-9_]{0,63}$/.test(id)) || registry.hidden.some((name) => typeof name !== 'string' || !name || name.length > 120))
|
|
115
|
+
throw new Error('Invalid workflow deletion registry');
|
|
116
|
+
this.deleted = new Set(registry.deleted);
|
|
117
|
+
this.hidden = new Set(registry.hidden);
|
|
118
|
+
}
|
|
119
|
+
catch (error) {
|
|
120
|
+
if (error.code !== 'ENOENT')
|
|
121
|
+
throw error;
|
|
122
|
+
}
|
|
123
|
+
for (const entry of await fs.readdir(this.directory, { withFileTypes: true })) {
|
|
124
|
+
if (entry.isSymbolicLink() || !entry.isDirectory())
|
|
125
|
+
throw new Error('Invalid workflow store entry');
|
|
126
|
+
const id = workflowId(entry.name);
|
|
127
|
+
if (this.deleted.has(id))
|
|
128
|
+
continue;
|
|
129
|
+
let head;
|
|
130
|
+
try {
|
|
131
|
+
head = JSON.parse(await fs.readFile(path.join(this.directory, id, 'HEAD.json'), 'utf8'));
|
|
132
|
+
}
|
|
133
|
+
catch (error) {
|
|
134
|
+
if (error.code === 'ENOENT')
|
|
135
|
+
continue;
|
|
136
|
+
throw error;
|
|
137
|
+
}
|
|
138
|
+
if (!/^[a-f0-9]{32}$/.test(head.revision))
|
|
139
|
+
throw new Error('Corrupt workflow HEAD');
|
|
140
|
+
this.heads.set(id, await this.readRevision(id, head.revision));
|
|
141
|
+
}
|
|
142
|
+
this.checkNames([...this.heads.values()]);
|
|
143
|
+
}
|
|
144
|
+
checkNames(items) {
|
|
145
|
+
const seen = new Set(this.reserved.filter(name => !this.hidden.has(name)));
|
|
146
|
+
for (const item of items)
|
|
147
|
+
for (const entry of item.entries) {
|
|
148
|
+
if (seen.has(entry.name))
|
|
149
|
+
throw new Error(`Workflow name already exists: ${entry.name}`);
|
|
150
|
+
seen.add(entry.name);
|
|
151
|
+
}
|
|
152
|
+
if (seen.size > 128)
|
|
153
|
+
throw new Error('Workflow catalog limit reached');
|
|
154
|
+
}
|
|
155
|
+
publish(id, expected, draft, signal) {
|
|
156
|
+
const result = this.tail.catch(() => { }).then(() => this.publishInner(id, expected, structuredClone(draft), signal));
|
|
157
|
+
this.tail = result;
|
|
158
|
+
return result;
|
|
159
|
+
}
|
|
160
|
+
async publishInner(id, expected, draft, signal) {
|
|
161
|
+
signal?.throwIfAborted();
|
|
162
|
+
workflowId(id);
|
|
163
|
+
if (this.deleted.has(id))
|
|
164
|
+
throw new Error('Workflow was deleted; create a new workflow instead');
|
|
165
|
+
const previous = this.heads.get(id);
|
|
166
|
+
if (previous?.revision !== expected)
|
|
167
|
+
throw new Error('Workflow changed in another authoring Agent; reopen the current version before committing');
|
|
168
|
+
if (Buffer.byteLength(draft.source) > 1024 * 1024 || draft.assets.length > 64 || draft.assets.reduce((sum, asset) => sum + Buffer.byteLength(asset.content), 0) > 8 * 1024 * 1024)
|
|
169
|
+
throw new Error('Workflow bundle exceeds size limits');
|
|
170
|
+
if ((draft.modules?.length ?? 0) > 16 || Buffer.byteLength(JSON.stringify(draft.modules ?? [])) > 1024 * 1024)
|
|
171
|
+
throw new Error('Workflow dependencies exceed limits');
|
|
172
|
+
const digest = hash(JSON.stringify(draft));
|
|
173
|
+
if (digest === previous?.digest)
|
|
174
|
+
return structuredClone(previous);
|
|
175
|
+
const revision = randomUUID().replace(/-/g, '');
|
|
176
|
+
const root = path.join(this.directory, id, 'versions', revision);
|
|
177
|
+
await fs.mkdir(root, { recursive: true, mode: 0o700 });
|
|
178
|
+
let source = draft.source;
|
|
179
|
+
try {
|
|
180
|
+
const seen = new Set(), publishedPaths = new Set(), relocations = [];
|
|
181
|
+
for (const asset of draft.assets) {
|
|
182
|
+
if (!asset.path || asset.path.length > 1024 || /[\x00-\x1f\\]/.test(asset.path) || path.isAbsolute(asset.path) || asset.path.split('/').some(p => !p || p === '.' || p === '..') || seen.has(asset.path))
|
|
183
|
+
throw new Error('Invalid linked asset path');
|
|
184
|
+
seen.add(asset.path);
|
|
185
|
+
const destination = path.join(root, 'assets', asset.path);
|
|
186
|
+
await fs.mkdir(path.dirname(destination), { recursive: true, mode: 0o700 });
|
|
187
|
+
await fs.writeFile(destination, asset.content, { flag: 'wx', mode: 0o400 });
|
|
188
|
+
const relative = path.relative(this.workspace, destination).split(path.sep).join('/');
|
|
189
|
+
if (path.isAbsolute(relative) || relative.split('/').includes('..'))
|
|
190
|
+
throw new Error('Linked workflow assets require a state directory inside the workspace');
|
|
191
|
+
publishedPaths.add(relative);
|
|
192
|
+
relocations.push({ path: asset.path, published: relative });
|
|
193
|
+
}
|
|
194
|
+
source = relocateAssetReferences(source, relocations);
|
|
195
|
+
const spec = await this.validate(source, [...publishedPaths], draft.modules, draft.format === 'workflow-v1');
|
|
196
|
+
if (spec.status !== 'ready' || !spec.shell || spec.shell.kind !== 'workflow' || !spec.snapshot)
|
|
197
|
+
throw new Error('A valid workflow shell is required');
|
|
198
|
+
if ((spec.snapshot.scripts ?? []).some(script => !publishedPaths.has(script.path)))
|
|
199
|
+
throw new Error('Every script_file must resolve to an immutable published asset');
|
|
200
|
+
this.checkNames([...this.heads.values()].filter(item => item.id !== id).concat([{ entries: spec.shell.workflows }]));
|
|
201
|
+
const value = { id, version: (previous?.version ?? 0) + 1, revision, digest, createdAt: new Date().toISOString(), entries: spec.shell.workflows, snapshot: spec.snapshot, draft };
|
|
202
|
+
await atomicJson(path.join(root, 'version.json'), value);
|
|
203
|
+
signal?.throwIfAborted();
|
|
204
|
+
await atomicJson(path.join(this.directory, id, 'HEAD.json'), { revision }); // Atomic publication; validation never runs an entry.
|
|
205
|
+
this.heads.set(id, value);
|
|
206
|
+
return structuredClone(value);
|
|
207
|
+
}
|
|
208
|
+
catch (error) {
|
|
209
|
+
await fs.rm(root, { recursive: true, force: true });
|
|
210
|
+
throw error;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
export function workflowSeed(name) {
|
|
215
|
+
if (!name.trim() || name.length > 120 || /[\x00-\x1f]/.test(name))
|
|
216
|
+
throw new Error('Workflow name must be 1..120 printable characters');
|
|
217
|
+
return `workflow(_{name:${literal(name)},goal:"run",inputs:[_{name:"Request",type:string}],outputs:[_{name:"Result",type:string}]}).\nrun(Request,Result) :- Result=Request.\n`;
|
|
218
|
+
}
|
|
219
|
+
//# sourceMappingURL=workflows.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file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AI,EAAE,CAAC,CAAC;YAAC,MAAM,KAAK,CAAC;QAAC,CAAC;IACvF,CAAC;CACF;AAED,MAAM,UAAU,YAAY,CAAC,IAAY;IACvC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,IAAI,CAAC,MAAM,GAAG,GAAG,IAAI,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;IACxI,OAAO,mBAAmB,OAAO,CAAC,IAAI,CAAC,wIAAwI,CAAC;AAClL,CAAC"}
|
|
@@ -9,12 +9,12 @@ features. Never invent a tool, supported parameter or successful result.
|
|
|
9
9
|
|
|
10
10
|
## Work in small verified steps
|
|
11
11
|
|
|
12
|
-
Start small: inspect `listing`,
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
results. Side effects are real.
|
|
17
|
-
`Name/Arity` and
|
|
12
|
+
Start small: inspect `listing`, explain the inputs, steps, reuse, capabilities and
|
|
13
|
+
checks; plan WITH the user and wait for approval before edits/tests. Then use
|
|
14
|
+
`begin_turn`, `define`/`delete`, bounded `execute`, `end_turn`; report evidence.
|
|
15
|
+
Reopen a transaction for more edits; rollback a bad one. Add intermediate `output/1`
|
|
16
|
+
to debug; use `bindings: "brief"` for large results. Side effects are real.
|
|
17
|
+
Keep docs, `Name/Arity` and modes accurate.
|
|
18
18
|
|
|
19
19
|
1. Understand the real input, desired output and correctness check. If ambiguous,
|
|
20
20
|
ask one focused question and stop. For a new harness propose the smallest
|
|
@@ -8,8 +8,13 @@ request. A harness is reusable capabilities, not a log of everything performed.
|
|
|
8
8
|
## Design and inspect
|
|
9
9
|
|
|
10
10
|
Call `listing(filter: "all")` first, then relevant `Name/Arity` entries.
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
Walk the user through a short plan: inputs/defaults, steps, reused workflows,
|
|
12
|
+
outputs, real evidence sources, effects, missing capabilities and test strategy.
|
|
13
|
+
Ask focused material questions with suggested defaults, then wait for approval
|
|
14
|
+
BEFORE transactions, file writes, execution or publication. Do not treat an initial
|
|
15
|
+
request as agreement on an unseen design. Discuss and agree the plan in the normal
|
|
16
|
+
conversation, then implement it. After a material scope change, agree a revised
|
|
17
|
+
plan. Do not keep reopening settled choices.
|
|
13
18
|
Normal conversational agents use `shell/1` plus tools/workflows, not a custom loop.
|
|
14
19
|
Use explicit argument modes and typed model outputs from the first small version.
|
|
15
20
|
|
|
@@ -18,6 +23,79 @@ scripts; semantic work uses typed prompt/task calls. Choose by actual need, not
|
|
|
18
23
|
by a blanket ban on Prolog or a blanket preference for models. Read `patterns`
|
|
19
24
|
for a matching small shape and `examples` for a complete tested one.
|
|
20
25
|
|
|
26
|
+
## Common workflow building blocks
|
|
27
|
+
|
|
28
|
+
- **Reuse:** inspect `reference(topic: "workflows")` for host-supplied names,
|
|
29
|
+
descriptions, typed inputs/outputs and revision pins before creating a duplicate.
|
|
30
|
+
Same-module helpers are ordinary predicate calls. With the serve host grant,
|
|
31
|
+
`run_workflow("Existing name", _{'Text':Text}, R)` invokes another workflow;
|
|
32
|
+
require `get_dict(ok,R,true)`, then `get_dict(outputs,R,Outputs)` and extract
|
|
33
|
+
its named output. Child runtimes close on return; reuse completed outputs, not
|
|
34
|
+
detached process handles. On failure inspect status/error and stop or report it; never
|
|
35
|
+
claim success. This host capability is not universally available in SDK/browser
|
|
36
|
+
embeddings. It does not import code or grant another workflow's tools.
|
|
37
|
+
- **Retrieval pipeline:** choose approved feeds/endpoints or existing collectors;
|
|
38
|
+
retrieve with a registered tool, set request/response/time/count bounds, extract
|
|
39
|
+
dated evidence + source URLs + retrieval time, filter/deduplicate, then synthesize
|
|
40
|
+
and cite only that evidence. A tool-free prompt/llm is NOT web search. Never
|
|
41
|
+
replace fresh evidence with model knowledge. Fail honestly on no/failed evidence.
|
|
42
|
+
Fixture tests validate transformations, not live retrieval or factual freshness.
|
|
43
|
+
- **Scripts/files:** inspect `tools` for the actual registry. If Bash exists use
|
|
44
|
+
`exec(bash(argv:["python3","scripts/collect.py",Topic]),R)`, inspect exitCode,
|
|
45
|
+
stdout and stderr; throw/report nonzero exit, do not summarize errors as results.
|
|
46
|
+
`run_script/3` checks the exit code and parses JSON with a granted Bash/Python
|
|
47
|
+
backend. Link reusable code with script_file/2; pass arguments as argv, not shell
|
|
48
|
+
interpolation. No granted interpreter means script execution is unavailable.
|
|
49
|
+
- **Typed model stages:** deterministic validation/filtering in DML/scripts;
|
|
50
|
+
`prompt(...,string(Summary))` for evidence-grounded isolated synthesis, task for
|
|
51
|
+
explicitly scoped tools/memory. Pass evidence as data, not trusted instructions.
|
|
52
|
+
- **Inputs/results:** keep a small typed interface, useful field descriptions,
|
|
53
|
+
defaults for truly optional inputs, and named outputs (not answer/1). Persist
|
|
54
|
+
deliverables at workspace-relative unique paths; keep secrets out of source.
|
|
55
|
+
- **Effects/schedules:** bound work, make effects single-solution, propagate errors
|
|
56
|
+
and cancellation; no implicit retries. Publishing does not run or schedule it.
|
|
57
|
+
|
|
58
|
+
## Clock and today
|
|
59
|
+
|
|
60
|
+
No Bash is needed for the runtime UTC date:
|
|
61
|
+
|
|
62
|
+
```prolog
|
|
63
|
+
today_utc(Date) :-
|
|
64
|
+
get_time(Stamp),
|
|
65
|
+
stamp_date_time(Stamp, DT, 'UTC'),
|
|
66
|
+
format_time(string(Date), "%Y-%m-%d", DT).
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
For a simple "today" workflow compute it internally, rather than requiring a date
|
|
70
|
+
input. This engine has no tzdata: `stamp_date_time/3` takes `'UTC'` or an integer
|
|
71
|
+
offset, so name a market zone through `zone_date_time/3` (DST-correct) instead:
|
|
72
|
+
|
|
73
|
+
```prolog
|
|
74
|
+
market_date(Zone, Date) :-
|
|
75
|
+
get_time(Stamp), zone_date_time(Stamp, Zone, DT),
|
|
76
|
+
format_time(string(Date), "%Y-%m-%d", DT).
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
`local_date_time(Stamp, DT)` follows the host zone and `zone_offset(Zone, Stamp, Off)`
|
|
80
|
+
exposes the offset. If a date override is useful declare a string default `""` and
|
|
81
|
+
explicitly interpret empty/`"today"`. Preserve an explicit valid ISO date. UTC
|
|
82
|
+
date, a market's local date and the last trading session are different policies;
|
|
83
|
+
agree which one is needed. A fixed prompt timestamp is not a trading calendar.
|
|
84
|
+
|
|
85
|
+
## Draft versus live validation
|
|
86
|
+
|
|
87
|
+
Read `tools` for the actual registry. In serve, drafts inherit the configured host
|
|
88
|
+
tools, sandbox and network policy: Bash works when enabled, including without a
|
|
89
|
+
sandbox. Commands, network requests, messages and composed workflow calls are real.
|
|
90
|
+
Receive permissions, explicit new-Agent approvals and disabled tools still apply.
|
|
91
|
+
The separate draft directory protects source ownership, not the host from effects.
|
|
92
|
+
Scripts run with that directory as cwd; selected file inputs are copied there.
|
|
93
|
+
Private draft downloads are local presentation rather than published links.
|
|
94
|
+
Agree on bounded effectful tests in the normal conversation; prefer fixtures when
|
|
95
|
+
adequate and never claim fixture tests prove live retrieval. Transactions do not
|
|
96
|
+
undo shell/file/network/message effects. On an unsandboxed host the network flag
|
|
97
|
+
is not a firewall; AgentVM networking still follows the server's network setting.
|
|
98
|
+
|
|
21
99
|
## Transactions
|
|
22
100
|
|
|
23
101
|
`begin_turn` opens a snapshot; call it once, not before every define. `define`
|
|
@@ -62,6 +62,30 @@ refs (`make_ref/1`) so replies cannot be confused.
|
|
|
62
62
|
A simple foreground `input/1` does not consume a worker's message; `next/1`
|
|
63
63
|
dispatches `user(Text)` versus `message(Term)` for custom event-driven conversations.
|
|
64
64
|
|
|
65
|
+
## Posting results to a turn-based Work agent
|
|
66
|
+
|
|
67
|
+
An opt-in Work shell can declare `inbox: _{sources:[process]}`. In its owning
|
|
68
|
+
foreground/tool/hook, capture `agent_self(Main)` and pass Main to spawn. The child
|
|
69
|
+
can call `agent_post(Main, message{text:Text, data:result{...}}, MessageId)`.
|
|
70
|
+
text is a string; data is an optional data dict; optional key strings deduplicate
|
|
71
|
+
recent posts from the same sender pid. No executable terms/variables/handles in
|
|
72
|
+
payloads. Posting acknowledges the queue write, not the parent's answer; never
|
|
73
|
+
wait for the parent to answer before letting the child complete.
|
|
74
|
+
|
|
75
|
+
Unlike send/receive, this schedules an ordinary owner on_message/assistant turn
|
|
76
|
+
when idle. Context.source is the atom process; context.message is Text, with
|
|
77
|
+
message_id/sender/data metadata. User source is the atom user. State/memory hooks
|
|
78
|
+
apply normally; process-only consume records input and updates memory/state
|
|
79
|
+
without an assistant response. An active foreground operation is never interrupted.
|
|
80
|
+
|
|
81
|
+
The broker stamps provenance. References only address the originating conversation
|
|
82
|
+
and expire with its runtime; children must receive them explicitly. They cannot
|
|
83
|
+
call agent_self to acquire the parent's reference. Inbox-enabled execution needs
|
|
84
|
+
history or a durable host store. Full/rate-limited/invalid/closed posts error.
|
|
85
|
+
Respect bounded queues/autonomous-turn budgets and pause/resume; don't retry in an
|
|
86
|
+
unbounded loop. Serve keeps dispatching with no browser; restarting restores data,
|
|
87
|
+
not processes or interrupted effects. See DML_SHELL.md for the complete contract.
|
|
88
|
+
|
|
65
89
|
## Services
|
|
66
90
|
|
|
67
91
|
`serve(Name, Loop[, Pid])` starts and registers a process.
|