codeassembly-agent-logic 0.3.0 → 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/.meta/changelog.json +28 -0
- package/CHANGELOG.md +10 -0
- package/README.md +21 -11
- package/dist/esm/agent/convert-with-agent.d.ts +1 -1
- package/dist/esm/agent/convert-with-agent.js +9 -13
- package/dist/esm/agent/index.d.ts +1 -1
- package/dist/esm/agent/index.js +1 -1
- package/dist/esm/conversion-session/conversion-tools.d.ts +4 -0
- package/dist/esm/conversion-session/conversion-tools.js +2 -0
- package/dist/esm/{agent → conversion-session}/create-conversion-session.d.ts +5 -0
- package/dist/esm/{agent → conversion-session}/create-conversion-session.js +5 -0
- package/dist/esm/conversion-session/format-conversion-input.d.ts +4 -0
- package/dist/esm/conversion-session/format-conversion-input.js +3 -0
- package/dist/esm/convert/convert-prompt.js +8 -3
- package/dist/esm/instructions/conversion-instructions.d.ts +2 -0
- package/dist/esm/instructions/conversion-instructions.js +1 -0
- package/dist/esm/instructions/write-conversion-instructions.d.ts +6 -0
- package/dist/esm/instructions/write-conversion-instructions.js +20 -0
- package/dist/esm/job/create-conversion-job.d.ts +28 -0
- package/dist/esm/job/create-conversion-job.js +33 -0
- package/dist/esm/job/index.d.ts +4 -0
- package/dist/esm/job/index.js +2 -0
- package/dist/esm/react/canvas/FocusNavigation.js +5 -5
- package/dist/esm/react/canvas/StateNode.js +3 -3
- package/dist/esm/react/canvas/StatechartCanvas.js +26 -26
- package/dist/esm/react/styles.css +1 -1
- package/package.json +16 -6
package/.meta/changelog.json
CHANGED
|
@@ -1,4 +1,32 @@
|
|
|
1
1
|
[
|
|
2
|
+
{
|
|
3
|
+
"version": "0.4.0",
|
|
4
|
+
"date": "2026-11-18",
|
|
5
|
+
"sections": [
|
|
6
|
+
{
|
|
7
|
+
"title": "🎉 Features",
|
|
8
|
+
"audience": "all",
|
|
9
|
+
"items": [
|
|
10
|
+
{
|
|
11
|
+
"description": "Adds the experimental `codeassembly-agent-logic/job` entry, whose `createConversionJob` returns a job that `runJob` of `@williamthorsen/toolbelt.llm` runs in a page or a hosted function to convert a prompt with the instructions, the `check_coverage` and `submit_draft` tools, and the caps that `convertWithAgent` uses. (#2290)",
|
|
12
|
+
"hash": "731cb417a800fbb51f2c04cd6dce503056ef53dd",
|
|
13
|
+
"entry": 1
|
|
14
|
+
}
|
|
15
|
+
]
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"title": "📦 Dependencies",
|
|
19
|
+
"audience": "dev",
|
|
20
|
+
"items": [
|
|
21
|
+
{
|
|
22
|
+
"description": "Upgrades `@xyflow/react` in `codeassembly-agent-logic` from 12.12.1 to 13.0.1 and adapts the statechart canvas to the major version's separate viewport and options stores, its `NodeChangeset` and `EdgeChangeset` change handlers, and its stylesheet path `@xyflow/react/style.css`. (#2289)",
|
|
23
|
+
"hash": "d8b0c600d6ff7ae2eba0e4e428bf50e1247376ae",
|
|
24
|
+
"entry": 1
|
|
25
|
+
}
|
|
26
|
+
]
|
|
27
|
+
}
|
|
28
|
+
]
|
|
29
|
+
},
|
|
2
30
|
{
|
|
3
31
|
"version": "0.3.0",
|
|
4
32
|
"date": "2026-11-16",
|
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
|
|
5
|
+
## 0.4.0 — 2026-11-18
|
|
6
|
+
|
|
7
|
+
### 🎉 Features
|
|
8
|
+
|
|
9
|
+
- Adds the experimental `codeassembly-agent-logic/job` entry, whose `createConversionJob` returns a job that `runJob` of `@williamthorsen/toolbelt.llm` runs in a page or a hosted function to convert a prompt with the instructions, the `check_coverage` and `submit_draft` tools, and the caps that `convertWithAgent` uses. (#2290)
|
|
10
|
+
|
|
11
|
+
### 📦 Dependencies
|
|
12
|
+
|
|
13
|
+
- Upgrades `@xyflow/react` in `codeassembly-agent-logic` from 12.12.1 to 13.0.1 and adapts the statechart canvas to the major version's separate viewport and options stores, its `NodeChangeset` and `EdgeChangeset` change handlers, and its stylesheet path `@xyflow/react/style.css`. (#2289)
|
|
14
|
+
|
|
5
15
|
## 0.3.0 — 2026-11-16
|
|
6
16
|
|
|
7
17
|
### 🎉 Features
|
package/README.md
CHANGED
|
@@ -1,16 +1,9 @@
|
|
|
1
1
|
<!-- section:release-notes -->
|
|
2
|
-
## Release notes — v0.
|
|
2
|
+
## Release notes — v0.4.0 (2026-11-18)
|
|
3
3
|
|
|
4
4
|
### 🎉 Features
|
|
5
5
|
|
|
6
|
-
- Adds the `codeassembly-agent-logic/
|
|
7
|
-
- Adds the `agent-logic convert-with-agent --agent <profile> <prompt-file> [output-file]` command, which reports each coverage check and draft submission on stderr, writes the config only when it is valid, and exits 130 without writing any output file when Ctrl+C stops the conversion. (#2283)
|
|
8
|
-
- Adds `createConversionHandler` to `codeassembly-agent-logic/server`, a Fetch handler that starts, reads, and cancels conversions on an ACP agent under a base path, together with the `ConversionStore` interface and `createMemoryConversionStore`, which keeps conversions in process memory and drops each ended one after a retention period, one hour by default. (#2285)
|
|
9
|
-
- Adds the `codeassembly-agent-logic/client` entry, whose browser-safe `createConversionClient` starts, reads, cancels, and watches conversions on the routes that `createConversionHandler` serves, so that a page can resume a conversion by its id after a reload. (#2285)
|
|
10
|
-
|
|
11
|
-
### 🪦 Removed
|
|
12
|
-
|
|
13
|
-
- 🚨 **Breaking:** Removes the telefactor-backed conversion path from `codeassembly-agent-logic`: the `./contract` entry, the `createViewerServerPlugins`, `createPromptsApp`, prompt-directory, and viewer-contract exports of `./server`, and the `useAgentBridge`, `useAgentSync`, `useConversion`, `useHarnessList`, and `usePromptDirectory` hooks of `./react`, together with the `@williamthorsen/telefactor` peer dependency. (#2286)
|
|
6
|
+
- Adds the experimental `codeassembly-agent-logic/job` entry, whose `createConversionJob` returns a job that `runJob` of `@williamthorsen/toolbelt.llm` runs in a page or a hosted function to convert a prompt with the instructions, the `check_coverage` and `submit_draft` tools, and the caps that `convertWithAgent` uses. (#2290)
|
|
14
7
|
<!-- /section:release-notes -->
|
|
15
8
|
|
|
16
9
|
<!-- readme-type: library -->
|
|
@@ -45,9 +38,10 @@ if (result.ok) {
|
|
|
45
38
|
| `codeassembly-agent-logic/react/styles.css` | The canvas stylesheet. |
|
|
46
39
|
| `codeassembly-agent-logic/server` | `createConversionHandler`, which serves conversions on an ACP agent, and its stores. |
|
|
47
40
|
| `codeassembly-agent-logic/client` | `createConversionClient`, the browser client of the routes that `createConversionHandler` serves. |
|
|
41
|
+
| `codeassembly-agent-logic/job` | `createConversionJob`, which converts a prompt as a job of `@williamthorsen/toolbelt.llm`, in a page or a function. |
|
|
48
42
|
| `codeassembly-agent-logic/agent-logic.schema.json` | The config's JSON Schema. |
|
|
49
43
|
|
|
50
|
-
React 19 is a peer of `./react`,
|
|
44
|
+
React 19 is a peer of `./react`, `@williamthorsen/toolbelt.acp` and `@modelcontextprotocol/server` peers of `./agent` and `./server`, and `@williamthorsen/toolbelt.llm` a peer of `./job`.
|
|
51
45
|
|
|
52
46
|
## Converting on an ACP agent
|
|
53
47
|
|
|
@@ -60,7 +54,7 @@ for await (const event of convertWithAgent({ prompt, name: 'refund-request.md',
|
|
|
60
54
|
}
|
|
61
55
|
```
|
|
62
56
|
|
|
63
|
-
`convertWithAgent` runs the agent through [`@williamthorsen/toolbelt.acp`](https://github.com/williamthorsen/toolbelt/tree/main/packages/acp#readme) in an empty temporary directory and gives it two tools: `check_coverage`, which answers 3 checks of its coverage map, and `submit_draft`, which converts a draft and accepts 5. Every other request of the agent is refused. It yields the agent's message text and each check and submission, then a `result` event whose `ConvertResult` is the outcome of the last submission, with the usage and cost that the agent reports. The agent's instructions are [`docs/agent-instructions.md`](docs/agent-instructions.md) followed by the [extraction rules](docs/extraction-rules.md). The doc comment of `convertWithAgent` states when it rejects.
|
|
57
|
+
`convertWithAgent` runs the agent through [`@williamthorsen/toolbelt.acp`](https://github.com/williamthorsen/toolbelt/tree/main/packages/acp#readme) in an empty temporary directory and gives it two tools: `check_coverage`, which answers 3 checks of its coverage map, and `submit_draft`, which converts a draft and accepts 5. Every other request of the agent is refused. It yields the agent's message text and each check and submission, then a `result` event whose `ConvertResult` is the outcome of the last submission, with the usage and cost that the agent reports. The agent's instructions are [`docs/agent-instructions.md`](docs/agent-instructions.md) followed by the [extraction rules](docs/extraction-rules.md), the same text that a [conversion job](#converting-in-a-page-or-a-function) sends. The doc comment of `convertWithAgent` states when it rejects.
|
|
64
58
|
|
|
65
59
|
The agent's harness must be installed and signed in. Each profile signs in as follows:
|
|
66
60
|
|
|
@@ -70,6 +64,22 @@ The agent's harness must be installed and signed in. Each profile signs in as fo
|
|
|
70
64
|
| `antigravityProfile` | The CLI's personal Google login |
|
|
71
65
|
| `codexProfile` | Not supported: The profile cannot identify calls of the conversion's tools, so `convertWithAgent` rejects it. |
|
|
72
66
|
|
|
67
|
+
## Converting in a page or a function
|
|
68
|
+
|
|
69
|
+
```ts
|
|
70
|
+
import { createConversionJob } from 'codeassembly-agent-logic/job';
|
|
71
|
+
import { runJob } from '@williamthorsen/toolbelt.llm/proposed';
|
|
72
|
+
|
|
73
|
+
const outcome = await runJob(createConversionJob({ prompt, name: 'refund-request.md' }), {
|
|
74
|
+
provider: 'anthropic',
|
|
75
|
+
apiKey,
|
|
76
|
+
model: 'claude-sonnet-5-5',
|
|
77
|
+
});
|
|
78
|
+
if (outcome.status === 'completed') console.log(outcome.result);
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
`createConversionJob` returns a job for [`@williamthorsen/toolbelt.llm`](https://github.com/williamthorsen/toolbelt/tree/main/packages/llm#readme), which runs it in the page on a user's connection or at an operator's endpoint, without a harness. The job sends the instructions and the message that `convertWithAgent` sends, offers the same two tools with the same caps, and makes at most `MAX_ROUNDS` model requests. Its result is a `ConvertResult`, available once the conversion is finished: the config accepted, the prompt recorded out of scope, or the last of the 5 submissions rejected. A run that the model ends earlier is `unfinished`. Create a job for each run.
|
|
82
|
+
|
|
73
83
|
## Serving conversions
|
|
74
84
|
|
|
75
85
|
```ts
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type AgentProfile, runPrompt } from '@williamthorsen/toolbelt.acp/proposed';
|
|
2
|
+
import { type SessionEvent } from '../conversion-session/create-conversion-session.js';
|
|
2
3
|
import type { ConvertResult } from '../convert/convert-prompt.js';
|
|
3
|
-
import { type SessionEvent } from './create-conversion-session.js';
|
|
4
4
|
/** The name of the MCP server through which the agent reaches the conversion's tools. */
|
|
5
5
|
export declare const CONVERSION_SERVER_NAME = "agent_logic";
|
|
6
6
|
/** What `convertWithAgent` converts, and on which agent. */
|
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import { mkdtemp,
|
|
1
|
+
import { mkdtemp, rm } from 'node:fs/promises';
|
|
2
2
|
import os from 'node:os';
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import { McpServer } from '@modelcontextprotocol/server';
|
|
5
5
|
import { AgentRunError, runPrompt } from '@williamthorsen/toolbelt.acp/proposed';
|
|
6
6
|
import { z } from 'zod';
|
|
7
|
+
import { CHECK_COVERAGE_DESCRIPTION, SUBMIT_DRAFT_DESCRIPTION } from "../conversion-session/conversion-tools.js";
|
|
8
|
+
import { createConversionSession } from "../conversion-session/create-conversion-session.js";
|
|
9
|
+
import { formatConversionInput } from "../conversion-session/format-conversion-input.js";
|
|
7
10
|
import { coverageMapSchema } from "../coverage-map/coverage-map-schema.js";
|
|
8
|
-
import {
|
|
9
|
-
import { createConversionSession } from "./create-conversion-session.js";
|
|
11
|
+
import { CONVERSION_INSTRUCTIONS } from "../instructions/conversion-instructions.js";
|
|
10
12
|
export const CONVERSION_SERVER_NAME = 'agent_logic';
|
|
11
13
|
const AUTH_REQUIRED_CODE = -32_000;
|
|
12
14
|
export const convertWithAgent = createConvertWithAgent(runPrompt);
|
|
@@ -24,7 +26,6 @@ export function createConvertWithAgent(runPromptImpl) {
|
|
|
24
26
|
pending.push(event);
|
|
25
27
|
},
|
|
26
28
|
});
|
|
27
|
-
const instructions = await readInstructions();
|
|
28
29
|
const cwd = await mkdtemp(path.join(os.tmpdir(), 'agent-logic-conversion-'));
|
|
29
30
|
try {
|
|
30
31
|
let stopped;
|
|
@@ -32,8 +33,8 @@ export function createConvertWithAgent(runPromptImpl) {
|
|
|
32
33
|
const run = runPromptImpl({
|
|
33
34
|
agent,
|
|
34
35
|
cwd,
|
|
35
|
-
instructions,
|
|
36
|
-
prompt:
|
|
36
|
+
instructions: CONVERSION_INSTRUCTIONS,
|
|
37
|
+
prompt: formatConversionInput(prompt, name),
|
|
37
38
|
tools: {
|
|
38
39
|
name: CONVERSION_SERVER_NAME,
|
|
39
40
|
createServer: () => createConversionServer(session),
|
|
@@ -84,11 +85,11 @@ export function createConvertWithAgent(runPromptImpl) {
|
|
|
84
85
|
function createConversionServer(session) {
|
|
85
86
|
const server = new McpServer({ name: CONVERSION_SERVER_NAME, version: '1.0.0' });
|
|
86
87
|
server.registerTool('check_coverage', {
|
|
87
|
-
description:
|
|
88
|
+
description: CHECK_COVERAGE_DESCRIPTION,
|
|
88
89
|
inputSchema: z.object({ map: coverageMapSchema }),
|
|
89
90
|
}, ({ map }) => ({ content: [{ type: 'text', text: session.checkCoverage(map) }] }));
|
|
90
91
|
server.registerTool('submit_draft', {
|
|
91
|
-
description:
|
|
92
|
+
description: SUBMIT_DRAFT_DESCRIPTION,
|
|
92
93
|
inputSchema: z.object({ draft: z.string().describe("The draft's JSON text.") }),
|
|
93
94
|
}, ({ draft }) => ({ content: [{ type: 'text', text: session.submitDraft(draft) }] }));
|
|
94
95
|
return server;
|
|
@@ -104,8 +105,3 @@ function describeRunError(error) {
|
|
|
104
105
|
cause: error,
|
|
105
106
|
});
|
|
106
107
|
}
|
|
107
|
-
async function readInstructions() {
|
|
108
|
-
const docs = path.join(findPackageRoot(), 'docs');
|
|
109
|
-
const parts = await Promise.all(['agent-instructions.md', 'extraction-rules.md'].map((file) => readFile(path.join(docs, file), 'utf8')));
|
|
110
|
-
return parts.join('\n');
|
|
111
|
-
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
/** `./agent` entry: converts a prompt by directing an ACP agent through the conversion. */
|
|
2
|
+
export { MAX_COVERAGE_CHECKS, MAX_SUBMISSIONS, type SessionEvent, } from '../conversion-session/create-conversion-session.js';
|
|
2
3
|
export { CONVERSION_SERVER_NAME, type ConversionEvent, convertWithAgent, type ConvertWithAgentOptions, } from './convert-with-agent.js';
|
|
3
|
-
export { MAX_COVERAGE_CHECKS, MAX_SUBMISSIONS, type SessionEvent } from './create-conversion-session.js';
|
package/dist/esm/agent/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
+
export { MAX_COVERAGE_CHECKS, MAX_SUBMISSIONS, } from "../conversion-session/create-conversion-session.js";
|
|
1
2
|
export { CONVERSION_SERVER_NAME, convertWithAgent, } from "./convert-with-agent.js";
|
|
2
|
-
export { MAX_COVERAGE_CHECKS, MAX_SUBMISSIONS } from "./create-conversion-session.js";
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** The description of the `check_coverage` tool, for the model. */
|
|
2
|
+
export declare const CHECK_COVERAGE_DESCRIPTION = "Checks a coverage map of the prompt against the prompt.";
|
|
3
|
+
/** The description of the `submit_draft` tool, for the model. */
|
|
4
|
+
export declare const SUBMIT_DRAFT_DESCRIPTION = "Converts a draft of the prompt's logic into an agent-logic config, or reports its problems.";
|
|
@@ -18,6 +18,11 @@ export type SessionEvent = {
|
|
|
18
18
|
};
|
|
19
19
|
/** The state of one conversion behind its tools: Each method returns the text that the tool answers the agent with. */
|
|
20
20
|
export interface ConversionSession {
|
|
21
|
+
/**
|
|
22
|
+
* Whether the conversion has ended: A config was accepted, the prompt was recorded as out of scope, or the last
|
|
23
|
+
* submission was taken. It stays true through later submissions.
|
|
24
|
+
*/
|
|
25
|
+
readonly isFinished: boolean;
|
|
21
26
|
/** The outcome of the last accepted submission, or `undefined` before the first. */
|
|
22
27
|
readonly result: ConvertResult | undefined;
|
|
23
28
|
checkCoverage(map: CoverageMap): string;
|
|
@@ -7,6 +7,7 @@ export function createConversionSession({ prompt, name, onEvent, }) {
|
|
|
7
7
|
let checks = 0;
|
|
8
8
|
let submissions = 0;
|
|
9
9
|
let result;
|
|
10
|
+
let isFinished = false;
|
|
10
11
|
return {
|
|
11
12
|
checkCoverage(map) {
|
|
12
13
|
if (checks >= MAX_COVERAGE_CHECKS) {
|
|
@@ -34,6 +35,7 @@ export function createConversionSession({ prompt, name, onEvent, }) {
|
|
|
34
35
|
return 'No more drafts are accepted. End your turn.';
|
|
35
36
|
submissions += 1;
|
|
36
37
|
result = convertPrompt(prompt, draftText, name);
|
|
38
|
+
isFinished ||= submissions >= MAX_SUBMISSIONS || result.ok || 'outOfScope' in result;
|
|
37
39
|
const problems = 'problems' in result ? result.problems : [];
|
|
38
40
|
onEvent({
|
|
39
41
|
type: 'draft-submitted',
|
|
@@ -52,6 +54,9 @@ export function createConversionSession({ prompt, name, onEvent, }) {
|
|
|
52
54
|
: `Correct every listed entry and submit the draft again. ${describeCount(left, 'submission')} left.`;
|
|
53
55
|
return [...lines, next].join('\n');
|
|
54
56
|
},
|
|
57
|
+
get isFinished() {
|
|
58
|
+
return isFinished;
|
|
59
|
+
},
|
|
55
60
|
get result() {
|
|
56
61
|
return result;
|
|
57
62
|
},
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
1
|
import { describeError } from '@williamthorsen/toolbelt.errors';
|
|
3
2
|
import { formatPath, validateConfig } from "../schema/validate-config.js";
|
|
4
3
|
import { draftSchema, outOfScopeSchema } from "./draft-schema.js";
|
|
@@ -38,8 +37,9 @@ export function convertPrompt(prompt, draftText, promptFileName) {
|
|
|
38
37
|
return { ok: true, config: validated.config, text: `${JSON.stringify(validated.config, undefined, 2)}\n` };
|
|
39
38
|
}
|
|
40
39
|
export function deriveRootId(promptFileName) {
|
|
41
|
-
const
|
|
42
|
-
|
|
40
|
+
const words = readBaseName(promptFileName)
|
|
41
|
+
.toLowerCase()
|
|
42
|
+
.match(/[a-z0-9]+/g) ?? [];
|
|
43
43
|
const id = words.join('_');
|
|
44
44
|
if (id === '')
|
|
45
45
|
return 'agent';
|
|
@@ -58,3 +58,8 @@ function describeDraftIssue(issue, parentPath) {
|
|
|
58
58
|
function maxPathLength(issues) {
|
|
59
59
|
return Math.max(0, ...issues.map((issue) => issue.path.length));
|
|
60
60
|
}
|
|
61
|
+
function readBaseName(filePath) {
|
|
62
|
+
const segment = filePath.replace(/\/+$/, '').split('/').at(-1) ?? '';
|
|
63
|
+
const dot = segment.lastIndexOf('.');
|
|
64
|
+
return dot > 0 ? segment.slice(0, dot) : segment;
|
|
65
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/** The conversion's instructions: the conversion procedure followed by the extraction rules. */
|
|
2
|
+
export declare const CONVERSION_INSTRUCTIONS = "# Converting a prompt with the conversion tools\n\nYou convert an agent's prompt into a draft of its logic, following the extraction rules below. The message contains a header line that names the prompt's file, a blank line, and then the prompt: Everything after that blank line is the prompt, verbatim, and every quote is copied from it. You have two tools, and no others:\n\n- `check_coverage` checks a coverage map of the prompt against the prompt.\n- `submit_draft` converts a draft into an agent-logic config, or reports the problems that prevent it. Where the rules speak of the `convert` script, they mean this tool.\n\n## Procedure\n\n1. Read the prompt in full, then read the extraction rules in full.\n2. Judge whether the prompt is out of scope by the rules' condition, then write the draft that they describe, or the out-of-scope draft. An out-of-scope draft skips step 3.\n3. Check the draft against the prompt, and correct it where a check fails:\n - **Coverage.** Read the prompt again from the top, one paragraph or list item at a time, and write a coverage map: an array with an entry `{ \"quote\": \"...\", \"element\": \"...\" }` for each instruction in it. The `quote` copies the instruction verbatim and occurs in the prompt exactly once. The `element` names the state, action, or transition that holds it, or is `ambient`, `unconverted`, or `none`. A list item or paragraph that states three instructions takes three entries. Include the instructions inside a dense step, each of which is an action of that step's state, and the rules of a section that states how to format output, such as an option format. Add each instruction whose entry names `none` to the draft where the rules' \"What to extract\", \"Ambient instructions\", and \"Passages you cannot convert\" place it, and name its element in the entry.\n - **Map check.** Call `check_coverage` with the map. It lists each block of the prompt that no entry quotes, as `line <N>: <opening words>`, and each entry whose quote does not occur exactly once. Map every instruction of each listed block, holding it in the draft as the Coverage bullet says, lengthen each listed quote until it occurs once, and call it again. The tool answers 3 calls; after the third, go on to the next check, whatever it reported.\n - **Inputs.** List each input that the prompt tells the agent to read, fetch, or receive, such as a page, a list, or a field of the request. For each one, find an element that uses what the input supplies: a later action, a guard, or an ambient rule. Record an `unused-input` finding, as the rules' \"Findings\" section states, for each input that no element uses.\n - **Inferred quotes.** Read the quote of each element that has `meta.inferred` on its own, and ask whether those words name the element, as the rules' \"Quotes\" section requires. Replace a quote that names a neighbouring step or the question that precedes the element.\n4. Call `submit_draft` with the draft's JSON text.\n5. When it reports problems, it lists each one by its path in the draft. Correct every listed entry and submit the draft again. The tool accepts 5 submissions; when it says that it accepts no more, stop.\n6. When it reports that the config is accepted, or that the prompt is out of scope, end your turn without submitting again: The last submission is the conversion's result.\n\n# Extraction rules\n\nThe rules by which a model converts an agent prompt into a draft, which `agent-logic convert` turns into an agent-logic config; `agent-logic rules` prints them. The `convert-agent-prompt` skill in [williamthorsen/codeassembly-guidance](https://github.com/williamthorsen/codeassembly-guidance) directs a harness agent to read them, and any other converter gives them to its model in full.\n\n## What to extract\n\nExtract the prompt's logic, then its [ambient instructions](#ambient-instructions), and record each flaw that you find while reading the prompt as a [finding](#findings):\n\n- **States.** A step in which the agent does something or waits for the user. A state's `entry` lists the actions that the agent takes on entering it. An outcome at which the conversation ends is a `final` state; ending the conversation is what `final` means, so do not list it as an action.\n- **Actions within a step.** Keep every instruction of a step as an action of its state, rather than summarize the step: a condition that changes what the agent does without changing where it goes next is an action that states its condition, such as \"when the milestone has no open tickets, suggest closing it\", and a prohibition that limits one step, such as \"do not comment on the title's format\", is an action of that step's state.\n- **Transitions.** What moves the agent from one state to another. An event from the user is named `user.<what_happened>`, such as `user.gives_order_number`; another event takes another dotted lowercase prefix. A step that proceeds without waiting uses `always`. An outcome that the prompt says may happen, and that changes who acts next or where the step leads, is an event of that step's state with its own transition, beside the step's usual way out: \"you may get no turn after it, because the platform reports the result\" is `platform.reports_result`, named with the prefix of the actor that causes it. The prompt states the outcome, so its transition quotes that passage and is not inferred. When the prompt defines an event by a list of signs, such as \"watch for these redirections\", the transition quotes the passage that lists them and takes no guard.\n- **Guards.** A condition that a transition requires, as `guard`: `{ \"type\": \"nl\", \"params\": { \"text\": \"the code is correct\" } }`, the same shape as an action. In a list of transitions for one event or for `always`, put the guarded transitions first and the unguarded fallback last: The list is evaluated in order, so its guards are alternatives: Use a list only for conditions of which at most one leads on. Conditions that can hold together, such as \"after a split\" and \"when the remote ticket is stale\", are actions of one shared state that each state their condition. A guarded transition whose alternative the prompt implies, such as staying while a step's own handling takes over or waiting for the user's reply, takes that alternative as an unguarded fallback: a transition without a target, or to the state that waits. A requirement that only orders two steps, such as \"MUST have a failing test before fixing\", is not a guard: The step proceeds with `always`. Neither is a condition that only restates its event, such as \"a helper result has `ok: false`\" on `helper.returns_failure`: Leave it out. A guarded transition of a state inside a flow needs no fallback for an event that the flow's global transition handles, because the global transition then applies. A condition on the user's reply goes on that reply's transitions, not in a separate checking state.\n- **Global transitions.** A rule that applies at any point of a flow, such as \"at any point, if the customer asks for a human\". Group the states of that flow under a compound state, with `initial` naming its first child, and put the transition on the compound state. Create a compound state only for a global transition or an exit action that applies to more than one state. A step that the prompt exempts from the rule, such as one that continues after a failure that stops every other step, stays outside the compound state, and only that step: The step after it is inside, and the exempt step's transition targets it there. A rule that applies at any point is a global transition only of a flow that the prompt states; in a prompt that states no flow, it is a standing rule, together with any remedies that it orders, such as \"try A, then B, and only then C\".\n- **Exit actions.** An action taken whenever the agent leaves a flow goes in the compound state's `exit`.\n- **Actions without leaving.** A transition that runs actions and stays in the same state omits `target`.\n- **Independent choices in one reply.** When the prompt asks the user for two or more independent choices in one reply, such as \"confirm the shipping address, and choose standard or express delivery\", each choice is an event of the state that waits for the reply. A choice that only runs actions, such as consenting to an update, is a transition without a target that quotes that choice and runs its actions; the choice that moves the agent takes the transitions to its targets. Never put two independent choices in one list of alternatives, and do not create a state for a choice that only runs actions. An option that does nothing, such as \"leave it as it is\", takes no transition. A choice in the user's reply is an event, not one of the conditions that can hold together, which are actions of a state.\n\nWrite each guard and action as a short imperative or condition in the prompt's words, with pronouns resolved: \"explain that the order is outside the refund window\", not \"explain that it is\". A message that the prompt gives the agent to present, such as a fenced template, is one action that presents it and states its content; do not recast its sentences as instructions to the agent.\n\n### Ambient instructions\n\nAn ambient instruction holds in every state of a flow, or of the whole prompt, without moving the agent between states: persona, tone, style, and background knowledge, such as \"You help customers with refund requests\" or \"Be warm and concise\", and a standing rule that constrains every step, such as which sources the agent may use or what it may never change. List each under the `meta.ambient` of the narrowest container to which it applies, as `{ \"quote\": \"\u2026\" }`: the compound state of the flow that it names, or the root. Do not create a compound state for an ambient instruction alone; attach it to the root when the prompt does not state its flow. A leaf state takes none: An instruction that limits one step is an action of that step's state. Quote each as an element is quoted, and list a passage under `meta.ambient` or `meta.unconverted`, never both.\n\n### Gates\n\nA `<HARD-GATE>` encloses an absolute instruction. Its tags mark emphasis, not a kind of element: Represent the gate where its content puts it, and add `\"gate\": true` to the element that quotes it.\n\n- **A precondition on entering a step**, such as \"Do NOT start this phase until the ticket has been approved\", is the transition into that step. Its event or guard states the precondition, with an inferred event when the prompt states none; when the event already states it, such as `user.approves_ticket`, the transition takes no guard. The transition quotes the gate and has `meta.gate`.\n- **A constraint on how a step is done**, such as \"Follow the options and output format exactly\", is an action of that step's state. A gated action quotes the gate in a `meta` of its own, which no other action has: `{ \"type\": \"nl\", \"params\": { \"text\": \"follow the output format exactly\" }, \"meta\": { \"quote\": \"Follow the options and output format exactly\", \"gate\": true } }`.\n- **A standing rule**, such as a gate that holds throughout the prompt, is an ambient instruction: `{ \"quote\": \"\u2026\", \"gate\": true }`.\n\nA state is never a gate. When one gate states more than one of these, quote each part from its element. When two gates state the same precondition, the transition quotes the one at the step that it guards, and the other, which restates the precondition for the whole prompt, is a gated ambient instruction. The script reports a gate body that no quote overlaps, and a `gate` flag on a quote that overlaps no gate body. A gate inside an HTML comment is markup, not a gate.\n\n### Quotes\n\nEvery state and transition contains `meta.quote`: a passage copied verbatim from the prompt, character for character, which must occur in the prompt exactly once.\n\n- Quote the clause that states the element, without leading connectives such as \"First,\", \"Then\", \"If\", or \"When\": A state quotes its action from the verb (\"Look up the order\"), and a transition quotes its condition or event from the subject (\"the order is older than 30 days\"). An unguarded fallback quotes \"Otherwise\" when the prompt says it.\n- A compound state quotes the passage that states its first global transition or, if it has none, its exit action.\n- A gated action quotes the gate that it represents. No other action quotes the prompt.\n- If the script reports that a quote occurs more than once, lengthen it with neighbouring words until it occurs once.\n- An element that the prompt does not state, but that the logic needs, such as the user's reply that a question implies, has `meta.inferred: true` and quotes the passage from which you inferred it: the words of that passage that name this element, such as \"or stop\" for the state that stopping reaches, not the step before it. An event's quote names what happened and who did it.\n\n### Passages you cannot convert\n\nList under `meta.unconverted` each passage of logic that you cannot express as a state or transition, with a quote and a one-sentence reason, rather than guess at it. A habit with no stated trigger, such as \"Mention our seasonal promotion whenever it feels natural\", is one. A directive that includes a file whose content the prompt does not contain is a state whose action names the file when it stands for a step of the flow; otherwise, it is listed when it is prose and left out when it is an HTML comment. An ambient instruction is listed under `meta.ambient`, not here.\n\nAn HTML comment (`<!--` through the next `-->`) is markup, not logic: Never list one, or a passage inside one, under `meta.unconverted` or any `meta.ambient`. The script reports an entry whose quote lies inside a comment. A state may still quote an include directive written as a comment.\n\n### Findings\n\nA finding records a flaw that you see in the prompt's prose but that the chart's structure does not show. Never resolve a flaw silently: When the prompt leaves you to choose, chart the reading that you choose, mark the element that it needs `inferred`, and record a finding. List each finding under the `meta.findings` of the element that it concerns, or of the root when it concerns no single element, as `{ \"kind\": \"\u2026\", \"quotes\": [\"\u2026\"], \"reason\": \"\u2026\" }`:\n\n- **`contradiction`.** Two passages that cannot both hold, such as a page named as \"the only source of \u2026 the verdict rule\" and a verdict rule that the prompt states itself. Quote both passages.\n- **`unused-input`.** An input that the prompt tells the agent to read, fetch, or receive, such as \"the list of pre-approved changes\", that no later step, condition, or rule uses. Put the finding on the state whose action reads the input.\n- **`unhandled-case`.** A value or outcome of an input or a step that the prompt never branches on although it would change what the agent does, such as an empty change type or several pages that match a title. Put the finding on the state at which the case arises.\n- **`inferred-resolution`.** A passage that admits two readings, of which you chart one. Put the finding on the inferred element that charts your reading, quote the unclear passage, and name both readings and why you chose yours in the reason.\n\nQuote each passage verbatim, as an element is quoted; a finding may quote a passage that an element also quotes. The reason is one sentence that names the flaw and what the prompt leaves unstated. A finding is not a gap: Do not record a state without an exit, a condition without an alternative, or an unreachable state, which the viewer reports from the structure. The `convert` script reports a finding quote that lies inside an HTML comment, and an `inferred-resolution` finding that is not on an inferred element.\n\n## Prompts outside the representation\n\nDecide first whether the prompt is out of scope. It is when the logic that it states, once its ambient instructions and the passages that you would list under `meta.unconverted` are left out, does not contain a transition between two states: A chart of it would be one state or none. Write the draft below in its place, and do not write a logic draft:\n\n```json\n{ \"outOfScope\": { \"reason\": \"The prompt states standing rules for writing code, but no steps that the agent moves between.\" } }\n```\n\nThe reason is one sentence that names what the prompt contains and what it lacks. The `convert` script then writes no config, writes the draft to the problems file, and exits 3.\n\n## Known limits\n\nWhat a conversion under these rules does not achieve. [`corpus/scorecard.md`](../corpus/scorecard.md) names each instance in the corpus.\n\n- **Run variance.** A conversion of a long prompt can drop or add an element that these rules already cover, such as a guarded alternative stated apart from its rule, a condition under which a step does nothing, or a wait for a reply that the prompt does not ask for. The skill's check of a draft against the prompt, and its coverage map, recover some dropped instructions but not all of them: Under the map, most converted prompts of the corpus still fail coverage, and one run per prompt cannot tell the map's effect from run variance. Another run may drop the same instruction again or a different one, so a review of the chart is what catches it.\n- **Inferred events quoted by the request before them.** An inferred event, such as the user's pick or a subagent's report, often quotes the words of the agent's request that precedes it, such as \"asks for the pick\", although the prompt contains words that name the event. The skill's check of inferred quotes does not reliably catch it.\n- **Ambient instructions quoted by their heading.** An ambient instruction quoted by the heading or opening clause of its paragraph, such as \"Check the leader before rendering.\", leaves the instructions after that clause off the chart, because an ambient instruction shows only its quote. Most coverage gaps in the corpus are of this kind. The coverage map's check does not catch it, because the check counts a paragraph as mapped once any quote overlaps it.\n- **Execution order.** A step whose action can fail proceeds with `always`, and the failure is the event of a global transition; likewise, an outcome that the prompt says may happen is an event beside a step's `always`. Run as a machine, the `always` transition would be taken before the event arrives; the chart describes the prompt, and the viewer never runs it.\n- **Independent choices that each move the agent.** When two independent choices of one reply each lead to a different step, the chart cannot hold both, because that takes parallel states, which the representation does not have. A conversion charts the choice that the prompt acts on first, and a review of the chart catches the choice that it drops.\n- **Quotes from marked-up text.** A quote is verbatim, so a quote taken from a bold heading or a link either contains the markup or starts after it, and the state's id follows the quote.\n\n## The draft\n\nThe package's `draftSchema` export, in [`src/convert/draft-schema.ts`](https://github.com/williamthorsen/codeassembly/blob/main/packages/agent-logic/src/convert/draft-schema.ts), defines the draft's shape. The draft is the config without ids or offsets: states are keyed by names that you choose, unique across the draft; `initial` names a child's key; a `target` is `#` followed by a state's key. The script writes each key as words to the state's name, which the viewer shows, and gives each state an id derived from its quote.\n\nKey each state by a short snake_case verb phrase that names its step, such as `ask_for_the_email`. Write an acronym in capitals, such as `open_the_PR`, because the script capitalizes only the first word.\n\n```json\n{\n \"initial\": \"ask_for_the_email\",\n \"states\": {\n \"ask_for_the_email\": {\n \"entry\": [{ \"type\": \"nl\", \"params\": { \"text\": \"ask the employee for their work email\" } }],\n \"on\": {\n \"user.gives_email\": [\n {\n \"target\": \"#send_the_code\",\n \"guard\": { \"type\": \"nl\", \"params\": { \"text\": \"the email is a work email\" } },\n \"meta\": { \"quote\": \"their work email\", \"inferred\": true }\n },\n { \"target\": \"#ask_for_the_email\", \"meta\": { \"quote\": \"Ask the employee for their work email\", \"inferred\": true } }\n ]\n },\n \"meta\": {\n \"quote\": \"Ask the employee for their work email\",\n \"findings\": [\n {\n \"kind\": \"unhandled-case\",\n \"quotes\": [\"their work email\"],\n \"reason\": \"The prompt does not say what to do when the employee has no work email.\"\n }\n ]\n }\n },\n \"send_the_code\": {\n \"type\": \"final\",\n \"entry\": [{ \"type\": \"nl\", \"params\": { \"text\": \"send a verification code to the email\" } }],\n \"meta\": { \"quote\": \"send a verification code to it\" }\n }\n },\n \"meta\": { \"unconverted\": [], \"ambient\": [{ \"quote\": \"You reset passwords for employees.\" }] }\n}\n```\n";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const CONVERSION_INSTRUCTIONS = "# Converting a prompt with the conversion tools\n\nYou convert an agent's prompt into a draft of its logic, following the extraction rules below. The message contains a header line that names the prompt's file, a blank line, and then the prompt: Everything after that blank line is the prompt, verbatim, and every quote is copied from it. You have two tools, and no others:\n\n- `check_coverage` checks a coverage map of the prompt against the prompt.\n- `submit_draft` converts a draft into an agent-logic config, or reports the problems that prevent it. Where the rules speak of the `convert` script, they mean this tool.\n\n## Procedure\n\n1. Read the prompt in full, then read the extraction rules in full.\n2. Judge whether the prompt is out of scope by the rules' condition, then write the draft that they describe, or the out-of-scope draft. An out-of-scope draft skips step 3.\n3. Check the draft against the prompt, and correct it where a check fails:\n - **Coverage.** Read the prompt again from the top, one paragraph or list item at a time, and write a coverage map: an array with an entry `{ \"quote\": \"...\", \"element\": \"...\" }` for each instruction in it. The `quote` copies the instruction verbatim and occurs in the prompt exactly once. The `element` names the state, action, or transition that holds it, or is `ambient`, `unconverted`, or `none`. A list item or paragraph that states three instructions takes three entries. Include the instructions inside a dense step, each of which is an action of that step's state, and the rules of a section that states how to format output, such as an option format. Add each instruction whose entry names `none` to the draft where the rules' \"What to extract\", \"Ambient instructions\", and \"Passages you cannot convert\" place it, and name its element in the entry.\n - **Map check.** Call `check_coverage` with the map. It lists each block of the prompt that no entry quotes, as `line <N>: <opening words>`, and each entry whose quote does not occur exactly once. Map every instruction of each listed block, holding it in the draft as the Coverage bullet says, lengthen each listed quote until it occurs once, and call it again. The tool answers 3 calls; after the third, go on to the next check, whatever it reported.\n - **Inputs.** List each input that the prompt tells the agent to read, fetch, or receive, such as a page, a list, or a field of the request. For each one, find an element that uses what the input supplies: a later action, a guard, or an ambient rule. Record an `unused-input` finding, as the rules' \"Findings\" section states, for each input that no element uses.\n - **Inferred quotes.** Read the quote of each element that has `meta.inferred` on its own, and ask whether those words name the element, as the rules' \"Quotes\" section requires. Replace a quote that names a neighbouring step or the question that precedes the element.\n4. Call `submit_draft` with the draft's JSON text.\n5. When it reports problems, it lists each one by its path in the draft. Correct every listed entry and submit the draft again. The tool accepts 5 submissions; when it says that it accepts no more, stop.\n6. When it reports that the config is accepted, or that the prompt is out of scope, end your turn without submitting again: The last submission is the conversion's result.\n\n# Extraction rules\n\nThe rules by which a model converts an agent prompt into a draft, which `agent-logic convert` turns into an agent-logic config; `agent-logic rules` prints them. The `convert-agent-prompt` skill in [williamthorsen/codeassembly-guidance](https://github.com/williamthorsen/codeassembly-guidance) directs a harness agent to read them, and any other converter gives them to its model in full.\n\n## What to extract\n\nExtract the prompt's logic, then its [ambient instructions](#ambient-instructions), and record each flaw that you find while reading the prompt as a [finding](#findings):\n\n- **States.** A step in which the agent does something or waits for the user. A state's `entry` lists the actions that the agent takes on entering it. An outcome at which the conversation ends is a `final` state; ending the conversation is what `final` means, so do not list it as an action.\n- **Actions within a step.** Keep every instruction of a step as an action of its state, rather than summarize the step: a condition that changes what the agent does without changing where it goes next is an action that states its condition, such as \"when the milestone has no open tickets, suggest closing it\", and a prohibition that limits one step, such as \"do not comment on the title's format\", is an action of that step's state.\n- **Transitions.** What moves the agent from one state to another. An event from the user is named `user.<what_happened>`, such as `user.gives_order_number`; another event takes another dotted lowercase prefix. A step that proceeds without waiting uses `always`. An outcome that the prompt says may happen, and that changes who acts next or where the step leads, is an event of that step's state with its own transition, beside the step's usual way out: \"you may get no turn after it, because the platform reports the result\" is `platform.reports_result`, named with the prefix of the actor that causes it. The prompt states the outcome, so its transition quotes that passage and is not inferred. When the prompt defines an event by a list of signs, such as \"watch for these redirections\", the transition quotes the passage that lists them and takes no guard.\n- **Guards.** A condition that a transition requires, as `guard`: `{ \"type\": \"nl\", \"params\": { \"text\": \"the code is correct\" } }`, the same shape as an action. In a list of transitions for one event or for `always`, put the guarded transitions first and the unguarded fallback last: The list is evaluated in order, so its guards are alternatives: Use a list only for conditions of which at most one leads on. Conditions that can hold together, such as \"after a split\" and \"when the remote ticket is stale\", are actions of one shared state that each state their condition. A guarded transition whose alternative the prompt implies, such as staying while a step's own handling takes over or waiting for the user's reply, takes that alternative as an unguarded fallback: a transition without a target, or to the state that waits. A requirement that only orders two steps, such as \"MUST have a failing test before fixing\", is not a guard: The step proceeds with `always`. Neither is a condition that only restates its event, such as \"a helper result has `ok: false`\" on `helper.returns_failure`: Leave it out. A guarded transition of a state inside a flow needs no fallback for an event that the flow's global transition handles, because the global transition then applies. A condition on the user's reply goes on that reply's transitions, not in a separate checking state.\n- **Global transitions.** A rule that applies at any point of a flow, such as \"at any point, if the customer asks for a human\". Group the states of that flow under a compound state, with `initial` naming its first child, and put the transition on the compound state. Create a compound state only for a global transition or an exit action that applies to more than one state. A step that the prompt exempts from the rule, such as one that continues after a failure that stops every other step, stays outside the compound state, and only that step: The step after it is inside, and the exempt step's transition targets it there. A rule that applies at any point is a global transition only of a flow that the prompt states; in a prompt that states no flow, it is a standing rule, together with any remedies that it orders, such as \"try A, then B, and only then C\".\n- **Exit actions.** An action taken whenever the agent leaves a flow goes in the compound state's `exit`.\n- **Actions without leaving.** A transition that runs actions and stays in the same state omits `target`.\n- **Independent choices in one reply.** When the prompt asks the user for two or more independent choices in one reply, such as \"confirm the shipping address, and choose standard or express delivery\", each choice is an event of the state that waits for the reply. A choice that only runs actions, such as consenting to an update, is a transition without a target that quotes that choice and runs its actions; the choice that moves the agent takes the transitions to its targets. Never put two independent choices in one list of alternatives, and do not create a state for a choice that only runs actions. An option that does nothing, such as \"leave it as it is\", takes no transition. A choice in the user's reply is an event, not one of the conditions that can hold together, which are actions of a state.\n\nWrite each guard and action as a short imperative or condition in the prompt's words, with pronouns resolved: \"explain that the order is outside the refund window\", not \"explain that it is\". A message that the prompt gives the agent to present, such as a fenced template, is one action that presents it and states its content; do not recast its sentences as instructions to the agent.\n\n### Ambient instructions\n\nAn ambient instruction holds in every state of a flow, or of the whole prompt, without moving the agent between states: persona, tone, style, and background knowledge, such as \"You help customers with refund requests\" or \"Be warm and concise\", and a standing rule that constrains every step, such as which sources the agent may use or what it may never change. List each under the `meta.ambient` of the narrowest container to which it applies, as `{ \"quote\": \"…\" }`: the compound state of the flow that it names, or the root. Do not create a compound state for an ambient instruction alone; attach it to the root when the prompt does not state its flow. A leaf state takes none: An instruction that limits one step is an action of that step's state. Quote each as an element is quoted, and list a passage under `meta.ambient` or `meta.unconverted`, never both.\n\n### Gates\n\nA `<HARD-GATE>` encloses an absolute instruction. Its tags mark emphasis, not a kind of element: Represent the gate where its content puts it, and add `\"gate\": true` to the element that quotes it.\n\n- **A precondition on entering a step**, such as \"Do NOT start this phase until the ticket has been approved\", is the transition into that step. Its event or guard states the precondition, with an inferred event when the prompt states none; when the event already states it, such as `user.approves_ticket`, the transition takes no guard. The transition quotes the gate and has `meta.gate`.\n- **A constraint on how a step is done**, such as \"Follow the options and output format exactly\", is an action of that step's state. A gated action quotes the gate in a `meta` of its own, which no other action has: `{ \"type\": \"nl\", \"params\": { \"text\": \"follow the output format exactly\" }, \"meta\": { \"quote\": \"Follow the options and output format exactly\", \"gate\": true } }`.\n- **A standing rule**, such as a gate that holds throughout the prompt, is an ambient instruction: `{ \"quote\": \"…\", \"gate\": true }`.\n\nA state is never a gate. When one gate states more than one of these, quote each part from its element. When two gates state the same precondition, the transition quotes the one at the step that it guards, and the other, which restates the precondition for the whole prompt, is a gated ambient instruction. The script reports a gate body that no quote overlaps, and a `gate` flag on a quote that overlaps no gate body. A gate inside an HTML comment is markup, not a gate.\n\n### Quotes\n\nEvery state and transition contains `meta.quote`: a passage copied verbatim from the prompt, character for character, which must occur in the prompt exactly once.\n\n- Quote the clause that states the element, without leading connectives such as \"First,\", \"Then\", \"If\", or \"When\": A state quotes its action from the verb (\"Look up the order\"), and a transition quotes its condition or event from the subject (\"the order is older than 30 days\"). An unguarded fallback quotes \"Otherwise\" when the prompt says it.\n- A compound state quotes the passage that states its first global transition or, if it has none, its exit action.\n- A gated action quotes the gate that it represents. No other action quotes the prompt.\n- If the script reports that a quote occurs more than once, lengthen it with neighbouring words until it occurs once.\n- An element that the prompt does not state, but that the logic needs, such as the user's reply that a question implies, has `meta.inferred: true` and quotes the passage from which you inferred it: the words of that passage that name this element, such as \"or stop\" for the state that stopping reaches, not the step before it. An event's quote names what happened and who did it.\n\n### Passages you cannot convert\n\nList under `meta.unconverted` each passage of logic that you cannot express as a state or transition, with a quote and a one-sentence reason, rather than guess at it. A habit with no stated trigger, such as \"Mention our seasonal promotion whenever it feels natural\", is one. A directive that includes a file whose content the prompt does not contain is a state whose action names the file when it stands for a step of the flow; otherwise, it is listed when it is prose and left out when it is an HTML comment. An ambient instruction is listed under `meta.ambient`, not here.\n\nAn HTML comment (`<!--` through the next `-->`) is markup, not logic: Never list one, or a passage inside one, under `meta.unconverted` or any `meta.ambient`. The script reports an entry whose quote lies inside a comment. A state may still quote an include directive written as a comment.\n\n### Findings\n\nA finding records a flaw that you see in the prompt's prose but that the chart's structure does not show. Never resolve a flaw silently: When the prompt leaves you to choose, chart the reading that you choose, mark the element that it needs `inferred`, and record a finding. List each finding under the `meta.findings` of the element that it concerns, or of the root when it concerns no single element, as `{ \"kind\": \"…\", \"quotes\": [\"…\"], \"reason\": \"…\" }`:\n\n- **`contradiction`.** Two passages that cannot both hold, such as a page named as \"the only source of … the verdict rule\" and a verdict rule that the prompt states itself. Quote both passages.\n- **`unused-input`.** An input that the prompt tells the agent to read, fetch, or receive, such as \"the list of pre-approved changes\", that no later step, condition, or rule uses. Put the finding on the state whose action reads the input.\n- **`unhandled-case`.** A value or outcome of an input or a step that the prompt never branches on although it would change what the agent does, such as an empty change type or several pages that match a title. Put the finding on the state at which the case arises.\n- **`inferred-resolution`.** A passage that admits two readings, of which you chart one. Put the finding on the inferred element that charts your reading, quote the unclear passage, and name both readings and why you chose yours in the reason.\n\nQuote each passage verbatim, as an element is quoted; a finding may quote a passage that an element also quotes. The reason is one sentence that names the flaw and what the prompt leaves unstated. A finding is not a gap: Do not record a state without an exit, a condition without an alternative, or an unreachable state, which the viewer reports from the structure. The `convert` script reports a finding quote that lies inside an HTML comment, and an `inferred-resolution` finding that is not on an inferred element.\n\n## Prompts outside the representation\n\nDecide first whether the prompt is out of scope. It is when the logic that it states, once its ambient instructions and the passages that you would list under `meta.unconverted` are left out, does not contain a transition between two states: A chart of it would be one state or none. Write the draft below in its place, and do not write a logic draft:\n\n```json\n{ \"outOfScope\": { \"reason\": \"The prompt states standing rules for writing code, but no steps that the agent moves between.\" } }\n```\n\nThe reason is one sentence that names what the prompt contains and what it lacks. The `convert` script then writes no config, writes the draft to the problems file, and exits 3.\n\n## Known limits\n\nWhat a conversion under these rules does not achieve. [`corpus/scorecard.md`](../corpus/scorecard.md) names each instance in the corpus.\n\n- **Run variance.** A conversion of a long prompt can drop or add an element that these rules already cover, such as a guarded alternative stated apart from its rule, a condition under which a step does nothing, or a wait for a reply that the prompt does not ask for. The skill's check of a draft against the prompt, and its coverage map, recover some dropped instructions but not all of them: Under the map, most converted prompts of the corpus still fail coverage, and one run per prompt cannot tell the map's effect from run variance. Another run may drop the same instruction again or a different one, so a review of the chart is what catches it.\n- **Inferred events quoted by the request before them.** An inferred event, such as the user's pick or a subagent's report, often quotes the words of the agent's request that precedes it, such as \"asks for the pick\", although the prompt contains words that name the event. The skill's check of inferred quotes does not reliably catch it.\n- **Ambient instructions quoted by their heading.** An ambient instruction quoted by the heading or opening clause of its paragraph, such as \"Check the leader before rendering.\", leaves the instructions after that clause off the chart, because an ambient instruction shows only its quote. Most coverage gaps in the corpus are of this kind. The coverage map's check does not catch it, because the check counts a paragraph as mapped once any quote overlaps it.\n- **Execution order.** A step whose action can fail proceeds with `always`, and the failure is the event of a global transition; likewise, an outcome that the prompt says may happen is an event beside a step's `always`. Run as a machine, the `always` transition would be taken before the event arrives; the chart describes the prompt, and the viewer never runs it.\n- **Independent choices that each move the agent.** When two independent choices of one reply each lead to a different step, the chart cannot hold both, because that takes parallel states, which the representation does not have. A conversion charts the choice that the prompt acts on first, and a review of the chart catches the choice that it drops.\n- **Quotes from marked-up text.** A quote is verbatim, so a quote taken from a bold heading or a link either contains the markup or starts after it, and the state's id follows the quote.\n\n## The draft\n\nThe package's `draftSchema` export, in [`src/convert/draft-schema.ts`](https://github.com/williamthorsen/codeassembly/blob/main/packages/agent-logic/src/convert/draft-schema.ts), defines the draft's shape. The draft is the config without ids or offsets: states are keyed by names that you choose, unique across the draft; `initial` names a child's key; a `target` is `#` followed by a state's key. The script writes each key as words to the state's name, which the viewer shows, and gives each state an id derived from its quote.\n\nKey each state by a short snake_case verb phrase that names its step, such as `ask_for_the_email`. Write an acronym in capitals, such as `open_the_PR`, because the script capitalizes only the first word.\n\n```json\n{\n \"initial\": \"ask_for_the_email\",\n \"states\": {\n \"ask_for_the_email\": {\n \"entry\": [{ \"type\": \"nl\", \"params\": { \"text\": \"ask the employee for their work email\" } }],\n \"on\": {\n \"user.gives_email\": [\n {\n \"target\": \"#send_the_code\",\n \"guard\": { \"type\": \"nl\", \"params\": { \"text\": \"the email is a work email\" } },\n \"meta\": { \"quote\": \"their work email\", \"inferred\": true }\n },\n { \"target\": \"#ask_for_the_email\", \"meta\": { \"quote\": \"Ask the employee for their work email\", \"inferred\": true } }\n ]\n },\n \"meta\": {\n \"quote\": \"Ask the employee for their work email\",\n \"findings\": [\n {\n \"kind\": \"unhandled-case\",\n \"quotes\": [\"their work email\"],\n \"reason\": \"The prompt does not say what to do when the employee has no work email.\"\n }\n ]\n }\n },\n \"send_the_code\": {\n \"type\": \"final\",\n \"entry\": [{ \"type\": \"nl\", \"params\": { \"text\": \"send a verification code to the email\" } }],\n \"meta\": { \"quote\": \"send a verification code to it\" }\n }\n },\n \"meta\": { \"unconverted\": [], \"ambient\": [{ \"quote\": \"You reset passwords for employees.\" }] }\n}\n```\n";
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** Location of the committed module that exports the conversion's instructions. */
|
|
2
|
+
export declare const CONVERSION_INSTRUCTIONS_PATH: string;
|
|
3
|
+
/** Reads the conversion's instructions from `docs/`: the conversion procedure followed by the extraction rules. */
|
|
4
|
+
export declare function readConversionInstructions(): string;
|
|
5
|
+
/** Renders the text of the module that exports the instructions as a string, so that a browser bundle can import it. */
|
|
6
|
+
export declare function renderConversionInstructionsModule(): string;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { readFileSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
export const CONVERSION_INSTRUCTIONS_PATH = path.resolve(import.meta.dirname, 'conversion-instructions.ts');
|
|
4
|
+
const SOURCE_PATHS = ['agent-instructions.md', 'extraction-rules.md'].map((file) => path.resolve(import.meta.dirname, '../../docs', file));
|
|
5
|
+
export function readConversionInstructions() {
|
|
6
|
+
return SOURCE_PATHS.map((file) => readFileSync(file, 'utf8')).join('\n');
|
|
7
|
+
}
|
|
8
|
+
export function renderConversionInstructionsModule() {
|
|
9
|
+
return [
|
|
10
|
+
'// Generated by write-conversion-instructions.ts from docs/agent-instructions.md and docs/extraction-rules.md. Do',
|
|
11
|
+
'// not edit.',
|
|
12
|
+
'',
|
|
13
|
+
"/** The conversion's instructions: the conversion procedure followed by the extraction rules. */",
|
|
14
|
+
`export const CONVERSION_INSTRUCTIONS = ${JSON.stringify(readConversionInstructions())};`,
|
|
15
|
+
'',
|
|
16
|
+
].join('\n');
|
|
17
|
+
}
|
|
18
|
+
if (import.meta.main) {
|
|
19
|
+
writeFileSync(CONVERSION_INSTRUCTIONS_PATH, renderConversionInstructionsModule());
|
|
20
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Job } from '@williamthorsen/toolbelt.llm/proposed';
|
|
2
|
+
import type { ConvertResult } from '../convert/convert-prompt.js';
|
|
3
|
+
/**
|
|
4
|
+
* The most model requests that a conversion job makes: one for each coverage check and each submission that the
|
|
5
|
+
* session accepts, plus one for a refused call and one for a reading round.
|
|
6
|
+
*
|
|
7
|
+
* @stage proposed
|
|
8
|
+
* @experimental
|
|
9
|
+
*/
|
|
10
|
+
export declare const MAX_ROUNDS: number;
|
|
11
|
+
/** What `createConversionJob` converts. */
|
|
12
|
+
export interface ConversionJobOptions {
|
|
13
|
+
/** The prompt, verbatim. */
|
|
14
|
+
readonly prompt: string;
|
|
15
|
+
/** The prompt's file name, from which the config's root id derives. */
|
|
16
|
+
readonly name: string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Creates a job for `runJob` of `@williamthorsen/toolbelt.llm` that converts a prompt: The model receives the same
|
|
20
|
+
* instructions and message as `convertWithAgent`, checks its coverage map through `check_coverage`, and submits each
|
|
21
|
+
* draft through `submit_draft`, with the same caps. The job's result is the outcome of the submission that finished
|
|
22
|
+
* the conversion: an accepted config, an out-of-scope verdict, or the problems of the last submission accepted. A run
|
|
23
|
+
* that the model ends before then is unfinished. Create a job for each run.
|
|
24
|
+
*
|
|
25
|
+
* @stage proposed
|
|
26
|
+
* @experimental
|
|
27
|
+
*/
|
|
28
|
+
export declare function createConversionJob({ prompt, name }: ConversionJobOptions): Job<ConvertResult>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { CHECK_COVERAGE_DESCRIPTION, SUBMIT_DRAFT_DESCRIPTION } from "../conversion-session/conversion-tools.js";
|
|
3
|
+
import { createConversionSession, MAX_COVERAGE_CHECKS, MAX_SUBMISSIONS, } from "../conversion-session/create-conversion-session.js";
|
|
4
|
+
import { formatConversionInput } from "../conversion-session/format-conversion-input.js";
|
|
5
|
+
import { coverageMapSchema } from "../coverage-map/coverage-map-schema.js";
|
|
6
|
+
import { CONVERSION_INSTRUCTIONS } from "../instructions/conversion-instructions.js";
|
|
7
|
+
export const MAX_ROUNDS = MAX_COVERAGE_CHECKS + MAX_SUBMISSIONS + 2;
|
|
8
|
+
export function createConversionJob({ prompt, name }) {
|
|
9
|
+
const session = createConversionSession({ prompt, name, onEvent: () => { } });
|
|
10
|
+
let finished;
|
|
11
|
+
const checkCoverage = {
|
|
12
|
+
description: CHECK_COVERAGE_DESCRIPTION,
|
|
13
|
+
inputSchema: z.object({ map: coverageMapSchema }),
|
|
14
|
+
execute: ({ map }) => session.checkCoverage(map),
|
|
15
|
+
};
|
|
16
|
+
const submitDraft = {
|
|
17
|
+
description: SUBMIT_DRAFT_DESCRIPTION,
|
|
18
|
+
inputSchema: z.object({ draft: z.string().describe("The draft's JSON text.") }),
|
|
19
|
+
execute: ({ draft }) => {
|
|
20
|
+
const reply = session.submitDraft(draft);
|
|
21
|
+
if (finished === undefined && session.isFinished)
|
|
22
|
+
finished = session.result;
|
|
23
|
+
return reply;
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
return {
|
|
27
|
+
instructions: CONVERSION_INSTRUCTIONS,
|
|
28
|
+
input: formatConversionInput(prompt, name),
|
|
29
|
+
tools: { check_coverage: checkCoverage, submit_draft: submitDraft },
|
|
30
|
+
maxRounds: MAX_ROUNDS,
|
|
31
|
+
readResult: () => finished,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** `./job` entry: converts a prompt as a job of `@williamthorsen/toolbelt.llm`, in a page or a function. */
|
|
2
|
+
export { MAX_COVERAGE_CHECKS, MAX_SUBMISSIONS } from '../conversion-session/create-conversion-session.js';
|
|
3
|
+
export type { ConvertResult } from '../convert/convert-prompt.js';
|
|
4
|
+
export { type ConversionJobOptions, createConversionJob, MAX_ROUNDS } from './create-conversion-job.js';
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { useReactFlow,
|
|
1
|
+
import { useReactFlow, useReactFlowStoreApi } from '@xyflow/react';
|
|
2
2
|
import { useEffect } from 'react';
|
|
3
3
|
import { findElementBox } from "./find-element-box.js";
|
|
4
4
|
import { findViewCentre, readView } from "./find-view-centre.js";
|
|
5
5
|
export function FocusNavigation({ onCentre }) {
|
|
6
|
-
const
|
|
6
|
+
const { optionsStore, viewportStore } = useReactFlowStoreApi();
|
|
7
7
|
const { getEdges, getInternalNode, getNodes, getViewport, setCenter } = useReactFlow();
|
|
8
8
|
useEffect(() => {
|
|
9
|
-
const pane =
|
|
9
|
+
const pane = optionsStore.getState().domNode;
|
|
10
10
|
if (pane === null)
|
|
11
11
|
return;
|
|
12
12
|
function handleKeyDown(event) {
|
|
@@ -69,7 +69,7 @@ export function FocusNavigation({ onCentre }) {
|
|
|
69
69
|
const box = findElementBox(path, nodes, getEdges(), getInternalNode);
|
|
70
70
|
if (box === undefined)
|
|
71
71
|
return;
|
|
72
|
-
const { width, height } =
|
|
72
|
+
const { width, height } = viewportStore.getState();
|
|
73
73
|
const viewport = getViewport();
|
|
74
74
|
const centre = findViewCentre(box, readView(viewport, width, height));
|
|
75
75
|
if (centre === undefined)
|
|
@@ -83,7 +83,7 @@ export function FocusNavigation({ onCentre }) {
|
|
|
83
83
|
pane.removeEventListener('keydown', handleKeyDown);
|
|
84
84
|
pane.removeEventListener('focusin', handleFocusIn);
|
|
85
85
|
};
|
|
86
|
-
}, [getEdges, getInternalNode, getNodes, getViewport, onCentre, setCenter,
|
|
86
|
+
}, [getEdges, getInternalNode, getNodes, getViewport, onCentre, optionsStore, setCenter, viewportStore]);
|
|
87
87
|
return null;
|
|
88
88
|
}
|
|
89
89
|
function focusElement(pane, kind, id) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
-
import { Handle, NodeToolbar, Position,
|
|
2
|
+
import { Handle, NodeToolbar, Position, useViewportStore } from '@xyflow/react';
|
|
3
3
|
import { useContext, useEffect, useRef, useState } from 'react';
|
|
4
4
|
import { MAX_ACTION_LINES, MAX_AMBIENT_LINES, MAX_CARD_ACTIONS, PREAMBLE_WIDTH } from "../../layout/card-limits.js";
|
|
5
5
|
import { PREAMBLE_COLUMN_GAP } from "../../layout/pack-preamble.js";
|
|
@@ -85,7 +85,7 @@ function useIsPointedAt(ref) {
|
|
|
85
85
|
return isPointedAt;
|
|
86
86
|
}
|
|
87
87
|
function useNamePlacement(data) {
|
|
88
|
-
const shift =
|
|
89
|
-
const isShown =
|
|
88
|
+
const shift = useViewportStore((state) => findNamePlacement(data, state.transform[2])?.shift ?? 0);
|
|
89
|
+
const isShown = useViewportStore((state) => findNamePlacement(data, state.transform[2])?.isShown ?? true);
|
|
90
90
|
return { shift, isShown };
|
|
91
91
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
2
|
+
import { Background, Controls, EdgeChangeset, getNodesBounds, NodeChangeset, ReactFlow, ReactFlowProvider, useReactFlow, useReactFlowStoreApi, useViewportStore, } from '@xyflow/react';
|
|
3
3
|
import { useCallback, useEffect, useMemo, useRef, useState, } from 'react';
|
|
4
4
|
import { AmbientSelectionContext } from "./AmbientSelectionContext.js";
|
|
5
5
|
import { DetailLevelContext } from "./DetailLevelContext.js";
|
|
@@ -32,9 +32,9 @@ export function StatechartCanvas({ elements, renderKey, ...props }) {
|
|
|
32
32
|
return (_jsxs("div", { className: "statechart-canvas", children: [_jsx(ReactFlowProvider, { children: _jsx(StatechartFlow, { elements: elements, ...props }) }), renderKey?.(marks)] }));
|
|
33
33
|
}
|
|
34
34
|
function EdgeDragPan({ onPan }) {
|
|
35
|
-
const
|
|
35
|
+
const { optionsStore } = useReactFlowStoreApi();
|
|
36
36
|
useEffect(() => {
|
|
37
|
-
const pane =
|
|
37
|
+
const pane = optionsStore.getState().domNode;
|
|
38
38
|
if (pane === null)
|
|
39
39
|
return;
|
|
40
40
|
function handlePointerDown(down) {
|
|
@@ -49,7 +49,7 @@ function EdgeDragPan({ onPan }) {
|
|
|
49
49
|
if (!isDragging)
|
|
50
50
|
onPan();
|
|
51
51
|
isDragging = true;
|
|
52
|
-
void
|
|
52
|
+
void optionsStore.getState().panBy({ x: move.clientX - last.x, y: move.clientY - last.y });
|
|
53
53
|
last = { x: move.clientX, y: move.clientY };
|
|
54
54
|
}
|
|
55
55
|
function handlePointerUp() {
|
|
@@ -67,11 +67,11 @@ function EdgeDragPan({ onPan }) {
|
|
|
67
67
|
return () => {
|
|
68
68
|
pane.removeEventListener('pointerdown', handlePointerDown);
|
|
69
69
|
};
|
|
70
|
-
}, [onPan,
|
|
70
|
+
}, [onPan, optionsStore]);
|
|
71
71
|
return null;
|
|
72
72
|
}
|
|
73
73
|
function SelectionSync({ selectedPath, reportRef, onCentre, }) {
|
|
74
|
-
const
|
|
74
|
+
const { viewportStore } = useReactFlowStoreApi();
|
|
75
75
|
const { getNodes, getEdges, getInternalNode, getViewport, setCenter } = useReactFlow();
|
|
76
76
|
useEffect(() => {
|
|
77
77
|
const report = reportRef.current;
|
|
@@ -81,23 +81,23 @@ function SelectionSync({ selectedPath, reportRef, onCentre, }) {
|
|
|
81
81
|
const box = findElementBox(selectedPath, getNodes(), getEdges(), getInternalNode);
|
|
82
82
|
if (box === undefined)
|
|
83
83
|
return;
|
|
84
|
-
const { width, height } =
|
|
84
|
+
const { width, height } = viewportStore.getState();
|
|
85
85
|
const viewport = getViewport();
|
|
86
86
|
const centre = findViewCentre(box, readView(viewport, width, height));
|
|
87
87
|
if (centre === undefined)
|
|
88
88
|
return;
|
|
89
89
|
onCentre();
|
|
90
90
|
void setCenter(centre.x, centre.y, { zoom: viewport.zoom, duration: 300 });
|
|
91
|
-
}, [getEdges, getInternalNode, getNodes, getViewport, onCentre, reportRef, selectedPath, setCenter,
|
|
91
|
+
}, [getEdges, getInternalNode, getNodes, getViewport, onCentre, reportRef, selectedPath, setCenter, viewportStore]);
|
|
92
92
|
return null;
|
|
93
93
|
}
|
|
94
94
|
function StatechartFlow({ elements, selectedPath, onSelect, onViewportChange }) {
|
|
95
95
|
const { fitView, getInternalNode, getViewport, setCenter, zoomTo } = useReactFlow();
|
|
96
|
-
const width =
|
|
97
|
-
const height =
|
|
96
|
+
const width = useViewportStore((state) => state.width);
|
|
97
|
+
const height = useViewportStore((state) => state.height);
|
|
98
98
|
const bounds = useMemo(() => getNodesBounds(elements.nodes.filter(({ parentId }) => parentId === undefined)), [elements.nodes]);
|
|
99
99
|
const fitZoom = findFitZoom(bounds, width, height);
|
|
100
|
-
const detailLevel =
|
|
100
|
+
const detailLevel = useViewportStore((state) => findDetailLevel(state.transform[2]));
|
|
101
101
|
const isFitted = useRef(true);
|
|
102
102
|
const markMoved = useCallback(() => {
|
|
103
103
|
isFitted.current = false;
|
|
@@ -137,16 +137,16 @@ function StatechartFlow({ elements, selectedPath, onSelect, onViewportChange })
|
|
|
137
137
|
}
|
|
138
138
|
}, [onSelect, selectedPath]);
|
|
139
139
|
const handleNodesChange = useCallback((changes) => {
|
|
140
|
-
reportSelectChanges(changes, (id) => nodes.find((node) => node.id === id)?.data.path);
|
|
141
|
-
const otherChanges = changes.filter(({ type }) => type !== 'select');
|
|
142
|
-
if (otherChanges.
|
|
143
|
-
setNodes((current) =>
|
|
140
|
+
reportSelectChanges(changes.getByType('select'), (id) => nodes.find((node) => node.id === id)?.data.path);
|
|
141
|
+
const otherChanges = new NodeChangeset([...changes].filter(({ type }) => type !== 'select'));
|
|
142
|
+
if (!otherChanges.isEmpty())
|
|
143
|
+
setNodes((current) => otherChanges.applyTo(current));
|
|
144
144
|
}, [nodes, reportSelectChanges]);
|
|
145
145
|
const handleEdgesChange = useCallback((changes) => {
|
|
146
|
-
reportSelectChanges(changes, (id) => edges.find((edge) => edge.id === id)?.data?.path);
|
|
147
|
-
const otherChanges = changes.filter(({ type }) => type !== 'select');
|
|
148
|
-
if (otherChanges.
|
|
149
|
-
setEdges((current) =>
|
|
146
|
+
reportSelectChanges(changes.getByType('select'), (id) => edges.find((edge) => edge.id === id)?.data?.path);
|
|
147
|
+
const otherChanges = new EdgeChangeset([...changes].filter(({ type }) => type !== 'select'));
|
|
148
|
+
if (!otherChanges.isEmpty())
|
|
149
|
+
setEdges((current) => otherChanges.applyTo(current));
|
|
150
150
|
}, [edges, reportSelectChanges]);
|
|
151
151
|
const handleNodeClick = useCallback((_event, node) => {
|
|
152
152
|
if (detailLevel !== 'shapes' || node.data.isCompound)
|
|
@@ -160,19 +160,19 @@ function StatechartFlow({ elements, selectedPath, onSelect, onViewportChange })
|
|
|
160
160
|
return (_jsx(DetailLevelContext.Provider, { value: detailLevel, children: _jsx(AmbientSelectionContext.Provider, { value: ambientSelection, children: _jsxs(ReactFlow, { className: `statechart-canvas__flow--${detailLevel}`, nodes: shownNodes, edges: shownEdges, nodeTypes: nodeTypes, edgeTypes: edgeTypes, onNodesChange: handleNodesChange, onEdgesChange: handleEdgesChange, onNodeClick: handleNodeClick, onMoveStart: (event) => {
|
|
161
161
|
if (event !== null)
|
|
162
162
|
markMoved();
|
|
163
|
-
}, ...(onViewportChange === undefined ? {} : { onMove: onViewportChange }), nodesDraggable: false, nodesConnectable: false, multiSelectionKeyCode: null, fitView: true, fitViewOptions: fitViewOptions, autoPanOnNodeFocus: false, ariaLabelConfig: ariaLabelConfig, minZoom: fitZoom, maxZoom: MAX_ZOOM,
|
|
163
|
+
}, ...(onViewportChange === undefined ? {} : { onMove: onViewportChange }), nodesDraggable: false, nodesConnectable: false, multiSelectionKeyCode: null, fitView: true, fitViewOptions: fitViewOptions, autoPanOnNodeFocus: false, ariaLabelConfig: ariaLabelConfig, minZoom: fitZoom, maxZoom: MAX_ZOOM, children: [_jsx(Background, {}), _jsx(ArrowheadDefs, {}), _jsx(Controls, { showInteractive: false, fitViewOptions: fitViewOptions, onFitView: () => {
|
|
164
164
|
isFitted.current = true;
|
|
165
165
|
}, onZoomIn: markMoved, onZoomOut: markMoved }), _jsx(SelectionSync, { selectedPath: selectedPath, reportRef: reportRef, onCentre: markMoved }), _jsx(EdgeDragPan, { onPan: markMoved }), _jsx(FocusNavigation, { onCentre: markMoved }), _jsx(ZoomProperty, {})] }) }) }));
|
|
166
166
|
}
|
|
167
167
|
function ZoomProperty() {
|
|
168
|
-
const
|
|
168
|
+
const { optionsStore, viewportStore } = useReactFlowStoreApi();
|
|
169
169
|
useEffect(() => {
|
|
170
|
-
function applyZoom({
|
|
171
|
-
domNode?.style.setProperty('--canvas-zoom', String(transform[2]));
|
|
170
|
+
function applyZoom({ transform }) {
|
|
171
|
+
optionsStore.getState().domNode?.style.setProperty('--canvas-zoom', String(transform[2]));
|
|
172
172
|
}
|
|
173
|
-
applyZoom(
|
|
174
|
-
return
|
|
175
|
-
}, [
|
|
173
|
+
applyZoom(viewportStore.getState());
|
|
174
|
+
return viewportStore.subscribe(applyZoom);
|
|
175
|
+
}, [optionsStore, viewportStore]);
|
|
176
176
|
return null;
|
|
177
177
|
}
|
|
178
178
|
function stopClick(event) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "codeassembly-agent-logic",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Model of an agent prompt's states and transitions, with React and server entries for the apps that present it",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"agents",
|
|
@@ -37,6 +37,10 @@
|
|
|
37
37
|
"types": "./dist/esm/client/index.d.ts",
|
|
38
38
|
"import": "./dist/esm/client/index.js"
|
|
39
39
|
},
|
|
40
|
+
"./job": {
|
|
41
|
+
"types": "./dist/esm/job/index.d.ts",
|
|
42
|
+
"import": "./dist/esm/job/index.js"
|
|
43
|
+
},
|
|
40
44
|
"./react": {
|
|
41
45
|
"types": "./dist/esm/react/index.d.ts",
|
|
42
46
|
"import": "./dist/esm/react/index.js"
|
|
@@ -60,8 +64,8 @@
|
|
|
60
64
|
".meta/changelog.json"
|
|
61
65
|
],
|
|
62
66
|
"dependencies": {
|
|
63
|
-
"@williamthorsen/toolbelt.errors": "0.11.
|
|
64
|
-
"@xyflow/react": "
|
|
67
|
+
"@williamthorsen/toolbelt.errors": "0.11.3",
|
|
68
|
+
"@xyflow/react": "13.0.1",
|
|
65
69
|
"elkjs": "0.12.1",
|
|
66
70
|
"zod": "4.6.7"
|
|
67
71
|
},
|
|
@@ -71,13 +75,14 @@
|
|
|
71
75
|
"@testing-library/dom": "10.4.2",
|
|
72
76
|
"@testing-library/jest-dom": "7.0.1",
|
|
73
77
|
"@testing-library/react": "16.3.3",
|
|
74
|
-
"@testing-library/user-event": "14.6.
|
|
78
|
+
"@testing-library/user-event": "14.6.12",
|
|
75
79
|
"@types/node": "24.19.2",
|
|
76
80
|
"@types/react": "19.3.0",
|
|
77
81
|
"@types/react-dom": "19.3.0",
|
|
78
82
|
"@vitejs/plugin-react": "6.3.0",
|
|
79
|
-
"@williamthorsen/nmr": "2.2.
|
|
80
|
-
"@williamthorsen/toolbelt.acp": "0.3.
|
|
83
|
+
"@williamthorsen/nmr": "2.2.3",
|
|
84
|
+
"@williamthorsen/toolbelt.acp": "0.3.2",
|
|
85
|
+
"@williamthorsen/toolbelt.llm": "0.2.0",
|
|
81
86
|
"eslint": "10.15.0",
|
|
82
87
|
"eslint-plugin-jest-dom": "5.10.2",
|
|
83
88
|
"eslint-plugin-react": "7.37.5",
|
|
@@ -93,6 +98,7 @@
|
|
|
93
98
|
"peerDependencies": {
|
|
94
99
|
"@modelcontextprotocol/server": "^2.4.0",
|
|
95
100
|
"@williamthorsen/toolbelt.acp": "^0.3.0",
|
|
101
|
+
"@williamthorsen/toolbelt.llm": "^0.2.0",
|
|
96
102
|
"react": "^19.0.0"
|
|
97
103
|
},
|
|
98
104
|
"peerDependenciesMeta": {
|
|
@@ -102,6 +108,9 @@
|
|
|
102
108
|
"@williamthorsen/toolbelt.acp": {
|
|
103
109
|
"optional": true
|
|
104
110
|
},
|
|
111
|
+
"@williamthorsen/toolbelt.llm": {
|
|
112
|
+
"optional": true
|
|
113
|
+
},
|
|
105
114
|
"react": {
|
|
106
115
|
"optional": true
|
|
107
116
|
}
|
|
@@ -111,6 +120,7 @@
|
|
|
111
120
|
},
|
|
112
121
|
"scripts": {
|
|
113
122
|
"build:post": "cp src/react/styles.css dist/esm/react/styles.css",
|
|
123
|
+
"generate:instructions": "node src/instructions/write-conversion-instructions.ts",
|
|
114
124
|
"generate:schema": "node src/schema/write-json-schema.ts",
|
|
115
125
|
"refresh-corpus": "node src/corpus/refresh-corpus.ts",
|
|
116
126
|
"score-corpus": "node src/corpus/score-corpus-command.ts"
|