Repository navigation
feat(kix): render planning decisions into PRs from recorded answers #172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
495446b
chore(quest): claim quest/m0/kix/paper-trail.md
kixelated 3f6164d
feat(kix): render planning decisions into PRs from recorded answers
kixelated 8ed43a7
Merge remote-tracking branch 'origin/main' into paper-trail
kixelated f0631bf
fix(kix): keep a failed planning job's decisions when a retry continu…
kixelated 0add401
Merge remote-tracking branch 'origin/main' into paper-trail
kixelated b695ddb
Merge remote-tracking branch 'origin/main' into paper-trail
kixelated 1f61fb8
fix(kix): end a decision section only at a marker on its own line
kixelated 7415b7d
Merge remote-tracking branch 'origin/main' into paper-trail
kixelated 4947d5f
Merge remote-tracking branch 'origin/main' into paper-trail
kixelated File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| // A planning pull request's paper trail. The service renders the decision | ||
| // section from the job's recorded questions and answers, so it cannot be | ||
| // paraphrased or drift from what the maintainer chose. Prompts and answers are | ||
| // untrusted text: every piece appears only inside a code span, where GitHub | ||
| // renders no Markdown or HTML and links no mention, issue or commit reference, | ||
| // URL, or closing keyword. | ||
| import { type Answer, type Prompt, parseAnswer, parsePrompt } from "./prompt"; | ||
| import type { Workflow } from "./store"; | ||
|
|
||
| /** Brackets the service's section, which replaces any copy in the agent's body. */ | ||
| export const START = "<!-- kix:decisions -->"; | ||
| export const END = "<!-- /kix:decisions -->"; | ||
| /** GitHub's limit on a pull request body, in characters. */ | ||
| export const BODY_LIMIT = 65_536; | ||
|
|
||
| /** What a job's agent is told beyond the workflow's own skill, or null. */ | ||
| export function instructions(workflow: Workflow): string | null { | ||
| if (workflow !== "plan") return null; | ||
| return "kix adds this pull request's decision record from the maintainer's recorded answers. Do not write the interview's questions, options, or answers into the pull request body; summarize the proposed quests instead. Still record each settled decision and its reason in the quest's Plan."; | ||
| } | ||
|
|
||
| /** | ||
| * Untrusted text as one inline code span. Line breaks and control characters | ||
| * become spaces, so the span cannot end its paragraph or start a line; | ||
| * bidirectional controls are dropped so the text reads as stored. The fence is | ||
| * longer than any backtick run inside, so the text cannot close it. | ||
| */ | ||
| export function code(value: string): string { | ||
| const flat = value | ||
| .replace(/[\u061c\u200e\u200f\u202a-\u202e\u2066-\u2069]/g, "") | ||
| .replace(/[\x00-\x1f\x7f-\x9f\u2028\u2029]/g, " "); | ||
| const longest = Math.max(0, ...(flat.match(/`+/g) ?? []).map((run) => run.length)); | ||
| const fence = "`".repeat(longest + 1); | ||
| // One space on each side is stripped when rendering, so a leading or trailing backtick stays literal. | ||
| return `${fence} ${flat} ${fence}`; | ||
| } | ||
|
|
||
| /** One question's record: the prompt, every option with ✅ on each choice, and any free text. */ | ||
| function question(ask: Prompt["questions"][number], reply: Answer["answers"][number]): string { | ||
| const lines = [`- ${ask.header ? `${code(ask.header)} ` : ""}${code(ask.question)}`]; | ||
| for (const option of ask.options) | ||
| lines.push(` - ${reply.choices.includes(option.label) ? "✅" : "⬜"} ${code(option.label)}`); | ||
| if (reply.text) lines.push(` - ✍️ ${code(reply.text)}`); | ||
| return lines.join("\n"); | ||
| } | ||
|
|
||
| /** A stored question's prompt and answer, when it is an answered decision. */ | ||
| function decision(stored: { prompt: unknown; answer: unknown }): { prompt: Prompt; answer: Answer } | null { | ||
| try { | ||
| const prompt = parsePrompt(stored.prompt); | ||
| if (prompt.kind !== "decision") return null; | ||
| return { prompt, answer: parseAnswer(prompt, stored.answer) }; | ||
| } catch { | ||
| // Not a valid round, so there is nothing faithful to render. | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * The decision section for a job's answered agent questions, oldest first, in | ||
| * at most `budget` characters. Rounds past the budget are counted, not cut. | ||
| * Null when there is nothing to record. | ||
| */ | ||
| export function render(questions: { prompt: unknown; answer: unknown }[], budget: number): string | null { | ||
| const rounds = questions.map(decision).filter((round) => round !== null); | ||
| if (!rounds.length) return null; | ||
| const head = `${START}\n## Decisions\n\nRecorded by kix from the maintainer's answers.`; | ||
| const blocks = rounds.map( | ||
| ({ prompt, answer }, i) => | ||
| `### Round ${i + 1}\n\n${prompt.questions.map((ask, j) => question(ask, answer.answers[j]!)).join("\n")}`, | ||
| ); | ||
| const omitted = (n: number) => `_${n} more ${n === 1 ? "round is" : "rounds are"} in the job's record on kix._`; | ||
| let section = head; | ||
| for (const [i, block] of blocks.entries()) { | ||
| const rest = blocks.length - i - 1; | ||
| const tail = rest ? `\n\n${omitted(rest)}` : ""; | ||
| if (`${section}\n\n${block}${tail}\n${END}`.length > budget) { | ||
| section += `\n\n${omitted(blocks.length - i)}`; | ||
| break; | ||
| } | ||
| section += `\n\n${block}`; | ||
| } | ||
| section += `\n${END}`; | ||
| return section.length > budget ? null : section; | ||
| } | ||
|
|
||
| /** | ||
| * The agent's pull request body with the service's decision section: any | ||
| * section the agent wrote is removed, and the rendered one is appended. A | ||
| * section ends only at an end marker on its own line, which untrusted text | ||
| * inside a code span can never start, or else at the end of the body. | ||
| */ | ||
| export function withDecisions(body: string, questions: { prompt: unknown; answer: unknown }[]): string { | ||
| const own = body | ||
| .replace(/<!-- kix:decisions -->[\s\S]*?(?:^<!-- \/kix:decisions -->$|(?![\s\S]))/gm, "") | ||
| .replaceAll(END, "") | ||
| .trimEnd(); | ||
| const section = render(questions, BODY_LIMIT - own.length - 2); | ||
| return section ? (own ? `${own}\n\n${section}` : section) : own; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For every planning PR with at least one recorded decision, this append places the generated section after the agent-supplied body, so an otherwise compliant
(written by <model>)footer is no longer the final content of the GitHub post. Preserve that footer after the generated section, or insert the section before it, so publication continues to satisfy the repository policy.AGENTS.md reference: AGENTS.md:L31-L31
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not changing this. The
(written by <model>)line is this repository's convention for agents developing quest (AGENTS.md), not part of the shared workflow inassets/AGENTS.md, and the core stays independent of any one repository's conventions. Detecting a trailing attribution line would couple kix to that convention. The appended section is the service's own content, labeled "Recorded by kix from the maintainer's answers", so the agent's attribution still ends the agent's text. Appending at the end of the body is one of this PR's recorded decisions, which the maintainer accepted. If an agent should control where the section goes, a follow-up could honor an empty<!-- kix:decisions -->placeholder the agent writes.(Written by Claude Opus 5.5)