@yagni-app/code-staging 1.2.14-staging.2389.1 → 1.2.14-staging.2390.1

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.
@@ -16,6 +16,7 @@
16
16
  * lives (`packages/shared/src/attempts.ts`): the two meet only at this JSON.
17
17
  */
18
18
  import type { ContinuationStage } from "./continuation.js";
19
+ import type { AttemptAsk } from "./needsPerson.js";
19
20
  import { type RunFinishOpts } from "./finish.js";
20
21
  import { type PlanChange } from "./planChanges.js";
21
22
  import { type VerifyCheckRun, type VerifyOutcome } from "./verify.js";
@@ -78,7 +79,9 @@ export declare function prepareCloudLane(input: {
78
79
  problem: string;
79
80
  };
80
81
  /** The stop reasons `result.json` carries. */
81
- export type ResultStopReason = "clean" | "round_cap" | "no_changes" | "budget_exceeded" | "failed" | "aborted";
82
+ export type ResultStopReason = "clean" | "round_cap" | "no_changes" | "budget_exceeded" | "failed" | "aborted"
83
+ /** The session lane's turn stopped to ask a person, with its ask (`needsPerson.ts`). */
84
+ | "needs_person";
82
85
  /**
83
86
  * The pipeline's stop as the result names it. `partial` (a write stage cut off
84
87
  * after it began editing) is `failed` here; its change is still committed, and
@@ -140,6 +143,8 @@ export interface AttemptResult extends CloudIdentity {
140
143
  * Absent on every other turn: the host then drafts the preview itself.
141
144
  */
142
145
  uiPreview?: "drawn" | "none" | "not_drawn";
146
+ /** The session lane's ask on a `needs_person` stop (`needsPerson.ts`). */
147
+ ask?: AttemptAsk;
143
148
  }
144
149
  /** The findings the result reports, blocking first. */
145
150
  export declare function openFindings(findings: readonly Finding[]): OpenFinding[];
