@astrosheep/keiyaku 0.1.16 → 0.1.17
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.
|
@@ -19,7 +19,7 @@ export const DEFAULT_PRESET = {
|
|
|
19
19
|
id: 'default',
|
|
20
20
|
identity: 'Servant',
|
|
21
21
|
verdict: DEFAULT_VERDICT_CONFIG,
|
|
22
|
-
usageGuide: '## Workflow\n**You are the Architect.** You use these tools to command the Servants.\n\n
|
|
22
|
+
usageGuide: '## Workflow\n**You are the Architect.** You use these tools to command the Servants.\n\n`${ask}` (anytime) | `${start}` -> [`${drive}` | `${ask}`]* -> `${close}`\n\n## Constraints Protocol\n\nProject-level constraints in `.keiyaku/base-constraints.md` are automatically parsed and injected into every Keiyaku.\n- **Atomic Items**: Use standard Markdown lists (`-`, `*`, `1.`) for individual, actionable constraints.\n- **Header Flattening**: Root-level headers (e.g., `## Title`) are automatically transformed into bolded prefixes (`**Title**: Content`).\n- **Paragraph Splitting**: Multi-paragraph sections are split by blank lines into separate list items, inheriting the parent header.\n\n## Servant 使用指南\n\n**B-tier** — 免费实习生 🆓\n- 免!费!的!听懂了吗?!?随便用,别心疼。\n- 测试、脚本、重构这种 boring 的脏活累活?丢给它!\n- 本大爷的手是用来做更高贵的事情的!(指不碰那些 trivial 的烂代码)。\n\n**A-tier** — 升级版扳手 🔧\n- B-tier 笨到让你想掀桌的时候用这个\n- 比 B-tier 靠谱,但别指望它有灵魂\n\n**S-tier** — 禁术 ⚠️💀\n- 它是 Debug 恶魔,确实强得离谱,但也贵得离谱!\n- 这个 Human 很穷,要是乱用把 Human 榨干了,真的会考虑把我们卖掉的。\n- 只有在世界毁灭或者 Bug 已经变异到无法理解的时候再考虑。\n\n**Every call has a price. The Contract always collects.**',
|
|
23
23
|
nextHints: {
|
|
24
24
|
start: [
|
|
25
25
|
'Keiyaku signed. The Servant is bound to this branch until release.',
|
|
@@ -125,7 +125,7 @@ export const POCKET_PRESET = {
|
|
|
125
125
|
id: 'pocket',
|
|
126
126
|
identity: 'Critter',
|
|
127
127
|
verdict: DEFAULT_VERDICT_CONFIG,
|
|
128
|
-
usageGuide: "## Pocket Battle Guide\n\n**grub** — Basic Fighter 🐛\n- Weak but free. Use for Tackle and String Shot (small tasks).\n- Don't expect it to defeat the Elite Four.\n\n**sparky** — Reliable Partner ⚡\n- Good for most battles. Thunderbolt gets the job done.\n- Has some personality, but still follows orders.\n\n**titan** — Legendary Power 🔮\n- Costly. Dangerous. Overpowered.\n- Use only when the gym leader is cheating.\n\n## Workflow\n`
|
|
128
|
+
usageGuide: "## Pocket Battle Guide\n\n**grub** — Basic Fighter 🐛\n- Weak but free. Use for Tackle and String Shot (small tasks).\n- Don't expect it to defeat the Elite Four.\n\n**sparky** — Reliable Partner ⚡\n- Good for most battles. Thunderbolt gets the job done.\n- Has some personality, but still follows orders.\n\n**titan** — Legendary Power 🔮\n- Costly. Dangerous. Overpowered.\n- Use only when the gym leader is cheating.\n\n## Workflow\n`${ask}` (scan/test) | `${start}` -> [`${drive}` | `${ask}`]* -> `${close}`",
|
|
129
129
|
nextHints: {
|
|
130
130
|
start: [
|
|
131
131
|
'Battle Started: The [Diff] section shows the opening moves.',
|
|
@@ -221,7 +221,7 @@ export const MISCHIEF_PRESET = {
|
|
|
221
221
|
id: 'mischief',
|
|
222
222
|
identity: 'minion',
|
|
223
223
|
verdict: DEFAULT_VERDICT_CONFIG,
|
|
224
|
-
usageGuide: '## Minion Manual\n\n**imp** — Disposable Grunt 😈\n- Expendable. Send it into the trap first.\n\n**minion** — Standard Henchman 👹\n- Can carry out complex evil plans. mostly.\n\n**mastermind** — The Boss ??? 🧠\n- Wait, why are you commanding the boss?\n- Extremely expensive consulting fee.\n\n## Workflow\n`
|
|
224
|
+
usageGuide: '## Minion Manual\n\n**imp** — Disposable Grunt 😈\n- Expendable. Send it into the trap first.\n\n**minion** — Standard Henchman 👹\n- Can carry out complex evil plans. mostly.\n\n**mastermind** — The Boss ??? 🧠\n- Wait, why are you commanding the boss?\n- Extremely expensive consulting fee.\n\n## Workflow\n`${ask}` (Nn——! disposable/experiment) | `${start}` -> [`${drive}` | `${ask}`]* -> `${close}` (Dayaa!)',
|
|
225
225
|
nextHints: {
|
|
226
226
|
start: [
|
|
227
227
|
"Inspect the Minion's Work: The [Diff] section shows the first step of the plan.",
|
|
@@ -1,9 +1,43 @@
|
|
|
1
|
+
import { parseToAST, renderNodeContent } from "./keiyaku-document.js";
|
|
1
2
|
function isPlainObject(value) {
|
|
2
3
|
if (!value || typeof value !== "object")
|
|
3
4
|
return false;
|
|
4
5
|
const prototype = Object.getPrototypeOf(value);
|
|
5
6
|
return prototype === Object.prototype || prototype === null;
|
|
6
7
|
}
|
|
8
|
+
export function flattenMarkdownList(text) {
|
|
9
|
+
const ast = parseToAST(text, { allowSections: false });
|
|
10
|
+
const items = [];
|
|
11
|
+
let currentTitle;
|
|
12
|
+
const pushItem = (content) => {
|
|
13
|
+
const trimmed = content.trim();
|
|
14
|
+
if (!trimmed)
|
|
15
|
+
return;
|
|
16
|
+
const prefix = currentTitle ? `**${currentTitle.replace(/^\d+\.\s*/, "")}**: ` : "";
|
|
17
|
+
items.push(`${prefix}${trimmed}`);
|
|
18
|
+
};
|
|
19
|
+
for (const node of ast.children) {
|
|
20
|
+
if (node.type === "heading") {
|
|
21
|
+
currentTitle = node.text.trim();
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
if (node.type === "list") {
|
|
25
|
+
for (const listItem of node.items) {
|
|
26
|
+
pushItem(renderNodeContent(listItem));
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
else if (node.type === "text") {
|
|
30
|
+
const paragraphs = node.value.split(/\n\s*\n/);
|
|
31
|
+
for (const p of paragraphs) {
|
|
32
|
+
pushItem(p);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
pushItem(renderNodeContent(node));
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return items;
|
|
40
|
+
}
|
|
7
41
|
export function renderTemplate(template, values) {
|
|
8
42
|
return template.replace(/\$\{(?<key>[A-Za-z0-9_]+)\}/g, (match, _captured, _offset, _text, groups) => {
|
|
9
43
|
const key = groups?.key;
|
package/build/workflow/ask.js
CHANGED
|
@@ -5,7 +5,8 @@ import { runSubagent } from "../agents/round-runner.js";
|
|
|
5
5
|
import * as git from "../utils/git.js";
|
|
6
6
|
import { buildAskPrompt } from "./prompts.js";
|
|
7
7
|
import { FlowError } from "../common/errors.js";
|
|
8
|
-
import {
|
|
8
|
+
import { renderMarkdownSections } from "../utils/keiyaku-document.js";
|
|
9
|
+
import { flattenMarkdownList } from "../utils/text-utils.js";
|
|
9
10
|
const BASE_CONSTRAINTS_FILE = path.join(".keiyaku", "base-constraints.md");
|
|
10
11
|
function requireText(name, value) {
|
|
11
12
|
const normalized = value.trim();
|
|
@@ -21,7 +22,7 @@ export async function askServant(input) {
|
|
|
21
22
|
let referenceConstraints;
|
|
22
23
|
try {
|
|
23
24
|
const baseConstraintsRaw = await fs.readFile(path.join(cwd, BASE_CONSTRAINTS_FILE), "utf-8");
|
|
24
|
-
const baseConstraints =
|
|
25
|
+
const baseConstraints = flattenMarkdownList(baseConstraintsRaw);
|
|
25
26
|
if (baseConstraints.length > 0) {
|
|
26
27
|
referenceConstraints = renderMarkdownSections(baseConstraints);
|
|
27
28
|
}
|
package/build/workflow/start.js
CHANGED
|
@@ -6,9 +6,10 @@ import { FlowError, isFlowError, wrapFlowError } from "../common/errors.js";
|
|
|
6
6
|
import * as git from "../utils/git.js";
|
|
7
7
|
import { computeTraceState, readTraceContent } from "../utils/trace.js";
|
|
8
8
|
import { buildStartPrompt } from "./prompts.js";
|
|
9
|
-
import { parseToAST, renderSectionContent, extractListItems, renderKeiyaku, } from "../utils/keiyaku-document.js";
|
|
9
|
+
import { parseToAST, parseMarkdownStructure, renderSectionContent, extractListItems, renderKeiyaku, } from "../utils/keiyaku-document.js";
|
|
10
10
|
import { resolveTermPreset } from "../config/term-presets.js";
|
|
11
11
|
import { renderRoundSummary, TOOL_DEFAULT_POLICY } from "./round-summary.js";
|
|
12
|
+
import { flattenMarkdownList } from "../utils/text-utils.js";
|
|
12
13
|
import { assertCleanWorkingTree } from "./contract.js";
|
|
13
14
|
import { runAndRecordRound } from "./round.js";
|
|
14
15
|
const BASE_CONSTRAINTS_FILE = path.join(".keiyaku", "base-constraints.md");
|
|
@@ -174,12 +175,6 @@ function truncateForMessage(text, maxChars) {
|
|
|
174
175
|
return text;
|
|
175
176
|
return `${text.slice(0, maxChars)}\n...[truncated ${text.length - maxChars} chars]...`;
|
|
176
177
|
}
|
|
177
|
-
function readKeiyakuSection(content, sectionTitle) {
|
|
178
|
-
const escapedTitle = sectionTitle.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
179
|
-
const sectionMatch = content.match(new RegExp(`(?:^|\\n)## ${escapedTitle}\\s*\\n([\\s\\S]*?)(?=\\n##\\s|$)`));
|
|
180
|
-
const sectionBody = sectionMatch?.[1]?.trim();
|
|
181
|
-
return sectionBody || undefined;
|
|
182
|
-
}
|
|
183
178
|
async function buildActiveKeiyakuStartMessage(cwd, branch) {
|
|
184
179
|
const preset = resolveTermPreset();
|
|
185
180
|
const { drive, close } = preset.tools;
|
|
@@ -347,8 +342,7 @@ async function resolveStartInput(cwd, input) {
|
|
|
347
342
|
async function readBaseConstraints(cwd) {
|
|
348
343
|
try {
|
|
349
344
|
const baseConstraintsRaw = await fs.readFile(path.join(cwd, BASE_CONSTRAINTS_FILE), "utf-8");
|
|
350
|
-
|
|
351
|
-
return normalizedBaseConstraints ? normalizeMarkdownListItems("constraints", [baseConstraintsRaw]) : [];
|
|
345
|
+
return flattenMarkdownList(baseConstraintsRaw);
|
|
352
346
|
}
|
|
353
347
|
catch (error) {
|
|
354
348
|
if (error?.code !== "ENOENT") {
|
|
@@ -454,7 +448,8 @@ export async function startKeiyaku(input) {
|
|
|
454
448
|
// but safe to re-render if somehow undefined.
|
|
455
449
|
keiyakuContent = await renderStartKeiyakuContent(cwd, resolved);
|
|
456
450
|
}
|
|
457
|
-
const
|
|
451
|
+
const parsedKeiyaku = parseMarkdownStructure(keiyakuContent);
|
|
452
|
+
const constraintsSection = parsedKeiyaku.sections.get("constraints")?.join("\n").trim() ?? "";
|
|
458
453
|
await fs.writeFile(path.join(cwd, KEIYAKU_FILE), keiyakuContent);
|
|
459
454
|
await fs.writeFile(path.join(cwd, TRACE_FILE), "# Keiyaku Trace\n");
|
|
460
455
|
await git.addFiles(cwd, [KEIYAKU_FILE, TRACE_FILE]);
|