@kitman-sh/software-engineering 0.44.0 → 0.46.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/dist/bundle.js CHANGED
@@ -12410,6 +12410,12 @@ var AgentSandboxPolicy = Struct({
12410
12410
 
12411
12411
  // ../../packages/core/src/runtime-type.ts
12412
12412
  var UnsafeJsonObjectKeys = new Set(["__proto__", "constructor", "prototype"]);
12413
+ function isBoolean2(value) {
12414
+ return isBoolean(value);
12415
+ }
12416
+ function isNumber2(value) {
12417
+ return isNumber(value);
12418
+ }
12413
12419
  function isObject2(value) {
12414
12420
  return isObjectOrArray(value);
12415
12421
  }
@@ -13152,6 +13158,22 @@ function looksLikeCredential(raw, matched) {
13152
13158
  return /^[^\s:=]+=\S/u.test(matched) || value.length >= 6 && /[0-9]/u.test(value) || value.length >= 20 && /[a-z]/u.test(value) && /[A-Z]/u.test(value);
13153
13159
  }
13154
13160
  var globalPatterns = new WeakMap;
13161
+ var globalPattern = (rule) => {
13162
+ const known = globalPatterns.get(rule);
13163
+ if (known !== undefined)
13164
+ return known;
13165
+ const pattern = new RegExp(rule.pattern.source, `${rule.pattern.flags}g`);
13166
+ globalPatterns.set(rule, pattern);
13167
+ return pattern;
13168
+ };
13169
+ var redactedBy = (text, rule) => text.replace(globalPattern(rule), (matched, ...rest) => {
13170
+ const groups = rest.at(-1);
13171
+ const offset = isObject2(groups) ? rest.at(-3) : rest.at(-2);
13172
+ const named = isObject2(groups) && groups !== null && "value" in groups ? groups.value : undefined;
13173
+ const value = isString2(named) ? named : matched;
13174
+ const start = (isNumber2(offset) ? offset : 0) + matched.lastIndexOf(value);
13175
+ return rule.holds === undefined || rule.holds(value, matched, text, start) ? `[REDACTED:${rule.classification}]` : matched;
13176
+ });
13155
13177
  var credentialUrlRule = {
13156
13178
  classification: "url",
13157
13179
  name: "credential-url",
@@ -13161,6 +13183,9 @@ var keptClassifications = new Set(["secret", "credential", "unknown"]);
13161
13183
  var normalizedKeys = new Map;
13162
13184
  var CREDENTIAL_RULES = VALUE_RULES.filter((rule) => rule.classification === "secret" || rule.classification === "credential");
13163
13185
  var RESPONSE_RULES = [...CREDENTIAL_RULES, credentialUrlRule];
13186
+ function redactCredentialText(text) {
13187
+ return RESPONSE_RULES.reduce(redactedBy, text);
13188
+ }
13164
13189
 
13165
13190
  // ../../packages/core/src/run.ts
13166
13191
  var RunContractVersion = Literal2("run.v1");
@@ -14080,6 +14105,213 @@ var failedFileLine = new RegExp(`^${failedFileStart}((?:${failedFilePaths.join("
14080
14105
  var attempt = String.raw`(?:\d+ times in )?(?:initial run|\d+[a-z]{2} (?:retry(?: of \d+[a-z]{2} repeat)?|repeat))`;
14081
14106
  var vitestAttempts = new RegExp(String.raw` \(${attempt}(?:, ${attempt})*\)$`, "u");
14082
14107
 
14108
+ // ../../packages/core/src/json.ts
14109
+ var JsonFromString = fromJsonString2(Json2);
14110
+ var decodeJsonString = decodeUnknownEffect2(JsonFromString);
14111
+ var decodeJsonStringOption = decodeUnknownOption2(JsonFromString);
14112
+ var encodeJsonStringSync = encodeSync(JsonFromString);
14113
+ var encodePrettyJsonString = encodeEffect(fromJsonString2(Json2, { space: 2 }));
14114
+ var decodeJsonStringSync = decodeUnknownSync(JsonFromString);
14115
+ var encodeUnknownJsonStringSync = encodeSync(fromJsonString2(Unknown2));
14116
+
14117
+ // ../../packages/core/src/question-answer.ts
14118
+ var AnswerSchemaJson = Record(String5, Json2);
14119
+ var description = optionalKey2(String5);
14120
+ var Count = Int.check(isGreaterThanOrEqualTo3(0));
14121
+ var Nested = suspend3(() => DeclaredAnswerSchema);
14122
+ var DeclaredAnswerSchema = Union2([
14123
+ Struct({ description, type: Literal2("boolean"), const: optionalKey2(Boolean3) }),
14124
+ Struct({
14125
+ description,
14126
+ type: Literal2("string"),
14127
+ const: optionalKey2(String5),
14128
+ enum: optionalKey2(ArraySchema(String5).check(isMinLength(1))),
14129
+ minLength: optionalKey2(Count),
14130
+ maxLength: optionalKey2(Count)
14131
+ }),
14132
+ Struct({
14133
+ description,
14134
+ type: Literal2("integer"),
14135
+ const: optionalKey2(Int),
14136
+ minimum: optionalKey2(Int),
14137
+ maximum: optionalKey2(Int)
14138
+ }),
14139
+ Struct({
14140
+ description,
14141
+ type: Literal2("array"),
14142
+ items: Nested,
14143
+ minItems: optionalKey2(Count),
14144
+ maxItems: optionalKey2(Count)
14145
+ }),
14146
+ Struct({
14147
+ description,
14148
+ type: Literal2("object"),
14149
+ properties: Record(String5, Nested),
14150
+ required: ArraySchema(String5),
14151
+ additionalProperties: Literal2(false)
14152
+ }),
14153
+ Struct({ description, anyOf: ArraySchema(Nested).check(isMinLength(1)) })
14154
+ ]);
14155
+ var decodeDeclared = decodeUnknownExit2(DeclaredAnswerSchema, { onExcessProperty: "error" });
14156
+ var inverted = (low, high) => low !== undefined && high !== undefined && low > high;
14157
+ var declarationProblem = (schema, path) => {
14158
+ if ("anyOf" in schema) {
14159
+ for (const [index, form] of schema.anyOf.entries()) {
14160
+ const problem = declarationProblem(form, `${path}anyOf[${index}].`);
14161
+ if (problem !== undefined)
14162
+ return problem;
14163
+ }
14164
+ return;
14165
+ }
14166
+ switch (schema.type) {
14167
+ case "boolean":
14168
+ return;
14169
+ case "string":
14170
+ return inverted(schema.minLength, schema.maxLength) ? `${path}minLength is past maxLength` : undefined;
14171
+ case "integer":
14172
+ return inverted(schema.minimum, schema.maximum) ? `${path}minimum is past maximum` : undefined;
14173
+ case "array":
14174
+ return inverted(schema.minItems, schema.maxItems) ? `${path}minItems is past maxItems` : declarationProblem(schema.items, `${path}items.`);
14175
+ case "object": {
14176
+ const missing = schema.required.find((key) => !Object.hasOwn(schema.properties, key));
14177
+ if (missing !== undefined)
14178
+ return `${path}required names "${missing}", which is not one of its properties`;
14179
+ for (const [key, field] of Object.entries(schema.properties)) {
14180
+ const problem = declarationProblem(field, `${path}properties.${key}.`);
14181
+ if (problem !== undefined)
14182
+ return problem;
14183
+ }
14184
+ return;
14185
+ }
14186
+ }
14187
+ };
14188
+ var decodeAnswerSchema = (declared) => {
14189
+ const decoded = decodeDeclared(declared);
14190
+ if (decoded._tag === "Failure")
14191
+ return {
14192
+ problem: `The answer schema is not one Kitman supports: boolean, string, integer, array, object with additionalProperties false, or anyOf, each with only their own keywords`
14193
+ };
14194
+ const problem = declarationProblem(decoded.value, "");
14195
+ return problem === undefined ? { schema: decoded.value } : { problem: `The answer schema is invalid: ${problem}` };
14196
+ };
14197
+ var shown = (value) => encodeJsonStringSync(value);
14198
+ var valueProblem = (schema, value, path) => {
14199
+ const at = path === "" ? "The answer" : path;
14200
+ if ("anyOf" in schema)
14201
+ return schema.anyOf.some((form) => valueProblem(form, value, path) === undefined) ? undefined : `${at} is none of the forms it accepts`;
14202
+ switch (schema.type) {
14203
+ case "boolean":
14204
+ if (!isBoolean2(value))
14205
+ return `${at} must be true or false`;
14206
+ return schema.const !== undefined && value !== schema.const ? `${at} must be ${schema.const}` : undefined;
14207
+ case "string":
14208
+ if (!isString2(value))
14209
+ return `${at} must be a string`;
14210
+ if (schema.const !== undefined && value !== schema.const)
14211
+ return `${at} must be ${shown(schema.const)}`;
14212
+ if (schema.enum !== undefined && !schema.enum.includes(value))
14213
+ return `${at} must be one of ${schema.enum.map(shown).join(", ")}`;
14214
+ if (schema.minLength !== undefined && value.length < schema.minLength)
14215
+ return `${at} must be at least ${schema.minLength} characters`;
14216
+ return schema.maxLength !== undefined && value.length > schema.maxLength ? `${at} must be at most ${schema.maxLength} characters` : undefined;
14217
+ case "integer":
14218
+ if (!Number.isInteger(value))
14219
+ return `${at} must be an integer`;
14220
+ if (schema.const !== undefined && value !== schema.const)
14221
+ return `${at} must be ${schema.const}`;
14222
+ if (schema.minimum !== undefined && Number(value) < schema.minimum)
14223
+ return `${at} must be at least ${schema.minimum}`;
14224
+ return schema.maximum !== undefined && Number(value) > schema.maximum ? `${at} must be at most ${schema.maximum}` : undefined;
14225
+ case "array": {
14226
+ if (!Array.isArray(value))
14227
+ return `${at} must be an array`;
14228
+ if (schema.minItems !== undefined && value.length < schema.minItems)
14229
+ return `${at} must hold at least ${schema.minItems} item${schema.minItems === 1 ? "" : "s"}`;
14230
+ if (schema.maxItems !== undefined && value.length > schema.maxItems)
14231
+ return `${at} must hold at most ${schema.maxItems} item${schema.maxItems === 1 ? "" : "s"}`;
14232
+ for (const [index, item] of value.entries()) {
14233
+ const problem = valueProblem(schema.items, item, `${path === "" ? "" : path}[${index}]`);
14234
+ if (problem !== undefined)
14235
+ return problem;
14236
+ }
14237
+ return;
14238
+ }
14239
+ case "object": {
14240
+ if (!isJsonObject(value))
14241
+ return `${at} must be an object`;
14242
+ const extra = Object.keys(value).find((key) => !Object.hasOwn(schema.properties, key));
14243
+ if (extra !== undefined)
14244
+ return `${at} must not have "${extra}"`;
14245
+ const missing = schema.required.find((key) => !Object.hasOwn(value, key));
14246
+ if (missing !== undefined)
14247
+ return `${at} must have "${missing}"`;
14248
+ for (const [key, field] of Object.entries(schema.properties)) {
14249
+ const given = value[key];
14250
+ if (given === undefined)
14251
+ continue;
14252
+ const problem = valueProblem(field, given, path === "" ? key : `${path}.${key}`);
14253
+ if (problem !== undefined)
14254
+ return problem;
14255
+ }
14256
+ return;
14257
+ }
14258
+ }
14259
+ };
14260
+ var sketch = (schema) => {
14261
+ if ("anyOf" in schema)
14262
+ return schema.anyOf.map(sketch).join(" or ");
14263
+ switch (schema.type) {
14264
+ case "boolean":
14265
+ return schema.const === undefined ? "<true or false>" : String(schema.const);
14266
+ case "string":
14267
+ if (schema.const !== undefined)
14268
+ return shown(schema.const);
14269
+ return schema.enum === undefined ? '"<text>"' : schema.enum.map(shown).join(" or ");
14270
+ case "integer":
14271
+ return schema.const === undefined ? "<integer>" : String(schema.const);
14272
+ case "array":
14273
+ return `[${sketch(schema.items)}, \u2026]`;
14274
+ case "object":
14275
+ return `{${Object.entries(schema.properties).map(([key, field]) => `${shown(key)}${schema.required.includes(key) ? "" : "?"}:${sketch(field)}`).join(",")}}`;
14276
+ }
14277
+ };
14278
+ var answerAccepts = (declared) => {
14279
+ const read = decodeAnswerSchema(declared);
14280
+ if ("problem" in read)
14281
+ return "JSON its schema accepts";
14282
+ const described = read.schema.description?.trim();
14283
+ return redactCredentialText(described === undefined || described === "" ? `JSON like ${sketch(read.schema)}` : described);
14284
+ };
14285
+ var answerProblem = (schema, answer) => {
14286
+ const decoded = decodeJsonStringOption(answer);
14287
+ const problem = decoded._tag === "None" ? "The answer is not JSON" : valueProblem(schema, decoded.value, "");
14288
+ return problem === undefined ? undefined : redactCredentialText(`${problem}. It accepts ${answerAccepts(schema)}`);
14289
+ };
14290
+ var answerValue = (schema, answer) => {
14291
+ const decoded = decodeJsonStringOption(answer);
14292
+ return decoded._tag === "Some" && valueProblem(schema, decoded.value, "") === undefined ? { value: decoded.value } : undefined;
14293
+ };
14294
+ var typed = (schema) => schema;
14295
+ var Answer = {
14296
+ literal: (value) => typed(isString2(value) ? { type: "string", const: value } : isBoolean2(value) ? { type: "boolean", const: value } : { type: "integer", const: Number(value) }),
14297
+ string: (bounds) => typed({ type: "string", ...bounds }),
14298
+ integer: (bounds) => typed({ type: "integer", ...bounds }),
14299
+ boolean: () => typed({ type: "boolean" }),
14300
+ array: (items, bounds) => typed({ type: "array", items, ...bounds }),
14301
+ optional: (field) => ({ optional: field }),
14302
+ struct: (fields) => {
14303
+ const entries = Object.entries(fields);
14304
+ return typed({
14305
+ type: "object",
14306
+ properties: Object.fromEntries(entries.map(([key, field]) => [key, "optional" in field ? field.optional : field])),
14307
+ required: entries.flatMap(([key, field]) => ("optional" in field) ? [] : [key]),
14308
+ additionalProperties: false
14309
+ });
14310
+ },
14311
+ union: (...forms) => typed({ anyOf: forms }),
14312
+ describe: (schema, description) => ({ ...schema, description })
14313
+ };
14314
+
14083
14315
  // ../../packages/core/src/loop.ts
14084
14316
  var LoopStatuses = ["draft", "active", "disabled", "archived"];
14085
14317
  var LoopStepImplementationKinds = [
@@ -14306,6 +14538,7 @@ var LoopSafeInternalReferenceString = String5.check(isMinLength(1), isMaxLength(
14306
14538
  var loopSafeTextMaxLength = 4000;
14307
14539
  var LoopSafeText = String5.check(isMaxLength(loopSafeTextMaxLength), isPattern2(new RegExp(`^(?![\\s\\S]*(?:${LoopCredentialContentPattern}|[A-Za-z][A-Za-z0-9+.-]*://(?:[^\\s/?#]*@|[^\\s?#]*\\?)))[\\s\\S]*$`, "u")));
14308
14540
  var recommendedDefault = (recommended) => recommended !== undefined && is2(LoopSafeText)(recommended) ? recommended : undefined;
14541
+ var isLoopSafeText = is2(LoopSafeText);
14309
14542
  var unansweredQuestionLead = "Nobody answers in full auto, and the agent's Question has no answer to take";
14310
14543
  var isUnansweredQuestion = (reason) => reason.startsWith(unansweredQuestionLead);
14311
14544
  var QuestionText = String5;
@@ -14920,6 +15153,7 @@ var Question = Struct({
14920
15153
  prompt: QuestionText,
14921
15154
  options: optionalKey2(ArraySchema(QuestionText)),
14922
15155
  freeText: optionalKey2(Boolean3),
15156
+ answerSchema: optionalKey2(AnswerSchemaJson),
14923
15157
  optionDescriptions: optionalKey2(Record(String5, QuestionText)),
14924
15158
  recommended: optionalKey2(QuestionText),
14925
15159
  recommendationReason: optionalKey2(QuestionText),
@@ -20217,6 +20451,11 @@ var agentDeferredNamed = (deferredName) => make15(deferredName, { success: Json2
20217
20451
  var agentWorkDeferred = (step, round = 1) => agentDeferredNamed(agentRoundName(step, round));
20218
20452
  var syncDeferred = (step) => agentDeferredNamed(`sync/${step}`);
20219
20453
  var answerDeferred = (step) => make15(`ask/${step}`, { success: String5, error: StepFailed });
20454
+ var AnswerTakenBy = Literals(["person", "default", "auto"]);
20455
+ var structuredAnswerDeferred = (step) => make15(`ask/${step}`, {
20456
+ success: Struct({ answer: String5, by: AnswerTakenBy }),
20457
+ error: StepFailed
20458
+ });
20220
20459
  var childDeferred = (step) => make15(`call/${step}`, { success: Json2, error: ChildFailed });
20221
20460
  var eventDeferred = (step) => make15(`wait_for/${step}`, { success: LoopEvent, error: WaitTimedOut });
20222
20461
  var verifyDeferred = (step) => make15(`verify/${step}`, { success: VerifyResult, error: StepFailed });
@@ -20345,14 +20584,23 @@ var agent = (agentName) => (step, work) => {
20345
20584
  }), earlier !== undefined);
20346
20585
  });
20347
20586
  };
20348
- var ask = (name, question) => takeStep(name, "ask", "ask", (name) => gen2(function* () {
20349
- const deferred = answerDeferred(name);
20350
- const offered = "options" in question ? splitQuestionOptions(question.options) : undefined;
20351
- const options = offered?.options;
20352
- const recommended = "recommended" in question ? question.recommended : undefined;
20353
- const informationOnly = "informationOnly" in question ? question.informationOnly : undefined;
20587
+
20588
+ class Words {
20589
+ text;
20590
+ constructor(text) {
20591
+ this.text = text;
20592
+ }
20593
+ get blank() {
20594
+ return this.text.trim() === "";
20595
+ }
20596
+ toString() {
20597
+ return this.text;
20598
+ }
20599
+ }
20600
+ var putQuestion = (name, question, deferred) => gen2(function* () {
20601
+ const { options, recommended, informationOnly } = question;
20354
20602
  const advice = questionAdvice({
20355
- ...offered,
20603
+ ...question.optionDescriptions === undefined ? undefined : { optionDescriptions: question.optionDescriptions },
20356
20604
  ...recommended === undefined ? undefined : { recommended },
20357
20605
  recommendationReason: question.recommendationReason,
20358
20606
  ...informationOnly === undefined ? undefined : { informationOnly }
@@ -20371,6 +20619,7 @@ var ask = (name, question) => takeStep(name, "ask", "ask", (name) => gen2(functi
20371
20619
  step: name,
20372
20620
  prompt: question.prompt,
20373
20621
  ...options === undefined ? undefined : { options },
20622
+ ...question.answerSchema === undefined ? undefined : { answerSchema: question.answerSchema },
20374
20623
  ...advice,
20375
20624
  ...fallback === undefined ? undefined : { default: fallback },
20376
20625
  ...question.auto === undefined ? undefined : { auto: question.auto },
@@ -20379,15 +20628,62 @@ var ask = (name, question) => takeStep(name, "ask", "ask", (name) => gen2(functi
20379
20628
  ...question.timeout === undefined ? undefined : { timeoutMillis: toMillis(fromInputUnsafe2(question.timeout)) },
20380
20629
  token: token2
20381
20630
  }));
20382
- const answer = yield* await_2(deferred);
20383
- if (options === undefined) {
20384
- return answer;
20385
- }
20386
- const offeredAnswer = options.find((option) => option === answer);
20387
- if (offeredAnswer === undefined)
20631
+ return yield* await_2(deferred);
20632
+ });
20633
+ var askOptions = (name, question) => gen2(function* () {
20634
+ const { options, optionDescriptions } = splitQuestionOptions(question.options);
20635
+ const answer = yield* putQuestion(name, { ...question, options, ...optionDescriptions === undefined ? undefined : { optionDescriptions } }, answerDeferred(name));
20636
+ if (!options.includes(answer))
20388
20637
  return yield* new QuestionRefused({ step: name, answer, options });
20389
- return offeredAnswer;
20390
- }));
20638
+ return answer;
20639
+ });
20640
+ var askStructured = (name, question) => gen2(function* () {
20641
+ const read = decodeAnswerSchema(question.answer);
20642
+ if ("problem" in read)
20643
+ return yield* new StepFailed({ step: name, reason: read.problem });
20644
+ const { schema } = read;
20645
+ const declared = (what, value, stored) => {
20646
+ const answer = encodeUnknownJsonStringSync(value);
20647
+ const problem = stored && !isLoopSafeText(answer) ? "it is too long, or holds a credential" : answerProblem(schema, answer);
20648
+ return problem === undefined ? succeed7(answer) : fail7(new StepFailed({ step: name, reason: `The ${what} is refused: ${problem}` }));
20649
+ };
20650
+ const taken = yield* putQuestion(name, {
20651
+ prompt: question.prompt,
20652
+ answerSchema: schema,
20653
+ recommended: yield* declared("recommended answer", question.recommended, false),
20654
+ recommendationReason: question.recommendationReason,
20655
+ ...question.default === undefined ? undefined : { default: question.default === null ? null : yield* declared("default", question.default, true) },
20656
+ ...question.auto === undefined ? undefined : { auto: yield* declared("full-auto answer", question.auto, true) },
20657
+ ...question.unattendedAuto === undefined ? undefined : { unattendedAuto: yield* declared("full-auto answer", question.unattendedAuto, true) },
20658
+ ...question.evidence === undefined ? undefined : { evidence: question.evidence },
20659
+ ...question.timeout === undefined ? undefined : { timeout: question.timeout }
20660
+ }, structuredAnswerDeferred(name));
20661
+ const decoded = answerValue(schema, taken.answer);
20662
+ if (decoded === undefined)
20663
+ return yield* new QuestionRefused({ step: name, answer: taken.answer, options: [] });
20664
+ return { answer: decoded.value, by: taken.by };
20665
+ });
20666
+ function ask(name, question) {
20667
+ return takeStep(name, "ask", "ask", (name) => {
20668
+ const modes = [
20669
+ "options" in question && question.options !== undefined ? "options" : [],
20670
+ "answer" in question && question.answer !== undefined ? "answer" : [],
20671
+ "freeText" in question && question.freeText !== undefined ? "freeText" : []
20672
+ ].flat();
20673
+ if (modes.length === 1) {
20674
+ if ("options" in question && question.options !== undefined)
20675
+ return askOptions(name, question);
20676
+ if ("answer" in question && question.answer !== undefined)
20677
+ return askStructured(name, question);
20678
+ if ("freeText" in question && question.freeText === true)
20679
+ return map8(putQuestion(name, question, answerDeferred(name)), (text) => new Words(text));
20680
+ }
20681
+ return fail7(new StepFailed({
20682
+ step: name,
20683
+ reason: `A Question declares exactly one of options, answer or freeText: true; this one declares ${modes.length === 0 ? "none" : modes.join(" and ")}`
20684
+ }));
20685
+ });
20686
+ }
20391
20687
  var admitChild = (name, loop, input, byId, options) => {
20392
20688
  const constraints = options?.constraints ?? [];
20393
20689
  return launch(childDeferred(name), (host, token2) => host.admitChild({
@@ -23181,7 +23477,14 @@ var scriptedHost = (script, engine, agentLaunches, childLaunches, waits, verifyL
23181
23477
  value: answer,
23182
23478
  ...scripted === undefined && auto !== undefined ? { byAuto: true, ...launch.evidence === undefined ? undefined : { evidence: launch.evidence } } : undefined
23183
23479
  });
23184
- return andThen2(sync2(() => questions.push({ step: launch.step, prompt: launch.prompt })), resolve(answerDeferred(launch.step), launch.token, answer === undefined ? fail5(new StepFailed({ step: launch.step, reason: "no answer was scripted" })) : succeed4(answer)));
23480
+ return andThen2(sync2(() => questions.push({
23481
+ step: launch.step,
23482
+ prompt: launch.prompt,
23483
+ ...launch.answerSchema === undefined ? undefined : { answerSchema: launch.answerSchema }
23484
+ })), answer === undefined ? resolve(answerDeferred(launch.step), launch.token, fail5(new StepFailed({ step: launch.step, reason: "no answer was scripted" }))) : launch.answerSchema === undefined ? resolve(answerDeferred(launch.step), launch.token, succeed4(answer)) : resolve(structuredAnswerDeferred(launch.step), launch.token, succeed4({
23485
+ answer,
23486
+ by: scripted !== undefined ? "person" : auto !== undefined ? "auto" : "default"
23487
+ })));
23185
23488
  },
23186
23489
  admitChild: (launch) => {
23187
23490
  const refused = script.refusedChildren?.[launch.step];
@@ -24016,8 +24319,6 @@ var bumpPolicy = (name = "outcome", options = {}) => {
24016
24319
  }
24017
24320
  };
24018
24321
  // ../../packages/core/src/plan-review.ts
24019
- var PlanApproval = "Approve plan";
24020
- var UnattendedPlanApproval = "Approve plan, unattended";
24021
24322
  var Offset = Int.check(isGreaterThanOrEqualTo3(0));
24022
24323
  var PlanReviewComment = Struct({
24023
24324
  id: String5,
@@ -24033,14 +24334,27 @@ var PlanReview = Struct({
24033
24334
  revision: Int.check(isGreaterThanOrEqualTo3(1)),
24034
24335
  comments: ArraySchema(PlanReviewComment)
24035
24336
  });
24337
+ var AnswerOffset = Answer.optional(Answer.integer({ minimum: 0 }));
24338
+ var CommentAnswer = Answer.struct({
24339
+ id: Answer.string(),
24340
+ body: Answer.string(),
24341
+ quote: Answer.optional(Answer.string()),
24342
+ line: Answer.optional(Answer.integer({ minimum: 1 })),
24343
+ start: AnswerOffset,
24344
+ end: AnswerOffset,
24345
+ from: AnswerOffset,
24346
+ to: AnswerOffset
24347
+ });
24348
+ var decisionOf = (revision, description) => Answer.describe(Answer.union(Answer.struct({ approve: Answer.literal(true) }), Answer.struct({
24349
+ planReview: Answer.struct({ revision, comments: Answer.array(CommentAnswer, { minItems: 1 }) })
24350
+ })), description);
24351
+ var planReviewDecision = (revision) => decisionOf(Answer.literal(revision), `{"approve":true} to approve the plan, or {"planReview":{"revision":${revision},"comments":[{"id":"<any id>","body":"<what should change>"}]}} with at least one comment to request changes`);
24352
+ var anyRevisionDecision = decisionOf(Answer.integer({ minimum: 1 }), "a plan review decision");
24353
+ var PlanApproval = { approve: true };
24036
24354
  var PlanAddressed = Struct({ comment: String5, how: String5 });
24037
24355
  var PlanDeclined = Struct({ comment: String5, why: String5 });
24038
24356
  var lineAt = (text, offset) => text.slice(0, offset).split(`
24039
24357
  `).length;
24040
- var PlanReviewAnswer = fromJsonString2(Struct({ planReview: PlanReview }));
24041
- var decodeAnswer = decodeUnknownOption2(PlanReviewAnswer);
24042
- var encodeAnswer = encodeSync(PlanReviewAnswer);
24043
- var isPlanApproval = (answer) => [PlanApproval, UnattendedPlanApproval].some((approval) => answer.trim().toLowerCase() === approval.toLowerCase());
24044
24358
  var placed = (comment, markdown) => {
24045
24359
  const { from, to } = comment;
24046
24360
  if (from === undefined || to === undefined || from >= to || to > markdown.length) {
@@ -24049,12 +24363,10 @@ var placed = (comment, markdown) => {
24049
24363
  }
24050
24364
  return { ...comment, quote: markdown.slice(from, to), line: lineAt(markdown, from) };
24051
24365
  };
24052
- var readPlanReview = (answer, revision, markdown) => {
24053
- const decoded = decodeAnswer(answer);
24054
- if (decoded._tag === "None" || decoded.value.planReview.revision !== revision || decoded.value.planReview.comments.length === 0)
24055
- return { revision, comments: [{ id: "words", body: answer.trim() }] };
24056
- return { revision, comments: decoded.value.planReview.comments.map((comment) => placed(comment, markdown)) };
24057
- };
24366
+ var readPlanReview = (review, markdown) => ({
24367
+ revision: review.revision,
24368
+ comments: review.comments.map((comment) => placed(comment, markdown))
24369
+ });
24058
24370
  // src/out-of-scope.ts
24059
24371
  var outOfScopeCase = { outOfScope: optional2(Int) };
24060
24372
  var listedCases = (cases) => (cases ?? []).filter((item) => item.trim() !== "");
@@ -25916,7 +26228,7 @@ ${text}`,
25916
26228
  default: "No reason given",
25917
26229
  timeout: "1 day"
25918
26230
  });
25919
- return yield* new Rejected({ reason: why });
26231
+ return yield* new Rejected({ reason: why.text });
25920
26232
  }
25921
26233
  const edit = yield* ask(round === 1 ? "edit" : `edit:${round}`, {
25922
26234
  prompt: "What should change in the notes?",
@@ -25926,8 +26238,8 @@ ${text}`,
25926
26238
  default: "",
25927
26239
  timeout: "1 day"
25928
26240
  });
25929
- if (edit.trim() !== "")
25930
- return new Edit({ edit });
26241
+ if (!edit.blank)
26242
+ return new Edit({ edit: edit.text });
25931
26243
  }
25932
26244
  })
25933
26245
  });
@@ -30164,7 +30476,7 @@ var Input5 = Struct({
30164
30476
  description: "The base branch; the repository's default branch when left out."
30165
30477
  })
30166
30478
  });
30167
- var Answer = Struct({
30479
+ var Answer2 = Struct({
30168
30480
  status: Literals(["done", "blocked", "too_big"]),
30169
30481
  summary: ChangeRequestSummary,
30170
30482
  changed: Boolean3,
@@ -30211,7 +30523,7 @@ var done6 = step2("done", {
30211
30523
  const { status, summary, changed, title, checks } = yield* implementer("errand", {
30212
30524
  skill: "implement",
30213
30525
  prompt: prompt3(words),
30214
- output: Answer,
30526
+ output: Answer2,
30215
30527
  timeout: budget
30216
30528
  });
30217
30529
  if (status === "blocked")
@@ -31585,22 +31897,22 @@ var planReviewed = step2("planReviewed", {
31585
31897
  success: Union2([PlanApproved, Drafted2]),
31586
31898
  key: ({ draft }) => String(draft.revision),
31587
31899
  run: ({ draft: { plan, revision, disputed, asked }, implement }) => gen2(function* () {
31588
- const answer = yield* ask("review", {
31900
+ const { answer: decision, by } = yield* ask("review", {
31589
31901
  prompt: [
31590
31902
  `Review revision ${revision} of the plan "${plan.title}": approve it, or request changes by commenting on what should change.`,
31591
31903
  ...disputed.length === 0 ? [] : [
31592
31904
  `The plan reviewer still disputes ${disputed.length} point${disputed.length === 1 ? "" : "s"}, listed at the end of the plan.`
31593
31905
  ]
31594
31906
  ].join(" "),
31595
- freeText: true,
31907
+ answer: planReviewDecision(revision),
31596
31908
  recommended: PlanApproval,
31597
31909
  recommendationReason: "Approve it once the plan reads right; until then the Run waits for you.",
31598
- ...implement ? { default: UnattendedPlanApproval, timeout: "1 hour" } : { default: null },
31599
- unattendedAuto: UnattendedPlanApproval
31910
+ ...implement ? { default: PlanApproval, timeout: "1 hour" } : { default: null },
31911
+ unattendedAuto: PlanApproval
31600
31912
  });
31601
- if (isPlanApproval(answer))
31602
- return new PlanApproved({ revision, reviewed: disputed.length === 0 || answer !== UnattendedPlanApproval });
31603
- const review = readPlanReview(answer, revision, documentText(plan, disputed));
31913
+ if ("approve" in decision)
31914
+ return new PlanApproved({ revision, reviewed: disputed.length === 0 || by === "person" });
31915
+ const review = readPlanReview(decision.planReview, documentText(plan, disputed));
31604
31916
  const revised = yield* planner("revise-plan", {
31605
31917
  prompt: revisePrompt2(documentText(plan, disputed), review),
31606
31918
  output: Revised
@@ -31677,16 +31989,16 @@ var refined = step2("refined", {
31677
31989
  recommendationReason: "You chose to refine it, so only you know what should change."
31678
31990
  });
31679
31991
  const changed = yield* planner("refine-plan", {
31680
- prompt: refinePrompt(documentText(plan, disputed), words),
31992
+ prompt: refinePrompt(documentText(plan, disputed), words.text),
31681
31993
  output: Plan
31682
31994
  });
31683
- const askedNow = [...asked, words];
31995
+ const askedNow = [...asked, words.text];
31684
31996
  const after = yield* checked2({ plan: changed }, askedNow);
31685
31997
  yield* storePlan(after, revision + 1);
31686
31998
  yield* artifact("changes", {
31687
31999
  kind: "plan_changes",
31688
32000
  title: `Revision ${revision + 1} of ${after.plan.title}`,
31689
- text: changelog(plan, after.plan, words)
32001
+ text: changelog(plan, after.plan, words.text)
31690
32002
  });
31691
32003
  return new Drafted2({
31692
32004
  plan: after.plan,
@@ -31944,7 +32256,7 @@ var failureAnswered = step2("failureAnswered", {
31944
32256
  recommendationReason: "Pointing the retry at the reason it failed is the least a steer should do.",
31945
32257
  default: null
31946
32258
  });
31947
- return new Steer({ words });
32259
+ return new Steer({ words: words.text });
31948
32260
  })
31949
32261
  });
31950
32262
  var retried = step2("retried", {
@@ -32099,7 +32411,7 @@ var outputOfPlan = ({ plan, rejected }, docs, asTasks) => ({
32099
32411
  });
32100
32412
  var plan_default = defineLoop({
32101
32413
  id: "plan",
32102
- version: "4.0.0",
32414
+ version: "5.0.0",
32103
32415
  title: "Plan",
32104
32416
  description: "Plans a goal into reviewed tickets and a spec, then builds them or files them as Tasks.",
32105
32417
  input: Input8,
@@ -33656,7 +33968,7 @@ var surveyed = step2("surveyed", {
33656
33968
  recommendationReason: question.why,
33657
33969
  default: "No answer; go by the code.",
33658
33970
  timeout: "1 day"
33659
- }), (answer) => `- ${question.question} ${answer}`));
33971
+ }), (answer) => `- ${question.question} ${answer.text}`));
33660
33972
  const { report, htmlReport, candidates } = yield* surveyor("survey:answered", {
33661
33973
  skill: "improve-codebase-architecture",
33662
33974
  prompt: surveyPrompt(words, answers),
@@ -33879,7 +34191,7 @@ var kitman_config_default = defineKit({
33879
34191
  },
33880
34192
  planner: {
33881
34193
  harness: "claude",
33882
- model: "claude-fable-5-2",
34194
+ model: "opus",
33883
34195
  effort: "high",
33884
34196
  fallbacks,
33885
34197
  skills: ["grilling", "domain-modeling"],
@@ -36522,6 +36834,7 @@ class RunnerCapabilityRpcs extends make32(make31("PutQuestion", {
36522
36834
  step: String5,
36523
36835
  prompt: String5,
36524
36836
  options: optional2(ArraySchema(String5)),
36837
+ answerSchema: optional2(AnswerSchemaJson),
36525
36838
  optionDescriptions: optional2(Record(String5, String5)),
36526
36839
  recommended: optional2(String5),
36527
36840
  recommendationReason: optional2(String5),
@@ -37240,6 +37553,7 @@ var runnerHost = (capabilities) => ({
37240
37553
  deferredName: answerDeferred(launch.step).name,
37241
37554
  ...questionAdvice(launch),
37242
37555
  ...launch.options === undefined ? undefined : { options: launch.options },
37556
+ ...launch.answerSchema === undefined ? undefined : { answerSchema: launch.answerSchema },
37243
37557
  ...launch.verification === undefined ? undefined : { verification: launch.verification },
37244
37558
  ...launch.default === undefined ? undefined : { default: launch.default },
37245
37559
  ...launch.auto === undefined ? undefined : { auto: launch.auto },
@@ -37426,6 +37740,7 @@ var rpcProgramPorts = (rpc, work) => {
37426
37740
  deferredName: question.deferredName,
37427
37741
  ...questionAdvice(question),
37428
37742
  ...question.options === undefined ? undefined : { options: [...question.options] },
37743
+ ...question.answerSchema === undefined ? undefined : { answerSchema: question.answerSchema },
37429
37744
  ...question.verification === undefined ? undefined : { verification: question.verification },
37430
37745
  ...question.default === undefined ? undefined : { default: question.default },
37431
37746
  ...question.auto === undefined ? undefined : { auto: question.auto },
@@ -39741,4 +40056,4 @@ var runKit = (config, identity, packages) => {
39741
40056
  runMain2(program.pipe(flatMap3((code) => sync2(() => process.exit(code)))));
39742
40057
  };
39743
40058
  // .kitman-build-entry.ts
39744
- runKit(kitman_config_default, { name: "@kitman-sh/software-engineering", version: "0.44.0" }, []);
40059
+ runKit(kitman_config_default, { name: "@kitman-sh/software-engineering", version: "0.46.0" }, []);