@@ -0,0 +1,45 @@
1
+ /**
2
+ * A session that stops for a person writes its own ask: the question, what it
3
+ * found and the options it sees, in `needs-person.json` beside its report. The
4
+ * turn then ends `needs_person`, with the ask on `result.json`, and the host
5
+ * hands the ticket to a person with those words (cleaned of secrets and
6
+ * markup there). Only for a change of direction: the plan or the ticket is
7
+ * wrong about the code, or the right change is far larger than the ticket.
8
+ *
9
+ * This package does not depend on `@yagni/shared`, so the region between the
10
+ * markers below is a byte-for-byte copy of the same region of
11
+ * `packages/shared/src/attempts.ts`; `test/pipeline/needsPerson.test.ts` fails
12
+ * when the two differ. Change the shared file and copy the region here.
13
+ */
14
+ import type { AttemptResult } from "./cloud.js";
15
+ /** The session's ask, beside its report in the output folder. */
16
+ export declare const NEEDS_PERSON_FILE_NAME = "needs-person.json";
17
+ /** What a session asks a person when it stops for one. */
18
+ export interface AttemptAsk {
19
+ question: string;
20
+ /** What it found, each the file:line, command or query and what it showed. */
21
+ evidence: string[];
22
+ /** The ways on it sees, its own first when it has one. */
23
+ options: string[];
24
+ }
25
+ /** The longest question, the longest evidence or option line, and how many of each. */
26
+ export declare const MAX_ASK_QUESTION_CHARS = 600;
27
+ export declare const MAX_ASK_LINE_CHARS = 400;
28
+ export declare const MAX_ASK_LINES = 8;
29
+ /** The ask as written, each part on one line and bounded; null without a question. */
30
+ export declare function parseAttemptAsk(value: unknown): AttemptAsk | null;
31
+ /** The ask as the file holds it, or null when the file is missing, does not read or asks nothing. */
32
+ export declare function readNeedsPerson(text: string | null): AttemptAsk | null;
33
+ /**
34
+ * The build rule that says when the session stops for a person, and how. A
35
+ * person answers it and the session resumes with their answer.
36
+ */
37
+ export declare const NEEDS_PERSON_RULE: (outDir: string) => string;
38
+ /**
39
+ * A writing turn's result with the session's ask folded in: a turn that
40
+ * ended on its own (`clean`, or `no_changes`) with an ask stops
41
+ * `needs_person`, carrying the ask. A turn the host stopped (failed, aborted,
42
+ * out of time) keeps its own stop: that is what a person reads.
43
+ */
44
+ export declare function withNeedsPerson(attempt: AttemptResult, ask: AttemptAsk | null): AttemptResult;
45
+ //# sourceMappingURL=needsPerson.d.ts.map
@@ -0,0 +1,97 @@
1
+ /**
2
+ * A session that stops for a person writes its own ask: the question, what it
3
+ * found and the options it sees, in `needs-person.json` beside its report. The
4
+ * turn then ends `needs_person`, with the ask on `result.json`, and the host
5
+ * hands the ticket to a person with those words (cleaned of secrets and
6
+ * markup there). Only for a change of direction: the plan or the ticket is
7
+ * wrong about the code, or the right change is far larger than the ticket.
8
+ *
9
+ * This package does not depend on `@yagni/shared`, so the region between the
10
+ * markers below is a byte-for-byte copy of the same region of
11
+ * `packages/shared/src/attempts.ts`; `test/pipeline/needsPerson.test.ts` fails
12
+ * when the two differ. Change the shared file and copy the region here.
13
+ */
14
+ import { join } from "node:path";
15
+ /** The session's ask, beside its report in the output folder. */
16
+ export const NEEDS_PERSON_FILE_NAME = "needs-person.json";
17
+ /** The longest question, the longest evidence or option line, and how many of each. */
18
+ export const MAX_ASK_QUESTION_CHARS = 600;
19
+ export const MAX_ASK_LINE_CHARS = 400;
20
+ export const MAX_ASK_LINES = 8;
21
+ /** Words on one line, clipped; null for none. */
22
+ function askLine(value, max) {
23
+ if (typeof value !== "string")
24
+ return null;
25
+ const words = value.replace(/\s+/g, " ").trim();
26
+ return words ? words.slice(0, max) : null;
27
+ }
28
+ function askLines(value) {
29
+ if (!Array.isArray(value))
30
+ return [];
31
+ const lines = [];
32
+ for (const entry of value) {
33
+ if (lines.length >= MAX_ASK_LINES)
34
+ break;
35
+ const line = askLine(entry, MAX_ASK_LINE_CHARS);
36
+ if (line)
37
+ lines.push(line);
38
+ }
39
+ return lines;
40
+ }
41
+ /** The ask as written, each part on one line and bounded; null without a question. */
42
+ export function parseAttemptAsk(value) {
43
+ if (!value || typeof value !== "object" || Array.isArray(value))
44
+ return null;
45
+ const raw = value;
46
+ const question = askLine(raw.question, MAX_ASK_QUESTION_CHARS);
47
+ if (!question)
48
+ return null;
49
+ return { question, evidence: askLines(raw.evidence), options: askLines(raw.options) };
50
+ }
51
+ // --- mirrored ask region: end
52
+ /** The ask as the file holds it, or null when the file is missing, does not read or asks nothing. */
53
+ export function readNeedsPerson(text) {
54
+ if (!text)
55
+ return null;
56
+ try {
57
+ return parseAttemptAsk(JSON.parse(text));
58
+ }
59
+ catch {
60
+ return null;
61
+ }
62
+ }
63
+ /**
64
+ * The build rule that says when the session stops for a person, and how. A
65
+ * person answers it and the session resumes with their answer.
66
+ */
67
+ export const NEEDS_PERSON_RULE = (outDir) => `Stop and ask a person only for a change of direction: the plan or the ticket is wrong about the code, or the right change is far larger than the ticket, or a choice that cannot be undone that neither settles. Never for what a check, a read or a decision record answers. Then write ${join(outDir, NEEDS_PERSON_FILE_NAME)} as JSON: ` +
68
+ '{"question": "<one question a person can answer>", "evidence": ["<file:line, command or query, and what it showed>"], "options": ["<your recommendation first>", "<each other way on>"]}, ' +
69
+ "commit what is done so far, write the report, and end your turn: YAGNI hands the ticket to a person with your ask, and you resume with their answer.";
70
+ /**
71
+ * A writing turn's result with the session's ask folded in: a turn that
72
+ * ended on its own (`clean`, or `no_changes`) with an ask stops
73
+ * `needs_person`, carrying the ask. A turn the host stopped (failed, aborted,
74
+ * out of time) keeps its own stop: that is what a person reads.
75
+ */
76
+ export function withNeedsPerson(attempt, ask) {
77
+ if (!ask)
78
+ return attempt;
79
+ if (attempt.stopReason !== "clean" && attempt.stopReason !== "no_changes") {
80
+ return {
81
+ ...attempt,
82
+ notes: [
83
+ ...attempt.notes,
84
+ `The session also wrote an ask for a person, but the turn stopped (${attempt.stopReason}) first.`,
85
+ ],
86
+ };
87
+ }
88
+ return {
89
+ ...attempt,
90
+ stopReason: "needs_person",
91
+ ask,
92
+ // The ask's words ride on `ask` alone, where the host cleans them; a note
93
+ // is stored and read as it is.
94
+ notes: [...attempt.notes, "The session stopped to ask a person; its ask is on this result."],
95
+ };
96
+ }
97
+ //# sourceMappingURL=needsPerson.js.map
@@ -55,6 +55,7 @@ import { completeCloudSession, RESULT_FILE_NAME, } from "./cloud.js";
55
55
  import { finishExec } from "./finish.js";
56
56
  import { HELPER_SESSIONS_DIR_ENV } from "./helperSessions.js";
57
57
  import { MISSION_CHECKS_FILE_NAME, readMissionChecksFile } from "./missionChecks.js";
58
+ import { NEEDS_PERSON_FILE_NAME, NEEDS_PERSON_RULE, readNeedsPerson, withNeedsPerson, } from "./needsPerson.js";
58
59
  import { creditExhaustionReason } from "./orchestrator.js";
59
60
  import { WORK_A_TICKET_SKILL } from "./personas.js";
60
61
  import { healPlacedSecrets, publicationBase } from "./placedValueHeal.js";
@@ -262,6 +263,7 @@ const BUILD_RULES = (outDir, who) => [
262
263
  "- Each behavior change gets a test. Run it once without the change and see it fail, then with it; in the report, that test's check says in its note what failed without the change.",
263
264
  "- A check checks.json marks measureOnBase, or one you would call fails_on_base, is measured on the unchanged code during this attempt: before your first edit, or in a git worktree at the commit this branch started from. A red in the repository's record is not a measurement, however recent; a baseMeasured entry in checks.json is.",
264
265
  "- Commit on the branch you are on. Never push and never open or edit a pull request: YAGNI pushes your commits and opens it.",
266
+ `- ${NEEDS_PERSON_RULE(outDir)}`,
265
267
  `- ${PULL_REQUEST_CONTRACT(outDir)}`,
266
268
  `- ${REPORT_CONTRACT(outDir)}`,
267
269
  ].join("\n");
@@ -316,7 +318,7 @@ const QUESTION_RULE = "Where there is a real choice of approach, ask it as a dec
316
318
  * Where the yak approves its own plans (`own-plans.md`): YAGNI takes every
317
319
  * recommendation, so a question only records a change of direction.
318
320
  */
319
- const DECIDE_RULE = "This yak approves its own plans: no person answers this plan's questions, and YAGNI takes your recommendation on each one. So where there is a real choice of approach, decide on your recommendation: the plan's steps follow it, and ## Risks states it as the assumption you plan on, with what would change it. Put a question in the plan-json block only for a change of direction, with the evidence (file:line, command or query) in its checked lines: the ticket's premise is false, or the right change is far larger than the ticket.";
321
+ const DECIDE_RULE = "This yak approves its own plans: no person answers this plan's questions, and YAGNI takes your recommendation on each one. So where there is a real choice of approach, decide on your recommendation: the plan's steps follow it, and ## Risks states it as the assumption you plan on, with what would change it. Put a question in the plan-json block only for a change of direction, with the evidence (file:line, command or query) in its checked lines: the ticket's premise is false, or the right change is far larger than the ticket. Such a question hands the ticket to a person with your question, its evidence and its options: YAGNI does not answer it, and nothing is built until they do.";
320
322
  const PLAN_CLOSE_RULE = 'When the ticket check shows the problem is already gone, recommend closing the ticket instead of planning a change: ## Goal says so in one sentence, the ticket check holds the evidence, ## Plan says "Nothing to build." with no numbered steps, and the plan-json block carries "closeTicket" with the evidence and names no checks and no paths. A person then decides whether to close it.';
321
323
  const PLAN_STOP = "Then stop: next you review this plan yourself, in this session, for at most four rounds, fixing what you find. A person approves the plan before anything is built.";
322
324
  const OWN_PLANS_STOP = "Then stop: next you review this plan yourself, in this session, for at most four rounds, fixing what you find. Once the review ends, YAGNI approves the plan for this yak and the build starts.";
@@ -328,6 +330,8 @@ const OWN_PLANS_STOP = "Then stop: next you review this plan yourself, in this s
328
330
  * host posts the answer where it was asked.
329
331
  */
330
332
  const FIX_RULE = "For each item: check it against the pull request on GitHub as it is now (read it with gh, and only read), then fix it, with a test that fails without the fix where it changes behavior, or dispute it with evidence a reviewer can check, or, when it only asks a question, answer it from the code as it is and change nothing for it. Never reply, comment, react or resolve on GitHub: YAGNI posts your outcomes where each item was asked once your turn ends.";
333
+ /** Where a person's answer to the attempt's stop is, and when to read it. */
334
+ const handOffAnswerLine = (file, before) => `Read ${file} before you ${before}: why the attempt stopped, and what a person answered.`;
331
335
  /** The one message a turn sends the session. Pure. */
332
336
  export function turnMessage(facts) {
333
337
  const at = (file) => join(facts.inputDir, file);
@@ -354,6 +358,8 @@ export function turnMessage(facts) {
354
358
  parts.push(`A person sent an earlier plan back: what they asked is in ${at("ticket.md")}, and that plan is ${at("sent-back-plan.md")}. ${PLANNED_ANYWAY}`);
355
359
  }
356
360
  }
361
+ if (facts.handOffAnswer)
362
+ parts.push(handOffAnswerLine(at("hand-off-answer.md"), "plan"));
357
363
  if (newSince)
358
364
  parts.push(newSince);
359
365
  parts.push(planRules(facts.preview ? { inputDir: facts.inputDir, outDir: facts.outDir } : undefined, facts.ownPlans === true));
@@ -384,9 +390,8 @@ export function turnMessage(facts) {
384
390
  parts.push(`A review or the CI on this attempt's pull request asks for changes: they are in ${at("ticket.md")}, under "Review on this attempt's pull request". Address every item (answer an item that only asks a question, with no change for it) and write the outcomes file that section names.`, FIX_RULE);
385
391
  }
386
392
  }
387
- if (facts.handOffAnswer) {
388
- parts.push(`Read ${at("hand-off-answer.md")} before you go on: why the attempt stopped, and what a person answered.`);
389
- }
393
+ if (facts.handOffAnswer)
394
+ parts.push(handOffAnswerLine(at("hand-off-answer.md"), "go on"));
390
395
  // The host's file opens with "# A person added this while you worked" and
391
396
  // carries the note fenced, so the session hears it in this turn's message,
392
397
  // a resumed session included, whose ticket.md it read turns ago.
@@ -709,6 +714,16 @@ async function runTurn(input, deps, pulse) {
709
714
  }
710
715
  }
711
716
  }
717
+ // An ask an earlier turn left is never this turn's.
718
+ const needsPersonFile = join(input.outDir, NEEDS_PERSON_FILE_NAME);
719
+ if (writes) {
720
+ try {
721
+ remove(needsPersonFile);
722
+ }
723
+ catch {
724
+ // One that cannot be removed is read as this turn's ask: a person is asked, never skipped.
725
+ }
726
+ }
712
727
  // A yak's System's other repositories, each as the turn found it, for the
713
728
  // read of a writing turn's change for a placed secret (YAG-1211).
714
729
  const others = [];
@@ -973,7 +988,7 @@ async function runTurn(input, deps, pulse) {
973
988
  ...turnPromptFacts(input.childEnv),
974
989
  };
975
990
  const attempt = writes
976
- ? withSessionAccount(noted, parseSessionReport(readOrNull(join(input.outDir, SESSION_REPORT_FILE_NAME)), knownBaselines(input.inputDir, readFile)), pullRequestTextOf(readOrNull(join(input.outDir, PULL_REQUEST_FILE_NAME))))
991
+ ? withNeedsPerson(withSessionAccount(noted, parseSessionReport(readOrNull(join(input.outDir, SESSION_REPORT_FILE_NAME)), knownBaselines(input.inputDir, readFile)), pullRequestTextOf(readOrNull(join(input.outDir, PULL_REQUEST_FILE_NAME)))), readNeedsPerson(readOrNull(needsPersonFile)))
977
992
  : uiPreview
978
993
  ? { ...noted, uiPreview }
979
994
  : noted;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yagni-app/code-staging",
3
- "version": "1.2.14-staging.2389.1",
3
+ "version": "1.2.14-staging.2390.1",
4
4
  "description": "YAGNI Code: a terminal coding agent that already knows your company. One YAGNI login routes the model and grounds the agent in your team's context.",
5
5
  "license": "SEE LICENSE IN LICENSE.md",
6
6
  "author": "YAGNI, Inc. <jack@yagni.app> (https://yagni.app)",
@@ -58,5 +58,5 @@
58
58
  "turndown": "^7.2.4",
59
59
  "typebox": "^1.3.15"
60
60
  },
61
- "yagniSourceSha": "b395678afa4b7105c4b66301a6d1b68ce0df2324"
61
+ "yagniSourceSha": "05b87e8cc5cd5acfb5b577b04a145c8c566a2708"
62
62
  }