@c4a/context-cli 0.5.39-beta.2 → 0.5.39-beta.3
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/cli.js +1610 -837
- package/package.json +1 -1
- package/plugin/README.md +2 -2
- package/plugin/README_CN.md +2 -2
- package/plugin/commands/compile.md +1 -1
- package/plugin/skills/skill-align-workflow/SKILL.md +1 -1
- package/plugin/skills/skill-align-workflow/references/density-profile.md +2 -0
- package/plugin/skills/skill-align-workflow/references/gates.md +3 -3
- package/plugin/skills/skill-compile-draft/SKILL.md +1 -1
- package/plugin/skills/skill-compile-draft/references/action-domain-gates.md +1 -1
- package/plugin/skills/skill-compile-judge/SKILL.md +3 -1
package/cli.js
CHANGED
|
@@ -28425,8 +28425,8 @@ function stripEvidenceUrls(text5) {
|
|
|
28425
28425
|
}
|
|
28426
28426
|
var URL_RE, TRAILING_URL_PUNCTUATION_RE, TRACKING_QUERY_PARAM_RE;
|
|
28427
28427
|
var init_evidenceUrls = __esm(() => {
|
|
28428
|
-
URL_RE = /https?:\/\/[^\s)\]}>"')】》」』,。;:!?]+/giu;
|
|
28429
|
-
TRAILING_URL_PUNCTUATION_RE = /[
|
|
28428
|
+
URL_RE = /https?:\/\/[^\s`*)\]}>"')】》」』,。;:!?]+/giu;
|
|
28429
|
+
TRAILING_URL_PUNCTUATION_RE = /[`*.,;:!?)\]\}>"',。;:!?)】》」』]+$/u;
|
|
28430
28430
|
TRACKING_QUERY_PARAM_RE = /^(?:utm_|fbclid$|gclid$|mc_cid$|mc_eid$)/iu;
|
|
28431
28431
|
});
|
|
28432
28432
|
|
|
@@ -52772,7 +52772,7 @@ function rejectLegacy(path13, message) {
|
|
|
52772
52772
|
}]
|
|
52773
52773
|
});
|
|
52774
52774
|
}
|
|
52775
|
-
function
|
|
52775
|
+
function stringValue2(value) {
|
|
52776
52776
|
return typeof value === "string" && value.trim().length > 0 ? value.trim() : undefined;
|
|
52777
52777
|
}
|
|
52778
52778
|
function stringArray2(value) {
|
|
@@ -54856,6 +54856,7 @@ var init_alignWorkflowSchemas = __esm(() => {
|
|
|
54856
54856
|
"CLI compiles section_groups[] into canonical sections[] and generates section_id values.",
|
|
54857
54857
|
"nodes[].planned_sections defaults to the distinct section_groups[].section_kind values for that owner. Nodes with no section_groups must explicitly set planned_sections: [] to express no-write intent.",
|
|
54858
54858
|
"section_groups[] only accepts block_ids[]. Do not use source_window_ids, ranges, headings, or heading globs for Section evidence selection.",
|
|
54859
|
+
"section_groups[].block_ids may express one semantic grouping, but finalized ownership splits non-contiguous citation-eligible runs into draft-ready section plans. During compile, keep those emitted draft_action_templates separate unless one Section truly consumes every intervening citation-eligible block.",
|
|
54859
54860
|
"Every owned/shared citation evidence block selected by ownership_groups[] must appear in some section_groups[].block_ids, unless it is explicitly reclassified as context_only or ignored.",
|
|
54860
54861
|
"ownership_groups[].scope must be exactly one of: {source_id}, {source_id, structural_role}, or {block_ids}. Do not add except clauses or arbitrary filter expressions.",
|
|
54861
54862
|
"Ownership precedence is block_ids > source_id + structural_role > source_id; same specificity uses later group; explicit block_ownership[] patches override all groups.",
|
|
@@ -55009,7 +55010,8 @@ var init_alignWorkflowSchemas = __esm(() => {
|
|
|
55009
55010
|
...TERM_ENTITY_NOTES,
|
|
55010
55011
|
"Use align-segments.generation_policy when choosing node.title, node.summary, rationale prose, and planned Section wording.",
|
|
55011
55012
|
"nodes[].contains_parent is the only hierarchy field; edges[] only accepts depends_on.",
|
|
55012
|
-
"domain nodes need domain_gate
|
|
55013
|
+
"domain nodes need domain_gate with resolvable child_refs; invalid domain gates block validation instead of being auto-downgraded to entity. If the evidence is not a grouping scope, submit entity with agent-chosen tags.",
|
|
55014
|
+
"action nodes need action_probe and structured action_gate.inference_sources; invalid action gates block validation instead of being auto-downgraded to entity. If the evidence is not a repeatable process, submit entity or write the process wording as a Section under its owner.",
|
|
55013
55015
|
"When align-segments.incremental.mode is incremental, finalize preserves previous finalized ownership for unscanned sources. The current decision should describe only the scanned evidence while referencing previous active Nodes when needed.",
|
|
55014
55016
|
"In incremental mode, absence of an old Node or edge is not a deletion signal; use a full align, drop source, or explicit structure correction path for removals.",
|
|
55015
55017
|
"Incremental finalize may reference previous active Nodes from nodes[].contains_parent, edges[].from/to, domain_gate.child_refs, and block_ownership owners/visible_to/primary_owner. Do not redeclare an old parent/domain just to attach new children.",
|
|
@@ -55166,7 +55168,7 @@ function isNavigationExternalReference(block) {
|
|
|
55166
55168
|
return externalReferenceDisposition(block) === "navigation_reference";
|
|
55167
55169
|
}
|
|
55168
55170
|
function ownershipDefaultForBlock(raw, blockId, block) {
|
|
55169
|
-
const role =
|
|
55171
|
+
const role = stringValue2(raw.ownership_role);
|
|
55170
55172
|
if (role !== "owned" && role !== "shared") {
|
|
55171
55173
|
return { ...raw, block_id: blockId };
|
|
55172
55174
|
}
|
|
@@ -55176,14 +55178,14 @@ function ownershipDefaultForBlock(raw, blockId, block) {
|
|
|
55176
55178
|
const visibleTo2 = uniqueStrings3([
|
|
55177
55179
|
...stringArray2(raw.visible_to),
|
|
55178
55180
|
...stringArray2(raw.owners),
|
|
55179
|
-
...
|
|
55181
|
+
...stringValue2(raw.primary_owner) !== undefined ? [stringValue2(raw.primary_owner)] : []
|
|
55180
55182
|
]);
|
|
55181
55183
|
const next2 = {
|
|
55182
55184
|
...raw,
|
|
55183
55185
|
block_id: blockId,
|
|
55184
55186
|
ownership_role: structuralDefaultRole,
|
|
55185
55187
|
visible_to: visibleTo2,
|
|
55186
|
-
reason:
|
|
55188
|
+
reason: stringValue2(raw.reason) ?? `mechanical ${structuralRole} block does not need Section citation`,
|
|
55187
55189
|
provenance: "cli_demote"
|
|
55188
55190
|
};
|
|
55189
55191
|
Reflect.deleteProperty(next2, "owners");
|
|
@@ -55195,14 +55197,14 @@ function ownershipDefaultForBlock(raw, blockId, block) {
|
|
|
55195
55197
|
const visibleTo = uniqueStrings3([
|
|
55196
55198
|
...stringArray2(raw.visible_to),
|
|
55197
55199
|
...stringArray2(raw.owners),
|
|
55198
|
-
...
|
|
55200
|
+
...stringValue2(raw.primary_owner) !== undefined ? [stringValue2(raw.primary_owner)] : []
|
|
55199
55201
|
]);
|
|
55200
55202
|
const next = {
|
|
55201
55203
|
...raw,
|
|
55202
55204
|
block_id: blockId,
|
|
55203
55205
|
ownership_role: "context_only",
|
|
55204
55206
|
visible_to: visibleTo,
|
|
55205
|
-
reason:
|
|
55207
|
+
reason: stringValue2(raw.reason) ?? "navigation/reference-only block kept as context_only",
|
|
55206
55208
|
provenance: "cli_demote"
|
|
55207
55209
|
};
|
|
55208
55210
|
Reflect.deleteProperty(next, "owners");
|
|
@@ -55239,7 +55241,7 @@ function expandOwnershipDefaults(input) {
|
|
|
55239
55241
|
blocks.push(blockId);
|
|
55240
55242
|
blocksBySource.set(sourceId, blocks);
|
|
55241
55243
|
}
|
|
55242
|
-
const explicitBlockIds = new Set(input.blockOwnership.filter(isRecord18).map((entry) =>
|
|
55244
|
+
const explicitBlockIds = new Set(input.blockOwnership.filter(isRecord18).map((entry) => stringValue2(entry.block_id)).filter((blockId) => blockId !== undefined));
|
|
55243
55245
|
const issues = [];
|
|
55244
55246
|
const defaultsBySource = new Set;
|
|
55245
55247
|
const expanded = [];
|
|
@@ -55256,7 +55258,7 @@ function expandOwnershipDefaults(input) {
|
|
|
55256
55258
|
});
|
|
55257
55259
|
return;
|
|
55258
55260
|
}
|
|
55259
|
-
const sourceId =
|
|
55261
|
+
const sourceId = stringValue2(raw.source_id);
|
|
55260
55262
|
if (sourceId === undefined) {
|
|
55261
55263
|
issues.push({
|
|
55262
55264
|
path: `block_ownership_defaults[${index2}].source_id`,
|
|
@@ -55327,8 +55329,8 @@ function normalizeOwnership(value, refs, slugs, coverableBlockIds, coverableBloc
|
|
|
55327
55329
|
push2(`block_ownership[${index2}]`, "block ownership must be an object");
|
|
55328
55330
|
return;
|
|
55329
55331
|
}
|
|
55330
|
-
const blockId =
|
|
55331
|
-
const rawRole =
|
|
55332
|
+
const blockId = stringValue2(raw.block_id);
|
|
55333
|
+
const rawRole = stringValue2(raw.ownership_role);
|
|
55332
55334
|
const role = rawRole !== undefined && ["owned", "shared", "context_only", "ignored", "unresolved"].includes(rawRole) ? rawRole : undefined;
|
|
55333
55335
|
if (blockId === undefined) {
|
|
55334
55336
|
push2(`block_ownership[${index2}].block_id`, "block_id is required", { availableBlockIds: coverableBlockIds });
|
|
@@ -55435,7 +55437,7 @@ ${BLOCK_OWNERSHIP_CANONICAL_SHAPES.unresolved}`
|
|
|
55435
55437
|
});
|
|
55436
55438
|
entryHasIssues = true;
|
|
55437
55439
|
}
|
|
55438
|
-
const rawPrimaryOwner =
|
|
55440
|
+
const rawPrimaryOwner = stringValue2(raw.primary_owner);
|
|
55439
55441
|
const primaryOwner = rawPrimaryOwner === undefined ? undefined : tryResolve(rawPrimaryOwner, `block_ownership[${index2}].primary_owner`);
|
|
55440
55442
|
if (role === "shared" && (owners.length < 2 || primaryOwner === undefined)) {
|
|
55441
55443
|
push2(`block_ownership[${index2}].primary_owner`, "shared block must have at least two owners and primary_owner", {
|
|
@@ -55477,8 +55479,8 @@ ${BLOCK_OWNERSHIP_CANONICAL_SHAPES.unresolved}`
|
|
|
55477
55479
|
});
|
|
55478
55480
|
entryHasIssues = true;
|
|
55479
55481
|
}
|
|
55480
|
-
const reason =
|
|
55481
|
-
const provenance =
|
|
55482
|
+
const reason = stringValue2(raw.reason);
|
|
55483
|
+
const provenance = stringValue2(raw.provenance);
|
|
55482
55484
|
if ((role === "shared" || role === "unresolved") && reason === undefined) {
|
|
55483
55485
|
push2(`block_ownership[${index2}].reason`, `${role} block requires reason`, {
|
|
55484
55486
|
reasonCode: "missing-ownership-reason",
|
|
@@ -55487,7 +55489,7 @@ ${BLOCK_OWNERSHIP_CANONICAL_SHAPES.unresolved}`
|
|
|
55487
55489
|
});
|
|
55488
55490
|
entryHasIssues = true;
|
|
55489
55491
|
}
|
|
55490
|
-
const questionId =
|
|
55492
|
+
const questionId = stringValue2(raw.question_id);
|
|
55491
55493
|
if (role === "unresolved" && questionId === undefined) {
|
|
55492
55494
|
push2(`block_ownership[${index2}].question_id`, "unresolved block requires question_id", {
|
|
55493
55495
|
reasonCode: "missing-question-id",
|
|
@@ -55553,7 +55555,7 @@ var init_alignStructureOwnership = __esm(() => {
|
|
|
55553
55555
|
});
|
|
55554
55556
|
|
|
55555
55557
|
// src/workflow/alignBlockStructuralRole.ts
|
|
55556
|
-
function
|
|
55558
|
+
function stringValue3(value) {
|
|
55557
55559
|
return typeof value === "string" && value.trim().length > 0 ? value.trim() : undefined;
|
|
55558
55560
|
}
|
|
55559
55561
|
function blockText(block) {
|
|
@@ -55612,7 +55614,7 @@ function isNavigationReferenceQuote(blockKind, lines) {
|
|
|
55612
55614
|
return blockKind === "quote" && lines.length > 0 && lines.every((line) => isExternalReferenceLine(stripMarkdownQuotePrefix(line)));
|
|
55613
55615
|
}
|
|
55614
55616
|
function alignBlockStructuralRole(block) {
|
|
55615
|
-
const blockKind =
|
|
55617
|
+
const blockKind = stringValue3(block.block_kind);
|
|
55616
55618
|
const text6 = blockText(block);
|
|
55617
55619
|
if (text6 === undefined)
|
|
55618
55620
|
return "content";
|
|
@@ -59330,6 +59332,7 @@ var init_compileDraftSourceRefs = __esm(() => {
|
|
|
59330
59332
|
CONTIGUITY_SKIPPABLE_STRUCTURAL_ROLES = new Set([
|
|
59331
59333
|
"embed_tag",
|
|
59332
59334
|
"embedded_asset",
|
|
59335
|
+
"heading_only",
|
|
59333
59336
|
"navigation_reference",
|
|
59334
59337
|
"marker_quote"
|
|
59335
59338
|
]);
|
|
@@ -59808,6 +59811,42 @@ var init_compileDraftTemplateValidation = __esm(() => {
|
|
|
59808
59811
|
init_compileTemplateDetection();
|
|
59809
59812
|
});
|
|
59810
59813
|
|
|
59814
|
+
// src/workflow/markdownFormatSignals.ts
|
|
59815
|
+
function markdownListItemCount(value) {
|
|
59816
|
+
return [...value.matchAll(MARKDOWN_LIST_ITEM_RE)].length;
|
|
59817
|
+
}
|
|
59818
|
+
function markdownFormatSignals(value) {
|
|
59819
|
+
if (typeof value !== "string" || value.trim().length === 0) {
|
|
59820
|
+
return { format_sensitive: false };
|
|
59821
|
+
}
|
|
59822
|
+
const containsList = markdownListItemCount(value) >= 2;
|
|
59823
|
+
const containsTable = TABLE_SEPARATOR_RE.test(value);
|
|
59824
|
+
const containsFencedCode = FENCED_CODE_RE.test(value);
|
|
59825
|
+
return {
|
|
59826
|
+
format_sensitive: containsList || containsTable || containsFencedCode,
|
|
59827
|
+
...containsList ? { contains_markdown_list: true } : {},
|
|
59828
|
+
...containsTable ? { contains_markdown_table: true } : {},
|
|
59829
|
+
...containsFencedCode ? { contains_fenced_code: true } : {}
|
|
59830
|
+
};
|
|
59831
|
+
}
|
|
59832
|
+
function collapsedMarkdownListLikely(input) {
|
|
59833
|
+
const rawListItems = markdownListItemCount(input.raw);
|
|
59834
|
+
if (rawListItems < 2)
|
|
59835
|
+
return false;
|
|
59836
|
+
const contentLineListItems = markdownListItemCount(input.content);
|
|
59837
|
+
if (contentLineListItems >= rawListItems)
|
|
59838
|
+
return false;
|
|
59839
|
+
const compact2 = input.content.replace(/\s+/g, " ").trim();
|
|
59840
|
+
const bulletFragments = compact2.match(/(?:^|\s)(?:[-*+]\s+|\d+[.)]\s+)\S/gu) ?? [];
|
|
59841
|
+
return bulletFragments.length >= 2;
|
|
59842
|
+
}
|
|
59843
|
+
var MARKDOWN_LIST_ITEM_RE, FENCED_CODE_RE, TABLE_SEPARATOR_RE;
|
|
59844
|
+
var init_markdownFormatSignals = __esm(() => {
|
|
59845
|
+
MARKDOWN_LIST_ITEM_RE = /^\s{0,6}(?:[-*+]\s+|\d+[.)]\s+)\S/mgu;
|
|
59846
|
+
FENCED_CODE_RE = /(?:^|\n)\s{0,6}(?:```|~~~)/u;
|
|
59847
|
+
TABLE_SEPARATOR_RE = /^\s*\|?(?:\s*:?-{3,}:?\s*\|)+\s*:?-{3,}:?\s*\|?\s*$/mu;
|
|
59848
|
+
});
|
|
59849
|
+
|
|
59811
59850
|
// src/workflow/compileDraftWarningHints.ts
|
|
59812
59851
|
function pushSummaryWarnings(input) {
|
|
59813
59852
|
const content3 = input.content;
|
|
@@ -59832,6 +59871,19 @@ function pushSummaryWarnings(input) {
|
|
|
59832
59871
|
}
|
|
59833
59872
|
if (summary2 === undefined)
|
|
59834
59873
|
return;
|
|
59874
|
+
if (PLACEHOLDER_SUMMARY_RE.test(summary2.trim())) {
|
|
59875
|
+
input.state.warnings.push({
|
|
59876
|
+
code: "compile-section-summary-placeholder",
|
|
59877
|
+
severity: "warning",
|
|
59878
|
+
message: `${input.label}.summary looks like a generated placeholder, not a reader/query summary.`,
|
|
59879
|
+
next_action: `Replace ${input.label}.summary with a meaningful short summary, or omit summary entirely. Empty summary is better than a template placeholder.`,
|
|
59880
|
+
path: `${input.label}.summary`,
|
|
59881
|
+
diagnostics: {
|
|
59882
|
+
submitted_summary: summary2,
|
|
59883
|
+
summary_policy: "summary is optional reader/query aid; omit it when no meaningful summary is available"
|
|
59884
|
+
}
|
|
59885
|
+
});
|
|
59886
|
+
}
|
|
59835
59887
|
if (/\r|\n/u.test(summary2) || /```|~~~|^#{1,6}\s|^\s*[-*+]\s/mu.test(summary2)) {
|
|
59836
59888
|
input.state.warnings.push({
|
|
59837
59889
|
code: "compile-section-summary-format",
|
|
@@ -59962,18 +60014,56 @@ function collectDraftPlannedSectionWarnings(output, context, state) {
|
|
|
59962
60014
|
});
|
|
59963
60015
|
}
|
|
59964
60016
|
}
|
|
60017
|
+
function pushMarkdownListFormatWarning(input) {
|
|
60018
|
+
if (input.content === undefined || input.sourceRefs.length === 0)
|
|
60019
|
+
return;
|
|
60020
|
+
const requested = new Set(input.sourceRefs);
|
|
60021
|
+
const affected = input.context.raw_snippets.filter((snippet) => typeof snippet.source_ref === "string" && requested.has(snippet.source_ref) && collapsedMarkdownListLikely({ raw: snippet.quote, content: input.content })).map((snippet) => ({
|
|
60022
|
+
source_ref: snippet.source_ref,
|
|
60023
|
+
block_id: snippet.block_id,
|
|
60024
|
+
line_range: snippet.line_range,
|
|
60025
|
+
raw_list_items: markdownListItemCount(snippet.quote)
|
|
60026
|
+
}));
|
|
60027
|
+
if (affected.length === 0)
|
|
60028
|
+
return;
|
|
60029
|
+
input.state.warnings.push({
|
|
60030
|
+
code: "compile-markdown-list-format-collapsed",
|
|
60031
|
+
severity: "warning",
|
|
60032
|
+
message: `${input.label}.content may have collapsed a cited multi-line Markdown list into one line.`,
|
|
60033
|
+
next_action: "If this was not an intentional prose summary, rerun the listed request_full_text command(s) and patch content to preserve the source list line breaks. The CLI will not rewrite content automatically.",
|
|
60034
|
+
path: `${input.label}.content`,
|
|
60035
|
+
diagnostics: {
|
|
60036
|
+
affected_source_refs: affected,
|
|
60037
|
+
request_full_text_commands: affected.map((item) => typeof item.block_id === "string" ? `context compile context ${input.context.node.slug} --request-full-text ${item.block_id} --view text --format json` : undefined).filter((command) => command !== undefined)
|
|
60038
|
+
}
|
|
60039
|
+
});
|
|
60040
|
+
}
|
|
60041
|
+
function collectDraftMarkdownFormatWarnings(output, context, state) {
|
|
60042
|
+
for (const [index2, action] of output.actions.entries()) {
|
|
60043
|
+
if (action.op === "add") {
|
|
60044
|
+
pushMarkdownListFormatWarning({ state, context, content: action.content, sourceRefs: sourceRefsForAction(action), label: `actions[${index2}]` });
|
|
60045
|
+
} else if (action.op === "update") {
|
|
60046
|
+
pushMarkdownListFormatWarning({ state, context, content: action.content, sourceRefs: sourceRefsForAction(action), label: `actions[${index2}]` });
|
|
60047
|
+
} else if (action.op === "supersede") {
|
|
60048
|
+
pushMarkdownListFormatWarning({ state, context, content: action.new.content, sourceRefs: sourceRefsForAction(action), label: `actions[${index2}].new` });
|
|
60049
|
+
}
|
|
60050
|
+
}
|
|
60051
|
+
}
|
|
59965
60052
|
function collectCompileDraftWarnings(output, context) {
|
|
59966
60053
|
const state = { warnings: [] };
|
|
59967
60054
|
collectDraftSummaryWarnings(output, state);
|
|
59968
60055
|
collectDraftLanguageWarnings(output, context, state);
|
|
59969
60056
|
collectDraftPlannedSectionWarnings(output, context, state);
|
|
60057
|
+
collectDraftMarkdownFormatWarnings(output, context, state);
|
|
59970
60058
|
return state.warnings;
|
|
59971
60059
|
}
|
|
59972
|
-
var SUMMARY_RECOMMENDED_CONTENT_CHARS = 500, SUMMARY_MAX_CHARS = 280, SUMMARY_HINT_SEVERITY = "info", CJK_RE3, ENGLISH_WORD_RE;
|
|
60060
|
+
var SUMMARY_RECOMMENDED_CONTENT_CHARS = 500, SUMMARY_MAX_CHARS = 280, SUMMARY_HINT_SEVERITY = "info", CJK_RE3, ENGLISH_WORD_RE, PLACEHOLDER_SUMMARY_RE;
|
|
59973
60061
|
var init_compileDraftWarningHints = __esm(() => {
|
|
59974
60062
|
init_generationPolicy();
|
|
60063
|
+
init_markdownFormatSignals();
|
|
59975
60064
|
CJK_RE3 = /[\u3400-\u9fff]/gu;
|
|
59976
60065
|
ENGLISH_WORD_RE = /\b[A-Za-z][A-Za-z-]{2,}\b/gu;
|
|
60066
|
+
PLACEHOLDER_SUMMARY_RE = /^(?:description|spec|warning|principle|decision|incident|example|changelog|comparison|faq)?\s*section\s+covering\s+\d+\s+evidence\s+blocks?\s*(?:\(s\))?\.?$/iu;
|
|
59977
60067
|
});
|
|
59978
60068
|
|
|
59979
60069
|
// src/workflow/compileDraftValidation.ts
|
|
@@ -60851,12 +60941,12 @@ var init_agentHintRegistry = __esm(() => {
|
|
|
60851
60941
|
"align-candidate-ledger-invalid-op",
|
|
60852
60942
|
"align-candidate-ops-input-invalid",
|
|
60853
60943
|
"align-candidate-ops-segment-mismatch",
|
|
60854
|
-
"align-action-
|
|
60944
|
+
"align-action-gate-invalid",
|
|
60855
60945
|
"align-blocks-read-incomplete",
|
|
60856
60946
|
"align-coarse-read-required",
|
|
60857
60947
|
"align-coarse-read-segment-mismatch",
|
|
60858
60948
|
"align-decision-ledger-invalid",
|
|
60859
|
-
"align-domain-
|
|
60949
|
+
"align-domain-gate-invalid",
|
|
60860
60950
|
"align-entity-tag-term-mixed-with-a-b",
|
|
60861
60951
|
"align-finalize-node-without-citation-evidence",
|
|
60862
60952
|
"align-finalize-unplanned-evidence-blocks",
|
|
@@ -60866,10 +60956,12 @@ var init_agentHintRegistry = __esm(() => {
|
|
|
60866
60956
|
"align-ownership-default-cli-demoted",
|
|
60867
60957
|
"align-pending-relation-refs",
|
|
60868
60958
|
"align-read-plan-ready",
|
|
60959
|
+
"align-section-plan-crosses-headings",
|
|
60869
60960
|
"align-section-plans-auto-split-contiguous-runs",
|
|
60870
60961
|
"align-section-non-citable-blocks-ignored",
|
|
60871
60962
|
"align-source-bundle-budget-fallback",
|
|
60872
60963
|
"align-source-bundle-raw-c4a-sentinel-escaped",
|
|
60964
|
+
"align-source-bundle-use-read-plan",
|
|
60873
60965
|
"align-finalize-patch-invalid",
|
|
60874
60966
|
"align-ownership-patch-base-digest-stale",
|
|
60875
60967
|
"align-ownership-patch-invalid",
|
|
@@ -60923,6 +61015,7 @@ var init_agentHintRegistry = __esm(() => {
|
|
|
60923
61015
|
"compile-cycle-input-required",
|
|
60924
61016
|
"compile-draft-invalid",
|
|
60925
61017
|
"compile-draft-input-required",
|
|
61018
|
+
"compile-draft-patch-cycle-required",
|
|
60926
61019
|
"compile-draft-patch-invalid",
|
|
60927
61020
|
"compile-draft-patch-retired-field",
|
|
60928
61021
|
"compile-draft-patch-ready",
|
|
@@ -60931,9 +61024,11 @@ var init_agentHintRegistry = __esm(() => {
|
|
|
60931
61024
|
"compile-extract-normalized-match",
|
|
60932
61025
|
"compile-lead-in-guidance",
|
|
60933
61026
|
"compile-lead-in-skipped",
|
|
61027
|
+
"compile-markdown-list-format-collapsed",
|
|
60934
61028
|
"compile-missing-refers-to-node",
|
|
60935
61029
|
"compile-mode-required",
|
|
60936
61030
|
"compile-modes-conflict",
|
|
61031
|
+
"compile-planned-section-fragment-review",
|
|
60937
61032
|
"compile-node-type-guidance",
|
|
60938
61033
|
"compile-node-no-citation-evidence",
|
|
60939
61034
|
"compile-node-no-write-placeholder",
|
|
@@ -60950,6 +61045,7 @@ var init_agentHintRegistry = __esm(() => {
|
|
|
60950
61045
|
"compile-section-kind-outside-plan",
|
|
60951
61046
|
"compile-section-summary-format",
|
|
60952
61047
|
"compile-section-summary-language",
|
|
61048
|
+
"compile-section-summary-placeholder",
|
|
60953
61049
|
"compile-section-summary-recommended",
|
|
60954
61050
|
"compile-section-summary-too-long",
|
|
60955
61051
|
"compile-source-refs-draft-scaffold-available",
|
|
@@ -61007,6 +61103,8 @@ var init_agentHintRegistry = __esm(() => {
|
|
|
61007
61103
|
"raw-snapshot-pending-compile",
|
|
61008
61104
|
"ready-no-op-review",
|
|
61009
61105
|
"ready-review-output",
|
|
61106
|
+
"prepare-candidates-index",
|
|
61107
|
+
"reconcile-apply-consumes-ready-review",
|
|
61010
61108
|
"reconcile-prepare-draft-mode-invalid",
|
|
61011
61109
|
"reconcile-validate-compile-mode-required",
|
|
61012
61110
|
"reconcile-validate-decisions-required",
|
|
@@ -61115,17 +61213,17 @@ var init_agentHintRegistry = __esm(() => {
|
|
|
61115
61213
|
command: "context schema align-structure-intent --view minimal --format json"
|
|
61116
61214
|
},
|
|
61117
61215
|
{
|
|
61118
|
-
code: "align-domain-
|
|
61119
|
-
severity: "
|
|
61120
|
-
description: "A submitted Domain node
|
|
61121
|
-
trigger: "Align validation/finalize
|
|
61216
|
+
code: "align-domain-gate-invalid",
|
|
61217
|
+
severity: "error",
|
|
61218
|
+
description: "A submitted Domain node is missing a valid domain_gate with resolvable child refs.",
|
|
61219
|
+
trigger: "Align validation/finalize rejects node_type=domain when domain_gate.scope_blocks, child_refs, grouping_reason, or resolvable children are missing.",
|
|
61122
61220
|
command: "context schema align-structure-intent --view minimal --format json"
|
|
61123
61221
|
},
|
|
61124
61222
|
{
|
|
61125
|
-
code: "align-action-
|
|
61126
|
-
severity: "
|
|
61127
|
-
description: "A submitted Action node
|
|
61128
|
-
trigger: "Align validation/finalize
|
|
61223
|
+
code: "align-action-gate-invalid",
|
|
61224
|
+
severity: "error",
|
|
61225
|
+
description: "A submitted Action node is missing action_probe or structured action_gate evidence.",
|
|
61226
|
+
trigger: "Align validation/finalize rejects node_type=action when action_probe.has_steps_or_phases or action_gate.inference_sources is missing.",
|
|
61129
61227
|
command: "context schema align-structure-intent --view minimal --format json"
|
|
61130
61228
|
},
|
|
61131
61229
|
{
|
|
@@ -61135,6 +61233,13 @@ var init_agentHintRegistry = __esm(() => {
|
|
|
61135
61233
|
trigger: "Agent submits canonical align-structure-decision to validate/finalize instead of align-structure-intent.",
|
|
61136
61234
|
command: "context schema align-structure-intent --view minimal --format json"
|
|
61137
61235
|
},
|
|
61236
|
+
{
|
|
61237
|
+
code: "align-section-plan-crosses-headings",
|
|
61238
|
+
severity: "warning",
|
|
61239
|
+
description: "A planned Section spans multiple source heading paths; the CLI reports the risky shape without rewriting the agent's grouping.",
|
|
61240
|
+
trigger: "Align validate/finalize sees one section plan whose block_ids cross source heading boundaries.",
|
|
61241
|
+
command: "context schema align-structure-intent --view minimal --format json"
|
|
61242
|
+
},
|
|
61138
61243
|
{
|
|
61139
61244
|
code: "section-plan-non-contiguous",
|
|
61140
61245
|
severity: "error",
|
|
@@ -61156,6 +61261,13 @@ var init_agentHintRegistry = __esm(() => {
|
|
|
61156
61261
|
trigger: "The legacy flag form selected multiple compile modes together.",
|
|
61157
61262
|
command: "context compile scan --format json"
|
|
61158
61263
|
},
|
|
61264
|
+
{
|
|
61265
|
+
code: "compile-planned-section-fragment-review",
|
|
61266
|
+
severity: "info",
|
|
61267
|
+
description: "Adjacent planned Sections under the same source heading may be over-fragmented.",
|
|
61268
|
+
trigger: "The source-refs view sees a single-block planned group next to a larger or list-like planned group with the same owner, source, and heading path.",
|
|
61269
|
+
command: "context compile context <slug> --view source-refs --format json"
|
|
61270
|
+
},
|
|
61159
61271
|
{
|
|
61160
61272
|
code: "compile-section-kind-outside-plan",
|
|
61161
61273
|
severity: "warning",
|
|
@@ -61282,6 +61394,20 @@ var init_agentHintRegistry = __esm(() => {
|
|
|
61282
61394
|
trigger: "accept-safe-defaults sees items with duplicate, supersede, conflict, unknown-input, or confirmation blockers.",
|
|
61283
61395
|
command: "context reconcile review"
|
|
61284
61396
|
},
|
|
61397
|
+
{
|
|
61398
|
+
code: "prepare-candidates-index",
|
|
61399
|
+
severity: "info",
|
|
61400
|
+
description: "The default prepare candidates view is an index and requires item-level drilldown before judging relation.",
|
|
61401
|
+
trigger: "context workflow show --payload prepare --view candidates is called without --item-id or --candidate-id.",
|
|
61402
|
+
command: "context workflow show --payload prepare --view candidates --item-id <item-id> --unwrap --format json"
|
|
61403
|
+
},
|
|
61404
|
+
{
|
|
61405
|
+
code: "reconcile-apply-consumes-ready-review",
|
|
61406
|
+
severity: "error",
|
|
61407
|
+
description: "reconcile apply was called with decisions input even though apply consumes the current ready review artifact.",
|
|
61408
|
+
trigger: "context reconcile apply receives --decisions.",
|
|
61409
|
+
command: "context reconcile apply --format json"
|
|
61410
|
+
},
|
|
61285
61411
|
{
|
|
61286
61412
|
code: "example-code-prose-summary",
|
|
61287
61413
|
severity: "warning",
|
|
@@ -61308,7 +61434,7 @@ var init_agentHintRegistry = __esm(() => {
|
|
|
61308
61434
|
severity: "error",
|
|
61309
61435
|
description: "A proposed write combines facts that should be split across separate evidence blocks.",
|
|
61310
61436
|
trigger: "source_support candidates indicate multiple evidence blocks are needed for independently supported claims.",
|
|
61311
|
-
command: "context compile
|
|
61437
|
+
command: "context compile cycle <slug> --input - --format json"
|
|
61312
61438
|
}
|
|
61313
61439
|
];
|
|
61314
61440
|
DETAILED_AGENT_HINT_BY_CODE = new Map(DETAILED_AGENT_HINTS.map((entry) => [entry.code, entry]));
|
|
@@ -62415,6 +62541,9 @@ function draftSessionError(message, hint = {}) {
|
|
|
62415
62541
|
}]
|
|
62416
62542
|
});
|
|
62417
62543
|
}
|
|
62544
|
+
function compileDraftPatchSubmitCommand(options = {}) {
|
|
62545
|
+
return options.submitCommand ?? "context compile cycle <slug> --input - --format json";
|
|
62546
|
+
}
|
|
62418
62547
|
function cloneAction(action) {
|
|
62419
62548
|
if (action.op === "supersede")
|
|
62420
62549
|
return { ...action, new: { ...action.new } };
|
|
@@ -62502,9 +62631,79 @@ function compileDraftPatchCorrectShape() {
|
|
|
62502
62631
|
}]
|
|
62503
62632
|
}, null, 2);
|
|
62504
62633
|
}
|
|
62634
|
+
function isCompileDraftPatchLikeInput(value) {
|
|
62635
|
+
if (!isRecord29(value))
|
|
62636
|
+
return false;
|
|
62637
|
+
if (Array.isArray(value.operations))
|
|
62638
|
+
return true;
|
|
62639
|
+
if (typeof value.schema_version === "string" && value.schema_version.startsWith("compile.draft-patch."))
|
|
62640
|
+
return true;
|
|
62641
|
+
if (Array.isArray(value.patches))
|
|
62642
|
+
return true;
|
|
62643
|
+
return false;
|
|
62644
|
+
}
|
|
62645
|
+
function compileDraftPatchShapeIssues(value) {
|
|
62646
|
+
const issues = [];
|
|
62647
|
+
if (!isRecord29(value)) {
|
|
62648
|
+
return [{
|
|
62649
|
+
path: "$",
|
|
62650
|
+
message: "compile draft patch payload must be an object",
|
|
62651
|
+
expected: { operations: "non-empty array" },
|
|
62652
|
+
current_value: value
|
|
62653
|
+
}];
|
|
62654
|
+
}
|
|
62655
|
+
if (value.schema_version !== undefined && value.schema_version !== COMPILE_DRAFT_PATCH_SCHEMA_VERSION) {
|
|
62656
|
+
issues.push({
|
|
62657
|
+
path: "schema_version",
|
|
62658
|
+
message: `schema_version may be omitted; when present it must be ${COMPILE_DRAFT_PATCH_SCHEMA_VERSION}`,
|
|
62659
|
+
expected: COMPILE_DRAFT_PATCH_SCHEMA_VERSION,
|
|
62660
|
+
current_value: value.schema_version
|
|
62661
|
+
});
|
|
62662
|
+
}
|
|
62663
|
+
if (value.actions !== undefined) {
|
|
62664
|
+
issues.push({
|
|
62665
|
+
path: "actions",
|
|
62666
|
+
message: "compile draft patch payload uses operations[]",
|
|
62667
|
+
expected: "operations[]",
|
|
62668
|
+
current_value: value.actions
|
|
62669
|
+
});
|
|
62670
|
+
}
|
|
62671
|
+
if (value.patches !== undefined) {
|
|
62672
|
+
issues.push({
|
|
62673
|
+
path: "patches",
|
|
62674
|
+
message: "compile draft patch payload uses operations[]",
|
|
62675
|
+
expected: "operations[]",
|
|
62676
|
+
current_value: value.patches
|
|
62677
|
+
});
|
|
62678
|
+
}
|
|
62679
|
+
if (!Array.isArray(value.operations) || value.operations.length === 0) {
|
|
62680
|
+
issues.push({
|
|
62681
|
+
path: "operations",
|
|
62682
|
+
message: "operations[] is required and must contain at least one patch operation",
|
|
62683
|
+
expected: [{ op: "replace_action", action_id: "act_001", action: {} }],
|
|
62684
|
+
current_value: value.operations
|
|
62685
|
+
});
|
|
62686
|
+
}
|
|
62687
|
+
return issues;
|
|
62688
|
+
}
|
|
62689
|
+
function throwCompileDraftPatchShapeError(issues, options = {}) {
|
|
62690
|
+
const first = issues[0];
|
|
62691
|
+
const message = first?.message ?? "compile draft patch payload must use operations[]";
|
|
62692
|
+
const command = compileDraftPatchSubmitCommand(options);
|
|
62693
|
+
throw draftSessionError(message, {
|
|
62694
|
+
command,
|
|
62695
|
+
next_action: "Submit a compile-draft-patch payload with operations[] to the compile cycle command.",
|
|
62696
|
+
correct_shape: compileDraftPatchCorrectShape(),
|
|
62697
|
+
diagnostics: {
|
|
62698
|
+
current_schema_version: COMPILE_DRAFT_PATCH_SCHEMA_VERSION,
|
|
62699
|
+
command,
|
|
62700
|
+
issues
|
|
62701
|
+
}
|
|
62702
|
+
});
|
|
62703
|
+
}
|
|
62505
62704
|
function parsePatchOp(operation, path13) {
|
|
62506
62705
|
if (operation.op === "replace") {
|
|
62507
|
-
throw draftSessionError(`${path13}.op
|
|
62706
|
+
throw draftSessionError(`${path13}.op must be replace_action|remove_action|add_action`, {
|
|
62508
62707
|
next_action: "Run context compile draft-status <slug> --format json, copy the action_id for the action to revise, then submit replace_action with action.",
|
|
62509
62708
|
command: "context schema compile-draft-patch",
|
|
62510
62709
|
path: `${path13}.op`,
|
|
@@ -62542,19 +62741,16 @@ function assertPatchActionId(value, path13) {
|
|
|
62542
62741
|
}
|
|
62543
62742
|
});
|
|
62544
62743
|
}
|
|
62545
|
-
function parseCompileDraftPatch(value) {
|
|
62744
|
+
function parseCompileDraftPatch(value, options = {}) {
|
|
62745
|
+
const shapeIssues = compileDraftPatchShapeIssues(value);
|
|
62746
|
+
if (shapeIssues.length > 0)
|
|
62747
|
+
throwCompileDraftPatchShapeError(shapeIssues, options);
|
|
62546
62748
|
if (!isRecord29(value))
|
|
62547
62749
|
throw draftSessionError("compile draft patch must be an object");
|
|
62548
|
-
|
|
62549
|
-
|
|
62550
|
-
|
|
62551
|
-
|
|
62552
|
-
throw draftSessionError(`schema_version must be ${COMPILE_DRAFT_PATCH_SCHEMA_VERSION}`);
|
|
62553
|
-
}
|
|
62554
|
-
if (!Array.isArray(value.operations) || value.operations.length === 0) {
|
|
62555
|
-
throw draftSessionError("compile draft patch must contain non-empty operations[]");
|
|
62556
|
-
}
|
|
62557
|
-
const operations = value.operations.map((operation, index2) => {
|
|
62750
|
+
const operationsInput = value.operations;
|
|
62751
|
+
if (!Array.isArray(operationsInput))
|
|
62752
|
+
throwCompileDraftPatchShapeError(compileDraftPatchShapeIssues(value), options);
|
|
62753
|
+
const operations = operationsInput.map((operation, index2) => {
|
|
62558
62754
|
const path13 = `operations[${index2}]`;
|
|
62559
62755
|
if (!isRecord29(operation))
|
|
62560
62756
|
throw draftSessionError(`${path13} must be an object`);
|
|
@@ -63734,6 +63930,24 @@ function filterCurrentDraftCandidates(input) {
|
|
|
63734
63930
|
}));
|
|
63735
63931
|
return { candidates, filtered: input.candidates.length - candidates.length };
|
|
63736
63932
|
}
|
|
63933
|
+
function sameCycleAppliedSectionIds(input) {
|
|
63934
|
+
if (input.since === undefined)
|
|
63935
|
+
return new Set;
|
|
63936
|
+
return new Set(input.records.flatMap((record) => {
|
|
63937
|
+
const node3 = record.node ?? record.target?.node;
|
|
63938
|
+
const sectionId = record.target?.section_id;
|
|
63939
|
+
if (record.mode !== "compile" || node3 !== input.node || typeof sectionId !== "string" || compareTemporal(record.applied_at, input.since) !== 1) {
|
|
63940
|
+
return [];
|
|
63941
|
+
}
|
|
63942
|
+
return [sectionId];
|
|
63943
|
+
}));
|
|
63944
|
+
}
|
|
63945
|
+
function filterSameCycleAppliedCandidates(input) {
|
|
63946
|
+
if (input.sectionIds.size === 0)
|
|
63947
|
+
return { candidates: [...input.candidates], filtered: 0 };
|
|
63948
|
+
const candidates = input.candidates.filter((candidate) => !input.sectionIds.has(candidate.section_id));
|
|
63949
|
+
return { candidates, filtered: input.candidates.length - candidates.length };
|
|
63950
|
+
}
|
|
63737
63951
|
function sectionOutputSnapshot(nodeSlug, section) {
|
|
63738
63952
|
return {
|
|
63739
63953
|
node: nodeSlug,
|
|
@@ -63963,6 +64177,11 @@ async function prepareCompileReconcileContext(input) {
|
|
|
63963
64177
|
const challengeReceipt = recordedChallenges(challengePayloads);
|
|
63964
64178
|
const { index: index2 } = await prepareRetrieval(input);
|
|
63965
64179
|
const ledger = await readSemanticLedger(input.ctxDir);
|
|
64180
|
+
const sameCycleAppliedSections = sameCycleAppliedSectionIds({
|
|
64181
|
+
records: ledger.document.decisions,
|
|
64182
|
+
node: node3,
|
|
64183
|
+
...input.workflowStartedAt !== undefined ? { since: input.workflowStartedAt } : {}
|
|
64184
|
+
});
|
|
63966
64185
|
const restoredArchiveCandidates = await restoredArchiveCandidatesForNode(input.ctxDir, node3);
|
|
63967
64186
|
const sources = await loadSources(input.ctxDir);
|
|
63968
64187
|
const sourceById = new Map(sources.sources.map((source2) => [source2.id, source2]));
|
|
@@ -64031,6 +64250,10 @@ async function prepareCompileReconcileContext(input) {
|
|
|
64031
64250
|
activeSectionIds,
|
|
64032
64251
|
proposed: temporal.proposed
|
|
64033
64252
|
});
|
|
64253
|
+
const sameCycleFiltered = filterSameCycleAppliedCandidates({
|
|
64254
|
+
candidates: draftFiltered.candidates,
|
|
64255
|
+
sectionIds: sameCycleAppliedSections
|
|
64256
|
+
});
|
|
64034
64257
|
resolvedItems.push({
|
|
64035
64258
|
item_id: itemId,
|
|
64036
64259
|
...typeof action.action_id === "string" ? { action_id: action.action_id, draft_action_id: action.action_id } : {},
|
|
@@ -64040,11 +64263,16 @@ async function prepareCompileReconcileContext(input) {
|
|
|
64040
64263
|
proposed: temporal.proposed,
|
|
64041
64264
|
...defaultDecision !== undefined ? { default_decision: defaultDecision } : {},
|
|
64042
64265
|
...target !== undefined ? { target } : {},
|
|
64043
|
-
candidates: stripCompileRelationHints(
|
|
64266
|
+
candidates: stripCompileRelationHints(sameCycleFiltered.candidates),
|
|
64044
64267
|
retrieval: draftFiltered.filtered > 0 ? {
|
|
64045
64268
|
...recalled.retrieval,
|
|
64046
|
-
returned_candidates: Math.max(0, recalled.retrieval.returned_candidates - draftFiltered.filtered),
|
|
64047
|
-
self_draft_candidates_filtered: draftFiltered.filtered
|
|
64269
|
+
returned_candidates: Math.max(0, recalled.retrieval.returned_candidates - draftFiltered.filtered - sameCycleFiltered.filtered),
|
|
64270
|
+
self_draft_candidates_filtered: draftFiltered.filtered,
|
|
64271
|
+
...sameCycleFiltered.filtered > 0 ? { same_cycle_candidates_filtered: sameCycleFiltered.filtered } : {}
|
|
64272
|
+
} : sameCycleFiltered.filtered > 0 ? {
|
|
64273
|
+
...recalled.retrieval,
|
|
64274
|
+
returned_candidates: Math.max(0, recalled.retrieval.returned_candidates - sameCycleFiltered.filtered),
|
|
64275
|
+
same_cycle_candidates_filtered: sameCycleFiltered.filtered
|
|
64048
64276
|
} : recalled.retrieval,
|
|
64049
64277
|
previous_decisions: recentSemanticLedgerRecords(ledger.document.decisions, (record) => record.mode === "compile" && (record.node === node3 || record.target?.node === node3)),
|
|
64050
64278
|
...evidence !== undefined ? { evidence } : {},
|
|
@@ -64108,6 +64336,7 @@ var init_prepareCompile = __esm(() => {
|
|
|
64108
64336
|
init_compileDraftReferenceHints();
|
|
64109
64337
|
init_compileNode();
|
|
64110
64338
|
init_sectionFingerprints();
|
|
64339
|
+
init_temporal();
|
|
64111
64340
|
init_sources();
|
|
64112
64341
|
init_shared();
|
|
64113
64342
|
init_evidence();
|
|
@@ -64512,7 +64741,8 @@ async function prepareReconcileContext(input) {
|
|
|
64512
64741
|
...input.node !== undefined ? { node: input.node } : {},
|
|
64513
64742
|
...input.draftPath !== undefined ? { draftPath: input.draftPath } : {},
|
|
64514
64743
|
...input.draft !== undefined ? { draft: input.draft } : {},
|
|
64515
|
-
...input.draftDigest !== undefined ? { draftDigest: input.draftDigest } : {}
|
|
64744
|
+
...input.draftDigest !== undefined ? { draftDigest: input.draftDigest } : {},
|
|
64745
|
+
...input.workflowStartedAt !== undefined ? { workflowStartedAt: input.workflowStartedAt } : {}
|
|
64516
64746
|
});
|
|
64517
64747
|
}
|
|
64518
64748
|
case "drop": {
|
|
@@ -66193,6 +66423,44 @@ var defaultRunner = (args2) => new Promise((resolve6, reject) => {
|
|
|
66193
66423
|
resolve6({ stdout, stderr, exitCode: code3 });
|
|
66194
66424
|
});
|
|
66195
66425
|
});
|
|
66426
|
+
var docsFetchCapabilitiesCache = new WeakMap;
|
|
66427
|
+
async function detectDocsFetchCapabilities(runner) {
|
|
66428
|
+
const result = await runner(["docs", "+fetch", "--help"]).catch(() => ({
|
|
66429
|
+
stdout: "",
|
|
66430
|
+
stderr: "",
|
|
66431
|
+
exitCode: 1
|
|
66432
|
+
}));
|
|
66433
|
+
const help = `${result.stdout}
|
|
66434
|
+
${result.stderr}`;
|
|
66435
|
+
const supportsApiVersion = result.exitCode === 0 && /\s--api-version\b/u.test(help);
|
|
66436
|
+
return {
|
|
66437
|
+
apiVersion: supportsApiVersion ? "v2" : "v1",
|
|
66438
|
+
supportsDocFormatMarkdown: result.exitCode === 0 && /\s--doc-format\b/u.test(help)
|
|
66439
|
+
};
|
|
66440
|
+
}
|
|
66441
|
+
function resolveDocsFetchPlan(requested, runner) {
|
|
66442
|
+
if (requested === "v1" || requested === "v2")
|
|
66443
|
+
return Promise.resolve({ apiVersion: requested });
|
|
66444
|
+
let capabilitiesPromise = docsFetchCapabilitiesCache.get(runner);
|
|
66445
|
+
if (capabilitiesPromise === undefined) {
|
|
66446
|
+
capabilitiesPromise = detectDocsFetchCapabilities(runner);
|
|
66447
|
+
docsFetchCapabilitiesCache.set(runner, capabilitiesPromise);
|
|
66448
|
+
}
|
|
66449
|
+
return capabilitiesPromise.then((capabilities) => ({
|
|
66450
|
+
apiVersion: capabilities.apiVersion,
|
|
66451
|
+
...capabilities.apiVersion === "v2" && capabilities.supportsDocFormatMarkdown ? { docFormat: "markdown" } : {}
|
|
66452
|
+
}));
|
|
66453
|
+
}
|
|
66454
|
+
function docsFetchFailureMessage(stderr, apiVersion) {
|
|
66455
|
+
const trimmed = stderr.trim();
|
|
66456
|
+
const base = `${LARK_BIN} docs +fetch failed (auth / permission / unsupported doc type): ${trimmed}`;
|
|
66457
|
+
const mentionsV2 = /api-version|--api-version|v2|deprecated|lark-cli update/iu.test(stderr);
|
|
66458
|
+
if (apiVersion === "v1" && mentionsV2) {
|
|
66459
|
+
return `${base}
|
|
66460
|
+
Detected docs API v2 guidance from lark-cli. Upgrade @larksuite/cli and run \`lark-cli update\`; newer docs +fetch supports \`--api-version v2\`.`;
|
|
66461
|
+
}
|
|
66462
|
+
return base;
|
|
66463
|
+
}
|
|
66196
66464
|
function parseDocsFetchPayload(stdout) {
|
|
66197
66465
|
const trimmed = stdout.trim();
|
|
66198
66466
|
if (trimmed.length === 0) {
|
|
@@ -66213,25 +66481,144 @@ function parseDocsFetchPayload(stdout) {
|
|
|
66213
66481
|
}
|
|
66214
66482
|
return envelope;
|
|
66215
66483
|
}
|
|
66484
|
+
function stringValue(value) {
|
|
66485
|
+
return typeof value === "string" && value.length > 0 ? value : undefined;
|
|
66486
|
+
}
|
|
66487
|
+
function decodeXmlEntities(value) {
|
|
66488
|
+
return value.replace(/</gu, "<").replace(/>/gu, ">").replace(/"/gu, '"').replace(/'/gu, "'").replace(/'/gu, "'").replace(/&/gu, "&");
|
|
66489
|
+
}
|
|
66490
|
+
function xmlInlineText(xml) {
|
|
66491
|
+
const withLinks = xml.replace(/<a\b[^>]*\bhref=(["'])(.*?)\1[^>]*>([\s\S]*?)<\/a>/giu, (_match, _quote, href, label) => {
|
|
66492
|
+
const text5 = xmlInlineText(label);
|
|
66493
|
+
return text5.length > 0 ? `[${text5}](${decodeXmlEntities(href)})` : decodeXmlEntities(href);
|
|
66494
|
+
});
|
|
66495
|
+
return decodeXmlEntities(withLinks.replace(/<!\[CDATA\[([\s\S]*?)\]\]>/gu, "$1").replace(/<br\s*\/?>/giu, `
|
|
66496
|
+
`).replace(/<[^>]+>/gu, "").replace(/[ \t\r\n]+/gu, " ").trim());
|
|
66497
|
+
}
|
|
66498
|
+
function renderXmlTable(tableXml) {
|
|
66499
|
+
const rows = [...tableXml.matchAll(/<(?:tr|table_row|table-row)\b[^>]*>([\s\S]*?)<\/(?:tr|table_row|table-row)>/giu)].map((row) => {
|
|
66500
|
+
const rowXml = row[1] ?? "";
|
|
66501
|
+
return [...rowXml.matchAll(/<(?:th|td|table_cell|table-cell)\b[^>]*>([\s\S]*?)<\/(?:th|td|table_cell|table-cell)>/giu)].map((cell) => xmlInlineText(cell[1] ?? "").replace(/\|/gu, "\\|"));
|
|
66502
|
+
}).filter((cells) => cells.length > 0);
|
|
66503
|
+
if (rows.length === 0)
|
|
66504
|
+
return xmlInlineText(tableXml);
|
|
66505
|
+
const width = Math.max(...rows.map((row) => row.length));
|
|
66506
|
+
const normalized = rows.map((row) => [...row, ...Array.from({ length: width - row.length }, () => "")]);
|
|
66507
|
+
const header = normalized[0] ?? [];
|
|
66508
|
+
const separator = header.map(() => "---");
|
|
66509
|
+
const bodyRows = normalized.slice(1);
|
|
66510
|
+
return [header, separator, ...bodyRows].map((row) => `| ${row.join(" | ")} |`).join(`
|
|
66511
|
+
`);
|
|
66512
|
+
}
|
|
66513
|
+
function renderDocxXmlToMarkdown(xml) {
|
|
66514
|
+
const tableBlocks = [];
|
|
66515
|
+
const withoutTables = xml.replace(/<table\b[^>]*>[\s\S]*?<\/table>/giu, (tableXml) => {
|
|
66516
|
+
const marker = `
|
|
66517
|
+
|
|
66518
|
+
@@C4A_DOCX_TABLE_${tableBlocks.length}@@
|
|
66519
|
+
|
|
66520
|
+
`;
|
|
66521
|
+
tableBlocks.push(renderXmlTable(tableXml));
|
|
66522
|
+
return marker;
|
|
66523
|
+
});
|
|
66524
|
+
const titleMatch = /<title\b[^>]*>([\s\S]*?)<\/title>/iu.exec(withoutTables);
|
|
66525
|
+
const title = titleMatch ? xmlInlineText(titleMatch[1] ?? "") : undefined;
|
|
66526
|
+
let body2 = withoutTables.replace(/<\?xml[\s\S]*?\?>/giu, "").replace(/<title\b[^>]*>[\s\S]*?<\/title>/giu, "").replace(/<h([1-6])\b[^>]*>([\s\S]*?)<\/h\1>/giu, (_match, level, content3) => {
|
|
66527
|
+
const text5 = xmlInlineText(content3);
|
|
66528
|
+
return text5.length > 0 ? `
|
|
66529
|
+
|
|
66530
|
+
${"#".repeat(Number(level))} ${text5}
|
|
66531
|
+
|
|
66532
|
+
` : `
|
|
66533
|
+
|
|
66534
|
+
`;
|
|
66535
|
+
}).replace(/<heading\b[^>]*\blevel=(["'])([1-6])\1[^>]*>([\s\S]*?)<\/heading>/giu, (_match, _quote, level, content3) => {
|
|
66536
|
+
const text5 = xmlInlineText(content3);
|
|
66537
|
+
return text5.length > 0 ? `
|
|
66538
|
+
|
|
66539
|
+
${"#".repeat(Number(level))} ${text5}
|
|
66540
|
+
|
|
66541
|
+
` : `
|
|
66542
|
+
|
|
66543
|
+
`;
|
|
66544
|
+
}).replace(/<(?:p|paragraph|div|section)\b[^>]*>/giu, `
|
|
66545
|
+
|
|
66546
|
+
`).replace(/<\/(?:p|paragraph|div|section)>/giu, `
|
|
66547
|
+
|
|
66548
|
+
`).replace(/<li\b[^>]*>/giu, `
|
|
66549
|
+
- `).replace(/<\/li>/giu, `
|
|
66550
|
+
`).replace(/<br\s*\/?>/giu, `
|
|
66551
|
+
`).replace(/<a\b[^>]*\bhref=(["'])(.*?)\1[^>]*>([\s\S]*?)<\/a>/giu, (_match, _quote, href, label) => {
|
|
66552
|
+
const text5 = xmlInlineText(label);
|
|
66553
|
+
return text5.length > 0 ? `[${text5}](${decodeXmlEntities(href)})` : decodeXmlEntities(href);
|
|
66554
|
+
}).replace(/<[^>]+>/gu, "").replace(/@@C4A_DOCX_TABLE_(\d+)@@/gu, (_match, index2) => `
|
|
66555
|
+
|
|
66556
|
+
${tableBlocks[Number(index2)] ?? ""}
|
|
66557
|
+
|
|
66558
|
+
`);
|
|
66559
|
+
body2 = decodeXmlEntities(body2).split(/\n/gu).map((line) => line.trimEnd()).join(`
|
|
66560
|
+
`).replace(/\n{3,}/gu, `
|
|
66561
|
+
|
|
66562
|
+
`).trim();
|
|
66563
|
+
return [title !== undefined && title.length > 0 ? `# ${title}` : "", body2].filter((part) => part.length > 0).join(`
|
|
66564
|
+
|
|
66565
|
+
`);
|
|
66566
|
+
}
|
|
66567
|
+
function payloadShapeSummary(payload) {
|
|
66568
|
+
const keys = Object.keys(payload).sort().join(", ") || "(none)";
|
|
66569
|
+
const document4 = payload.document;
|
|
66570
|
+
if (document4 && typeof document4 === "object") {
|
|
66571
|
+
const documentKeys = Object.keys(document4).sort().join(", ") || "(none)";
|
|
66572
|
+
return `top-level keys: ${keys}; document keys: ${documentKeys}`;
|
|
66573
|
+
}
|
|
66574
|
+
return `top-level keys: ${keys}`;
|
|
66575
|
+
}
|
|
66576
|
+
function extractDocsFetchContent(payload) {
|
|
66577
|
+
const document4 = payload.document && typeof payload.document === "object" ? payload.document : undefined;
|
|
66578
|
+
const title = stringValue(payload.title) ?? stringValue(document4?.title);
|
|
66579
|
+
const markdown = stringValue(payload.markdown) ?? stringValue(document4?.markdown);
|
|
66580
|
+
const withTitle = (result) => title === undefined ? result : { ...result, title };
|
|
66581
|
+
if (markdown !== undefined)
|
|
66582
|
+
return withTitle({ body: markdown, recognizedShape: true });
|
|
66583
|
+
const documentContent = stringValue(document4?.content);
|
|
66584
|
+
if (documentContent !== undefined) {
|
|
66585
|
+
const body2 = /^\s*</u.test(documentContent) ? renderDocxXmlToMarkdown(documentContent) : documentContent;
|
|
66586
|
+
return withTitle({ body: body2, recognizedShape: true });
|
|
66587
|
+
}
|
|
66588
|
+
return withTitle({
|
|
66589
|
+
recognizedShape: payload.title !== undefined || payload.markdown !== undefined || document4?.title !== undefined || document4?.markdown !== undefined || document4?.content !== undefined
|
|
66590
|
+
});
|
|
66591
|
+
}
|
|
66216
66592
|
async function fetchFeishuDoc(input, runner = defaultRunner) {
|
|
66217
66593
|
const chunks = [];
|
|
66218
66594
|
let title;
|
|
66595
|
+
let unsupportedShape;
|
|
66596
|
+
const docsFetchPlan = await resolveDocsFetchPlan(input.docsApiVersion ?? "auto", runner);
|
|
66219
66597
|
let nextOffset;
|
|
66220
66598
|
for (let page = 0;page < MAX_FETCH_PAGES; page++) {
|
|
66221
66599
|
const args2 = ["docs", "+fetch", "--doc", input.url, "--format", "json"];
|
|
66600
|
+
if (docsFetchPlan.apiVersion === "v2") {
|
|
66601
|
+
args2.push("--api-version", "v2");
|
|
66602
|
+
}
|
|
66603
|
+
if (docsFetchPlan.docFormat === "markdown") {
|
|
66604
|
+
args2.push("--doc-format", "markdown");
|
|
66605
|
+
}
|
|
66222
66606
|
if (nextOffset !== undefined) {
|
|
66223
66607
|
args2.push("--offset", String(nextOffset));
|
|
66224
66608
|
}
|
|
66225
66609
|
const result = await runner(args2);
|
|
66226
66610
|
if (result.exitCode !== 0) {
|
|
66227
|
-
throw new LarkCliError(
|
|
66611
|
+
throw new LarkCliError(docsFetchFailureMessage(result.stderr, docsFetchPlan.apiVersion), result.exitCode, result.stderr);
|
|
66228
66612
|
}
|
|
66229
66613
|
const payload = parseDocsFetchPayload(result.stdout);
|
|
66230
|
-
|
|
66231
|
-
|
|
66614
|
+
const extracted = extractDocsFetchContent(payload);
|
|
66615
|
+
if (page === 0 && extracted.title !== undefined) {
|
|
66616
|
+
title = extracted.title;
|
|
66232
66617
|
}
|
|
66233
|
-
if (
|
|
66234
|
-
chunks.push(
|
|
66618
|
+
if (extracted.body !== undefined && extracted.body.length > 0) {
|
|
66619
|
+
chunks.push(extracted.body);
|
|
66620
|
+
} else if (!extracted.recognizedShape && unsupportedShape === undefined) {
|
|
66621
|
+
unsupportedShape = payloadShapeSummary(payload);
|
|
66235
66622
|
}
|
|
66236
66623
|
if (payload.has_more !== true)
|
|
66237
66624
|
break;
|
|
@@ -66247,6 +66634,9 @@ async function fetchFeishuDoc(input, runner = defaultRunner) {
|
|
|
66247
66634
|
|
|
66248
66635
|
`);
|
|
66249
66636
|
if (body2.trim().length === 0 && (title === undefined || title.length === 0)) {
|
|
66637
|
+
if (unsupportedShape !== undefined) {
|
|
66638
|
+
throw new LarkCliError(`${LARK_BIN} docs +fetch returned an unsupported payload shape (${unsupportedShape}). Expected data.markdown or data.document.content; this is a format adapter issue, not a permission error.`, 0, "");
|
|
66639
|
+
}
|
|
66250
66640
|
throw new LarkCliError("document is empty — it may not exist or you lack permission", 0, "");
|
|
66251
66641
|
}
|
|
66252
66642
|
if (title !== undefined && title.length > 0 && !/^#\s/.test(body2)) {
|
|
@@ -80347,8 +80737,8 @@ function reviewAgentHints(input) {
|
|
|
80347
80737
|
code: "split-by-evidence-blocks",
|
|
80348
80738
|
severity: "error",
|
|
80349
80739
|
message: `${splitByEvidenceBlockCount} unsupported decision(s) appear to combine facts from multiple evidence blocks.`,
|
|
80350
|
-
next_action: "Split the proposed content into one draft action per source_support.evidence_block_candidates[] entry, then rerun prepare/review. If the draft session is available,
|
|
80351
|
-
command: "context compile
|
|
80740
|
+
next_action: "Split the proposed content into one draft action per source_support.evidence_block_candidates[] entry, then rerun prepare/review. If the draft session is available, submit a compile-draft-patch payload through context compile cycle <slug> --input - --format json.",
|
|
80741
|
+
command: "context compile cycle <slug> --input - --format json"
|
|
80352
80742
|
});
|
|
80353
80743
|
}
|
|
80354
80744
|
const contentShapeIssueCount = input.issues.filter((issue2) => issue2.severity === "error" && issue2.path.includes(".proposed") && issue2.path.endsWith(".content") && issue2.message.startsWith("content must")).length;
|
|
@@ -80842,7 +81232,7 @@ function assertDelegatedDecisionsAllowed(input) {
|
|
|
80842
81232
|
|
|
80843
81233
|
// src/reconcile/reviewSourceSupport.ts
|
|
80844
81234
|
init_sourceSupport();
|
|
80845
|
-
var
|
|
81235
|
+
var FENCED_CODE_RE2 = /(^|\n)\s*(```|~~~)/u;
|
|
80846
81236
|
function preparedSupportContentMatches(input) {
|
|
80847
81237
|
return typeof input.item?.proposed?.content === "string" && input.item.proposed.content === input.content || typeof input.item?.default_decision?.proposed?.content === "string" && input.item.default_decision.proposed.content === input.content;
|
|
80848
81238
|
}
|
|
@@ -81058,9 +81448,9 @@ function needsExampleDetailPreservationWarning(input) {
|
|
|
81058
81448
|
return false;
|
|
81059
81449
|
if (supportKind(input.decision, input.item) !== "example")
|
|
81060
81450
|
return false;
|
|
81061
|
-
if (!
|
|
81451
|
+
if (!FENCED_CODE_RE2.test(citedTextForDecision2(input.decision, input.item)))
|
|
81062
81452
|
return false;
|
|
81063
|
-
return !
|
|
81453
|
+
return !FENCED_CODE_RE2.test(input.decision.proposed?.content ?? "");
|
|
81064
81454
|
}
|
|
81065
81455
|
function exampleDetailPreservationWarning(input) {
|
|
81066
81456
|
return {
|
|
@@ -83409,6 +83799,26 @@ function prepareCandidateRows(context, options = {}) {
|
|
|
83409
83799
|
}
|
|
83410
83800
|
return rows;
|
|
83411
83801
|
}
|
|
83802
|
+
function candidateIndexRows(context) {
|
|
83803
|
+
return context.items.map((item) => ({
|
|
83804
|
+
item_id: item.item_id,
|
|
83805
|
+
...item.action_id !== undefined ? { action_id: item.action_id } : {},
|
|
83806
|
+
...item.action_op_index !== undefined ? { action_op_index: item.action_op_index } : {},
|
|
83807
|
+
...item.action_selector !== undefined ? { action_selector: item.action_selector } : {},
|
|
83808
|
+
status: item.status ?? "pending",
|
|
83809
|
+
target: item.target,
|
|
83810
|
+
candidates: item.candidates.length,
|
|
83811
|
+
candidate_count: item.candidates.length,
|
|
83812
|
+
...item.source_support !== undefined ? {
|
|
83813
|
+
source_support: {
|
|
83814
|
+
verdict: item.source_support.verdict,
|
|
83815
|
+
missing_hard_terms_count: item.source_support.missing_hard_terms.length,
|
|
83816
|
+
missing_content_terms_count: item.source_support.missing_content_terms.length
|
|
83817
|
+
}
|
|
83818
|
+
} : {},
|
|
83819
|
+
...item.candidates.length > 0 ? { candidate_detail_command: prepareCandidateDetailCommand(item.item_id) } : {}
|
|
83820
|
+
}));
|
|
83821
|
+
}
|
|
83412
83822
|
function candidateViewHowToExplore(options, tokenBudget) {
|
|
83413
83823
|
const baseCommand = [
|
|
83414
83824
|
"context workflow show --payload prepare --view candidates",
|
|
@@ -83427,6 +83837,35 @@ function candidateViewHowToExplore(options, tokenBudget) {
|
|
|
83427
83837
|
];
|
|
83428
83838
|
}
|
|
83429
83839
|
function projectPrepareCandidates(context, options = {}) {
|
|
83840
|
+
if (options.itemId === undefined && options.candidateId === undefined) {
|
|
83841
|
+
const rows2 = candidateIndexRows(context);
|
|
83842
|
+
const page = paginate(rows2, options);
|
|
83843
|
+
return {
|
|
83844
|
+
schema_version: context.schema_version,
|
|
83845
|
+
mode: context.mode,
|
|
83846
|
+
workspace: context.workspace,
|
|
83847
|
+
target: context.target,
|
|
83848
|
+
view: "candidates",
|
|
83849
|
+
mode_hint: "index",
|
|
83850
|
+
filters: {},
|
|
83851
|
+
counts: {
|
|
83852
|
+
items: context.items.length,
|
|
83853
|
+
candidates: context.items.reduce((sum, item) => sum + item.candidates.length, 0),
|
|
83854
|
+
items_with_candidates: context.items.filter((item) => item.candidates.length > 0).length,
|
|
83855
|
+
shown: page.items.length
|
|
83856
|
+
},
|
|
83857
|
+
item_id_field: "item_id",
|
|
83858
|
+
items: page.items,
|
|
83859
|
+
...page.page !== undefined ? { page: page.page } : {},
|
|
83860
|
+
agent_hints: [{
|
|
83861
|
+
code: "prepare-candidates-index",
|
|
83862
|
+
severity: "info",
|
|
83863
|
+
message: "Default candidates view lists prepare items and candidate counts only.",
|
|
83864
|
+
next_action: "Use candidate_detail_command or --item-id <item-id> to inspect one item's candidate Section content before judging relation.",
|
|
83865
|
+
command: "context workflow show --payload prepare --view candidates --item-id <item-id> --unwrap --format json"
|
|
83866
|
+
}]
|
|
83867
|
+
};
|
|
83868
|
+
}
|
|
83430
83869
|
const tokenBudget = parseTokenBudgetOption(options.tokenBudget);
|
|
83431
83870
|
const rows = prepareCandidateRows(context, options);
|
|
83432
83871
|
return {
|
|
@@ -83517,6 +83956,40 @@ function sourceSupportMissingTerms2(support) {
|
|
|
83517
83956
|
}))
|
|
83518
83957
|
};
|
|
83519
83958
|
}
|
|
83959
|
+
function sourceSupportSummary(support) {
|
|
83960
|
+
return {
|
|
83961
|
+
verdict: support.verdict,
|
|
83962
|
+
...support.reason_code !== undefined ? { reason_code: support.reason_code } : {},
|
|
83963
|
+
matched: support.matched_term_count,
|
|
83964
|
+
total: support.content_term_count,
|
|
83965
|
+
required: support.required_term_count,
|
|
83966
|
+
missing_hard_terms_count: support.missing_hard_terms.length,
|
|
83967
|
+
missing_content_terms_count: support.missing_content_terms.length,
|
|
83968
|
+
...support.missing_terms !== undefined ? { missing_terms_count: support.missing_terms.length } : {},
|
|
83969
|
+
...support.evidence_block_candidates !== undefined ? { evidence_block_candidates: support.evidence_block_candidates.length } : {},
|
|
83970
|
+
...support.evidence_block_source_ref !== undefined ? { evidence_block_source_ref: support.evidence_block_source_ref } : {},
|
|
83971
|
+
...support.evidence_block_line_range !== undefined ? { evidence_block_line_range: support.evidence_block_line_range } : {},
|
|
83972
|
+
...support.merged_from_source_refs !== undefined ? { merged_source_ref_count: support.merged_from_source_refs.length } : {},
|
|
83973
|
+
...support.merge_kind !== undefined ? { merge_kind: support.merge_kind } : {}
|
|
83974
|
+
};
|
|
83975
|
+
}
|
|
83976
|
+
function sourceSupportDetail(support, projection) {
|
|
83977
|
+
if (projection === "summary")
|
|
83978
|
+
return sourceSupportSummary(support);
|
|
83979
|
+
return {
|
|
83980
|
+
verdict: support.verdict,
|
|
83981
|
+
...support.reason_code !== undefined ? { reason_code: support.reason_code } : {},
|
|
83982
|
+
matched: support.matched_term_count,
|
|
83983
|
+
total: support.content_term_count,
|
|
83984
|
+
required: support.required_term_count,
|
|
83985
|
+
...sourceSupportFailureTerms(support),
|
|
83986
|
+
...sourceSupportMissingTerms2(support),
|
|
83987
|
+
...support.evidence_block_source_ref !== undefined ? { evidence_block_source_ref: support.evidence_block_source_ref } : {},
|
|
83988
|
+
...support.evidence_block_line_range !== undefined ? { evidence_block_line_range: support.evidence_block_line_range } : {},
|
|
83989
|
+
...support.merged_from_source_refs !== undefined ? { merged_from_source_refs: support.merged_from_source_refs } : {},
|
|
83990
|
+
...support.merge_kind !== undefined ? { merge_kind: support.merge_kind } : {}
|
|
83991
|
+
};
|
|
83992
|
+
}
|
|
83520
83993
|
function nextDecisionsTemplate(context) {
|
|
83521
83994
|
return context.next_decisions_template ?? {
|
|
83522
83995
|
schema_version: context.schema_version,
|
|
@@ -83648,6 +84121,8 @@ function requirePrepareIssueStatus(value) {
|
|
|
83648
84121
|
function compactPrepareItem(item, input = {}) {
|
|
83649
84122
|
const proposed = isRecord35(item.proposed) ? item.proposed : {};
|
|
83650
84123
|
const safeDefaultBlockers = computeSafeDefaultBlockers(item, input.mode ?? "compile");
|
|
84124
|
+
const candidates = item.candidates.length;
|
|
84125
|
+
const sourceSupportProjection = input.sourceSupportProjection ?? "summary";
|
|
83651
84126
|
return {
|
|
83652
84127
|
item_id: item.item_id,
|
|
83653
84128
|
...item.action_id !== undefined ? { action_id: item.action_id } : {},
|
|
@@ -83665,21 +84140,13 @@ function compactPrepareItem(item, input = {}) {
|
|
|
83665
84140
|
...item.default_decision !== undefined ? { default_decision: { relation: item.default_decision.relation, action: item.default_decision.action } } : {},
|
|
83666
84141
|
...safeDefaultBlockers.length > 0 ? { safe_default_blockers: safeDefaultBlockers } : {},
|
|
83667
84142
|
...item.source_support !== undefined ? {
|
|
83668
|
-
source_support:
|
|
83669
|
-
verdict: item.source_support.verdict,
|
|
83670
|
-
matched: item.source_support.matched_term_count,
|
|
83671
|
-
total: item.source_support.content_term_count,
|
|
83672
|
-
required: item.source_support.required_term_count,
|
|
83673
|
-
...sourceSupportFailureTerms(item.source_support),
|
|
83674
|
-
...sourceSupportMissingTerms2(item.source_support),
|
|
83675
|
-
...item.source_support.evidence_block_source_ref !== undefined ? { evidence_block_source_ref: item.source_support.evidence_block_source_ref } : {},
|
|
83676
|
-
...item.source_support.merged_from_source_refs !== undefined ? { merged_from_source_refs: item.source_support.merged_from_source_refs } : {},
|
|
83677
|
-
...item.source_support.merge_kind !== undefined ? { merge_kind: item.source_support.merge_kind } : {}
|
|
83678
|
-
}
|
|
84143
|
+
source_support: sourceSupportDetail(item.source_support, sourceSupportProjection)
|
|
83679
84144
|
} : {},
|
|
83680
84145
|
...item.temporal_prior !== undefined ? { temporal_prior: item.temporal_prior } : {},
|
|
83681
|
-
candidates
|
|
83682
|
-
|
|
84146
|
+
candidates,
|
|
84147
|
+
candidate_count: candidates,
|
|
84148
|
+
item_detail_command: `context workflow show --payload prepare --view issues --item-id ${item.item_id} --unwrap --format json`,
|
|
84149
|
+
...candidates > 0 ? {
|
|
83683
84150
|
candidate_detail_command: prepareCandidateDetailCommand(item.item_id)
|
|
83684
84151
|
} : {},
|
|
83685
84152
|
previous_decisions: item.previous_decisions.length,
|
|
@@ -83688,6 +84155,7 @@ function compactPrepareItem(item, input = {}) {
|
|
|
83688
84155
|
profile: item.retrieval.profile,
|
|
83689
84156
|
returned_candidates: item.retrieval.returned_candidates,
|
|
83690
84157
|
...item.retrieval.self_draft_candidates_filtered !== undefined ? { self_draft_candidates_filtered: item.retrieval.self_draft_candidates_filtered } : {},
|
|
84158
|
+
...item.retrieval.same_cycle_candidates_filtered !== undefined ? { same_cycle_candidates_filtered: item.retrieval.same_cycle_candidates_filtered } : {},
|
|
83691
84159
|
truncated: item.retrieval.truncated,
|
|
83692
84160
|
...item.retrieval.blocked !== undefined ? { blocked: item.retrieval.blocked } : {},
|
|
83693
84161
|
...item.retrieval.blocked_reason !== undefined ? { blocked_reason: item.retrieval.blocked_reason } : {}
|
|
@@ -83700,7 +84168,10 @@ function issuePrepareItem(item, input = {}) {
|
|
|
83700
84168
|
const issueStatus = prepareIssueStatus(item);
|
|
83701
84169
|
if (issueStatus === undefined)
|
|
83702
84170
|
return null;
|
|
83703
|
-
const compact2 = compactPrepareItem(item,
|
|
84171
|
+
const compact2 = compactPrepareItem(item, {
|
|
84172
|
+
...input,
|
|
84173
|
+
sourceSupportProjection: "issue"
|
|
84174
|
+
});
|
|
83704
84175
|
if (support === undefined)
|
|
83705
84176
|
return { ...compact2, issue_status: issueStatus };
|
|
83706
84177
|
return {
|
|
@@ -84765,7 +85236,7 @@ function registerReconcileCommand(program2) {
|
|
|
84765
85236
|
}
|
|
84766
85237
|
});
|
|
84767
85238
|
});
|
|
84768
|
-
reconcile.command("apply").description("Apply semantic decisions to active knowledge and record the ledger after verify").option("--format <format>", "json | yaml", "json").addHelpText("after", [
|
|
85239
|
+
reconcile.command("apply").description("Apply semantic decisions to active knowledge and record the ledger after verify").option("--format <format>", "json | yaml", "json").addOption(new Option("--decisions <path>", "invalid for apply; apply consumes the ready review artifact").hideHelp()).addHelpText("after", [
|
|
84769
85240
|
"",
|
|
84770
85241
|
"Apply consumes the current workflow scope's unique ready immutable review artifact.",
|
|
84771
85242
|
"Do not pass hand-edited decisions or review-output files to apply.",
|
|
@@ -84778,6 +85249,18 @@ function registerReconcileCommand(program2) {
|
|
|
84778
85249
|
stateRequirement: "state-required",
|
|
84779
85250
|
flags: {},
|
|
84780
85251
|
run: async (ctx) => {
|
|
85252
|
+
if (typeof options.decisions === "string") {
|
|
85253
|
+
throw new ContextError(ExitCode.UserError, "reconcile apply does not accept --decisions", {
|
|
85254
|
+
category: ErrorCategory.UserInputInvalid,
|
|
85255
|
+
agent_hints: [{
|
|
85256
|
+
code: "reconcile-apply-consumes-ready-review",
|
|
85257
|
+
severity: "error",
|
|
85258
|
+
message: "context reconcile apply reads the current workflow's ready immutable review artifact; it does not read semantic decisions from stdin.",
|
|
85259
|
+
next_action: "Run plain context reconcile apply for the current workflow scope.",
|
|
85260
|
+
command: "context reconcile apply --format json"
|
|
85261
|
+
}]
|
|
85262
|
+
});
|
|
85263
|
+
}
|
|
84781
85264
|
const ctxDir = requireWorkspace2(ctx.ctxDir, "reconcile apply");
|
|
84782
85265
|
const currentArtifact = await readUniqueReadyReviewArtifactForCurrent(ctxDir);
|
|
84783
85266
|
const currentWorkflow = await readReadyCurrentWorkflow(ctxDir, "reconcile apply");
|
|
@@ -86775,6 +87258,14 @@ function activeContentSourceIds(value) {
|
|
|
86775
87258
|
function sourcePlanById(value) {
|
|
86776
87259
|
return new Map(sourcePlanRows(value).map((source2) => [source2.source_id, source2]));
|
|
86777
87260
|
}
|
|
87261
|
+
function resolveSourceBundleSourceId(value, sourceIdOrAlias) {
|
|
87262
|
+
if (sourceIdOrAlias === undefined)
|
|
87263
|
+
return;
|
|
87264
|
+
const plans = sourcePlanRows(value);
|
|
87265
|
+
if (plans.some((source2) => source2.source_id === sourceIdOrAlias))
|
|
87266
|
+
return sourceIdOrAlias;
|
|
87267
|
+
return plans.find((source2) => source2.source_alias === sourceIdOrAlias)?.source_id ?? sourceIdOrAlias;
|
|
87268
|
+
}
|
|
86778
87269
|
function sourceBundleCommand(record, options = {}, format = "text") {
|
|
86779
87270
|
const parts = ["--view source-bundle"];
|
|
86780
87271
|
if (options.sourceId !== undefined)
|
|
@@ -86789,19 +87280,16 @@ function sourceBundleCommand(record, options = {}, format = "text") {
|
|
|
86789
87280
|
parts.push(`--page-size ${shellQuote(options.pageSize)}`);
|
|
86790
87281
|
if (options.pageToken !== undefined)
|
|
86791
87282
|
parts.push(`--page-token ${shellQuote(options.pageToken)}`);
|
|
86792
|
-
if (options.tokenBudget !== undefined)
|
|
86793
|
-
parts.push(`--token-budget ${shellQuote(options.tokenBudget)}`);
|
|
86794
|
-
if (options.budget !== undefined)
|
|
86795
|
-
parts.push(`--budget ${shellQuote(options.budget)}`);
|
|
86796
87283
|
return workflowPayloadShowCommand(record, [parts.join(" "), "--unwrap", `--format ${format}`]);
|
|
86797
87284
|
}
|
|
86798
87285
|
function sourceBundleScopeBlocks(value, options) {
|
|
86799
87286
|
const activeIds = activeAlignSourceIds(value);
|
|
87287
|
+
const selectedSourceId = resolveSourceBundleSourceId(value, options.sourceId);
|
|
86800
87288
|
const windows = alignWindowRows(value);
|
|
86801
87289
|
const selectedWindows = typeof options.windowId === "string" ? resolveWindowSelectors(windows, options.windowId) : [];
|
|
86802
87290
|
const windowBlockIds = selectedWindows.length === 0 ? undefined : new Set(selectedWindows.flatMap((window2) => window2.block_ids));
|
|
86803
87291
|
const range = parseOrdinalRange(options.range);
|
|
86804
|
-
return alignBlockRows(value).filter((block) => typeof block.source_id === "string" && activeIds.has(block.source_id) && (
|
|
87292
|
+
return alignBlockRows(value).filter((block) => typeof block.source_id === "string" && activeIds.has(block.source_id) && (selectedSourceId === undefined || block.source_id === selectedSourceId) && (windowBlockIds === undefined || typeof block.block_id === "string" && windowBlockIds.has(block.block_id)) && headingMatches(block.heading_path, options.heading) && (range === undefined || block.ordinal_in_source >= range.start && block.ordinal_in_source <= range.end));
|
|
86805
87293
|
}
|
|
86806
87294
|
function estimateSourceBundleBlocksBudget(blocks) {
|
|
86807
87295
|
const sourceIds = new Set(blocks.map((block) => block.source_id).filter((sourceId) => typeof sourceId === "string"));
|
|
@@ -86854,6 +87342,25 @@ function withSourceBundleRecommendedPageSize(value, options) {
|
|
|
86854
87342
|
const pageSize = sourceBundleRecommendedPageSize(value, options);
|
|
86855
87343
|
return pageSize === undefined ? options : { ...options, pageSize };
|
|
86856
87344
|
}
|
|
87345
|
+
function sourceBundleScopeFitsBudget(value, options) {
|
|
87346
|
+
const budget = estimateSourceBundleBlocksBudget(sourceBundleScopeBlocks(value, options));
|
|
87347
|
+
return budget.safe === true;
|
|
87348
|
+
}
|
|
87349
|
+
function firstSourceWindowId(value, sourceId) {
|
|
87350
|
+
if (sourceId === undefined)
|
|
87351
|
+
return;
|
|
87352
|
+
const first = alignWindowRows(value).filter((window2) => window2.source_id === sourceId && typeof window2.window_id === "string").sort((left, right) => (typeof right.token_estimate === "number" ? right.token_estimate : 0) - (typeof left.token_estimate === "number" ? left.token_estimate : 0))[0];
|
|
87353
|
+
return typeof first?.window_id === "string" ? first.window_id : undefined;
|
|
87354
|
+
}
|
|
87355
|
+
function sourceBundlePreferredScopeForSource(value, sourceId) {
|
|
87356
|
+
const sourceScope = { sourceId };
|
|
87357
|
+
if (sourceBundleScopeFitsBudget(value, sourceScope))
|
|
87358
|
+
return sourceScope;
|
|
87359
|
+
const windowId = firstSourceWindowId(value, sourceId);
|
|
87360
|
+
if (windowId !== undefined)
|
|
87361
|
+
return withSourceBundleRecommendedPageSize(value, { windowId });
|
|
87362
|
+
return withSourceBundleRecommendedPageSize(value, sourceScope);
|
|
87363
|
+
}
|
|
86857
87364
|
function sourceBundleBudget(sourcePlans) {
|
|
86858
87365
|
const tokenEstimate4 = sourcePlans.reduce((sum, source2) => sum + source2.bundle_token_estimate, 0);
|
|
86859
87366
|
const blockCount = sourcePlans.reduce((sum, source2) => sum + source2.block_count, 0);
|
|
@@ -86883,17 +87390,13 @@ function routeKindForReadPlan(value, bundleSafe, firstSource) {
|
|
|
86883
87390
|
if (routeMode === "batched_review_required") {
|
|
86884
87391
|
if (firstSource === undefined)
|
|
86885
87392
|
return "batched_route";
|
|
86886
|
-
return firstSource.
|
|
87393
|
+
return sourceBundleScopeFitsBudget(value, { sourceId: firstSource.source_id }) ? "source_drilldown" : "window_drilldown";
|
|
86887
87394
|
}
|
|
86888
87395
|
if (bundleSafe)
|
|
86889
87396
|
return "source_bundle";
|
|
86890
|
-
|
|
86891
|
-
|
|
86892
|
-
|
|
86893
|
-
if (sourceId === undefined)
|
|
86894
|
-
return;
|
|
86895
|
-
const first = alignWindowRows(value).filter((window2) => window2.source_id === sourceId && typeof window2.window_id === "string").sort((left, right) => (typeof right.token_estimate === "number" ? right.token_estimate : 0) - (typeof left.token_estimate === "number" ? left.token_estimate : 0))[0];
|
|
86896
|
-
return typeof first?.window_id === "string" ? first.window_id : undefined;
|
|
87397
|
+
if (firstSource === undefined)
|
|
87398
|
+
return "source_drilldown";
|
|
87399
|
+
return sourceBundleScopeFitsBudget(value, { sourceId: firstSource.source_id }) ? "source_drilldown" : "window_drilldown";
|
|
86897
87400
|
}
|
|
86898
87401
|
function readPlanNextAction(record, value, routeKind, firstSource) {
|
|
86899
87402
|
if (routeKind === "no_align_needed") {
|
|
@@ -86912,11 +87415,10 @@ function readPlanNextAction(record, value, routeKind, firstSource) {
|
|
|
86912
87415
|
};
|
|
86913
87416
|
}
|
|
86914
87417
|
if (routeKind === "window_drilldown") {
|
|
86915
|
-
|
|
86916
|
-
if (windowId !== undefined) {
|
|
87418
|
+
if (firstSource !== undefined) {
|
|
86917
87419
|
return {
|
|
86918
87420
|
kind: "show_view",
|
|
86919
|
-
command: sourceBundleCommand(record,
|
|
87421
|
+
command: sourceBundleCommand(record, sourceBundlePreferredScopeForSource(value, firstSource.source_id)),
|
|
86920
87422
|
reason_code: "align-read-plan-window-drilldown",
|
|
86921
87423
|
blocking: true
|
|
86922
87424
|
};
|
|
@@ -86925,7 +87427,7 @@ function readPlanNextAction(record, value, routeKind, firstSource) {
|
|
|
86925
87427
|
if (firstSource !== undefined) {
|
|
86926
87428
|
return {
|
|
86927
87429
|
kind: "show_view",
|
|
86928
|
-
command: sourceBundleCommand(record,
|
|
87430
|
+
command: sourceBundleCommand(record, { sourceId: firstSource.source_id }),
|
|
86929
87431
|
reason_code: "align-read-plan-source-drilldown",
|
|
86930
87432
|
blocking: true
|
|
86931
87433
|
};
|
|
@@ -87108,7 +87610,7 @@ function activeWindowQueue(value) {
|
|
|
87108
87610
|
return String(left.window_id).localeCompare(String(right.window_id));
|
|
87109
87611
|
});
|
|
87110
87612
|
}
|
|
87111
|
-
function
|
|
87613
|
+
function nextWindowReadAfter(value, windowSelector) {
|
|
87112
87614
|
const selected = resolveWindowSelectors(alignWindowRows(value), windowSelector);
|
|
87113
87615
|
const selectedIds = new Set(selected.map((window2) => window2.window_id));
|
|
87114
87616
|
const queue = activeWindowQueue(value);
|
|
@@ -87118,9 +87620,18 @@ function nextWindowAfter(value, windowSelector) {
|
|
|
87118
87620
|
lastIndex = index2;
|
|
87119
87621
|
}
|
|
87120
87622
|
if (lastIndex < 0)
|
|
87121
|
-
return;
|
|
87623
|
+
return {};
|
|
87624
|
+
const currentSourceId = queue[lastIndex]?.source_id;
|
|
87625
|
+
if (typeof currentSourceId === "string") {
|
|
87626
|
+
const sameSourceNext = queue.slice(lastIndex + 1).find((window2) => window2.source_id === currentSourceId);
|
|
87627
|
+
if (typeof sameSourceNext?.window_id === "string")
|
|
87628
|
+
return { windowId: sameSourceNext.window_id };
|
|
87629
|
+
const nextSource = nextSourceAfter(value, currentSourceId);
|
|
87630
|
+
if (nextSource !== undefined)
|
|
87631
|
+
return { sourceId: nextSource };
|
|
87632
|
+
}
|
|
87122
87633
|
const next = queue[lastIndex + 1];
|
|
87123
|
-
return typeof next?.window_id === "string" ? next.window_id :
|
|
87634
|
+
return typeof next?.window_id === "string" ? { windowId: next.window_id } : {};
|
|
87124
87635
|
}
|
|
87125
87636
|
function firstSourceId(blocks) {
|
|
87126
87637
|
const first = blocks.find((block) => typeof block.source_id === "string");
|
|
@@ -87190,7 +87701,7 @@ function sourceBundleNextAction(record, value, options, blocks, complete, pageNe
|
|
|
87190
87701
|
if (nextSource !== undefined) {
|
|
87191
87702
|
return {
|
|
87192
87703
|
kind: "show_view",
|
|
87193
|
-
command: sourceBundleCommand(record,
|
|
87704
|
+
command: sourceBundleCommand(record, sourceBundlePreferredScopeForSource(value, nextSource)),
|
|
87194
87705
|
reason_code: "align-source-bundle-next-source",
|
|
87195
87706
|
blocking: true
|
|
87196
87707
|
};
|
|
@@ -87198,15 +87709,23 @@ function sourceBundleNextAction(record, value, options, blocks, complete, pageNe
|
|
|
87198
87709
|
return partialScopeTerminalAction(record, routeMode, "align-source-bundle-last-source");
|
|
87199
87710
|
}
|
|
87200
87711
|
if (options.windowId !== undefined) {
|
|
87201
|
-
const
|
|
87202
|
-
if (
|
|
87712
|
+
const nextRead = nextWindowReadAfter(value, options.windowId);
|
|
87713
|
+
if (nextRead.windowId !== undefined) {
|
|
87203
87714
|
return {
|
|
87204
87715
|
kind: "show_view",
|
|
87205
|
-
command: sourceBundleCommand(record, withSourceBundleRecommendedPageSize(value, { windowId:
|
|
87716
|
+
command: sourceBundleCommand(record, withSourceBundleRecommendedPageSize(value, { windowId: nextRead.windowId })),
|
|
87206
87717
|
reason_code: "align-source-bundle-next-window",
|
|
87207
87718
|
blocking: true
|
|
87208
87719
|
};
|
|
87209
87720
|
}
|
|
87721
|
+
if (nextRead.sourceId !== undefined) {
|
|
87722
|
+
return {
|
|
87723
|
+
kind: "show_view",
|
|
87724
|
+
command: sourceBundleCommand(record, sourceBundlePreferredScopeForSource(value, nextRead.sourceId)),
|
|
87725
|
+
reason_code: "align-source-bundle-next-source-after-window",
|
|
87726
|
+
blocking: true
|
|
87727
|
+
};
|
|
87728
|
+
}
|
|
87210
87729
|
return partialScopeTerminalAction(record, routeMode, "align-source-bundle-last-window");
|
|
87211
87730
|
}
|
|
87212
87731
|
if (options.heading !== undefined || options.range !== undefined) {
|
|
@@ -87215,7 +87734,7 @@ function sourceBundleNextAction(record, value, options, blocks, complete, pageNe
|
|
|
87215
87734
|
if (nextSource !== undefined) {
|
|
87216
87735
|
return {
|
|
87217
87736
|
kind: "show_view",
|
|
87218
|
-
command: sourceBundleCommand(record,
|
|
87737
|
+
command: sourceBundleCommand(record, sourceBundlePreferredScopeForSource(value, nextSource)),
|
|
87219
87738
|
reason_code: "align-source-bundle-next-source-after-scope",
|
|
87220
87739
|
blocking: true
|
|
87221
87740
|
};
|
|
@@ -87245,6 +87764,8 @@ function estimateBundleTokens(blocks, renderedBytes) {
|
|
|
87245
87764
|
return Math.max(sourceTokenEstimate + annotationTokenEstimate, Math.ceil(renderedBytes / 2));
|
|
87246
87765
|
}
|
|
87247
87766
|
function nextFallbackOptions(value, options) {
|
|
87767
|
+
if (!hasSemanticSourceBundleScope(options))
|
|
87768
|
+
return;
|
|
87248
87769
|
const currentPageSize = parsePositiveIntegerOption(options.pageSize, "--page-size");
|
|
87249
87770
|
if (currentPageSize === undefined) {
|
|
87250
87771
|
const recommended = sourceBundleRecommendedPageSize(value, options);
|
|
@@ -87255,6 +87776,28 @@ function nextFallbackOptions(value, options) {
|
|
|
87255
87776
|
return { ...options, pageSize: String(Math.max(1, Math.floor(currentPageSize / 2))) };
|
|
87256
87777
|
return;
|
|
87257
87778
|
}
|
|
87779
|
+
function hasSemanticSourceBundleScope(options) {
|
|
87780
|
+
return options.sourceId !== undefined || options.windowId !== undefined || options.heading !== undefined || options.range !== undefined;
|
|
87781
|
+
}
|
|
87782
|
+
function normalizeSourceBundleOptions(value, options) {
|
|
87783
|
+
const sourceId = resolveSourceBundleSourceId(value, options.sourceId);
|
|
87784
|
+
if (sourceId === undefined)
|
|
87785
|
+
return options;
|
|
87786
|
+
return sourceId === options.sourceId ? options : { ...options, sourceId };
|
|
87787
|
+
}
|
|
87788
|
+
function safeSourceBundleBudgets(options) {
|
|
87789
|
+
const requestedByteBudget = parsePositiveIntegerOption(options.budget, "--budget");
|
|
87790
|
+
const requestedTokenBudget = options.tokenBudget !== undefined ? parseTokenBudgetOption(options.tokenBudget) : undefined;
|
|
87791
|
+
const byteBudget = Math.min(requestedByteBudget ?? SOURCE_BUNDLE_DEFAULT_BYTE_BUDGET, SOURCE_BUNDLE_DEFAULT_BYTE_BUDGET);
|
|
87792
|
+
const tokenBudget = Math.min(requestedTokenBudget ?? AGENT_VIEW_SIZE_POLICY.acceptable.maxTokens, AGENT_VIEW_SIZE_POLICY.acceptable.maxTokens);
|
|
87793
|
+
return {
|
|
87794
|
+
byteBudget,
|
|
87795
|
+
tokenBudget,
|
|
87796
|
+
...requestedByteBudget !== undefined ? { requestedByteBudget } : {},
|
|
87797
|
+
...requestedTokenBudget !== undefined ? { requestedTokenBudget } : {},
|
|
87798
|
+
clamped: requestedByteBudget !== undefined && requestedByteBudget > SOURCE_BUNDLE_DEFAULT_BYTE_BUDGET || requestedTokenBudget !== undefined && requestedTokenBudget > AGENT_VIEW_SIZE_POLICY.acceptable.maxTokens
|
|
87799
|
+
};
|
|
87800
|
+
}
|
|
87258
87801
|
function bundleOmittedText(input) {
|
|
87259
87802
|
const full = [
|
|
87260
87803
|
renderC4aTextAnnotation("bundle-omitted", {
|
|
@@ -87263,7 +87806,10 @@ function bundleOmittedText(input) {
|
|
|
87263
87806
|
...input.estimatedBytes !== undefined ? { estimated_bytes: input.estimatedBytes } : {},
|
|
87264
87807
|
...input.byteBudget !== undefined ? { byte_budget: input.byteBudget } : {},
|
|
87265
87808
|
...input.estimatedTokens !== undefined ? { estimated_tokens: input.estimatedTokens } : {},
|
|
87266
|
-
...input.tokenBudget !== undefined ? { token_budget: input.tokenBudget } : {}
|
|
87809
|
+
...input.tokenBudget !== undefined ? { token_budget: input.tokenBudget } : {},
|
|
87810
|
+
...input.budgetClamped === true ? { budget_clamped: true } : {},
|
|
87811
|
+
...input.requestedByteBudget !== undefined ? { requested_byte_budget: input.requestedByteBudget } : {},
|
|
87812
|
+
...input.requestedTokenBudget !== undefined ? { requested_token_budget: input.requestedTokenBudget } : {}
|
|
87267
87813
|
}),
|
|
87268
87814
|
renderC4aTextAnnotation("next-action", input.nextAction),
|
|
87269
87815
|
""
|
|
@@ -87359,6 +87905,7 @@ function renderSourceBundleText(input) {
|
|
|
87359
87905
|
}
|
|
87360
87906
|
function compactAlignSegmentSourceBundle(record, value, options) {
|
|
87361
87907
|
validateSourceBundleScope(record, options);
|
|
87908
|
+
const normalizedOptions = normalizeSourceBundleOptions(value, options);
|
|
87362
87909
|
if (activeAlignSourceIds(value).size === 0) {
|
|
87363
87910
|
const nextAction2 = { kind: "start_compile_scan", command: COMPILE_SCAN_COMMAND, reason_code: "align-source-bundle-no-active-source" };
|
|
87364
87911
|
return {
|
|
@@ -87371,8 +87918,33 @@ function compactAlignSegmentSourceBundle(record, value, options) {
|
|
|
87371
87918
|
read_scope_complete: false
|
|
87372
87919
|
};
|
|
87373
87920
|
}
|
|
87374
|
-
|
|
87375
|
-
|
|
87921
|
+
if (!hasSemanticSourceBundleScope(normalizedOptions) && (normalizedOptions.pageSize !== undefined || normalizedOptions.pageToken !== undefined)) {
|
|
87922
|
+
const nextAction2 = {
|
|
87923
|
+
kind: "show_view",
|
|
87924
|
+
command: workflowPayloadShowCommand(record, ["--view read-plan", "--unwrap", "--format json"]),
|
|
87925
|
+
reason_code: "align-source-bundle-unscoped-pagination-disabled",
|
|
87926
|
+
blocking: true
|
|
87927
|
+
};
|
|
87928
|
+
return {
|
|
87929
|
+
view_schema_version: ALIGN_SOURCE_BUNDLE_VIEW_SCHEMA_VERSION,
|
|
87930
|
+
mode: "source-bundle",
|
|
87931
|
+
text: bundleOmittedText({ reasonCode: "source_bundle_unscoped_pagination_disabled", nextAction: nextAction2 }),
|
|
87932
|
+
bundle_omitted: true,
|
|
87933
|
+
reason_code: "source_bundle_unscoped_pagination_disabled",
|
|
87934
|
+
next_action: nextAction2,
|
|
87935
|
+
read_scope_complete: false,
|
|
87936
|
+
filters: compactFilters(normalizedOptions),
|
|
87937
|
+
agent_hints: [{
|
|
87938
|
+
code: "align-source-bundle-use-read-plan",
|
|
87939
|
+
severity: "warning",
|
|
87940
|
+
message: "Unscoped source-bundle pagination is disabled because it encourages reconstructing a large batch outside the workflow plan.",
|
|
87941
|
+
next_action: "Run next_action.command and follow the scoped source-bundle command chosen by read-plan.",
|
|
87942
|
+
command: nextAction2.command
|
|
87943
|
+
}]
|
|
87944
|
+
};
|
|
87945
|
+
}
|
|
87946
|
+
const allBlocks = sourceBundleScopeBlocks(value, normalizedOptions);
|
|
87947
|
+
if (hasSemanticSourceBundleScope(normalizedOptions) && allBlocks.length === 0) {
|
|
87376
87948
|
const nextAction2 = {
|
|
87377
87949
|
kind: "show_view",
|
|
87378
87950
|
command: workflowPayloadShowCommand(record, ["--view read-plan", "--unwrap", "--format json"]),
|
|
@@ -87387,13 +87959,13 @@ function compactAlignSegmentSourceBundle(record, value, options) {
|
|
|
87387
87959
|
reason_code: "source_bundle_scope_empty",
|
|
87388
87960
|
next_action: nextAction2,
|
|
87389
87961
|
read_scope_complete: false,
|
|
87390
|
-
filters: compactFilters(
|
|
87962
|
+
filters: compactFilters(normalizedOptions)
|
|
87391
87963
|
};
|
|
87392
87964
|
}
|
|
87393
|
-
const page = paginate(allBlocks,
|
|
87965
|
+
const page = paginate(allBlocks, normalizedOptions);
|
|
87394
87966
|
const pageNextToken = typeof page.page?.next_token === "string" ? page.page.next_token : undefined;
|
|
87395
|
-
const complete = sourceBundleScopeComplete(value, page.items,
|
|
87396
|
-
const nextAction = sourceBundleNextAction(record, value,
|
|
87967
|
+
const complete = sourceBundleScopeComplete(value, page.items, normalizedOptions, pageNextToken !== undefined);
|
|
87968
|
+
const nextAction = sourceBundleNextAction(record, value, normalizedOptions, page.items, complete, pageNextToken);
|
|
87397
87969
|
const rendered = renderSourceBundleText({
|
|
87398
87970
|
value,
|
|
87399
87971
|
blocks: page.items,
|
|
@@ -87401,17 +87973,22 @@ function compactAlignSegmentSourceBundle(record, value, options) {
|
|
|
87401
87973
|
readScopeComplete: complete,
|
|
87402
87974
|
...page.page !== undefined ? { page: page.page } : {}
|
|
87403
87975
|
});
|
|
87404
|
-
const
|
|
87405
|
-
const
|
|
87976
|
+
const budget = safeSourceBundleBudgets(normalizedOptions);
|
|
87977
|
+
const { byteBudget, tokenBudget } = budget;
|
|
87406
87978
|
const estimatedBytes = Buffer.byteLength(rendered.text, "utf8");
|
|
87407
87979
|
const estimatedTokens = estimateBundleTokens(page.items, estimatedBytes);
|
|
87408
87980
|
if (estimatedBytes > byteBudget || estimatedTokens > tokenBudget) {
|
|
87409
|
-
const fallbackOptions = nextFallbackOptions(value,
|
|
87410
|
-
const fallbackAction =
|
|
87981
|
+
const fallbackOptions = nextFallbackOptions(value, normalizedOptions);
|
|
87982
|
+
const fallbackAction = !hasSemanticSourceBundleScope(normalizedOptions) ? {
|
|
87983
|
+
kind: "show_view",
|
|
87984
|
+
command: workflowPayloadShowCommand(record, ["--view read-plan", "--unwrap", "--format json"]),
|
|
87985
|
+
reason_code: "align-source-bundle-return-read-plan",
|
|
87986
|
+
blocking: true
|
|
87987
|
+
} : fallbackOptions === undefined ? {
|
|
87411
87988
|
kind: "show_view",
|
|
87412
87989
|
command: workflowPayloadShowCommand(record, [
|
|
87413
87990
|
"--view block-index",
|
|
87414
|
-
...
|
|
87991
|
+
...normalizedOptions.sourceId !== undefined ? [`--source ${shellQuote(normalizedOptions.sourceId)}`] : [],
|
|
87415
87992
|
"--unwrap",
|
|
87416
87993
|
"--format json"
|
|
87417
87994
|
]),
|
|
@@ -87432,6 +88009,9 @@ function compactAlignSegmentSourceBundle(record, value, options) {
|
|
|
87432
88009
|
byteBudget,
|
|
87433
88010
|
estimatedTokens,
|
|
87434
88011
|
tokenBudget,
|
|
88012
|
+
budgetClamped: budget.clamped,
|
|
88013
|
+
...budget.requestedByteBudget !== undefined ? { requestedByteBudget: budget.requestedByteBudget } : {},
|
|
88014
|
+
...budget.requestedTokenBudget !== undefined ? { requestedTokenBudget: budget.requestedTokenBudget } : {},
|
|
87435
88015
|
nextAction: fallbackAction
|
|
87436
88016
|
}),
|
|
87437
88017
|
bundle_omitted: true,
|
|
@@ -87439,6 +88019,11 @@ function compactAlignSegmentSourceBundle(record, value, options) {
|
|
|
87439
88019
|
byte_budget: byteBudget,
|
|
87440
88020
|
estimated_tokens: estimatedTokens,
|
|
87441
88021
|
token_budget: tokenBudget,
|
|
88022
|
+
...budget.clamped ? {
|
|
88023
|
+
budget_clamped: true,
|
|
88024
|
+
...budget.requestedByteBudget !== undefined ? { requested_byte_budget: budget.requestedByteBudget } : {},
|
|
88025
|
+
...budget.requestedTokenBudget !== undefined ? { requested_token_budget: budget.requestedTokenBudget } : {}
|
|
88026
|
+
} : {},
|
|
87442
88027
|
next_action: fallbackAction,
|
|
87443
88028
|
read_scope_complete: false,
|
|
87444
88029
|
agent_hints: [{
|
|
@@ -87452,12 +88037,12 @@ function compactAlignSegmentSourceBundle(record, value, options) {
|
|
|
87452
88037
|
byte_budget: byteBudget,
|
|
87453
88038
|
estimated_tokens: estimatedTokens,
|
|
87454
88039
|
token_budget: tokenBudget,
|
|
87455
|
-
|
|
87456
|
-
|
|
87457
|
-
|
|
87458
|
-
|
|
87459
|
-
},
|
|
87460
|
-
|
|
88040
|
+
...budget.clamped ? {
|
|
88041
|
+
budget_clamped: true,
|
|
88042
|
+
requested_byte_budget: budget.requestedByteBudget,
|
|
88043
|
+
requested_token_budget: budget.requestedTokenBudget
|
|
88044
|
+
} : {},
|
|
88045
|
+
feedback: "If this fallback seems too conservative during testing, report estimated_tokens/token_budget and estimated_bytes/byte_budget. Source-bundle keeps generated commands inside the agent-safe budget policy."
|
|
87461
88046
|
}
|
|
87462
88047
|
}]
|
|
87463
88048
|
};
|
|
@@ -87466,10 +88051,15 @@ function compactAlignSegmentSourceBundle(record, value, options) {
|
|
|
87466
88051
|
view_schema_version: ALIGN_SOURCE_BUNDLE_VIEW_SCHEMA_VERSION,
|
|
87467
88052
|
mode: "source-bundle",
|
|
87468
88053
|
format: "c4a-annotated-text",
|
|
87469
|
-
filters: compactFilters(
|
|
88054
|
+
filters: compactFilters(normalizedOptions),
|
|
87470
88055
|
text: rendered.text,
|
|
87471
88056
|
text_bytes: estimatedBytes,
|
|
87472
88057
|
estimated_tokens: estimatedTokens,
|
|
88058
|
+
...budget.clamped ? {
|
|
88059
|
+
budget_clamped: true,
|
|
88060
|
+
...budget.requestedByteBudget !== undefined ? { requested_byte_budget: budget.requestedByteBudget } : {},
|
|
88061
|
+
...budget.requestedTokenBudget !== undefined ? { requested_token_budget: budget.requestedTokenBudget } : {}
|
|
88062
|
+
} : {},
|
|
87473
88063
|
read_scope_complete: complete,
|
|
87474
88064
|
raw_c4a_sentinel_escaped: rendered.collisionEscaped,
|
|
87475
88065
|
...rendered.collisionEscapedBlockIds.length > 0 ? {
|
|
@@ -88134,7 +88724,7 @@ function coverageRows(value) {
|
|
|
88134
88724
|
const row = {
|
|
88135
88725
|
candidate_id: candidateId2,
|
|
88136
88726
|
issue_type: issueType,
|
|
88137
|
-
node_slug:
|
|
88727
|
+
node_slug: stringValue4(candidate.node_slug, "unknown"),
|
|
88138
88728
|
signal: coverageSignal(candidate),
|
|
88139
88729
|
why_flagged: whyFlagged(candidate),
|
|
88140
88730
|
source_ref_count: sourceRefs2.length,
|
|
@@ -88250,7 +88840,7 @@ function compareCoverageGroups(a, b) {
|
|
|
88250
88840
|
return signalRank(b.signal) - signalRank(a.signal) || a.issue_type.localeCompare(b.issue_type) || b.count - a.count;
|
|
88251
88841
|
}
|
|
88252
88842
|
function coverageSignal(candidate) {
|
|
88253
|
-
return
|
|
88843
|
+
return stringValue4(candidate.signal, "unknown");
|
|
88254
88844
|
}
|
|
88255
88845
|
function whyFlagged(candidate) {
|
|
88256
88846
|
const direct = strings(candidate.why_flagged);
|
|
@@ -88295,7 +88885,7 @@ function strings(value) {
|
|
|
88295
88885
|
function isRecord37(value) {
|
|
88296
88886
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
88297
88887
|
}
|
|
88298
|
-
function
|
|
88888
|
+
function stringValue4(value, fallback) {
|
|
88299
88889
|
return typeof value === "string" && value.length > 0 ? value : fallback;
|
|
88300
88890
|
}
|
|
88301
88891
|
function setString(target, key, value) {
|
|
@@ -88320,6 +88910,7 @@ function headingMatches2(path13, input) {
|
|
|
88320
88910
|
|
|
88321
88911
|
// src/commands/workflowNodeContextPayloadViews.ts
|
|
88322
88912
|
init_workflowPayloadStore();
|
|
88913
|
+
init_markdownFormatSignals();
|
|
88323
88914
|
var SOURCE_REFS_SELECTION_POLICY = {
|
|
88324
88915
|
id: "source-refs-v2",
|
|
88325
88916
|
order: [
|
|
@@ -88376,6 +88967,7 @@ function nodeContextSourceRefRows(value) {
|
|
|
88376
88967
|
const quotePreview = previewText(snippet.quote);
|
|
88377
88968
|
const quoteText = normalizedPreviewBasis(snippet.quote);
|
|
88378
88969
|
const quoteCharCount = quoteText?.length;
|
|
88970
|
+
const formatSignals = markdownFormatSignals(snippet.quote);
|
|
88379
88971
|
const blockId = typeof snippet.block_id === "string" ? snippet.block_id : undefined;
|
|
88380
88972
|
const sourceId = typeof snippet.source_id === "string" ? snippet.source_id : undefined;
|
|
88381
88973
|
const finalizedOwnershipRole = typeof snippet.finalized_ownership_role === "string" ? snippet.finalized_ownership_role : undefined;
|
|
@@ -88398,6 +88990,10 @@ function nodeContextSourceRefRows(value) {
|
|
|
88398
88990
|
...quoteCharCount !== undefined ? { quote_char_count: quoteCharCount } : {},
|
|
88399
88991
|
...quotePreview !== undefined ? { preview_char_count: quotePreview.length } : {},
|
|
88400
88992
|
...quotePreview !== undefined && quoteCharCount !== undefined ? { preview_is_complete: quotePreview.length >= quoteCharCount } : {},
|
|
88993
|
+
...formatSignals.format_sensitive ? {
|
|
88994
|
+
...formatSignals,
|
|
88995
|
+
quote_preview_preserves_line_breaks: false
|
|
88996
|
+
} : {},
|
|
88401
88997
|
...node3 !== undefined && blockId !== undefined && canRequestFullTextForSnippet(snippet) ? { request_full_text_command: `context compile context ${shellQuote(node3)} --request-full-text ${shellQuote(blockId)} --view text --format json` } : {}
|
|
88402
88998
|
};
|
|
88403
88999
|
});
|
|
@@ -88653,26 +89249,28 @@ function sanitizeNodeContextValue(value) {
|
|
|
88653
89249
|
};
|
|
88654
89250
|
}
|
|
88655
89251
|
function compactPreparePayload(value, view, options = {}) {
|
|
88656
|
-
const wantsIssueDetail = view === "issues" &&
|
|
89252
|
+
const wantsIssueDetail = view === "issues" && options.itemId !== undefined;
|
|
89253
|
+
const shouldDefaultPage = view === "summary" || view === "issues" || view === "candidates" && options.itemId === undefined && options.candidateId === undefined;
|
|
89254
|
+
const pagedOptions = shouldDefaultPage && options.pageSize === undefined ? { ...options, pageSize: "20" } : options;
|
|
88657
89255
|
const projected = projectPrepareContext(value, view, {
|
|
88658
|
-
...
|
|
88659
|
-
...
|
|
88660
|
-
...
|
|
88661
|
-
...
|
|
88662
|
-
...
|
|
88663
|
-
...
|
|
89256
|
+
...pagedOptions.status !== undefined ? { status: pagedOptions.status } : {},
|
|
89257
|
+
...pagedOptions.itemId !== undefined ? { itemId: pagedOptions.itemId } : {},
|
|
89258
|
+
...pagedOptions.candidateId !== undefined ? { candidateId: pagedOptions.candidateId } : {},
|
|
89259
|
+
...pagedOptions.pageSize !== undefined ? { pageSize: pagedOptions.pageSize } : {},
|
|
89260
|
+
...pagedOptions.pageToken !== undefined ? { pageToken: pagedOptions.pageToken } : {},
|
|
89261
|
+
...pagedOptions.tokenBudget !== undefined ? { tokenBudget: pagedOptions.tokenBudget } : {},
|
|
88664
89262
|
...wantsIssueDetail ? { detail: true } : {}
|
|
88665
89263
|
});
|
|
88666
89264
|
if (!isRecord36(projected))
|
|
88667
89265
|
return { value: projected };
|
|
88668
|
-
if (view
|
|
89266
|
+
if (view === "candidates")
|
|
88669
89267
|
return projected;
|
|
88670
|
-
const
|
|
88671
|
-
const page = paginate(
|
|
89268
|
+
const projectedItems = asRecords(projected.items);
|
|
89269
|
+
const page = paginate(projectedItems, pagedOptions);
|
|
88672
89270
|
const existingFilters = isRecord36(projected.filters) ? projected.filters : {};
|
|
88673
89271
|
const filters = {
|
|
88674
89272
|
...existingFilters,
|
|
88675
|
-
...compactFilters(
|
|
89273
|
+
...compactFilters(pagedOptions)
|
|
88676
89274
|
};
|
|
88677
89275
|
return {
|
|
88678
89276
|
...projected,
|
|
@@ -89509,7 +90107,13 @@ function writeWorkflowShowOutput(input) {
|
|
|
89509
90107
|
return;
|
|
89510
90108
|
}
|
|
89511
90109
|
const metadata2 = workflowPayloadMetadata(input.record);
|
|
89512
|
-
const
|
|
90110
|
+
const rawCompactValue = input.view === undefined ? undefined : compactWorkflowPayloadView(input.record, input.view, input.viewOptions);
|
|
90111
|
+
const compactValue = input.view !== undefined && rawCompactValue !== undefined ? withPagedNextCommand({
|
|
90112
|
+
record: input.record,
|
|
90113
|
+
view: input.view,
|
|
90114
|
+
viewOptions: input.viewOptions,
|
|
90115
|
+
value: rawCompactValue
|
|
90116
|
+
}) : rawCompactValue;
|
|
89513
90117
|
const availableViews = workflowPayloadAvailableViews(input.record.payload);
|
|
89514
90118
|
const viewGuide = input.view === undefined && !input.metadataOnly && !input.unwrap ? workflowPayloadViewGuide(input.record) : {};
|
|
89515
90119
|
const shouldOmitFullValue = input.view === undefined && !input.metadataOnly && !input.unwrap && availableViews.length > 0;
|
|
@@ -90114,7 +90718,7 @@ init_alignBlockStructuralRole();
|
|
|
90114
90718
|
function isRecord39(value) {
|
|
90115
90719
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
90116
90720
|
}
|
|
90117
|
-
function
|
|
90721
|
+
function stringValue5(value) {
|
|
90118
90722
|
return typeof value === "string" && value.trim().length > 0 ? value.trim() : undefined;
|
|
90119
90723
|
}
|
|
90120
90724
|
function assertKnownEvidenceBlocks(input) {
|
|
@@ -90277,7 +90881,7 @@ function normalizeUnresolved(value) {
|
|
|
90277
90881
|
return Array.isArray(value) ? value.filter(isRecord39) : [];
|
|
90278
90882
|
}
|
|
90279
90883
|
function validateUnresolvedQuestions(input) {
|
|
90280
|
-
const questionIds = new Set(input.unresolved.map((item) =>
|
|
90884
|
+
const questionIds = new Set(input.unresolved.map((item) => stringValue5(item.question_id)).filter((item) => item !== undefined));
|
|
90281
90885
|
input.blockOwnership.forEach((item, index2) => {
|
|
90282
90886
|
if (item.ownership_role !== "unresolved")
|
|
90283
90887
|
return;
|
|
@@ -90832,9 +91436,9 @@ function parseNodes(value) {
|
|
|
90832
91436
|
return value.map((raw, index2) => {
|
|
90833
91437
|
if (!isRecord18(raw))
|
|
90834
91438
|
reject(`nodes[${index2}]`, "node must be an object");
|
|
90835
|
-
const rawSlug =
|
|
90836
|
-
const rawHint =
|
|
90837
|
-
const slugBase = rawSlug ?? (rawHint !== undefined ? slugBaseFromHint(rawHint) : undefined) ??
|
|
91439
|
+
const rawSlug = stringValue2(raw.slug);
|
|
91440
|
+
const rawHint = stringValue2(raw.llm_slug_hint);
|
|
91441
|
+
const slugBase = rawSlug ?? (rawHint !== undefined ? slugBaseFromHint(rawHint) : undefined) ?? stringValue2(raw.title);
|
|
90838
91442
|
if (!slugBase)
|
|
90839
91443
|
reject(`nodes[${index2}].slug`, "slug, llm_slug_hint, or title is required");
|
|
90840
91444
|
const slug = rawSlug !== undefined ? rawSlug.split("/").map((part) => slugify(part)).filter(Boolean).join("/") : slugify(slugBase);
|
|
@@ -90854,16 +91458,16 @@ function parseNodes(value) {
|
|
|
90854
91458
|
} : {}
|
|
90855
91459
|
});
|
|
90856
91460
|
}
|
|
90857
|
-
const llmSlugHint =
|
|
90858
|
-
const containsParent =
|
|
90859
|
-
const containsParentRef =
|
|
90860
|
-
const summary3 =
|
|
91461
|
+
const llmSlugHint = stringValue2(raw.llm_slug_hint);
|
|
91462
|
+
const containsParent = stringValue2(raw.contains_parent);
|
|
91463
|
+
const containsParentRef = stringValue2(raw.contains_parent_ref);
|
|
91464
|
+
const summary3 = stringValue2(raw.summary);
|
|
90861
91465
|
return {
|
|
90862
91466
|
slug,
|
|
90863
91467
|
...llmSlugHint !== undefined ? { llm_slug_hint: llmSlugHint } : {},
|
|
90864
91468
|
node_type: nodeType,
|
|
90865
91469
|
tags,
|
|
90866
|
-
title:
|
|
91470
|
+
title: stringValue2(raw.title) ?? slug,
|
|
90867
91471
|
...raw.contains_parent === null ? { contains_parent: null } : {},
|
|
90868
91472
|
...containsParent !== undefined ? { contains_parent: containsParent } : {},
|
|
90869
91473
|
...containsParentRef !== undefined ? { contains_parent_ref: containsParentRef } : {},
|
|
@@ -90913,33 +91517,6 @@ function validateInferenceSources(gate, path13) {
|
|
|
90913
91517
|
}
|
|
90914
91518
|
}
|
|
90915
91519
|
}
|
|
90916
|
-
function downgradeReason(node3) {
|
|
90917
|
-
if (node3.action_probe?.has_steps_or_phases !== true)
|
|
90918
|
-
return "action_probe lacks explicit steps or phases";
|
|
90919
|
-
if (node3.action_gate === undefined)
|
|
90920
|
-
return "action gate lacks structured inference sources";
|
|
90921
|
-
return null;
|
|
90922
|
-
}
|
|
90923
|
-
function downgradeNode(node3, warningKind, reason) {
|
|
90924
|
-
return {
|
|
90925
|
-
node: {
|
|
90926
|
-
...node3,
|
|
90927
|
-
node_type: "entity",
|
|
90928
|
-
tags: node3.tags.length > 0 && !node3.tags.some((tag) => ACTION_KIND_VALUES.includes(tag)) ? node3.tags : ["term"]
|
|
90929
|
-
},
|
|
90930
|
-
warning: {
|
|
90931
|
-
kind: warningKind,
|
|
90932
|
-
node_slug: node3.slug,
|
|
90933
|
-
reason,
|
|
90934
|
-
original_proposal: {
|
|
90935
|
-
node_type: node3.node_type,
|
|
90936
|
-
title: node3.title,
|
|
90937
|
-
rationale: node3.summary ?? ""
|
|
90938
|
-
},
|
|
90939
|
-
evidence_blocks: node3.evidence_blocks
|
|
90940
|
-
}
|
|
90941
|
-
};
|
|
90942
|
-
}
|
|
90943
91520
|
function scopeNameEntityWarning(node3) {
|
|
90944
91521
|
if (node3.node_type !== "entity")
|
|
90945
91522
|
return null;
|
|
@@ -90958,6 +91535,92 @@ function scopeNameEntityWarning(node3) {
|
|
|
90958
91535
|
evidence_blocks: node3.evidence_blocks
|
|
90959
91536
|
};
|
|
90960
91537
|
}
|
|
91538
|
+
function gateRepairOptions(type) {
|
|
91539
|
+
return type === "domain" ? [
|
|
91540
|
+
"If this is a Domain, add domain_gate.scope_blocks, domain_gate.child_refs, and domain_gate.grouping_reason with resolvable child_refs.",
|
|
91541
|
+
"If this is not a Domain, resubmit it as node_type=entity and choose the concrete Entity tag yourself; CLI will not auto-pick tags."
|
|
91542
|
+
] : [
|
|
91543
|
+
"If this is an Action, add action_probe plus action_gate.inference_sources with actor, outcome_or_goal, repeatability_or_plan, and answerability evidence.",
|
|
91544
|
+
"If this is not an Action, resubmit it as node_type=entity or move the process wording into a Section under the owning Node; CLI will not auto-pick tags."
|
|
91545
|
+
];
|
|
91546
|
+
}
|
|
91547
|
+
function normalizeDomainGate(input) {
|
|
91548
|
+
const gate = input.node.domain_gate;
|
|
91549
|
+
const rawChildRefs = Array.isArray(gate?.child_refs) ? gate.child_refs : undefined;
|
|
91550
|
+
const childRefs = rawChildRefs?.map((ref) => typeof ref === "string" ? ref.trim() : "") ?? [];
|
|
91551
|
+
const unresolvedChildRefs = childRefs.filter((ref) => ref.length === 0 || !input.refs.has(ref) && !input.allSlugs.has(ref));
|
|
91552
|
+
const validGate = gate !== undefined && Array.isArray(gate.scope_blocks) && rawChildRefs !== undefined && typeof gate.grouping_reason === "string" && childRefs.length === rawChildRefs.length && unresolvedChildRefs.length === 0;
|
|
91553
|
+
if (!validGate) {
|
|
91554
|
+
const missing = [
|
|
91555
|
+
gate === undefined ? "domain_gate" : undefined,
|
|
91556
|
+
gate !== undefined && !Array.isArray(gate.scope_blocks) ? "domain_gate.scope_blocks" : undefined,
|
|
91557
|
+
rawChildRefs === undefined ? "domain_gate.child_refs" : undefined,
|
|
91558
|
+
gate !== undefined && typeof gate.grouping_reason !== "string" ? "domain_gate.grouping_reason" : undefined,
|
|
91559
|
+
unresolvedChildRefs.length > 0 ? "domain_gate.child_refs.resolvable" : undefined
|
|
91560
|
+
].filter((item) => item !== undefined);
|
|
91561
|
+
reject(rawChildRefs === undefined || unresolvedChildRefs.length > 0 ? `nodes[${input.nodeIndex}].domain_gate.child_refs` : `nodes[${input.nodeIndex}].domain_gate`, "node_type=domain requires a valid domain_gate; CLI does not auto-downgrade invalid Domain nodes to entity", {
|
|
91562
|
+
hintCode: "align-domain-gate-invalid",
|
|
91563
|
+
reasonCode: "align-domain-gate-invalid",
|
|
91564
|
+
schemaLookup: "context schema align-structure-intent --view minimal --format json",
|
|
91565
|
+
repairOptions: gateRepairOptions("domain"),
|
|
91566
|
+
availableNodeRefs: nodeRefsForHint(input.refs),
|
|
91567
|
+
availableNodeSlugs: [...input.allSlugs],
|
|
91568
|
+
diagnostics: {
|
|
91569
|
+
missing_or_invalid: missing,
|
|
91570
|
+
unresolved_child_refs: unresolvedChildRefs,
|
|
91571
|
+
submitted_node_type: "domain",
|
|
91572
|
+
auto_downgrade: false
|
|
91573
|
+
}
|
|
91574
|
+
});
|
|
91575
|
+
}
|
|
91576
|
+
const canonicalChildRefs = childRefs.map((ref) => input.refs.get(ref) ?? ref);
|
|
91577
|
+
const duplicateChildRef = canonicalChildRefs.find((ref, refIndex) => canonicalChildRefs.indexOf(ref) !== refIndex);
|
|
91578
|
+
if (duplicateChildRef !== undefined) {
|
|
91579
|
+
reject(`nodes[${input.nodeIndex}].domain_gate.child_refs`, `domain_gate.child_refs contains duplicate child "${duplicateChildRef}"`, {
|
|
91580
|
+
reasonCode: "duplicate-domain-child-ref",
|
|
91581
|
+
failedRef: duplicateChildRef,
|
|
91582
|
+
availableNodeRefs: nodeRefsForHint(input.refs),
|
|
91583
|
+
availableNodeSlugs: [...input.allSlugs]
|
|
91584
|
+
});
|
|
91585
|
+
}
|
|
91586
|
+
return {
|
|
91587
|
+
...input.node,
|
|
91588
|
+
domain_gate: {
|
|
91589
|
+
...gate,
|
|
91590
|
+
child_refs: canonicalChildRefs
|
|
91591
|
+
}
|
|
91592
|
+
};
|
|
91593
|
+
}
|
|
91594
|
+
function validateActionGate(node3, nodeIndex) {
|
|
91595
|
+
if (node3.action_probe?.has_steps_or_phases !== true) {
|
|
91596
|
+
reject(`nodes[${nodeIndex}].action_probe.has_steps_or_phases`, "node_type=action requires action_probe.has_steps_or_phases=true; CLI does not auto-downgrade invalid Action nodes to entity", {
|
|
91597
|
+
hintCode: "align-action-gate-invalid",
|
|
91598
|
+
reasonCode: "align-action-gate-invalid",
|
|
91599
|
+
schemaLookup: "context schema align-structure-intent --view minimal --format json",
|
|
91600
|
+
repairOptions: gateRepairOptions("action"),
|
|
91601
|
+
diagnostics: {
|
|
91602
|
+
missing_or_invalid: ["action_probe.has_steps_or_phases"],
|
|
91603
|
+
submitted_node_type: "action",
|
|
91604
|
+
auto_downgrade: false
|
|
91605
|
+
}
|
|
91606
|
+
});
|
|
91607
|
+
}
|
|
91608
|
+
const gate = node3.action_gate;
|
|
91609
|
+
if (gate === undefined) {
|
|
91610
|
+
reject(`nodes[${nodeIndex}].action_gate`, "node_type=action requires action_gate.inference_sources; CLI does not auto-downgrade invalid Action nodes to entity", {
|
|
91611
|
+
hintCode: "align-action-gate-invalid",
|
|
91612
|
+
reasonCode: "align-action-gate-invalid",
|
|
91613
|
+
schemaLookup: "context schema align-structure-intent --view minimal --format json",
|
|
91614
|
+
repairOptions: gateRepairOptions("action"),
|
|
91615
|
+
diagnostics: {
|
|
91616
|
+
missing_or_invalid: ["action_gate.inference_sources"],
|
|
91617
|
+
submitted_node_type: "action",
|
|
91618
|
+
auto_downgrade: false
|
|
91619
|
+
}
|
|
91620
|
+
});
|
|
91621
|
+
}
|
|
91622
|
+
validateInferenceSources(gate, `nodes[${nodeIndex}].action_gate`);
|
|
91623
|
+
}
|
|
90961
91624
|
function normalizeNodes(nodes, refs, allSlugs, previousTypes) {
|
|
90962
91625
|
const warnings = [];
|
|
90963
91626
|
const normalized = nodes.map((node3, index2) => {
|
|
@@ -90974,46 +91637,10 @@ function normalizeNodes(nodes, refs, allSlugs, previousTypes) {
|
|
|
90974
91637
|
});
|
|
90975
91638
|
}
|
|
90976
91639
|
if (next.node_type === "domain") {
|
|
90977
|
-
|
|
90978
|
-
const rawChildRefs = Array.isArray(gate?.child_refs) ? gate.child_refs : undefined;
|
|
90979
|
-
const childRefs = rawChildRefs?.map((ref) => typeof ref === "string" ? ref.trim() : "") ?? [];
|
|
90980
|
-
const validGate = gate !== undefined && Array.isArray(gate.scope_blocks) && rawChildRefs !== undefined && typeof gate.grouping_reason === "string" && childRefs.length === rawChildRefs.length && childRefs.every((ref) => ref.length > 0 && (refs.has(ref) || allSlugs.has(ref)));
|
|
90981
|
-
if (!validGate) {
|
|
90982
|
-
const downgraded = downgradeNode(next, "domain_downgrade", "domain_gate is missing or references unresolved child refs");
|
|
90983
|
-
next = downgraded.node;
|
|
90984
|
-
warnings.push(downgraded.warning);
|
|
90985
|
-
} else {
|
|
90986
|
-
const canonicalChildRefs = childRefs.map((ref) => refs.get(ref) ?? ref);
|
|
90987
|
-
const duplicateChildRef = canonicalChildRefs.find((ref, refIndex) => canonicalChildRefs.indexOf(ref) !== refIndex);
|
|
90988
|
-
if (duplicateChildRef !== undefined) {
|
|
90989
|
-
reject(`nodes[${index2}].domain_gate.child_refs`, `domain_gate.child_refs contains duplicate child "${duplicateChildRef}"`, {
|
|
90990
|
-
reasonCode: "duplicate-domain-child-ref",
|
|
90991
|
-
failedRef: duplicateChildRef,
|
|
90992
|
-
availableNodeRefs: nodeRefsForHint(refs),
|
|
90993
|
-
availableNodeSlugs: [...allSlugs]
|
|
90994
|
-
});
|
|
90995
|
-
}
|
|
90996
|
-
next = {
|
|
90997
|
-
...next,
|
|
90998
|
-
domain_gate: {
|
|
90999
|
-
...gate,
|
|
91000
|
-
child_refs: canonicalChildRefs
|
|
91001
|
-
}
|
|
91002
|
-
};
|
|
91003
|
-
}
|
|
91640
|
+
next = normalizeDomainGate({ node: next, nodeIndex: index2, refs, allSlugs });
|
|
91004
91641
|
}
|
|
91005
91642
|
if (next.node_type === "action") {
|
|
91006
|
-
|
|
91007
|
-
if (reason !== null) {
|
|
91008
|
-
const downgraded = downgradeNode(next, "action_downgrade", reason);
|
|
91009
|
-
next = downgraded.node;
|
|
91010
|
-
warnings.push(downgraded.warning);
|
|
91011
|
-
} else {
|
|
91012
|
-
const gate = next.action_gate;
|
|
91013
|
-
if (gate === undefined)
|
|
91014
|
-
reject(`nodes[${index2}].action_gate`, "action_gate is required");
|
|
91015
|
-
validateInferenceSources(gate, `nodes[${index2}].action_gate`);
|
|
91016
|
-
}
|
|
91643
|
+
validateActionGate(next, index2);
|
|
91017
91644
|
}
|
|
91018
91645
|
const previousType = previousTypes.get(next.slug);
|
|
91019
91646
|
if (previousType !== undefined && previousType !== next.node_type) {
|
|
@@ -91093,7 +91720,7 @@ function normalizeSections(value, refs, currentSlugs) {
|
|
|
91093
91720
|
return value.map((raw, index2) => {
|
|
91094
91721
|
if (!isRecord18(raw))
|
|
91095
91722
|
reject(`sections[${index2}]`, "section must be an object");
|
|
91096
|
-
const rawOwner =
|
|
91723
|
+
const rawOwner = stringValue2(raw.owner);
|
|
91097
91724
|
if (rawOwner === undefined)
|
|
91098
91725
|
reject(`sections[${index2}].owner`, `sections[${index2}].owner is required`);
|
|
91099
91726
|
const owner = refs.get(rawOwner);
|
|
@@ -91112,9 +91739,9 @@ function normalizeSections(value, refs, currentSlugs) {
|
|
|
91112
91739
|
availableNodeSlugs: [...currentSlugs]
|
|
91113
91740
|
});
|
|
91114
91741
|
}
|
|
91115
|
-
const rationale =
|
|
91742
|
+
const rationale = stringValue2(raw.rationale);
|
|
91116
91743
|
return {
|
|
91117
|
-
section_id:
|
|
91744
|
+
section_id: stringValue2(raw.section_id) ?? `planned_section_${index2 + 1}`,
|
|
91118
91745
|
owner,
|
|
91119
91746
|
section_kind: raw.section_kind,
|
|
91120
91747
|
block_ids: stringArray2(raw.block_ids),
|
|
@@ -91132,8 +91759,8 @@ function normalizeEdges(value, refs, slugs) {
|
|
|
91132
91759
|
if (raw.edge_type !== "depends_on" && raw.type !== "depends_on") {
|
|
91133
91760
|
rejectLegacy(`edges[${index2}].edge_type`, `document edge type must be depends_on; allowed runtime EdgeType values are ${EDGE_TYPES.join("|")}`);
|
|
91134
91761
|
}
|
|
91135
|
-
const from = resolveRef2(refs,
|
|
91136
|
-
const to = resolveRef2(refs,
|
|
91762
|
+
const from = resolveRef2(refs, stringValue2(raw.from_ref) ?? stringValue2(raw.from), `edges[${index2}].from_ref`);
|
|
91763
|
+
const to = resolveRef2(refs, stringValue2(raw.to_ref) ?? stringValue2(raw.to), `edges[${index2}].to_ref`);
|
|
91137
91764
|
if (!from || !to || !slugs.has(from) || !slugs.has(to)) {
|
|
91138
91765
|
reject(`edges[${index2}]`, "edge endpoints must reference finalized nodes", {
|
|
91139
91766
|
reasonCode: "unknown-edge-endpoint",
|
|
@@ -91141,10 +91768,10 @@ function normalizeEdges(value, refs, slugs) {
|
|
|
91141
91768
|
availableNodeSlugs: [...slugs]
|
|
91142
91769
|
});
|
|
91143
91770
|
}
|
|
91144
|
-
const fromRef =
|
|
91145
|
-
const toRef =
|
|
91146
|
-
const confidence =
|
|
91147
|
-
const rationale =
|
|
91771
|
+
const fromRef = stringValue2(raw.from_ref);
|
|
91772
|
+
const toRef = stringValue2(raw.to_ref);
|
|
91773
|
+
const confidence = stringValue2(raw.confidence);
|
|
91774
|
+
const rationale = stringValue2(raw.rationale);
|
|
91148
91775
|
return {
|
|
91149
91776
|
edge_type: "depends_on",
|
|
91150
91777
|
from,
|
|
@@ -91243,7 +91870,7 @@ function normalizeAlignStructureDecision(input) {
|
|
|
91243
91870
|
});
|
|
91244
91871
|
const unresolved = normalizeUnresolved(input.payload.unresolved);
|
|
91245
91872
|
validateUnresolvedQuestions({ blockOwnership, unresolved, reject });
|
|
91246
|
-
const artifactKind =
|
|
91873
|
+
const artifactKind = stringValue2(input.payload.artifact_kind);
|
|
91247
91874
|
const auditWarnings = Array.isArray(input.payload.audit_warnings) ? input.payload.audit_warnings.filter((warning) => isRecord18(warning) && typeof warning.kind === "string" && typeof warning.reason === "string") : [];
|
|
91248
91875
|
return {
|
|
91249
91876
|
schema_version: ALIGN_STRUCTURE_DECISION_SCHEMA_VERSION,
|
|
@@ -91276,16 +91903,16 @@ var CITABLE_OWNERSHIP_ROLES = new Set(["owned", "shared"]);
|
|
|
91276
91903
|
function isRecord40(value) {
|
|
91277
91904
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
91278
91905
|
}
|
|
91279
|
-
function
|
|
91906
|
+
function stringValue6(value) {
|
|
91280
91907
|
return typeof value === "string" && value.trim().length > 0 ? value.trim() : undefined;
|
|
91281
91908
|
}
|
|
91282
91909
|
function stringArray6(value) {
|
|
91283
91910
|
return Array.isArray(value) ? value.filter((item) => typeof item === "string" && item.trim().length > 0).map((item) => item.trim()) : [];
|
|
91284
91911
|
}
|
|
91285
91912
|
function normalizedNodeSlug(rawNode) {
|
|
91286
|
-
const rawSlug =
|
|
91287
|
-
const rawHint =
|
|
91288
|
-
const slugBase = rawSlug ?? (rawHint !== undefined ? rawHint.replace(/^local:/u, "") : undefined) ??
|
|
91913
|
+
const rawSlug = stringValue6(rawNode.slug);
|
|
91914
|
+
const rawHint = stringValue6(rawNode.llm_slug_hint);
|
|
91915
|
+
const slugBase = rawSlug ?? (rawHint !== undefined ? rawHint.replace(/^local:/u, "") : undefined) ?? stringValue6(rawNode.title);
|
|
91289
91916
|
if (slugBase === undefined)
|
|
91290
91917
|
return;
|
|
91291
91918
|
const slug = rawSlug !== undefined ? rawSlug.split("/").map((part) => slugify(part)).filter(Boolean).join("/") : slugify(slugBase);
|
|
@@ -91314,7 +91941,7 @@ function nodeReferenceIndex(rawDecision, context) {
|
|
|
91314
91941
|
continue;
|
|
91315
91942
|
slugs.add(slug);
|
|
91316
91943
|
setRef2(slug, slug);
|
|
91317
|
-
setRef2(
|
|
91944
|
+
setRef2(stringValue6(rawNode.llm_slug_hint), slug);
|
|
91318
91945
|
}
|
|
91319
91946
|
return { refs, slugs };
|
|
91320
91947
|
}
|
|
@@ -91389,8 +92016,8 @@ function ownershipRolesByBlock(rawDecision, context) {
|
|
|
91389
92016
|
for (const raw of ownershipInput) {
|
|
91390
92017
|
if (!isRecord40(raw))
|
|
91391
92018
|
continue;
|
|
91392
|
-
const blockId =
|
|
91393
|
-
const role =
|
|
92019
|
+
const blockId = stringValue6(raw.block_id);
|
|
92020
|
+
const role = stringValue6(raw.ownership_role);
|
|
91394
92021
|
if (blockId !== undefined && role !== undefined && ["owned", "shared", "context_only", "ignored", "unresolved"].includes(role)) {
|
|
91395
92022
|
roles.set(blockId, role);
|
|
91396
92023
|
}
|
|
@@ -91422,7 +92049,7 @@ function collectSectionIssues(rawDecision, context, issues, ownershipRoles) {
|
|
|
91422
92049
|
issues.push({
|
|
91423
92050
|
path: `sections[${index2}].block_ids`,
|
|
91424
92051
|
reason_code: "non-coverable-block",
|
|
91425
|
-
message: `section "${
|
|
92052
|
+
message: `section "${stringValue6(rawSection.section_id) ?? index2}" includes non-coverable block_ids`,
|
|
91426
92053
|
diagnostics: citationEligibilityDiagnostics(blockIds, context.segments, citationEligible)
|
|
91427
92054
|
});
|
|
91428
92055
|
return;
|
|
@@ -91431,7 +92058,7 @@ function collectSectionIssues(rawDecision, context, issues, ownershipRoles) {
|
|
|
91431
92058
|
issues.push({
|
|
91432
92059
|
path: `sections[${index2}].block_ids`,
|
|
91433
92060
|
reason_code: nonCitable.length === blockIds.length ? "section-plan-no-citable-blocks" : "section-plan-non-citable-blocks",
|
|
91434
|
-
message: nonCitable.length === blockIds.length ? `section "${
|
|
92061
|
+
message: nonCitable.length === blockIds.length ? `section "${stringValue6(rawSection.section_id) ?? index2}" has no citation-eligible block_ids after excluding supporting context` : `section "${stringValue6(rawSection.section_id) ?? index2}" includes supporting-context block_ids that cannot support citations`,
|
|
91435
92062
|
diagnostics: citationEligibilityDiagnostics(blockIds, context.segments, citationEligible)
|
|
91436
92063
|
});
|
|
91437
92064
|
return;
|
|
@@ -91444,8 +92071,8 @@ function collectOwnershipIssues(rawDecision, context, issues, nodeRefs) {
|
|
|
91444
92071
|
ownership.forEach((raw, index2) => {
|
|
91445
92072
|
if (!isRecord40(raw))
|
|
91446
92073
|
return;
|
|
91447
|
-
const blockId =
|
|
91448
|
-
const role =
|
|
92074
|
+
const blockId = stringValue6(raw.block_id);
|
|
92075
|
+
const role = stringValue6(raw.ownership_role);
|
|
91449
92076
|
if (blockId !== undefined && !coverable.has(blockId)) {
|
|
91450
92077
|
issues.push({
|
|
91451
92078
|
path: `block_ownership[${index2}].block_id`,
|
|
@@ -91483,7 +92110,7 @@ function collectSupplementalIssues(rawDecision, context) {
|
|
|
91483
92110
|
for (const [index2, rawNode] of (Array.isArray(rawDecision.nodes) ? rawDecision.nodes : []).entries()) {
|
|
91484
92111
|
if (!isRecord40(rawNode))
|
|
91485
92112
|
continue;
|
|
91486
|
-
const nodeType =
|
|
92113
|
+
const nodeType = stringValue6(rawNode.node_type);
|
|
91487
92114
|
if (nodeType !== undefined && NODE_TYPES.includes(nodeType) && Array.isArray(rawNode.planned_sections)) {
|
|
91488
92115
|
for (const kind of stringArray6(rawNode.planned_sections)) {
|
|
91489
92116
|
if (!isSectionKindMountable(nodeType, kind)) {
|
|
@@ -91515,17 +92142,17 @@ function isAlignStructureIntentPayload(value) {
|
|
|
91515
92142
|
return isRecord18(value) && value.schema_version === ALIGN_STRUCTURE_INTENT_SCHEMA_VERSION;
|
|
91516
92143
|
}
|
|
91517
92144
|
function stableNodeSlug(raw) {
|
|
91518
|
-
const rawSlug =
|
|
92145
|
+
const rawSlug = stringValue2(raw.slug);
|
|
91519
92146
|
if (rawSlug !== undefined)
|
|
91520
92147
|
return rawSlug.split("/").map((part) => slugify(part)).filter(Boolean).join("/");
|
|
91521
|
-
const hint =
|
|
92148
|
+
const hint = stringValue2(raw.llm_slug_hint);
|
|
91522
92149
|
if (hint !== undefined)
|
|
91523
92150
|
return slugify(hint.replace(/^local:/u, ""));
|
|
91524
|
-
const title =
|
|
92151
|
+
const title = stringValue2(raw.title);
|
|
91525
92152
|
return title !== undefined ? slugify(title) : undefined;
|
|
91526
92153
|
}
|
|
91527
92154
|
function nodeRefs(raw) {
|
|
91528
|
-
return [stableNodeSlug(raw),
|
|
92155
|
+
return [stableNodeSlug(raw), stringValue2(raw.slug), stringValue2(raw.llm_slug_hint)].filter((value) => value !== undefined && value.length > 0);
|
|
91529
92156
|
}
|
|
91530
92157
|
function distinctStrings(values2) {
|
|
91531
92158
|
const seen = new Set;
|
|
@@ -91602,8 +92229,8 @@ function compileSections(input) {
|
|
|
91602
92229
|
});
|
|
91603
92230
|
}
|
|
91604
92231
|
}
|
|
91605
|
-
const owner =
|
|
91606
|
-
const kind =
|
|
92232
|
+
const owner = stringValue2(group.owner);
|
|
92233
|
+
const kind = stringValue2(group.section_kind);
|
|
91607
92234
|
if (owner !== undefined && kind !== undefined) {
|
|
91608
92235
|
const existing = sectionsByOwner.get(owner) ?? [];
|
|
91609
92236
|
existing.push(kind);
|
|
@@ -91628,7 +92255,7 @@ function compileSections(input) {
|
|
|
91628
92255
|
section_kind: kind,
|
|
91629
92256
|
block_ids: blockIds,
|
|
91630
92257
|
...Array.isArray(group.refers_to_nodes) ? { refers_to_nodes: distinctStrings(stringArray2(group.refers_to_nodes)) } : {},
|
|
91631
|
-
...
|
|
92258
|
+
...stringValue2(group.rationale) !== undefined ? { rationale: stringValue2(group.rationale) } : {}
|
|
91632
92259
|
};
|
|
91633
92260
|
});
|
|
91634
92261
|
const nodes = rawNodes.map((node3, index2) => {
|
|
@@ -91690,7 +92317,7 @@ function throwIntentIssues(issues) {
|
|
|
91690
92317
|
throwStructureIssues(issues.map(withIntentIssueContext));
|
|
91691
92318
|
}
|
|
91692
92319
|
function roleOf(record, block, applyDefaultDemotion = false) {
|
|
91693
|
-
const role =
|
|
92320
|
+
const role = stringValue2(record?.ownership_role);
|
|
91694
92321
|
if (applyDefaultDemotion && (role === "owned" || role === "shared") && block !== undefined) {
|
|
91695
92322
|
return defaultOwnershipRoleForStructuralRole(block.structural_role) ?? role;
|
|
91696
92323
|
}
|
|
@@ -91713,6 +92340,7 @@ function compileOwnership(input) {
|
|
|
91713
92340
|
}
|
|
91714
92341
|
const sourceDefaults = new Map;
|
|
91715
92342
|
const groupExplicit = new Map;
|
|
92343
|
+
const ownershipNoopGroups = [];
|
|
91716
92344
|
groups.forEach((group, index2) => {
|
|
91717
92345
|
const scope = isRecord18(group.scope) ? group.scope : undefined;
|
|
91718
92346
|
if (scope === undefined) {
|
|
@@ -91724,8 +92352,8 @@ function compileOwnership(input) {
|
|
|
91724
92352
|
return;
|
|
91725
92353
|
}
|
|
91726
92354
|
const blockIds = stringArray2(scope.block_ids);
|
|
91727
|
-
const sourceId =
|
|
91728
|
-
const structuralRole =
|
|
92355
|
+
const sourceId = stringValue2(scope.source_id);
|
|
92356
|
+
const structuralRole = stringValue2(scope.structural_role);
|
|
91729
92357
|
const hasBlockIds = blockIds.length > 0;
|
|
91730
92358
|
const sourceOnly = sourceId !== undefined && structuralRole === undefined && !hasBlockIds;
|
|
91731
92359
|
const sourceRole = sourceId !== undefined && structuralRole !== undefined && !hasBlockIds;
|
|
@@ -91764,6 +92392,17 @@ function compileOwnership(input) {
|
|
|
91764
92392
|
}
|
|
91765
92393
|
const selected = explicitBlocks ? blockIds.map((blockId) => blockById2.get(blockId)).filter((block) => block !== undefined) : (blocksBySource.get(sourceId) ?? []).filter((block) => block.structural_role === structuralRole);
|
|
91766
92394
|
if (selected.length === 0) {
|
|
92395
|
+
if (sourceRole && defaultOwnershipRoleForStructuralRole(structuralRole) !== undefined) {
|
|
92396
|
+
ownershipNoopGroups.push({
|
|
92397
|
+
index: index2,
|
|
92398
|
+
source_id: sourceId,
|
|
92399
|
+
structural_role: structuralRole,
|
|
92400
|
+
reason_code: "align-intent-ownership-scope-redundant",
|
|
92401
|
+
message: "No matching coverable blocks remain for this structural role; the source-wide default/automatic ownership policy already handles this non-content role when present.",
|
|
92402
|
+
next_action: "Remove this ownership_groups[] entry unless you need an explicit block_ownership[] override for a specific block."
|
|
92403
|
+
});
|
|
92404
|
+
return;
|
|
92405
|
+
}
|
|
91767
92406
|
input.issues.push({
|
|
91768
92407
|
path: `ownership_groups[${index2}].scope`,
|
|
91769
92408
|
message: "ownership group scope matched no coverable blocks",
|
|
@@ -91812,7 +92451,7 @@ function compileOwnership(input) {
|
|
|
91812
92451
|
finalRoles.set(blockId, roleOf(entry.record, block));
|
|
91813
92452
|
}
|
|
91814
92453
|
for (const patch of explicitPatches) {
|
|
91815
|
-
const blockId =
|
|
92454
|
+
const blockId = stringValue2(patch.block_id);
|
|
91816
92455
|
if (blockId !== undefined)
|
|
91817
92456
|
finalRoles.set(blockId, roleOf(patch, blockById2.get(blockId)));
|
|
91818
92457
|
}
|
|
@@ -91820,6 +92459,7 @@ function compileOwnership(input) {
|
|
|
91820
92459
|
blockOwnershipDefaults: defaults,
|
|
91821
92460
|
blockOwnership: [...groupExplicitRows, ...explicitPatches],
|
|
91822
92461
|
ownershipGroupCount: groups.length,
|
|
92462
|
+
ownershipNoopGroups,
|
|
91823
92463
|
finalRoles
|
|
91824
92464
|
};
|
|
91825
92465
|
}
|
|
@@ -91934,8 +92574,327 @@ function compileAlignStructureIntent(input) {
|
|
|
91934
92574
|
section_groups: sections.sectionGroupCount,
|
|
91935
92575
|
ownership_groups: ownership.ownershipGroupCount,
|
|
91936
92576
|
ownership_defaults: ownership.blockOwnershipDefaults.length,
|
|
91937
|
-
ownership_exceptions: ownership.blockOwnership.length
|
|
92577
|
+
ownership_exceptions: ownership.blockOwnership.length,
|
|
92578
|
+
...ownership.ownershipNoopGroups.length > 0 ? { ownership_noop_groups: ownership.ownershipNoopGroups } : {}
|
|
92579
|
+
}
|
|
92580
|
+
};
|
|
92581
|
+
}
|
|
92582
|
+
// src/commands/workflowAlignEnvelope.ts
|
|
92583
|
+
init_currentWorkflow();
|
|
92584
|
+
init_nextActionEnvelope();
|
|
92585
|
+
var ALIGN_FINALIZE_COMMAND = "context align finalize --input - --format json";
|
|
92586
|
+
var ALIGN_VALIDATE_COMMAND2 = "context align validate --input - --format json";
|
|
92587
|
+
var ALIGN_COARSE_READ_COMMAND2 = "context align coarse-read --input - --format json";
|
|
92588
|
+
var ALIGN_CANDIDATE_OPS_COMMAND = "context align ops --input - --format json";
|
|
92589
|
+
var ALIGN_RESCAN_COMMAND = "context align scan --format json";
|
|
92590
|
+
var COMPILE_SCAN_COMMAND2 = "context compile scan --format json";
|
|
92591
|
+
var ALIGN_READ_PLAN_COMMAND = "context workflow show --payload align-segments --view read-plan --unwrap --format json";
|
|
92592
|
+
var ALIGN_SOURCE_BUNDLE_COMMAND = "context workflow show --payload align-segments --view source-bundle --unwrap --format text";
|
|
92593
|
+
function alignWorkflowEnvelopeContext(state, digest2) {
|
|
92594
|
+
return {
|
|
92595
|
+
id: state.workflow_id,
|
|
92596
|
+
workflow_id: state.workflow_id,
|
|
92597
|
+
family: state.family,
|
|
92598
|
+
stage: state.stage,
|
|
92599
|
+
terminal: state.stage === "finalized" || state.stage === "closed" || state.stage === "abandoned",
|
|
92600
|
+
scope_id: workflowScope(state),
|
|
92601
|
+
...digest2 !== undefined ? { digest: digest2 } : {}
|
|
92602
|
+
};
|
|
92603
|
+
}
|
|
92604
|
+
function alignRouteId(route) {
|
|
92605
|
+
return route.mode;
|
|
92606
|
+
}
|
|
92607
|
+
function routeReasonBreach(threshold) {
|
|
92608
|
+
if (threshold.value > threshold.recommended_max)
|
|
92609
|
+
return "recommended_max";
|
|
92610
|
+
if (threshold.value > threshold.direct_max)
|
|
92611
|
+
return "direct_max";
|
|
92612
|
+
return;
|
|
92613
|
+
}
|
|
92614
|
+
function routeReason(indicator, threshold) {
|
|
92615
|
+
const breach = routeReasonBreach(threshold);
|
|
92616
|
+
if (breach === undefined)
|
|
92617
|
+
return;
|
|
92618
|
+
return {
|
|
92619
|
+
indicator,
|
|
92620
|
+
value: threshold.value,
|
|
92621
|
+
direct_max: threshold.direct_max,
|
|
92622
|
+
recommended_max: threshold.recommended_max,
|
|
92623
|
+
breach
|
|
92624
|
+
};
|
|
92625
|
+
}
|
|
92626
|
+
function alignRouteSummary(route) {
|
|
92627
|
+
return {
|
|
92628
|
+
id: alignRouteId(route),
|
|
92629
|
+
hard_gate: route.hard_gate,
|
|
92630
|
+
reasons: Object.entries(route.thresholds).map(([indicator, threshold]) => routeReason(indicator, threshold)).filter((reason) => reason !== undefined)
|
|
92631
|
+
};
|
|
92632
|
+
}
|
|
92633
|
+
function alignSegmentsViews() {
|
|
92634
|
+
return [
|
|
92635
|
+
{
|
|
92636
|
+
id: "read-plan",
|
|
92637
|
+
purpose: "Read the compact align reading plan and follow its single next_action command.",
|
|
92638
|
+
evidence_role: "primary",
|
|
92639
|
+
expected: true,
|
|
92640
|
+
budget_safety: "compact",
|
|
92641
|
+
command: ALIGN_READ_PLAN_COMMAND
|
|
92642
|
+
},
|
|
92643
|
+
{
|
|
92644
|
+
id: "source-bundle",
|
|
92645
|
+
purpose: "Read the near-source text bundle only when read-plan recommends it.",
|
|
92646
|
+
evidence_role: "primary",
|
|
92647
|
+
expected: false,
|
|
92648
|
+
budget_safety: "paged",
|
|
92649
|
+
command: ALIGN_SOURCE_BUNDLE_COMMAND
|
|
92650
|
+
},
|
|
92651
|
+
{
|
|
92652
|
+
id: "blocks",
|
|
92653
|
+
purpose: "Drill into paged align block JSON only when read-plan or source-bundle asks for a scoped fallback.",
|
|
92654
|
+
evidence_role: "primary",
|
|
92655
|
+
expected: false,
|
|
92656
|
+
budget_safety: "paged",
|
|
92657
|
+
command: "context workflow show --payload align-segments --view blocks --page-size 10 --token-budget 8000 --unwrap --format json"
|
|
92658
|
+
},
|
|
92659
|
+
{
|
|
92660
|
+
id: "block-index",
|
|
92661
|
+
purpose: "List block ids, ordinals, structural roles, and heading paths without text.",
|
|
92662
|
+
evidence_role: "supporting",
|
|
92663
|
+
expected: false,
|
|
92664
|
+
budget_safety: "compact",
|
|
92665
|
+
command: "context workflow show --payload align-segments --view block-index --unwrap --format json"
|
|
92666
|
+
},
|
|
92667
|
+
{
|
|
92668
|
+
id: "source-mapping",
|
|
92669
|
+
purpose: "Inspect source to block mapping without full block text.",
|
|
92670
|
+
evidence_role: "supporting",
|
|
92671
|
+
expected: false,
|
|
92672
|
+
budget_safety: "compact",
|
|
92673
|
+
command: "context workflow show --payload align-segments --view source-mapping --unwrap --format json"
|
|
92674
|
+
},
|
|
92675
|
+
{
|
|
92676
|
+
id: "pending-relation-refs",
|
|
92677
|
+
purpose: "Inspect explicit Parent/Children/Related markdown relation refs before deciding contains_parent or domain child refs.",
|
|
92678
|
+
evidence_role: "supporting",
|
|
92679
|
+
expected: false,
|
|
92680
|
+
budget_safety: "compact",
|
|
92681
|
+
command: "context workflow show --payload align-segments --view pending-relation-refs --unwrap --format json"
|
|
92682
|
+
},
|
|
92683
|
+
{
|
|
92684
|
+
id: "windows",
|
|
92685
|
+
purpose: "Page source windows to choose narrower block reads for large sources.",
|
|
92686
|
+
evidence_role: "supporting",
|
|
92687
|
+
expected: false,
|
|
92688
|
+
budget_safety: "paged",
|
|
92689
|
+
command: "context workflow show --payload align-segments --view windows --page-size 10 --compact-hints --unwrap --format json"
|
|
92690
|
+
},
|
|
92691
|
+
{
|
|
92692
|
+
id: "segment",
|
|
92693
|
+
purpose: "Read compact align segment summary and route metadata.",
|
|
92694
|
+
evidence_role: "diagnostic",
|
|
92695
|
+
expected: false,
|
|
92696
|
+
budget_safety: "compact",
|
|
92697
|
+
command: "context workflow show --payload align-segments --view segment --unwrap --format json"
|
|
91938
92698
|
}
|
|
92699
|
+
];
|
|
92700
|
+
}
|
|
92701
|
+
function alignInspectCommands() {
|
|
92702
|
+
return {
|
|
92703
|
+
read_plan: ALIGN_READ_PLAN_COMMAND,
|
|
92704
|
+
summary: "context workflow show --payload align-segments --view segment --unwrap --format json",
|
|
92705
|
+
pending_relation_refs: "context workflow show --payload align-segments --view pending-relation-refs --unwrap --format json"
|
|
92706
|
+
};
|
|
92707
|
+
}
|
|
92708
|
+
function alignInspectCommandTemplates() {
|
|
92709
|
+
return {
|
|
92710
|
+
source_bundle: ALIGN_SOURCE_BUNDLE_COMMAND,
|
|
92711
|
+
source_pending_relation_refs: "context workflow show --payload align-segments --view pending-relation-refs --source <source-id> --unwrap --format json",
|
|
92712
|
+
source_block_index: "context workflow show --payload align-segments --view block-index --source <source-id> --unwrap --format json",
|
|
92713
|
+
heading_block_index: "context workflow show --payload align-segments --view block-index --heading <heading-prefix> --unwrap --format json",
|
|
92714
|
+
source_blocks: "context workflow show --payload align-segments --view blocks --source <source-id> --page-size 10 --token-budget 8000 --unwrap --format json",
|
|
92715
|
+
heading_blocks: "context workflow show --payload align-segments --view blocks --heading <heading-prefix> --page-size 10 --token-budget 8000 --unwrap --format json",
|
|
92716
|
+
block_detail: "context workflow show --payload align-segments --view blocks --window <window-id|src-N:M[,selector...]> --page-size 10 --token-budget 8000 --unwrap --format json"
|
|
92717
|
+
};
|
|
92718
|
+
}
|
|
92719
|
+
function classifyAlignWindow(input) {
|
|
92720
|
+
if (input.tokenEstimate > 8000 || input.blockCount > 30 || input.multiSubsection)
|
|
92721
|
+
return "complex";
|
|
92722
|
+
if (input.tokenEstimate > 3000 || input.blockCount > 12)
|
|
92723
|
+
return "moderate";
|
|
92724
|
+
return "simple";
|
|
92725
|
+
}
|
|
92726
|
+
function readStrategyForComplexity(complexity) {
|
|
92727
|
+
if (complexity === "complex")
|
|
92728
|
+
return "drill_by_window_or_heading_before_deciding_structure";
|
|
92729
|
+
if (complexity === "moderate")
|
|
92730
|
+
return "read_budgeted_blocks_then_expand_selected_windows";
|
|
92731
|
+
return "read_budgeted_blocks_directly";
|
|
92732
|
+
}
|
|
92733
|
+
function alignSourceComplexitySummaries(segments) {
|
|
92734
|
+
const coverableBlockIds = new Set(segments.coverage.coverable_block_ids);
|
|
92735
|
+
return segments.sources.map((source2) => {
|
|
92736
|
+
const coverableBlocks2 = source2.blocks.filter((block) => coverableBlockIds.has(block.block_id));
|
|
92737
|
+
const largestWindowTokens = source2.windows.reduce((max, window2) => Math.max(max, window2.token_estimate), 0);
|
|
92738
|
+
const sourceComplexity = source2.windows.some((window2) => classifyAlignWindow({
|
|
92739
|
+
tokenEstimate: window2.token_estimate,
|
|
92740
|
+
blockCount: window2.block_ids.length,
|
|
92741
|
+
multiSubsection: window2.multi_subsection === true
|
|
92742
|
+
}) === "complex") || source2.windows.length > 6 || coverableBlocks2.length > 50 ? "complex" : source2.windows.some((window2) => classifyAlignWindow({
|
|
92743
|
+
tokenEstimate: window2.token_estimate,
|
|
92744
|
+
blockCount: window2.block_ids.length,
|
|
92745
|
+
multiSubsection: window2.multi_subsection === true
|
|
92746
|
+
}) === "moderate") || source2.windows.length > 3 || coverableBlocks2.length > 20 ? "moderate" : "simple";
|
|
92747
|
+
return {
|
|
92748
|
+
source_id: source2.source_id,
|
|
92749
|
+
block_count: source2.blocks.length,
|
|
92750
|
+
coverable_block_count: coverableBlocks2.length,
|
|
92751
|
+
window_count: source2.windows.length,
|
|
92752
|
+
total_tokens: source2.total_tokens,
|
|
92753
|
+
largest_window_tokens: largestWindowTokens,
|
|
92754
|
+
complexity_class: sourceComplexity,
|
|
92755
|
+
suggested_read_strategy: readStrategyForComplexity(sourceComplexity),
|
|
92756
|
+
windows: source2.windows.map((window2) => {
|
|
92757
|
+
const complexity = classifyAlignWindow({
|
|
92758
|
+
tokenEstimate: window2.token_estimate,
|
|
92759
|
+
blockCount: window2.block_ids.length,
|
|
92760
|
+
multiSubsection: window2.multi_subsection === true
|
|
92761
|
+
});
|
|
92762
|
+
return {
|
|
92763
|
+
window_id: window2.window_id,
|
|
92764
|
+
block_count: window2.block_ids.length,
|
|
92765
|
+
token_estimate: window2.token_estimate,
|
|
92766
|
+
line_start: window2.line_start,
|
|
92767
|
+
line_end: window2.line_end,
|
|
92768
|
+
heading_path: window2.heading_path,
|
|
92769
|
+
complexity_class: complexity,
|
|
92770
|
+
suggested_read_strategy: readStrategyForComplexity(complexity)
|
|
92771
|
+
};
|
|
92772
|
+
})
|
|
92773
|
+
};
|
|
92774
|
+
});
|
|
92775
|
+
}
|
|
92776
|
+
function pendingRelationRefsCount2(segments) {
|
|
92777
|
+
return segments.sources.reduce((sum, source2) => sum + (source2.pending_relation_refs?.length ?? 0), 0);
|
|
92778
|
+
}
|
|
92779
|
+
function alignComplexityDiagnostics(input) {
|
|
92780
|
+
const automaticOwnershipAdjustments = automaticOwnershipAdjustmentCandidates(input.segments);
|
|
92781
|
+
const relationRefsCount = pendingRelationRefsCount2(input.segments);
|
|
92782
|
+
return {
|
|
92783
|
+
summary: {
|
|
92784
|
+
route_mode: input.route.mode,
|
|
92785
|
+
complexity: input.route.complexity,
|
|
92786
|
+
source_count: input.route.thresholds.source_count.value,
|
|
92787
|
+
coverable_block_count: input.route.thresholds.coverable_block_count.value,
|
|
92788
|
+
estimated_coverable_tokens: input.route.thresholds.estimated_coverable_tokens.value,
|
|
92789
|
+
largest_window_tokens: input.route.thresholds.largest_window_tokens.value,
|
|
92790
|
+
estimated_response_chars: input.route.thresholds.estimated_response_chars.value,
|
|
92791
|
+
windows: input.segments.sources.reduce((sum, source2) => sum + source2.windows.length, 0),
|
|
92792
|
+
structural_changes: input.structuralChanges,
|
|
92793
|
+
content_only_changes: input.contentOnlyChanges,
|
|
92794
|
+
...relationRefsCount > 0 ? { pending_relation_refs: relationRefsCount } : {}
|
|
92795
|
+
},
|
|
92796
|
+
...relationRefsCount > 0 ? {
|
|
92797
|
+
warnings: [{
|
|
92798
|
+
code: "align-pending-relation-refs",
|
|
92799
|
+
severity: "info",
|
|
92800
|
+
message: `${relationRefsCount} explicit Parent/Children/Related markdown relation ref(s) were detected.`,
|
|
92801
|
+
detail_view_command: "context workflow show --payload align-segments --view pending-relation-refs --unwrap --format json"
|
|
92802
|
+
}]
|
|
92803
|
+
} : {},
|
|
92804
|
+
automatic_ownership_adjustments: compactAutomaticOwnershipAdjustments(automaticOwnershipAdjustments, {
|
|
92805
|
+
...input.automaticOwnershipDetailCommand !== undefined ? { detailCommand: input.automaticOwnershipDetailCommand } : {}
|
|
92806
|
+
})
|
|
92807
|
+
};
|
|
92808
|
+
}
|
|
92809
|
+
function alignNextActionForRoute(input) {
|
|
92810
|
+
if (input.hasWork) {
|
|
92811
|
+
return {
|
|
92812
|
+
kind: "show_view",
|
|
92813
|
+
command: ALIGN_READ_PLAN_COMMAND,
|
|
92814
|
+
reason_code: `${input.route.mode}-read-plan`,
|
|
92815
|
+
blocking: true
|
|
92816
|
+
};
|
|
92817
|
+
}
|
|
92818
|
+
if (input.contentOnlyChanges > 0) {
|
|
92819
|
+
return {
|
|
92820
|
+
kind: "start_compile_scan",
|
|
92821
|
+
command: COMPILE_SCAN_COMMAND2,
|
|
92822
|
+
reason_code: "align-content-only-changes"
|
|
92823
|
+
};
|
|
92824
|
+
}
|
|
92825
|
+
return {
|
|
92826
|
+
kind: "stop_noop",
|
|
92827
|
+
reason_code: "align-no-structural-work"
|
|
92828
|
+
};
|
|
92829
|
+
}
|
|
92830
|
+
function alignAllowedActionsForNextAction(nextAction) {
|
|
92831
|
+
if (nextAction.kind === "show_view")
|
|
92832
|
+
return ["show_view"];
|
|
92833
|
+
if (nextAction.kind === "submit_structure_decision")
|
|
92834
|
+
return ["show_view", "submit_structure_decision"];
|
|
92835
|
+
if (nextAction.kind === "validate_align_decision")
|
|
92836
|
+
return ["show_view", "validate_align_decision"];
|
|
92837
|
+
if (nextAction.kind === "submit_coarse_read")
|
|
92838
|
+
return ["show_view", "submit_coarse_read"];
|
|
92839
|
+
if (nextAction.kind === "submit_candidate_ops")
|
|
92840
|
+
return ["show_view", "submit_candidate_ops"];
|
|
92841
|
+
if (nextAction.kind === "abandon_or_rescan")
|
|
92842
|
+
return ["show_view", "abandon", "rescan"];
|
|
92843
|
+
if (nextAction.kind === "start_compile_scan")
|
|
92844
|
+
return ["show_view"];
|
|
92845
|
+
return;
|
|
92846
|
+
}
|
|
92847
|
+
function createAlignRouteEnvelope(input) {
|
|
92848
|
+
const allowedActions = alignAllowedActionsForNextAction(input.nextAction);
|
|
92849
|
+
const views = input.nextAction.kind === "stop_noop" || input.nextAction.kind === "start_compile_scan" ? undefined : alignSegmentsViews();
|
|
92850
|
+
return createNextActionEnvelope({
|
|
92851
|
+
workflow: alignWorkflowEnvelopeContext(input.workflowState),
|
|
92852
|
+
route: alignRouteSummary(input.route),
|
|
92853
|
+
...allowedActions !== undefined ? { allowed_actions: allowedActions } : {},
|
|
92854
|
+
next_action: input.nextAction,
|
|
92855
|
+
...views !== undefined ? { views } : {},
|
|
92856
|
+
...input.diagnostics !== undefined ? { diagnostics: input.diagnostics } : {}
|
|
92857
|
+
});
|
|
92858
|
+
}
|
|
92859
|
+
function alignDirectFinalizeNextAction(reasonCode = "align-route-direct-finalize", inputSchema = "align-structure-intent") {
|
|
92860
|
+
return {
|
|
92861
|
+
kind: "submit_structure_decision",
|
|
92862
|
+
command: ALIGN_FINALIZE_COMMAND,
|
|
92863
|
+
input_schema: inputSchema,
|
|
92864
|
+
reason_code: reasonCode,
|
|
92865
|
+
blocking: true
|
|
92866
|
+
};
|
|
92867
|
+
}
|
|
92868
|
+
function alignValidateNextAction(reasonCode = "align-validate-repair-required", inputSchema = "align-structure-intent") {
|
|
92869
|
+
return {
|
|
92870
|
+
kind: "validate_align_decision",
|
|
92871
|
+
command: ALIGN_VALIDATE_COMMAND2,
|
|
92872
|
+
input_schema: inputSchema,
|
|
92873
|
+
reason_code: reasonCode,
|
|
92874
|
+
blocking: true
|
|
92875
|
+
};
|
|
92876
|
+
}
|
|
92877
|
+
function alignBatchedNextAction(kind) {
|
|
92878
|
+
return kind === "submit_candidate_ops" ? {
|
|
92879
|
+
kind,
|
|
92880
|
+
command: ALIGN_CANDIDATE_OPS_COMMAND,
|
|
92881
|
+
input_schema: "align-candidate-ops",
|
|
92882
|
+
reason_code: "align-route-batched-review-required",
|
|
92883
|
+
blocking: true
|
|
92884
|
+
} : {
|
|
92885
|
+
kind,
|
|
92886
|
+
command: ALIGN_COARSE_READ_COMMAND2,
|
|
92887
|
+
input_schema: "align-coarse-read",
|
|
92888
|
+
reason_code: "align-route-batched-review-required",
|
|
92889
|
+
blocking: true
|
|
92890
|
+
};
|
|
92891
|
+
}
|
|
92892
|
+
function alignAbandonOrRescanNextAction(reasonCode) {
|
|
92893
|
+
return {
|
|
92894
|
+
kind: "abandon_or_rescan",
|
|
92895
|
+
command: ALIGN_RESCAN_COMMAND,
|
|
92896
|
+
reason_code: reasonCode,
|
|
92897
|
+
blocking: true
|
|
91939
92898
|
};
|
|
91940
92899
|
}
|
|
91941
92900
|
|
|
@@ -91988,7 +92947,7 @@ function unplannedEvidenceIssues(input) {
|
|
|
91988
92947
|
reason_code: input.inputSchema === "align-structure-intent" ? "align-intent-unplanned-evidence-blocks" : "align-finalize-unplanned-evidence-blocks",
|
|
91989
92948
|
message: `${unplanned.length} owned/shared citation evidence block(s) are not included in any planned Section.`,
|
|
91990
92949
|
diagnostics: {
|
|
91991
|
-
|
|
92950
|
+
target_field: path13,
|
|
91992
92951
|
unplanned_evidence_block_ids: blockIds,
|
|
91993
92952
|
unplanned_evidence_blocks: unplanned.slice(0, 12).map(unplannedEvidenceBlockContext),
|
|
91994
92953
|
unplanned_evidence_blocks_omitted: Math.max(0, unplanned.length - 12),
|
|
@@ -92032,6 +92991,132 @@ function unplannedEvidenceBlockContext(block) {
|
|
|
92032
92991
|
...block.text_preview !== undefined ? { text_preview: block.text_preview } : {}
|
|
92033
92992
|
};
|
|
92034
92993
|
}
|
|
92994
|
+
function sameHeadingPath2(left, right) {
|
|
92995
|
+
return left.length === right.length && left.every((item, index2) => item === right[index2]);
|
|
92996
|
+
}
|
|
92997
|
+
function commonHeadingPrefix(groups) {
|
|
92998
|
+
if (groups.length === 0)
|
|
92999
|
+
return [];
|
|
93000
|
+
const first = groups[0].heading_path;
|
|
93001
|
+
const prefix = [];
|
|
93002
|
+
for (let index2 = 0;index2 < first.length; index2 += 1) {
|
|
93003
|
+
const value = first[index2];
|
|
93004
|
+
if (value === undefined || groups.some((group) => group.heading_path[index2] !== value))
|
|
93005
|
+
break;
|
|
93006
|
+
prefix.push(value);
|
|
93007
|
+
}
|
|
93008
|
+
return prefix;
|
|
93009
|
+
}
|
|
93010
|
+
function splitSectionPlanByHeadingPath(ownership, plan) {
|
|
93011
|
+
const blockById2 = new Map(ownership.sources.flatMap((source2) => source2.blocks.map((block) => [block.block_id, block])));
|
|
93012
|
+
const groups = [];
|
|
93013
|
+
for (const blockId of plan.block_ids) {
|
|
93014
|
+
const block = blockById2.get(blockId);
|
|
93015
|
+
if (block === undefined)
|
|
93016
|
+
continue;
|
|
93017
|
+
const previous3 = groups.at(-1);
|
|
93018
|
+
if (previous3 !== undefined && sameHeadingPath2(previous3.heading_path, block.heading_path)) {
|
|
93019
|
+
previous3.block_ids.push(blockId);
|
|
93020
|
+
if (previous3.line_range !== undefined)
|
|
93021
|
+
previous3.line_range[1] = block.line_end;
|
|
93022
|
+
continue;
|
|
93023
|
+
}
|
|
93024
|
+
groups.push({
|
|
93025
|
+
heading_path: [...block.heading_path],
|
|
93026
|
+
block_ids: [blockId],
|
|
93027
|
+
source_id: block.source_id,
|
|
93028
|
+
line_range: [block.line_start, block.line_end]
|
|
93029
|
+
});
|
|
93030
|
+
}
|
|
93031
|
+
return groups;
|
|
93032
|
+
}
|
|
93033
|
+
function sectionPlanCrossHeadingHints(input) {
|
|
93034
|
+
const spans = (input.ownership.section_plans ?? []).map((plan) => ({ plan, heading_groups: splitSectionPlanByHeadingPath(input.ownership, plan) })).filter((item) => item.heading_groups.length > 1);
|
|
93035
|
+
if (spans.length === 0)
|
|
93036
|
+
return [];
|
|
93037
|
+
const targetField = input.inputSchema === "align-structure-intent" ? "section_groups" : "sections";
|
|
93038
|
+
const classifiedSpans = spans.map((span) => ({
|
|
93039
|
+
...span,
|
|
93040
|
+
shared_heading: commonHeadingPrefix(span.heading_groups)
|
|
93041
|
+
}));
|
|
93042
|
+
const examplesFor = (items, input2) => items.slice(0, 5).map(({ plan, heading_groups: headingGroups, shared_heading: sharedHeading }) => {
|
|
93043
|
+
return {
|
|
93044
|
+
section_id: plan.section_id,
|
|
93045
|
+
owner: plan.owner,
|
|
93046
|
+
section_kind: plan.section_kind,
|
|
93047
|
+
heading_group_count: headingGroups.length,
|
|
93048
|
+
...sharedHeading.length > 0 ? { shared_heading: sharedHeading } : {},
|
|
93049
|
+
heading_groups: headingGroups.map((group) => ({
|
|
93050
|
+
heading_path: group.heading_path,
|
|
93051
|
+
block_ids: group.block_ids,
|
|
93052
|
+
...group.source_id !== undefined ? { source_id: group.source_id } : {},
|
|
93053
|
+
...group.line_range !== undefined ? { line_range: group.line_range } : {}
|
|
93054
|
+
})),
|
|
93055
|
+
...input2.includeSplitPayload ? { suggested_split_payload: headingGroups.map((group) => ({
|
|
93056
|
+
owner: plan.owner,
|
|
93057
|
+
section_kind: plan.section_kind,
|
|
93058
|
+
block_ids: group.block_ids,
|
|
93059
|
+
rationale: `Evidence under ${group.heading_path.join(" > ") || "<root>"}.`
|
|
93060
|
+
})) } : {}
|
|
93061
|
+
};
|
|
93062
|
+
});
|
|
93063
|
+
const sharedParent = classifiedSpans.filter((item) => item.shared_heading.length > 0);
|
|
93064
|
+
const unrelated = classifiedSpans.filter((item) => item.shared_heading.length === 0);
|
|
93065
|
+
const hints = [];
|
|
93066
|
+
if (sharedParent.length > 0) {
|
|
93067
|
+
hints.push({
|
|
93068
|
+
code: "align-section-plan-crosses-headings",
|
|
93069
|
+
severity: "info",
|
|
93070
|
+
message: `${sharedParent.length} planned section(s) span sibling source headings under a shared parent heading. Semantic aggregation is allowed when the Section intentionally covers that parent topic.`,
|
|
93071
|
+
next_action: `Continue if each ${targetField} entry is one coherent semantic Section for the shared parent topic. Split only when the sibling headings should become independently drafted Sections.`,
|
|
93072
|
+
command: "context schema align-structure-intent --view minimal --format json",
|
|
93073
|
+
diagnostics: {
|
|
93074
|
+
section_count: sharedParent.length,
|
|
93075
|
+
target_field: targetField,
|
|
93076
|
+
heading_relationship: "shared_parent",
|
|
93077
|
+
examples: examplesFor(sharedParent, { includeSplitPayload: false }),
|
|
93078
|
+
examples_omitted: Math.max(0, sharedParent.length - 5)
|
|
93079
|
+
}
|
|
93080
|
+
});
|
|
93081
|
+
}
|
|
93082
|
+
if (unrelated.length > 0) {
|
|
93083
|
+
hints.push({
|
|
93084
|
+
code: "align-section-plan-crosses-headings",
|
|
93085
|
+
severity: "warning",
|
|
93086
|
+
message: `${unrelated.length} planned section(s) cross unrelated source heading boundaries. CLI will not rewrite the grouping; review whether this was intentional.`,
|
|
93087
|
+
next_action: `If accidental, split ${targetField} by the suggested heading groups and rerun align validate/finalize. If intentional, continue; compile source-refs will still expose separate draft templates for heading-boundary runs.`,
|
|
93088
|
+
command: "context schema align-structure-intent --view minimal --format json",
|
|
93089
|
+
diagnostics: {
|
|
93090
|
+
section_count: unrelated.length,
|
|
93091
|
+
target_field: targetField,
|
|
93092
|
+
heading_relationship: "unrelated_parent",
|
|
93093
|
+
examples: examplesFor(unrelated, { includeSplitPayload: true }),
|
|
93094
|
+
examples_omitted: Math.max(0, unrelated.length - 5)
|
|
93095
|
+
}
|
|
93096
|
+
});
|
|
93097
|
+
}
|
|
93098
|
+
return hints;
|
|
93099
|
+
}
|
|
93100
|
+
function sectionPlanAutoSplitAgentHints(ownership) {
|
|
93101
|
+
const splitPlans = (ownership.section_plans ?? []).filter((plan) => plan.split_reason !== undefined && typeof plan.origin_section_id === "string");
|
|
93102
|
+
if (splitPlans.length === 0)
|
|
93103
|
+
return [];
|
|
93104
|
+
const originSectionIds = [...new Set(splitPlans.map((plan) => plan.origin_section_id))].sort();
|
|
93105
|
+
const splitReasons = [...new Set(splitPlans.flatMap((plan) => plan.split_reason === undefined ? [] : [plan.split_reason]))].sort();
|
|
93106
|
+
return [{
|
|
93107
|
+
code: "align-section-plans-auto-split-contiguous-runs",
|
|
93108
|
+
severity: "info",
|
|
93109
|
+
message: `${originSectionIds.length} align planned section(s) will be split into ${splitPlans.length} draft-ready section plan(s) by citation continuity.`,
|
|
93110
|
+
next_action: "Continue. During compile, use the emitted section_plans/source-refs draft_action_templates as separate draft actions by default; origin_section_id preserves the original align grouping.",
|
|
93111
|
+
command: COMPILE_SCAN_COMMAND2,
|
|
93112
|
+
diagnostics: {
|
|
93113
|
+
origin_section_ids: originSectionIds,
|
|
93114
|
+
split_section_plan_count: originSectionIds.length,
|
|
93115
|
+
emitted_section_plan_count: splitPlans.length,
|
|
93116
|
+
split_reasons: splitReasons
|
|
93117
|
+
}
|
|
93118
|
+
}];
|
|
93119
|
+
}
|
|
92035
93120
|
function agentHintsForCitationAdvisories(issues) {
|
|
92036
93121
|
return issues.map((issue2) => ({
|
|
92037
93122
|
code: issue2.code,
|
|
@@ -92045,40 +93130,6 @@ function agentHintsForCitationAdvisories(issues) {
|
|
|
92045
93130
|
}
|
|
92046
93131
|
function agentHintsForAuditWarnings(warnings) {
|
|
92047
93132
|
return warnings.flatMap((warning) => {
|
|
92048
|
-
if (warning.kind === "domain_downgrade") {
|
|
92049
|
-
return [{
|
|
92050
|
-
code: "align-domain-downgraded-to-entity",
|
|
92051
|
-
severity: "warning",
|
|
92052
|
-
message: `Node "${warning.node_slug ?? "<unknown>"}" was finalized as an entity because ${warning.reason}. context status counts finalized node types, not submitted proposals.`,
|
|
92053
|
-
next_action: "Continue if an atomic placeholder/term is acceptable. If this should remain a Domain, revise domain_gate.child_refs to resolvable child Node slugs and rerun align validate/finalize.",
|
|
92054
|
-
command: "context schema align-structure-intent --view minimal --format json",
|
|
92055
|
-
...warning.node_slug !== undefined ? { target_node: warning.node_slug } : {},
|
|
92056
|
-
...warning.evidence_blocks !== undefined ? { available_block_ids: warning.evidence_blocks } : {},
|
|
92057
|
-
diagnostics: {
|
|
92058
|
-
finalized_node_type: "entity",
|
|
92059
|
-
status_count_source: "finalized_node_type",
|
|
92060
|
-
reason: warning.reason,
|
|
92061
|
-
...warning.original_proposal !== undefined ? { original_proposal: warning.original_proposal } : {}
|
|
92062
|
-
}
|
|
92063
|
-
}];
|
|
92064
|
-
}
|
|
92065
|
-
if (warning.kind === "action_downgrade") {
|
|
92066
|
-
return [{
|
|
92067
|
-
code: "align-action-downgraded-to-entity",
|
|
92068
|
-
severity: "warning",
|
|
92069
|
-
message: `Node "${warning.node_slug ?? "<unknown>"}" was finalized as an entity because ${warning.reason}. context status counts finalized node types, not submitted proposals.`,
|
|
92070
|
-
next_action: "Continue if the evidence describes a subject rather than a repeatable process. If this should remain an Action, add explicit action_probe/action_gate evidence and rerun align validate/finalize.",
|
|
92071
|
-
command: "context schema align-structure-intent --view minimal --format json",
|
|
92072
|
-
...warning.node_slug !== undefined ? { target_node: warning.node_slug } : {},
|
|
92073
|
-
...warning.evidence_blocks !== undefined ? { available_block_ids: warning.evidence_blocks } : {},
|
|
92074
|
-
diagnostics: {
|
|
92075
|
-
finalized_node_type: "entity",
|
|
92076
|
-
status_count_source: "finalized_node_type",
|
|
92077
|
-
reason: warning.reason,
|
|
92078
|
-
...warning.original_proposal !== undefined ? { original_proposal: warning.original_proposal } : {}
|
|
92079
|
-
}
|
|
92080
|
-
}];
|
|
92081
|
-
}
|
|
92082
93133
|
if (warning.kind === "scope_name_entity_hint") {
|
|
92083
93134
|
return [{
|
|
92084
93135
|
code: "align-scope-name-entity-warning",
|
|
@@ -92353,6 +93404,8 @@ function validateAlignStructureDecisionWithContext(input) {
|
|
|
92353
93404
|
const auditHints = built === undefined ? errorHints : [
|
|
92354
93405
|
...errorHints,
|
|
92355
93406
|
...canonicalDecisionDirectHint(input.rawDecision),
|
|
93407
|
+
...sectionPlanAutoSplitAgentHints(built.ownership),
|
|
93408
|
+
...sectionPlanCrossHeadingHints({ ownership: built.ownership, inputSchema: built.inputSchema }),
|
|
92356
93409
|
...agentHintsForAuditWarnings(built.decision.audit_warnings),
|
|
92357
93410
|
...agentHintsForCitationAdvisories(built.citationAdvisories),
|
|
92358
93411
|
...agentHintsForCliDemotions(cliDemotions)
|
|
@@ -92382,325 +93435,6 @@ function validateAlignStructureDecisionWithContext(input) {
|
|
|
92382
93435
|
};
|
|
92383
93436
|
}
|
|
92384
93437
|
|
|
92385
|
-
// src/commands/workflowAlignEnvelope.ts
|
|
92386
|
-
init_currentWorkflow();
|
|
92387
|
-
init_nextActionEnvelope();
|
|
92388
|
-
var ALIGN_FINALIZE_COMMAND = "context align finalize --input - --format json";
|
|
92389
|
-
var ALIGN_VALIDATE_COMMAND2 = "context align validate --input - --format json";
|
|
92390
|
-
var ALIGN_COARSE_READ_COMMAND2 = "context align coarse-read --input - --format json";
|
|
92391
|
-
var ALIGN_CANDIDATE_OPS_COMMAND = "context align ops --input - --format json";
|
|
92392
|
-
var ALIGN_RESCAN_COMMAND = "context align scan --format json";
|
|
92393
|
-
var COMPILE_SCAN_COMMAND2 = "context compile scan --format json";
|
|
92394
|
-
var ALIGN_READ_PLAN_COMMAND = "context workflow show --payload align-segments --view read-plan --unwrap --format json";
|
|
92395
|
-
var ALIGN_SOURCE_BUNDLE_COMMAND = "context workflow show --payload align-segments --view source-bundle --unwrap --format text";
|
|
92396
|
-
function alignWorkflowEnvelopeContext(state, digest2) {
|
|
92397
|
-
return {
|
|
92398
|
-
id: state.workflow_id,
|
|
92399
|
-
workflow_id: state.workflow_id,
|
|
92400
|
-
family: state.family,
|
|
92401
|
-
stage: state.stage,
|
|
92402
|
-
terminal: state.stage === "finalized" || state.stage === "closed" || state.stage === "abandoned",
|
|
92403
|
-
scope_id: workflowScope(state),
|
|
92404
|
-
...digest2 !== undefined ? { digest: digest2 } : {}
|
|
92405
|
-
};
|
|
92406
|
-
}
|
|
92407
|
-
function alignRouteId(route) {
|
|
92408
|
-
return route.mode;
|
|
92409
|
-
}
|
|
92410
|
-
function routeReasonBreach(threshold) {
|
|
92411
|
-
if (threshold.value > threshold.recommended_max)
|
|
92412
|
-
return "recommended_max";
|
|
92413
|
-
if (threshold.value > threshold.direct_max)
|
|
92414
|
-
return "direct_max";
|
|
92415
|
-
return;
|
|
92416
|
-
}
|
|
92417
|
-
function routeReason(indicator, threshold) {
|
|
92418
|
-
const breach = routeReasonBreach(threshold);
|
|
92419
|
-
if (breach === undefined)
|
|
92420
|
-
return;
|
|
92421
|
-
return {
|
|
92422
|
-
indicator,
|
|
92423
|
-
value: threshold.value,
|
|
92424
|
-
direct_max: threshold.direct_max,
|
|
92425
|
-
recommended_max: threshold.recommended_max,
|
|
92426
|
-
breach
|
|
92427
|
-
};
|
|
92428
|
-
}
|
|
92429
|
-
function alignRouteSummary(route) {
|
|
92430
|
-
return {
|
|
92431
|
-
id: alignRouteId(route),
|
|
92432
|
-
hard_gate: route.hard_gate,
|
|
92433
|
-
reasons: Object.entries(route.thresholds).map(([indicator, threshold]) => routeReason(indicator, threshold)).filter((reason) => reason !== undefined)
|
|
92434
|
-
};
|
|
92435
|
-
}
|
|
92436
|
-
function alignSegmentsViews() {
|
|
92437
|
-
return [
|
|
92438
|
-
{
|
|
92439
|
-
id: "read-plan",
|
|
92440
|
-
purpose: "Read the compact align reading plan and follow its single next_action command.",
|
|
92441
|
-
evidence_role: "primary",
|
|
92442
|
-
expected: true,
|
|
92443
|
-
budget_safety: "compact",
|
|
92444
|
-
command: ALIGN_READ_PLAN_COMMAND
|
|
92445
|
-
},
|
|
92446
|
-
{
|
|
92447
|
-
id: "source-bundle",
|
|
92448
|
-
purpose: "Read the near-source text bundle only when read-plan recommends it.",
|
|
92449
|
-
evidence_role: "primary",
|
|
92450
|
-
expected: false,
|
|
92451
|
-
budget_safety: "paged",
|
|
92452
|
-
command: ALIGN_SOURCE_BUNDLE_COMMAND
|
|
92453
|
-
},
|
|
92454
|
-
{
|
|
92455
|
-
id: "blocks",
|
|
92456
|
-
purpose: "Drill into paged align block JSON only when read-plan or source-bundle asks for a scoped fallback.",
|
|
92457
|
-
evidence_role: "primary",
|
|
92458
|
-
expected: false,
|
|
92459
|
-
budget_safety: "paged",
|
|
92460
|
-
command: "context workflow show --payload align-segments --view blocks --page-size 10 --token-budget 8000 --unwrap --format json"
|
|
92461
|
-
},
|
|
92462
|
-
{
|
|
92463
|
-
id: "block-index",
|
|
92464
|
-
purpose: "List block ids, ordinals, structural roles, and heading paths without text.",
|
|
92465
|
-
evidence_role: "supporting",
|
|
92466
|
-
expected: false,
|
|
92467
|
-
budget_safety: "compact",
|
|
92468
|
-
command: "context workflow show --payload align-segments --view block-index --unwrap --format json"
|
|
92469
|
-
},
|
|
92470
|
-
{
|
|
92471
|
-
id: "source-mapping",
|
|
92472
|
-
purpose: "Inspect source to block mapping without full block text.",
|
|
92473
|
-
evidence_role: "supporting",
|
|
92474
|
-
expected: false,
|
|
92475
|
-
budget_safety: "compact",
|
|
92476
|
-
command: "context workflow show --payload align-segments --view source-mapping --unwrap --format json"
|
|
92477
|
-
},
|
|
92478
|
-
{
|
|
92479
|
-
id: "pending-relation-refs",
|
|
92480
|
-
purpose: "Inspect explicit Parent/Children/Related markdown relation refs before deciding contains_parent or domain child refs.",
|
|
92481
|
-
evidence_role: "supporting",
|
|
92482
|
-
expected: false,
|
|
92483
|
-
budget_safety: "compact",
|
|
92484
|
-
command: "context workflow show --payload align-segments --view pending-relation-refs --unwrap --format json"
|
|
92485
|
-
},
|
|
92486
|
-
{
|
|
92487
|
-
id: "windows",
|
|
92488
|
-
purpose: "Page source windows to choose narrower block reads for large sources.",
|
|
92489
|
-
evidence_role: "supporting",
|
|
92490
|
-
expected: false,
|
|
92491
|
-
budget_safety: "paged",
|
|
92492
|
-
command: "context workflow show --payload align-segments --view windows --page-size 10 --compact-hints --unwrap --format json"
|
|
92493
|
-
},
|
|
92494
|
-
{
|
|
92495
|
-
id: "segment",
|
|
92496
|
-
purpose: "Read compact align segment summary and route metadata.",
|
|
92497
|
-
evidence_role: "diagnostic",
|
|
92498
|
-
expected: false,
|
|
92499
|
-
budget_safety: "compact",
|
|
92500
|
-
command: "context workflow show --payload align-segments --view segment --unwrap --format json"
|
|
92501
|
-
}
|
|
92502
|
-
];
|
|
92503
|
-
}
|
|
92504
|
-
function alignInspectCommands() {
|
|
92505
|
-
return {
|
|
92506
|
-
read_plan: ALIGN_READ_PLAN_COMMAND,
|
|
92507
|
-
summary: "context workflow show --payload align-segments --view segment --unwrap --format json",
|
|
92508
|
-
pending_relation_refs: "context workflow show --payload align-segments --view pending-relation-refs --unwrap --format json"
|
|
92509
|
-
};
|
|
92510
|
-
}
|
|
92511
|
-
function alignInspectCommandTemplates() {
|
|
92512
|
-
return {
|
|
92513
|
-
source_bundle: ALIGN_SOURCE_BUNDLE_COMMAND,
|
|
92514
|
-
source_pending_relation_refs: "context workflow show --payload align-segments --view pending-relation-refs --source <source-id> --unwrap --format json",
|
|
92515
|
-
source_block_index: "context workflow show --payload align-segments --view block-index --source <source-id> --unwrap --format json",
|
|
92516
|
-
heading_block_index: "context workflow show --payload align-segments --view block-index --heading <heading-prefix> --unwrap --format json",
|
|
92517
|
-
source_blocks: "context workflow show --payload align-segments --view blocks --source <source-id> --page-size 10 --token-budget 8000 --unwrap --format json",
|
|
92518
|
-
heading_blocks: "context workflow show --payload align-segments --view blocks --heading <heading-prefix> --page-size 10 --token-budget 8000 --unwrap --format json",
|
|
92519
|
-
block_detail: "context workflow show --payload align-segments --view blocks --window <window-id|src-N:M[,selector...]> --page-size 10 --token-budget 8000 --unwrap --format json"
|
|
92520
|
-
};
|
|
92521
|
-
}
|
|
92522
|
-
function classifyAlignWindow(input) {
|
|
92523
|
-
if (input.tokenEstimate > 8000 || input.blockCount > 30 || input.multiSubsection)
|
|
92524
|
-
return "complex";
|
|
92525
|
-
if (input.tokenEstimate > 3000 || input.blockCount > 12)
|
|
92526
|
-
return "moderate";
|
|
92527
|
-
return "simple";
|
|
92528
|
-
}
|
|
92529
|
-
function readStrategyForComplexity(complexity) {
|
|
92530
|
-
if (complexity === "complex")
|
|
92531
|
-
return "drill_by_window_or_heading_before_deciding_structure";
|
|
92532
|
-
if (complexity === "moderate")
|
|
92533
|
-
return "read_budgeted_blocks_then_expand_selected_windows";
|
|
92534
|
-
return "read_budgeted_blocks_directly";
|
|
92535
|
-
}
|
|
92536
|
-
function alignSourceComplexitySummaries(segments) {
|
|
92537
|
-
const coverableBlockIds = new Set(segments.coverage.coverable_block_ids);
|
|
92538
|
-
return segments.sources.map((source2) => {
|
|
92539
|
-
const coverableBlocks2 = source2.blocks.filter((block) => coverableBlockIds.has(block.block_id));
|
|
92540
|
-
const largestWindowTokens = source2.windows.reduce((max, window2) => Math.max(max, window2.token_estimate), 0);
|
|
92541
|
-
const sourceComplexity = source2.windows.some((window2) => classifyAlignWindow({
|
|
92542
|
-
tokenEstimate: window2.token_estimate,
|
|
92543
|
-
blockCount: window2.block_ids.length,
|
|
92544
|
-
multiSubsection: window2.multi_subsection === true
|
|
92545
|
-
}) === "complex") || source2.windows.length > 6 || coverableBlocks2.length > 50 ? "complex" : source2.windows.some((window2) => classifyAlignWindow({
|
|
92546
|
-
tokenEstimate: window2.token_estimate,
|
|
92547
|
-
blockCount: window2.block_ids.length,
|
|
92548
|
-
multiSubsection: window2.multi_subsection === true
|
|
92549
|
-
}) === "moderate") || source2.windows.length > 3 || coverableBlocks2.length > 20 ? "moderate" : "simple";
|
|
92550
|
-
return {
|
|
92551
|
-
source_id: source2.source_id,
|
|
92552
|
-
block_count: source2.blocks.length,
|
|
92553
|
-
coverable_block_count: coverableBlocks2.length,
|
|
92554
|
-
window_count: source2.windows.length,
|
|
92555
|
-
total_tokens: source2.total_tokens,
|
|
92556
|
-
largest_window_tokens: largestWindowTokens,
|
|
92557
|
-
complexity_class: sourceComplexity,
|
|
92558
|
-
suggested_read_strategy: readStrategyForComplexity(sourceComplexity),
|
|
92559
|
-
windows: source2.windows.map((window2) => {
|
|
92560
|
-
const complexity = classifyAlignWindow({
|
|
92561
|
-
tokenEstimate: window2.token_estimate,
|
|
92562
|
-
blockCount: window2.block_ids.length,
|
|
92563
|
-
multiSubsection: window2.multi_subsection === true
|
|
92564
|
-
});
|
|
92565
|
-
return {
|
|
92566
|
-
window_id: window2.window_id,
|
|
92567
|
-
block_count: window2.block_ids.length,
|
|
92568
|
-
token_estimate: window2.token_estimate,
|
|
92569
|
-
line_start: window2.line_start,
|
|
92570
|
-
line_end: window2.line_end,
|
|
92571
|
-
heading_path: window2.heading_path,
|
|
92572
|
-
complexity_class: complexity,
|
|
92573
|
-
suggested_read_strategy: readStrategyForComplexity(complexity)
|
|
92574
|
-
};
|
|
92575
|
-
})
|
|
92576
|
-
};
|
|
92577
|
-
});
|
|
92578
|
-
}
|
|
92579
|
-
function pendingRelationRefsCount2(segments) {
|
|
92580
|
-
return segments.sources.reduce((sum, source2) => sum + (source2.pending_relation_refs?.length ?? 0), 0);
|
|
92581
|
-
}
|
|
92582
|
-
function alignComplexityDiagnostics(input) {
|
|
92583
|
-
const automaticOwnershipAdjustments = automaticOwnershipAdjustmentCandidates(input.segments);
|
|
92584
|
-
const relationRefsCount = pendingRelationRefsCount2(input.segments);
|
|
92585
|
-
return {
|
|
92586
|
-
summary: {
|
|
92587
|
-
route_mode: input.route.mode,
|
|
92588
|
-
complexity: input.route.complexity,
|
|
92589
|
-
source_count: input.route.thresholds.source_count.value,
|
|
92590
|
-
coverable_block_count: input.route.thresholds.coverable_block_count.value,
|
|
92591
|
-
estimated_coverable_tokens: input.route.thresholds.estimated_coverable_tokens.value,
|
|
92592
|
-
largest_window_tokens: input.route.thresholds.largest_window_tokens.value,
|
|
92593
|
-
estimated_response_chars: input.route.thresholds.estimated_response_chars.value,
|
|
92594
|
-
windows: input.segments.sources.reduce((sum, source2) => sum + source2.windows.length, 0),
|
|
92595
|
-
structural_changes: input.structuralChanges,
|
|
92596
|
-
content_only_changes: input.contentOnlyChanges,
|
|
92597
|
-
...relationRefsCount > 0 ? { pending_relation_refs: relationRefsCount } : {}
|
|
92598
|
-
},
|
|
92599
|
-
...relationRefsCount > 0 ? {
|
|
92600
|
-
warnings: [{
|
|
92601
|
-
code: "align-pending-relation-refs",
|
|
92602
|
-
severity: "info",
|
|
92603
|
-
message: `${relationRefsCount} explicit Parent/Children/Related markdown relation ref(s) were detected.`,
|
|
92604
|
-
detail_view_command: "context workflow show --payload align-segments --view pending-relation-refs --unwrap --format json"
|
|
92605
|
-
}]
|
|
92606
|
-
} : {},
|
|
92607
|
-
automatic_ownership_adjustments: compactAutomaticOwnershipAdjustments(automaticOwnershipAdjustments, {
|
|
92608
|
-
...input.automaticOwnershipDetailCommand !== undefined ? { detailCommand: input.automaticOwnershipDetailCommand } : {}
|
|
92609
|
-
})
|
|
92610
|
-
};
|
|
92611
|
-
}
|
|
92612
|
-
function alignNextActionForRoute(input) {
|
|
92613
|
-
if (input.hasWork) {
|
|
92614
|
-
return {
|
|
92615
|
-
kind: "show_view",
|
|
92616
|
-
command: ALIGN_READ_PLAN_COMMAND,
|
|
92617
|
-
reason_code: `${input.route.mode}-read-plan`,
|
|
92618
|
-
blocking: true
|
|
92619
|
-
};
|
|
92620
|
-
}
|
|
92621
|
-
if (input.contentOnlyChanges > 0) {
|
|
92622
|
-
return {
|
|
92623
|
-
kind: "start_compile_scan",
|
|
92624
|
-
command: COMPILE_SCAN_COMMAND2,
|
|
92625
|
-
reason_code: "align-content-only-changes"
|
|
92626
|
-
};
|
|
92627
|
-
}
|
|
92628
|
-
return {
|
|
92629
|
-
kind: "stop_noop",
|
|
92630
|
-
reason_code: "align-no-structural-work"
|
|
92631
|
-
};
|
|
92632
|
-
}
|
|
92633
|
-
function alignAllowedActionsForNextAction(nextAction) {
|
|
92634
|
-
if (nextAction.kind === "show_view")
|
|
92635
|
-
return ["show_view"];
|
|
92636
|
-
if (nextAction.kind === "submit_structure_decision")
|
|
92637
|
-
return ["show_view", "submit_structure_decision"];
|
|
92638
|
-
if (nextAction.kind === "validate_align_decision")
|
|
92639
|
-
return ["show_view", "validate_align_decision"];
|
|
92640
|
-
if (nextAction.kind === "submit_coarse_read")
|
|
92641
|
-
return ["show_view", "submit_coarse_read"];
|
|
92642
|
-
if (nextAction.kind === "submit_candidate_ops")
|
|
92643
|
-
return ["show_view", "submit_candidate_ops"];
|
|
92644
|
-
if (nextAction.kind === "abandon_or_rescan")
|
|
92645
|
-
return ["show_view", "abandon", "rescan"];
|
|
92646
|
-
if (nextAction.kind === "start_compile_scan")
|
|
92647
|
-
return ["show_view"];
|
|
92648
|
-
return;
|
|
92649
|
-
}
|
|
92650
|
-
function createAlignRouteEnvelope(input) {
|
|
92651
|
-
const allowedActions = alignAllowedActionsForNextAction(input.nextAction);
|
|
92652
|
-
const views = input.nextAction.kind === "stop_noop" || input.nextAction.kind === "start_compile_scan" ? undefined : alignSegmentsViews();
|
|
92653
|
-
return createNextActionEnvelope({
|
|
92654
|
-
workflow: alignWorkflowEnvelopeContext(input.workflowState),
|
|
92655
|
-
route: alignRouteSummary(input.route),
|
|
92656
|
-
...allowedActions !== undefined ? { allowed_actions: allowedActions } : {},
|
|
92657
|
-
next_action: input.nextAction,
|
|
92658
|
-
...views !== undefined ? { views } : {},
|
|
92659
|
-
...input.diagnostics !== undefined ? { diagnostics: input.diagnostics } : {}
|
|
92660
|
-
});
|
|
92661
|
-
}
|
|
92662
|
-
function alignDirectFinalizeNextAction(reasonCode = "align-route-direct-finalize", inputSchema = "align-structure-intent") {
|
|
92663
|
-
return {
|
|
92664
|
-
kind: "submit_structure_decision",
|
|
92665
|
-
command: ALIGN_FINALIZE_COMMAND,
|
|
92666
|
-
input_schema: inputSchema,
|
|
92667
|
-
reason_code: reasonCode,
|
|
92668
|
-
blocking: true
|
|
92669
|
-
};
|
|
92670
|
-
}
|
|
92671
|
-
function alignValidateNextAction(reasonCode = "align-validate-repair-required", inputSchema = "align-structure-intent") {
|
|
92672
|
-
return {
|
|
92673
|
-
kind: "validate_align_decision",
|
|
92674
|
-
command: ALIGN_VALIDATE_COMMAND2,
|
|
92675
|
-
input_schema: inputSchema,
|
|
92676
|
-
reason_code: reasonCode,
|
|
92677
|
-
blocking: true
|
|
92678
|
-
};
|
|
92679
|
-
}
|
|
92680
|
-
function alignBatchedNextAction(kind) {
|
|
92681
|
-
return kind === "submit_candidate_ops" ? {
|
|
92682
|
-
kind,
|
|
92683
|
-
command: ALIGN_CANDIDATE_OPS_COMMAND,
|
|
92684
|
-
input_schema: "align-candidate-ops",
|
|
92685
|
-
reason_code: "align-route-batched-review-required",
|
|
92686
|
-
blocking: true
|
|
92687
|
-
} : {
|
|
92688
|
-
kind,
|
|
92689
|
-
command: ALIGN_COARSE_READ_COMMAND2,
|
|
92690
|
-
input_schema: "align-coarse-read",
|
|
92691
|
-
reason_code: "align-route-batched-review-required",
|
|
92692
|
-
blocking: true
|
|
92693
|
-
};
|
|
92694
|
-
}
|
|
92695
|
-
function alignAbandonOrRescanNextAction(reasonCode) {
|
|
92696
|
-
return {
|
|
92697
|
-
kind: "abandon_or_rescan",
|
|
92698
|
-
command: ALIGN_RESCAN_COMMAND,
|
|
92699
|
-
reason_code: reasonCode,
|
|
92700
|
-
blocking: true
|
|
92701
|
-
};
|
|
92702
|
-
}
|
|
92703
|
-
|
|
92704
93438
|
// src/commands/workflowAlignValidationViews.ts
|
|
92705
93439
|
init_cliFeedback();
|
|
92706
93440
|
init_errors();
|
|
@@ -93005,24 +93739,6 @@ function agentHintsForFinalizeIssues(issues) {
|
|
|
93005
93739
|
};
|
|
93006
93740
|
});
|
|
93007
93741
|
}
|
|
93008
|
-
function sectionPlanAutoSplitAgentHints(ownership) {
|
|
93009
|
-
const splitPlans = (ownership.section_plans ?? []).filter((plan) => plan.split_reason === "non_contiguous_citation_eligible_blocks" && typeof plan.origin_section_id === "string");
|
|
93010
|
-
if (splitPlans.length === 0)
|
|
93011
|
-
return [];
|
|
93012
|
-
const originSectionIds = [...new Set(splitPlans.map((plan) => plan.origin_section_id))].sort();
|
|
93013
|
-
return [{
|
|
93014
|
-
code: "align-section-plans-auto-split-contiguous-runs",
|
|
93015
|
-
severity: "info",
|
|
93016
|
-
message: `${originSectionIds.length} align planned section(s) were split into ${splitPlans.length} contiguous draft-ready section plan(s).`,
|
|
93017
|
-
next_action: "Continue to compile scan; use the emitted section_plans/source-refs draft_action_templates. origin_section_id preserves the original align grouping.",
|
|
93018
|
-
command: COMPILE_SCAN_COMMAND2,
|
|
93019
|
-
diagnostics: {
|
|
93020
|
-
origin_section_ids: originSectionIds,
|
|
93021
|
-
split_section_plan_count: originSectionIds.length,
|
|
93022
|
-
emitted_section_plan_count: splitPlans.length
|
|
93023
|
-
}
|
|
93024
|
-
}];
|
|
93025
|
-
}
|
|
93026
93742
|
function alignFinalizeCompileHandoffHint() {
|
|
93027
93743
|
return {
|
|
93028
93744
|
code: "align-finished-next-compile",
|
|
@@ -93178,11 +93894,9 @@ async function finalizeAlignStructureDecisionCommand(input) {
|
|
|
93178
93894
|
decision,
|
|
93179
93895
|
segments: finalizeContext.segments
|
|
93180
93896
|
});
|
|
93181
|
-
const
|
|
93182
|
-
const sectionPlanAutoSplitCount = (ownership.section_plans ?? []).filter((plan) => plan.split_reason === "non_contiguous_citation_eligible_blocks").length;
|
|
93897
|
+
const sectionPlanAutoSplitCount = (ownership.section_plans ?? []).filter((plan) => plan.split_reason !== undefined).length;
|
|
93183
93898
|
const auditHints = [
|
|
93184
93899
|
...validation.auditHints,
|
|
93185
|
-
...sectionPlanAutoSplitHints,
|
|
93186
93900
|
alignFinalizeCompileHandoffHint()
|
|
93187
93901
|
];
|
|
93188
93902
|
const automaticOwnershipAdjustments = automaticOwnershipAdjustmentsFromDemotions(cliDemotions);
|
|
@@ -94356,7 +95070,7 @@ function buildStructureProposalStarter(segments) {
|
|
|
94356
95070
|
recommended_no_write_shape: {
|
|
94357
95071
|
planned_sections: [],
|
|
94358
95072
|
ownership: "context_only_or_ignored",
|
|
94359
|
-
node_type_hint: "
|
|
95073
|
+
node_type_hint: "domain_if_children_resolve_else_agent_chosen_entity",
|
|
94360
95074
|
...titleHint !== undefined ? { title_hint: titleHint } : {},
|
|
94361
95075
|
rationale: "This source only carries relation/navigation or explicit no-detail placeholder text. Keep a Node only when the graph/slug is useful; do not create owned citation evidence or an active Section from these blocks."
|
|
94362
95076
|
}
|
|
@@ -95954,7 +96668,7 @@ async function nodeCycleCoverageGate(input) {
|
|
|
95954
96668
|
coverage_ratio: ratio,
|
|
95955
96669
|
high_signal_unresolved: highSignalUnresolved.length,
|
|
95956
96670
|
candidate_samples: candidateSamples,
|
|
95957
|
-
patch_draft_command: `context compile
|
|
96671
|
+
patch_draft_command: `context compile cycle ${shellQuote(input.slug)} --input - --format json`,
|
|
95958
96672
|
skip_unresolved_command: skipCommand
|
|
95959
96673
|
}
|
|
95960
96674
|
};
|
|
@@ -95998,7 +96712,7 @@ function isBlockingWeakSourceSupport(item) {
|
|
|
95998
96712
|
return true;
|
|
95999
96713
|
return support.reason_code !== undefined && support.reason_code !== "weak.soft_diff";
|
|
96000
96714
|
}
|
|
96001
|
-
function
|
|
96715
|
+
function sourceSupportSummary2(context) {
|
|
96002
96716
|
return {
|
|
96003
96717
|
supported: context.items.filter((item) => item.source_support?.verdict === "supported").length,
|
|
96004
96718
|
weak: context.items.filter((item) => item.source_support?.verdict === "weak").length,
|
|
@@ -96439,10 +97153,6 @@ function formatDraftPlanHeadline(result) {
|
|
|
96439
97153
|
function shellQuote2(value) {
|
|
96440
97154
|
return `'${value.replace(/'/g, "'\\''")}'`;
|
|
96441
97155
|
}
|
|
96442
|
-
function formatDraftPatchHeadline(result) {
|
|
96443
|
-
const counts = actionCounts(result);
|
|
96444
|
-
return `${counts.total} actions parsed; draft patched; continue cycle required`;
|
|
96445
|
-
}
|
|
96446
97156
|
function compileCycleContinueCommand(slug) {
|
|
96447
97157
|
return `context compile cycle ${shellQuote2(slug)} --continue --format json`;
|
|
96448
97158
|
}
|
|
@@ -96482,7 +97192,7 @@ function draftPlanBody(input) {
|
|
|
96482
97192
|
lines.push("**Next options**:");
|
|
96483
97193
|
lines.push("- continue: `/context:compile`");
|
|
96484
97194
|
if (draftDigest !== undefined) {
|
|
96485
|
-
lines.push(`- revise: \`context compile
|
|
97195
|
+
lines.push(`- revise: \`context compile cycle ${shellQuote2(slug)} --input - --format json\``);
|
|
96486
97196
|
lines.push(`- continue patched draft: \`${compileCycleContinueCommand(slug)}\``);
|
|
96487
97197
|
lines.push(`- primitive: \`context reconcile prepare --mode compile --node ${shellQuote2(slug)} --view summary --format json\``);
|
|
96488
97198
|
} else if (saved) {
|
|
@@ -96806,7 +97516,7 @@ function throwCompileDraftRecoveredError(input) {
|
|
|
96806
97516
|
delete detail.category;
|
|
96807
97517
|
delete detail.summary;
|
|
96808
97518
|
const draftStatusCommand = `context compile draft-status ${input.slug} --format json`;
|
|
96809
|
-
const patchCommand = `context compile
|
|
97519
|
+
const patchCommand = `context compile cycle ${input.slug} --input - --format json`;
|
|
96810
97520
|
const reasonCode = typeof input.error.detail?.reason_code === "string" ? input.error.detail.reason_code : "compile-draft-validation-failed";
|
|
96811
97521
|
const envelope = createNextActionEnvelope({
|
|
96812
97522
|
allowed_actions: ["show_view", "patch_payload"],
|
|
@@ -96962,7 +97672,8 @@ async function runCompileNodeCycle(input) {
|
|
|
96962
97672
|
mode: "compile",
|
|
96963
97673
|
node: input.slug,
|
|
96964
97674
|
draft: normalizedDraft,
|
|
96965
|
-
draftDigest: draftPayload.digest
|
|
97675
|
+
draftDigest: draftPayload.digest,
|
|
97676
|
+
workflowStartedAt: input.workflowState.created_at
|
|
96966
97677
|
});
|
|
96967
97678
|
const preparedWorkflow = await advanceCurrentWorkflow({
|
|
96968
97679
|
ctxDir: input.ctxDir,
|
|
@@ -97012,7 +97723,7 @@ async function runCompileNodeCycle(input) {
|
|
|
97012
97723
|
const narrowingSummary = sourceRefNarrowingOutput(narrowingHints, "advisory_no_action_required", input.slug);
|
|
97013
97724
|
if (!review.ready_to_apply) {
|
|
97014
97725
|
const cycleIssues = review.issues;
|
|
97015
|
-
const supportSummary =
|
|
97726
|
+
const supportSummary = sourceSupportSummary2(context);
|
|
97016
97727
|
const reconcileSummary = reconcileStatusSummary(context);
|
|
97017
97728
|
const issueStatus = prepareIssueStatus2({
|
|
97018
97729
|
sourceSupport: supportSummary,
|
|
@@ -97224,7 +97935,7 @@ async function runCompileNodeCycle(input) {
|
|
|
97224
97935
|
},
|
|
97225
97936
|
available_actions: [{
|
|
97226
97937
|
action: "patch_draft",
|
|
97227
|
-
command: `context compile
|
|
97938
|
+
command: `context compile cycle ${shellQuote(input.slug)} --input - --format json`
|
|
97228
97939
|
}, {
|
|
97229
97940
|
action: "inspect_coverage",
|
|
97230
97941
|
command: coverageGate.detailCommand
|
|
@@ -97487,7 +98198,7 @@ function rejectRetiredDraftPatchFields(patchInput, slug) {
|
|
|
97487
98198
|
if (issues.length === 0)
|
|
97488
98199
|
return;
|
|
97489
98200
|
const first = issues[0];
|
|
97490
|
-
const command = `context compile
|
|
98201
|
+
const command = `context compile cycle ${slug} --input - --format json`;
|
|
97491
98202
|
const envelope = createNextActionEnvelope({
|
|
97492
98203
|
allowed_actions: ["show_view", "patch_payload"],
|
|
97493
98204
|
next_action: {
|
|
@@ -97524,7 +98235,7 @@ function rejectRetiredDraftPatchFields(patchInput, slug) {
|
|
|
97524
98235
|
code: "compile-draft-patch-retired-field",
|
|
97525
98236
|
severity: "error",
|
|
97526
98237
|
message: first.message,
|
|
97527
|
-
next_action: "Patch actions must use content plus optional summary and source_refs[]
|
|
98238
|
+
next_action: "Patch actions must use content plus optional summary and source_refs[] or source_block_ids[]. Submit the corrected compile-draft-patch payload through context compile cycle.",
|
|
97528
98239
|
command,
|
|
97529
98240
|
node_slug: slug,
|
|
97530
98241
|
path: first.path,
|
|
@@ -97534,12 +98245,6 @@ function rejectRetiredDraftPatchFields(patchInput, slug) {
|
|
|
97534
98245
|
}
|
|
97535
98246
|
|
|
97536
98247
|
// src/commands/compileNodeCycleInput.ts
|
|
97537
|
-
function isRecord43(value) {
|
|
97538
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
97539
|
-
}
|
|
97540
|
-
function isCompileDraftPatchInput(value) {
|
|
97541
|
-
return isRecord43(value) && Array.isArray(value.operations);
|
|
97542
|
-
}
|
|
97543
98248
|
async function resolveNodeCycleInput(input) {
|
|
97544
98249
|
if (input.continueSaved === true) {
|
|
97545
98250
|
const payload2 = await readWorkflowPayloadByDigest({
|
|
@@ -97556,7 +98261,7 @@ async function resolveNodeCycleInput(input) {
|
|
|
97556
98261
|
...session2.agent_hints !== undefined ? { agentHints: session2.agent_hints } : {}
|
|
97557
98262
|
};
|
|
97558
98263
|
}
|
|
97559
|
-
if (!
|
|
98264
|
+
if (!isCompileDraftPatchLikeInput(input.value)) {
|
|
97560
98265
|
return { draft: input.value };
|
|
97561
98266
|
}
|
|
97562
98267
|
const payload = await readWorkflowPayloadByDigest({
|
|
@@ -97568,7 +98273,9 @@ async function resolveNodeCycleInput(input) {
|
|
|
97568
98273
|
});
|
|
97569
98274
|
const session = parseCompileDraftSession(payload.value);
|
|
97570
98275
|
assertCompileDraftSessionNode(session, input.slug);
|
|
97571
|
-
const patch = parseCompileDraftPatch(input.value
|
|
98276
|
+
const patch = parseCompileDraftPatch(input.value, {
|
|
98277
|
+
submitCommand: `context compile cycle ${shellQuote(input.slug)} --input - --format json`
|
|
98278
|
+
});
|
|
97572
98279
|
rejectRetiredDraftPatchFields(input.value, input.slug);
|
|
97573
98280
|
const patched = applyCompileDraftPatch({
|
|
97574
98281
|
session,
|
|
@@ -97726,6 +98433,9 @@ function draftActionTemplate(kind, rows) {
|
|
|
97726
98433
|
source_refs: rows.map((row) => row.source_ref)
|
|
97727
98434
|
};
|
|
97728
98435
|
}
|
|
98436
|
+
function uniqueStrings5(values2) {
|
|
98437
|
+
return [...new Set(values2)].sort();
|
|
98438
|
+
}
|
|
97729
98439
|
function citationEligibleOrdinals(context) {
|
|
97730
98440
|
const ordinalByBlock = new Map;
|
|
97731
98441
|
const rowsBySource = new Map;
|
|
@@ -97740,26 +98450,39 @@ function citationEligibleOrdinals(context) {
|
|
|
97740
98450
|
}
|
|
97741
98451
|
return { ordinalByBlock, rowsBySource };
|
|
97742
98452
|
}
|
|
97743
|
-
function
|
|
98453
|
+
function splitDraftRuns(rows, ordinalByBlock) {
|
|
97744
98454
|
const runs = [];
|
|
98455
|
+
const splitReasons = new Set;
|
|
97745
98456
|
let current = [];
|
|
97746
98457
|
let previousSource;
|
|
97747
98458
|
let previousOrdinal;
|
|
98459
|
+
let previousHeadingPath;
|
|
97748
98460
|
for (const row of rows) {
|
|
97749
98461
|
const key = sourceKey(row);
|
|
97750
98462
|
const ordinal = blockKey(row) === null ? undefined : ordinalByBlock.get(blockKey(row));
|
|
97751
98463
|
const contiguous = current.length > 0 && previousSource === key && previousOrdinal !== undefined && ordinal !== undefined && ordinal === previousOrdinal + 1;
|
|
97752
|
-
|
|
98464
|
+
const sameHeading2 = previousHeadingPath !== undefined && sameHeadingPath3(previousHeadingPath, row.heading_path);
|
|
98465
|
+
if (current.length > 0 && (!contiguous || !sameHeading2)) {
|
|
98466
|
+
splitReasons.add(contiguous ? "heading_path_changed" : "non_contiguous_citation_eligible_blocks");
|
|
97753
98467
|
runs.push(current);
|
|
97754
98468
|
current = [];
|
|
97755
98469
|
}
|
|
97756
98470
|
current.push(row);
|
|
97757
98471
|
previousSource = key;
|
|
97758
98472
|
previousOrdinal = ordinal;
|
|
98473
|
+
previousHeadingPath = row.heading_path;
|
|
97759
98474
|
}
|
|
97760
98475
|
if (current.length > 0)
|
|
97761
98476
|
runs.push(current);
|
|
97762
|
-
return runs;
|
|
98477
|
+
return { runs, splitReasons: [...splitReasons].sort() };
|
|
98478
|
+
}
|
|
98479
|
+
function sameHeadingPath3(left, right) {
|
|
98480
|
+
return left.length === right.length && left.every((item, index2) => item === right[index2]);
|
|
98481
|
+
}
|
|
98482
|
+
function headingPathKey(value) {
|
|
98483
|
+
if (!Array.isArray(value) || !value.every((item) => typeof item === "string"))
|
|
98484
|
+
return;
|
|
98485
|
+
return value.join("\x00");
|
|
97763
98486
|
}
|
|
97764
98487
|
function interveningBlockIds(input) {
|
|
97765
98488
|
const result = new Set;
|
|
@@ -97792,6 +98515,49 @@ function recordArray(value) {
|
|
|
97792
98515
|
function splitRunCount(group) {
|
|
97793
98516
|
return numberValue(group.contiguous_run_count) ?? recordArray(group.contiguous_runs).length;
|
|
97794
98517
|
}
|
|
98518
|
+
function stringArray9(value) {
|
|
98519
|
+
return Array.isArray(value) ? value.filter((item) => typeof item === "string") : [];
|
|
98520
|
+
}
|
|
98521
|
+
function groupNumber(value, key) {
|
|
98522
|
+
return numberValue(value[key]) ?? 0;
|
|
98523
|
+
}
|
|
98524
|
+
function groupHasMarkdownList(value) {
|
|
98525
|
+
return value.contains_markdown_list === true || recordArray(value.contiguous_runs).some((run2) => run2.contains_markdown_list === true);
|
|
98526
|
+
}
|
|
98527
|
+
function groupFragmentReviewExamples(sectionGroups) {
|
|
98528
|
+
const examples = [];
|
|
98529
|
+
for (let index2 = 0;index2 < sectionGroups.length - 1; index2 += 1) {
|
|
98530
|
+
const current = sectionGroups[index2];
|
|
98531
|
+
const next = sectionGroups[index2 + 1];
|
|
98532
|
+
if (current.owner !== next.owner)
|
|
98533
|
+
continue;
|
|
98534
|
+
const currentHeading = headingPathKey(current.heading_path);
|
|
98535
|
+
const nextHeading = headingPathKey(next.heading_path);
|
|
98536
|
+
if (currentHeading === undefined || currentHeading !== nextHeading)
|
|
98537
|
+
continue;
|
|
98538
|
+
const currentSources = stringArray9(current.source_ids);
|
|
98539
|
+
const nextSources = stringArray9(next.source_ids);
|
|
98540
|
+
if (currentSources.length !== 1 || nextSources.length !== 1 || currentSources[0] !== nextSources[0])
|
|
98541
|
+
continue;
|
|
98542
|
+
const currentBlocks = stringArray9(current.block_ids);
|
|
98543
|
+
const nextBlocks = stringArray9(next.block_ids);
|
|
98544
|
+
const currentSmall = groupNumber(current, "citation_block_count") <= 1 && currentBlocks.length <= 1 && !groupHasMarkdownList(current);
|
|
98545
|
+
const nextLooksLarger = groupNumber(next, "citation_block_count") > 1 || groupHasMarkdownList(next);
|
|
98546
|
+
if (!currentSmall || !nextLooksLarger)
|
|
98547
|
+
continue;
|
|
98548
|
+
examples.push({
|
|
98549
|
+
section_id: current.section_id,
|
|
98550
|
+
next_section_id: next.section_id,
|
|
98551
|
+
owner: current.owner,
|
|
98552
|
+
heading_path: current.heading_path,
|
|
98553
|
+
source_ids: currentSources,
|
|
98554
|
+
block_ids: currentBlocks,
|
|
98555
|
+
next_block_ids: nextBlocks,
|
|
98556
|
+
reason: groupHasMarkdownList(next) ? "single-block section is adjacent to a list-like section under the same heading" : "single-block section is adjacent to a larger section under the same heading"
|
|
98557
|
+
});
|
|
98558
|
+
}
|
|
98559
|
+
return examples;
|
|
98560
|
+
}
|
|
97795
98561
|
function plannedSectionSourceRefGroups(context, rows) {
|
|
97796
98562
|
const plans = context.finalized_ownership?.groups.section_plans ?? [];
|
|
97797
98563
|
if (plans.length === 0)
|
|
@@ -97805,9 +98571,12 @@ function plannedSectionSourceRefGroups(context, rows) {
|
|
|
97805
98571
|
});
|
|
97806
98572
|
const citationRows = resolvedRows.filter((row) => row.citation_eligible);
|
|
97807
98573
|
const sourceRefs2 = citationRows.map((row) => row.source_ref);
|
|
98574
|
+
const headingPaths = uniqueStrings5(citationRows.map((row) => row.heading_path.join("\x00")));
|
|
98575
|
+
const sourceIds = uniqueStrings5(citationRows.flatMap((row) => typeof row.source_id === "string" ? [row.source_id] : []));
|
|
98576
|
+
const containsMarkdownList = citationRows.some((row) => row.contains_markdown_list === true);
|
|
97808
98577
|
const missingBlockIds = plan.block_ids.filter((blockId) => !rowByBlockId.has(blockId));
|
|
97809
98578
|
const nonCitationBlockIds = resolvedRows.filter((row) => !row.citation_eligible).flatMap((row) => typeof row.block_id === "string" ? [row.block_id] : []);
|
|
97810
|
-
const runs =
|
|
98579
|
+
const { runs, splitReasons } = splitDraftRuns(citationRows, ordinals.ordinalByBlock);
|
|
97811
98580
|
const templates = runs.map((run2) => draftActionTemplate(plan.section_kind, run2));
|
|
97812
98581
|
const status = missingBlockIds.length > 0 || nonCitationBlockIds.length > 0 || sourceRefs2.length === 0 ? "needs-attention" : runs.length > 1 ? "ready_with_splits" : "ready";
|
|
97813
98582
|
const intervening = runs.length > 1 ? interveningBlockIds({
|
|
@@ -97822,14 +98591,27 @@ function plannedSectionSourceRefGroups(context, rows) {
|
|
|
97822
98591
|
section_kind: plan.section_kind,
|
|
97823
98592
|
status,
|
|
97824
98593
|
block_ids: [...plan.block_ids],
|
|
98594
|
+
citation_block_count: citationRows.length,
|
|
98595
|
+
...sourceIds.length > 0 ? { source_ids: sourceIds } : {},
|
|
98596
|
+
...headingPaths.length === 1 ? { heading_path: headingPaths[0].split("\x00") } : headingPaths.length > 1 ? { heading_paths: headingPaths.map((path14) => path14.split("\x00")) } : {},
|
|
98597
|
+
...containsMarkdownList ? { contains_markdown_list: true } : {},
|
|
97825
98598
|
source_refs: sourceRefs2,
|
|
97826
98599
|
...plan.refers_to_nodes !== undefined ? { refers_to_nodes: [...plan.refers_to_nodes] } : {},
|
|
97827
98600
|
...missingBlockIds.length > 0 ? { missing_block_ids: missingBlockIds } : {},
|
|
97828
98601
|
...nonCitationBlockIds.length > 0 ? { non_citation_block_ids: nonCitationBlockIds } : {},
|
|
97829
98602
|
...runs.length > 1 ? {
|
|
97830
98603
|
contiguous_run_count: runs.length,
|
|
98604
|
+
draft_run_count: runs.length,
|
|
97831
98605
|
intervening_citation_eligible_block_ids: intervening,
|
|
97832
|
-
split_reason: "non_contiguous_citation_eligible_blocks",
|
|
98606
|
+
split_reason: splitReasons.includes("non_contiguous_citation_eligible_blocks") ? "non_contiguous_citation_eligible_blocks" : "heading_path_changed",
|
|
98607
|
+
split_reasons: splitReasons,
|
|
98608
|
+
...splitReasons.includes("heading_path_changed") ? {
|
|
98609
|
+
heading_path_runs: runs.map((run2, index2) => ({
|
|
98610
|
+
run_index: index2 + 1,
|
|
98611
|
+
heading_path: run2[0]?.heading_path ?? [],
|
|
98612
|
+
block_ids: run2.flatMap((row) => typeof row.block_id === "string" ? [row.block_id] : [])
|
|
98613
|
+
}))
|
|
98614
|
+
} : {},
|
|
97833
98615
|
...siblingCoveredIntervening.length > 0 ? {
|
|
97834
98616
|
sibling_bridge_reason: "intervening_blocks_are_planned_by_sibling_sections",
|
|
97835
98617
|
sibling_bridge_block_ids: siblingCoveredIntervening
|
|
@@ -97838,13 +98620,32 @@ function plannedSectionSourceRefGroups(context, rows) {
|
|
|
97838
98620
|
contiguous_runs: runs.map((run2, index2) => ({
|
|
97839
98621
|
run_index: index2 + 1,
|
|
97840
98622
|
block_ids: run2.flatMap((row) => typeof row.block_id === "string" ? [row.block_id] : []),
|
|
97841
|
-
source_refs: run2.map((row) => row.source_ref)
|
|
98623
|
+
source_refs: run2.map((row) => row.source_ref),
|
|
98624
|
+
...run2[0]?.heading_path !== undefined ? { heading_path: run2[0].heading_path } : {},
|
|
98625
|
+
...run2.some((row) => row.contains_markdown_list === true) ? { contains_markdown_list: true } : {}
|
|
97842
98626
|
})),
|
|
97843
98627
|
draft_action_templates: templates,
|
|
97844
98628
|
...status === "ready_with_splits" ? {} : { draft_action_template: templates[0] ?? draftActionTemplate(plan.section_kind, []) }
|
|
97845
98629
|
};
|
|
97846
98630
|
});
|
|
97847
98631
|
}
|
|
98632
|
+
function plannedSectionFragmentReviewHint(input) {
|
|
98633
|
+
const examples = groupFragmentReviewExamples(input.sectionGroups);
|
|
98634
|
+
if (examples.length === 0)
|
|
98635
|
+
return;
|
|
98636
|
+
return {
|
|
98637
|
+
code: "compile-planned-section-fragment-review",
|
|
98638
|
+
severity: "info",
|
|
98639
|
+
message: `${examples.length} adjacent planned section pair(s) may be over-fragmented under the same source heading.`,
|
|
98640
|
+
next_action: "Review these pairs before drafting. If a small lead-in and the following section are one knowledge unit, intentionally combine them in the draft or revise align; otherwise keep the planned groups separate.",
|
|
98641
|
+
command: input.detailCommand,
|
|
98642
|
+
diagnostics: {
|
|
98643
|
+
pair_count: examples.length,
|
|
98644
|
+
examples: examples.slice(0, 8),
|
|
98645
|
+
examples_omitted: Math.max(0, examples.length - 8)
|
|
98646
|
+
}
|
|
98647
|
+
};
|
|
98648
|
+
}
|
|
97848
98649
|
function plannedSectionSplitRequiredHint(input) {
|
|
97849
98650
|
const sectionGroups = input.sectionGroups ?? plannedSectionSourceRefGroups(input.context, nodeContextSourceRefRows(input.context));
|
|
97850
98651
|
const splitGroups = sectionGroups.filter((group) => group.status === "ready_with_splits");
|
|
@@ -97860,7 +98661,7 @@ function plannedSectionSplitRequiredHint(input) {
|
|
|
97860
98661
|
code: "compile-planned-section-groups-require-split",
|
|
97861
98662
|
severity: "info",
|
|
97862
98663
|
message: `Node has ${sectionGroups.length} planned section group(s); ${splitGroups.length} must be split into separate draft actions${bridgeSuffix}.`,
|
|
97863
|
-
next_action: "Read source-refs view before drafting; copy each planned_section_groups[].draft_action_templates entry as a separate draft action. Do not merge templates or
|
|
98664
|
+
next_action: "Read source-refs view before drafting; copy each planned_section_groups[].draft_action_templates entry as a separate draft action. Do not merge templates, citation-gap runs, or heading-boundary runs.",
|
|
97864
98665
|
command: input.detailCommand,
|
|
97865
98666
|
diagnostics: {
|
|
97866
98667
|
planned_section_groups_count: sectionGroups.length,
|
|
@@ -98280,7 +99081,7 @@ var COMMON_DOTTED_IDENTIFIER_ROOTS = new Set([
|
|
|
98280
99081
|
"Buffer"
|
|
98281
99082
|
]);
|
|
98282
99083
|
var CODE_ROOT_SUFFIX_RE = /(?:API|Api|Service|Client|Controller|Repository|Manager|Handler|Factory|Provider|Module|Model|Config|Store|Router|Adapter|Component|Context|Runtime|Engine)$/u;
|
|
98283
|
-
function
|
|
99084
|
+
function stringValue7(value) {
|
|
98284
99085
|
return typeof value === "string" && value.length > 0 ? value : undefined;
|
|
98285
99086
|
}
|
|
98286
99087
|
function numberValue2(value) {
|
|
@@ -98289,11 +99090,23 @@ function numberValue2(value) {
|
|
|
98289
99090
|
function booleanValue(value) {
|
|
98290
99091
|
return typeof value === "boolean" ? value : undefined;
|
|
98291
99092
|
}
|
|
99093
|
+
function optionalBooleanField(key, value) {
|
|
99094
|
+
return typeof value === "boolean" ? { [key]: value } : {};
|
|
99095
|
+
}
|
|
99096
|
+
function formatFields(row) {
|
|
99097
|
+
return {
|
|
99098
|
+
...optionalBooleanField("format_sensitive", row.format_sensitive),
|
|
99099
|
+
...optionalBooleanField("contains_markdown_list", row.contains_markdown_list),
|
|
99100
|
+
...optionalBooleanField("contains_markdown_table", row.contains_markdown_table),
|
|
99101
|
+
...optionalBooleanField("contains_fenced_code", row.contains_fenced_code),
|
|
99102
|
+
...optionalBooleanField("quote_preview_preserves_line_breaks", row.quote_preview_preserves_line_breaks)
|
|
99103
|
+
};
|
|
99104
|
+
}
|
|
98292
99105
|
function quotePreview(row) {
|
|
98293
|
-
return
|
|
99106
|
+
return stringValue7(row.quote_preview) ?? stringValue7(row.quote);
|
|
98294
99107
|
}
|
|
98295
99108
|
function quoteFullText(row) {
|
|
98296
|
-
return
|
|
99109
|
+
return stringValue7(row.quote_full_text);
|
|
98297
99110
|
}
|
|
98298
99111
|
function literalTexts(row) {
|
|
98299
99112
|
const fullText = quoteFullText(row);
|
|
@@ -98323,9 +99136,9 @@ function contextRole(row) {
|
|
|
98323
99136
|
return "framing";
|
|
98324
99137
|
}
|
|
98325
99138
|
function mapCitable(row) {
|
|
98326
|
-
const sourceRef =
|
|
98327
|
-
const sourceId =
|
|
98328
|
-
const blockId =
|
|
99139
|
+
const sourceRef = stringValue7(row.source_ref);
|
|
99140
|
+
const sourceId = stringValue7(row.source_id);
|
|
99141
|
+
const blockId = stringValue7(row.block_id);
|
|
98329
99142
|
if (row.citation_eligible !== true || sourceRef === undefined || sourceId === undefined || blockId === undefined) {
|
|
98330
99143
|
return;
|
|
98331
99144
|
}
|
|
@@ -98345,19 +99158,20 @@ function mapCitable(row) {
|
|
|
98345
99158
|
...quoteCharCount !== undefined ? { quote_char_count: quoteCharCount } : {},
|
|
98346
99159
|
...previewCharCount !== undefined ? { preview_char_count: previewCharCount } : {},
|
|
98347
99160
|
...previewIsComplete !== undefined ? { preview_is_complete: previewIsComplete } : {},
|
|
99161
|
+
...formatFields(row),
|
|
98348
99162
|
...selector !== undefined ? { selector } : {}
|
|
98349
99163
|
};
|
|
98350
99164
|
}
|
|
98351
99165
|
function mapSupporting(row) {
|
|
98352
|
-
const sourceRef =
|
|
98353
|
-
const sourceId =
|
|
98354
|
-
const blockId =
|
|
99166
|
+
const sourceRef = stringValue7(row.source_ref);
|
|
99167
|
+
const sourceId = stringValue7(row.source_id);
|
|
99168
|
+
const blockId = stringValue7(row.block_id);
|
|
98355
99169
|
if (row.citation_eligible === true || sourceRef === undefined || sourceId === undefined || blockId === undefined) {
|
|
98356
99170
|
return;
|
|
98357
99171
|
}
|
|
98358
99172
|
const role = contextRole(row);
|
|
98359
99173
|
const preview = quotePreview(row);
|
|
98360
|
-
const structuralRole =
|
|
99174
|
+
const structuralRole = stringValue7(row.structural_role);
|
|
98361
99175
|
const quoteCharCount = numberValue2(row.quote_char_count);
|
|
98362
99176
|
const previewCharCount = numberValue2(row.preview_char_count);
|
|
98363
99177
|
const previewIsComplete = booleanValue(row.preview_is_complete);
|
|
@@ -98373,12 +99187,13 @@ function mapSupporting(row) {
|
|
|
98373
99187
|
...preview !== undefined ? { quote_preview: preview } : {},
|
|
98374
99188
|
...quoteCharCount !== undefined ? { quote_char_count: quoteCharCount } : {},
|
|
98375
99189
|
...previewCharCount !== undefined ? { preview_char_count: previewCharCount } : {},
|
|
98376
|
-
...previewIsComplete !== undefined ? { preview_is_complete: previewIsComplete } : {}
|
|
99190
|
+
...previewIsComplete !== undefined ? { preview_is_complete: previewIsComplete } : {},
|
|
99191
|
+
...formatFields(row)
|
|
98377
99192
|
};
|
|
98378
99193
|
}
|
|
98379
99194
|
function literalBase(row) {
|
|
98380
|
-
const sourceRef =
|
|
98381
|
-
const blockId =
|
|
99195
|
+
const sourceRef = stringValue7(row.source_ref);
|
|
99196
|
+
const blockId = stringValue7(row.block_id);
|
|
98382
99197
|
return {
|
|
98383
99198
|
...sourceRef !== undefined ? { source_ref: sourceRef } : {},
|
|
98384
99199
|
...blockId !== undefined ? { block_id: blockId } : {}
|
|
@@ -98507,11 +99322,32 @@ function plannedTemplateActions(sectionGroups) {
|
|
|
98507
99322
|
function scaffoldUsage() {
|
|
98508
99323
|
return "Fill each action.content, adjust kind when needed, keep source_block_ids as the citation shorthand, and keep every scaffold action / planned_section_groups[].draft_action_templates entry as a separate draft action. Do not merge multiple planned groups, templates, or contiguous runs into one action; non-contiguous evidence will be rejected. Submit the actions with context compile cycle <node> --input - --format json, or context compile draft <node> --input - for manual review.";
|
|
98509
99324
|
}
|
|
99325
|
+
function stringArray10(value) {
|
|
99326
|
+
return Array.isArray(value) ? value.filter((item) => typeof item === "string" && item.length > 0) : [];
|
|
99327
|
+
}
|
|
99328
|
+
function formatSensitiveMetadata(action, rows) {
|
|
99329
|
+
const blockIds = new Set(stringArray10(action.source_block_ids));
|
|
99330
|
+
const sourceRefs2 = new Set(stringArray10(action.source_refs));
|
|
99331
|
+
const selected = rows.filter((row) => row.format_sensitive === true && (typeof row.block_id === "string" && blockIds.has(row.block_id) || typeof row.source_ref === "string" && sourceRefs2.has(row.source_ref)));
|
|
99332
|
+
if (selected.length === 0)
|
|
99333
|
+
return {};
|
|
99334
|
+
const sensitiveBlockIds = selected.map((row) => row.block_id).filter((blockId) => typeof blockId === "string" && blockId.length > 0);
|
|
99335
|
+
const commands = selected.map((row) => row.request_full_text_command).filter((command) => typeof command === "string" && command.length > 0);
|
|
99336
|
+
return {
|
|
99337
|
+
format_sensitive_block_ids: sensitiveBlockIds,
|
|
99338
|
+
request_full_text_commands: commands,
|
|
99339
|
+
content_source_hint: "Use request_full_text output for user-facing Markdown content from these block_ids; quote_preview is compact and does not preserve line breaks."
|
|
99340
|
+
};
|
|
99341
|
+
}
|
|
99342
|
+
function formatSensitiveBlockIds(rows) {
|
|
99343
|
+
return rows.filter((row) => row.format_sensitive === true).map((row) => row.block_id).filter((blockId) => typeof blockId === "string" && blockId.length > 0);
|
|
99344
|
+
}
|
|
98510
99345
|
function sourceRefsDraftScaffold(input) {
|
|
98511
99346
|
const requested = new Set(input.requestedBlockIds ?? []);
|
|
98512
99347
|
const plannedActions = requested.size === 0 ? plannedTemplateActions(input.sectionGroups) : [];
|
|
98513
99348
|
if (plannedActions.length > 0) {
|
|
98514
99349
|
const evidence2 = input.compact === true ? undefined : compileEvidenceFields(input.rows);
|
|
99350
|
+
const formatSensitiveIds2 = formatSensitiveBlockIds(input.rows);
|
|
98515
99351
|
return {
|
|
98516
99352
|
schema_version: COMPILE_DRAFT_SCHEMA_VERSION,
|
|
98517
99353
|
node_slug: input.context.node.slug,
|
|
@@ -98522,17 +99358,25 @@ function sourceRefsDraftScaffold(input) {
|
|
|
98522
99358
|
planned_section_groups: input.sectionGroups.filter((group) => group.status === "ready" || group.status === "ready_with_splits").map((group) => group.section_id).filter((sectionId2) => typeof sectionId2 === "string")
|
|
98523
99359
|
},
|
|
98524
99360
|
usage: scaffoldUsage(),
|
|
99361
|
+
...formatSensitiveIds2.length > 0 ? {
|
|
99362
|
+
format_sensitive_block_ids: formatSensitiveIds2,
|
|
99363
|
+
content_source_hint: "Format-sensitive block_ids contain Markdown lists, tables, or fenced code. Use request_full_text_commands before filling user-facing content from quote previews."
|
|
99364
|
+
} : {},
|
|
98525
99365
|
...evidence2 !== undefined ? {
|
|
98526
99366
|
citable_source_refs: evidence2.citable_source_refs,
|
|
98527
99367
|
supporting_context_refs: evidence2.supporting_context_refs,
|
|
98528
99368
|
required_preserved_literals: evidence2.required_preserved_literals
|
|
98529
99369
|
} : {},
|
|
98530
|
-
actions: plannedActions.map((action) => ({
|
|
99370
|
+
actions: plannedActions.map((action) => ({
|
|
99371
|
+
...action,
|
|
99372
|
+
...formatSensitiveMetadata(action, input.rows)
|
|
99373
|
+
}))
|
|
98531
99374
|
};
|
|
98532
99375
|
}
|
|
98533
99376
|
const selectedRows = input.rows.filter((row) => row.citation_eligible === true && typeof row.source_ref === "string" && (requested.size === 0 || typeof row.block_id === "string" && requested.has(row.block_id)));
|
|
98534
99377
|
const kind = defaultScaffoldSectionKind(input.context);
|
|
98535
99378
|
const evidence = input.compact === true ? undefined : compileEvidenceFields(selectedRows);
|
|
99379
|
+
const formatSensitiveIds = formatSensitiveBlockIds(selectedRows);
|
|
98536
99380
|
return {
|
|
98537
99381
|
schema_version: COMPILE_DRAFT_SCHEMA_VERSION,
|
|
98538
99382
|
node_slug: input.context.node.slug,
|
|
@@ -98543,6 +99387,10 @@ function sourceRefsDraftScaffold(input) {
|
|
|
98543
99387
|
...requested.size > 0 ? { requested_block_ids: [...requested] } : {}
|
|
98544
99388
|
},
|
|
98545
99389
|
usage: scaffoldUsage(),
|
|
99390
|
+
...formatSensitiveIds.length > 0 ? {
|
|
99391
|
+
format_sensitive_block_ids: formatSensitiveIds,
|
|
99392
|
+
content_source_hint: "Format-sensitive block_ids contain Markdown lists, tables, or fenced code. Use request_full_text_commands before filling user-facing content from quote previews."
|
|
99393
|
+
} : {},
|
|
98546
99394
|
...evidence !== undefined ? {
|
|
98547
99395
|
citable_source_refs: evidence.citable_source_refs,
|
|
98548
99396
|
supporting_context_refs: evidence.supporting_context_refs,
|
|
@@ -98552,7 +99400,8 @@ function sourceRefsDraftScaffold(input) {
|
|
|
98552
99400
|
op: "add",
|
|
98553
99401
|
kind,
|
|
98554
99402
|
content: "",
|
|
98555
|
-
source_block_ids: typeof row.block_id === "string" ? [row.block_id] : []
|
|
99403
|
+
source_block_ids: typeof row.block_id === "string" ? [row.block_id] : [],
|
|
99404
|
+
...formatSensitiveMetadata({ source_block_ids: typeof row.block_id === "string" ? [row.block_id] : [] }, selectedRows)
|
|
98556
99405
|
}))
|
|
98557
99406
|
};
|
|
98558
99407
|
}
|
|
@@ -98581,8 +99430,15 @@ function compactDraftScaffoldGroup(group) {
|
|
|
98581
99430
|
"missing_block_ids",
|
|
98582
99431
|
"non_citation_block_ids",
|
|
98583
99432
|
"contiguous_run_count",
|
|
99433
|
+
"citation_block_count",
|
|
99434
|
+
"source_ids",
|
|
99435
|
+
"heading_path",
|
|
99436
|
+
"heading_paths",
|
|
99437
|
+
"contains_markdown_list",
|
|
98584
99438
|
"intervening_citation_eligible_block_ids",
|
|
98585
99439
|
"split_reason",
|
|
99440
|
+
"split_reasons",
|
|
99441
|
+
"heading_path_runs",
|
|
98586
99442
|
"sibling_bridge_reason",
|
|
98587
99443
|
"sibling_bridge_block_ids",
|
|
98588
99444
|
"contiguous_runs",
|
|
@@ -98650,7 +99506,7 @@ function sourceRefsSectionGroupHint(sectionGroups) {
|
|
|
98650
99506
|
code: "compile-source-refs-planned-section-groups",
|
|
98651
99507
|
severity: "info",
|
|
98652
99508
|
message: "planned_section_groups is the primary source-refs authoring path for finalized align section plans.",
|
|
98653
|
-
next_action: splitCount > 0 ? "Copy each planned_section_groups[].draft_action_templates entry as a separate draft action; split groups already avoid non-contiguous citation-eligible blocks and may use source_block_ids shorthand. Do not merge templates
|
|
99509
|
+
next_action: splitCount > 0 ? "Copy each planned_section_groups[].draft_action_templates entry as a separate draft action; split groups already avoid non-contiguous citation-eligible blocks and may use source_block_ids shorthand. Do not merge by default; only intentionally combine adjacent templates when a fragment-review hint flags them and the evidence is one knowledge unit." : "Copy each planned_section_groups[].draft_action_templates entry as a separate draft action; fill content from the cited evidence and keep source_block_ids shorthand when present. Do not merge by default; only intentionally combine adjacent groups when a fragment-review hint flags them and the evidence is one knowledge unit.",
|
|
98654
99510
|
diagnostics: {
|
|
98655
99511
|
planned_section_groups: sectionGroups.length,
|
|
98656
99512
|
split_planned_section_groups: splitCount
|
|
@@ -98661,7 +99517,7 @@ function sourceRefsDenseHintWithSectionGroups(hint, sectionGroups) {
|
|
|
98661
99517
|
return {
|
|
98662
99518
|
...hint,
|
|
98663
99519
|
message: `${hint.message} planned_section_groups are available for finalized align section plans.`,
|
|
98664
|
-
next_action: "Use planned_section_groups[].draft_action_templates first, keeping each template as a separate draft action. Fallback may split finer only when a planned group is missing, needs attention, or you intentionally need finer-grained Sections;
|
|
99520
|
+
next_action: "Use planned_section_groups[].draft_action_templates first, keeping each template as a separate draft action by default. Fallback may split finer only when a planned group is missing, needs attention, or you intentionally need finer-grained Sections; combine adjacent templates only when fragment-review evidence shows one knowledge unit.",
|
|
98665
99521
|
diagnostics: {
|
|
98666
99522
|
...hint.diagnostics ?? {},
|
|
98667
99523
|
planned_section_groups_available: true,
|
|
@@ -98671,6 +99527,11 @@ function sourceRefsDenseHintWithSectionGroups(hint, sectionGroups) {
|
|
|
98671
99527
|
}
|
|
98672
99528
|
function sourceRefsViewHints(input) {
|
|
98673
99529
|
const sectionGroupHints = sourceRefsSectionGroupHint(input.sectionGroups);
|
|
99530
|
+
const fragmentReviewHint = plannedSectionFragmentReviewHint({
|
|
99531
|
+
sectionGroups: input.sectionGroups,
|
|
99532
|
+
detailCommand: input.detailCommand
|
|
99533
|
+
});
|
|
99534
|
+
const fragmentHints = fragmentReviewHint === undefined ? [] : [fragmentReviewHint];
|
|
98674
99535
|
if (input.sectionGroups.length === 0) {
|
|
98675
99536
|
return [...input.projectedHints, input.scaffoldHint];
|
|
98676
99537
|
}
|
|
@@ -98683,7 +99544,7 @@ function sourceRefsViewHints(input) {
|
|
|
98683
99544
|
nonDenseHints.push(hint);
|
|
98684
99545
|
}
|
|
98685
99546
|
}
|
|
98686
|
-
return [...nonDenseHints, ...sectionGroupHints, ...denseHints, input.scaffoldHint];
|
|
99547
|
+
return [...nonDenseHints, ...sectionGroupHints, ...fragmentHints, ...denseHints, input.scaffoldHint];
|
|
98687
99548
|
}
|
|
98688
99549
|
function compileCycleCommand(slug) {
|
|
98689
99550
|
return `context compile cycle ${shellQuote(slug)} --input - --format json`;
|
|
@@ -98779,7 +99640,12 @@ function writeCompileSourceRefs(context, format, options = {}) {
|
|
|
98779
99640
|
command: sourceRefsIndex,
|
|
98780
99641
|
detail_view_command: sourceRefsDetail
|
|
98781
99642
|
};
|
|
98782
|
-
const viewHints = sourceRefsViewHints({
|
|
99643
|
+
const viewHints = sourceRefsViewHints({
|
|
99644
|
+
projectedHints,
|
|
99645
|
+
sectionGroups,
|
|
99646
|
+
scaffoldHint,
|
|
99647
|
+
detailCommand: sourceRefsDetail
|
|
99648
|
+
});
|
|
98783
99649
|
const envelope = sourceRefsNextActionEnvelope({
|
|
98784
99650
|
context,
|
|
98785
99651
|
...options.workflowState !== undefined ? { workflowState: options.workflowState } : {},
|
|
@@ -99059,13 +99925,13 @@ function writeCompileContextSummary(input) {
|
|
|
99059
99925
|
writeCompileContextTextSummary(input, coverageRepairRound, coverageScopeHint);
|
|
99060
99926
|
}
|
|
99061
99927
|
function compileDraftRevisionHints(slug, digest2) {
|
|
99062
|
-
const patchCommand = `context compile
|
|
99928
|
+
const patchCommand = `context compile cycle ${shellQuote(slug)} --input - --format json`;
|
|
99063
99929
|
const rebuildCommand = `context compile draft ${shellQuote(slug)} --input -`;
|
|
99064
99930
|
return [{
|
|
99065
99931
|
code: "compile-draft-patch-ready",
|
|
99066
99932
|
severity: "info",
|
|
99067
99933
|
message: "Current draft can be revised with a node-scoped patch instead of resubmitting all actions.",
|
|
99068
|
-
next_action: "Replace, add, or remove only the affected action. replace_action fully replaces that action while keeping action_id; add_action receives a new action_id. To rebuild from scratch, submit a full draft with context compile
|
|
99934
|
+
next_action: "Replace, add, or remove only the affected action, then submit the compile-draft-patch payload through context compile cycle. replace_action fully replaces that action while keeping action_id; add_action receives a new action_id. To rebuild from scratch, submit a full draft with context compile cycle <slug> --input - --format json.",
|
|
99069
99935
|
command: patchCommand,
|
|
99070
99936
|
patch_schema_version: COMPILE_DRAFT_PATCH_SCHEMA_VERSION,
|
|
99071
99937
|
correct_shape: compileDraftPatchCorrectShape(),
|
|
@@ -99103,7 +99969,7 @@ function writeCompileDraftStatus(input) {
|
|
|
99103
99969
|
view,
|
|
99104
99970
|
draft_digest: input.digest,
|
|
99105
99971
|
patch_schema_version: COMPILE_DRAFT_PATCH_SCHEMA_VERSION,
|
|
99106
|
-
patch_command: hints[0]?.command ?? `context compile
|
|
99972
|
+
patch_command: hints[0]?.command ?? `context compile cycle ${shellQuote(input.session.node)} --input - --format json`,
|
|
99107
99973
|
...input.session.suggested_patch_template !== undefined ? { suggested_patch_template: input.session.suggested_patch_template } : {},
|
|
99108
99974
|
show_command: input.showCommand,
|
|
99109
99975
|
next_command: input.showCommand,
|
|
@@ -99138,7 +100004,7 @@ function writeCompileDraftStatus(input) {
|
|
|
99138
100004
|
function claimIdForActionIndex(index2) {
|
|
99139
100005
|
return `claim-${String(index2 + 1).padStart(3, "0")}`;
|
|
99140
100006
|
}
|
|
99141
|
-
function
|
|
100007
|
+
function stringArray11(value) {
|
|
99142
100008
|
return Array.isArray(value) ? value.filter((entry) => typeof entry === "string") : [];
|
|
99143
100009
|
}
|
|
99144
100010
|
function sourceRefNarrowingByActionIndex(hints) {
|
|
@@ -99147,13 +100013,13 @@ function sourceRefNarrowingByActionIndex(hints) {
|
|
|
99147
100013
|
if (hint.code !== "compile-source-refs-narrowing-suggested" || typeof hint.op_index !== "number")
|
|
99148
100014
|
continue;
|
|
99149
100015
|
const diagnostics = hint.diagnostics ?? {};
|
|
99150
|
-
const original =
|
|
99151
|
-
const narrowed =
|
|
99152
|
-
const removed =
|
|
99153
|
-
const leadIn =
|
|
99154
|
-
const redundant =
|
|
99155
|
-
const suggestedRefs =
|
|
99156
|
-
const patchRefs =
|
|
100016
|
+
const original = stringArray11(diagnostics.original_source_refs);
|
|
100017
|
+
const narrowed = stringArray11(diagnostics.narrowed_source_refs);
|
|
100018
|
+
const removed = stringArray11(diagnostics.removed_source_refs);
|
|
100019
|
+
const leadIn = stringArray11(diagnostics.removed_lead_in_source_refs);
|
|
100020
|
+
const redundant = stringArray11(diagnostics.removed_redundant_source_refs);
|
|
100021
|
+
const suggestedRefs = stringArray11(diagnostics.suggested_source_refs);
|
|
100022
|
+
const patchRefs = stringArray11(diagnostics.patch_source_refs);
|
|
99157
100023
|
if (original.length === 0 || narrowed.length === 0 || removed.length === 0)
|
|
99158
100024
|
continue;
|
|
99159
100025
|
byIndex.set(hint.op_index, {
|
|
@@ -99178,8 +100044,8 @@ function sourceRefNarrowingByActionIndex(hints) {
|
|
|
99178
100044
|
function sourceSupportDiagnostics(support) {
|
|
99179
100045
|
if (support?.verdict === undefined || support.verdict === "supported")
|
|
99180
100046
|
return;
|
|
99181
|
-
const missingHardTerms =
|
|
99182
|
-
const missingContentTerms =
|
|
100047
|
+
const missingHardTerms = stringArray11(support.missing_hard_terms);
|
|
100048
|
+
const missingContentTerms = stringArray11(support.missing_content_terms);
|
|
99183
100049
|
const missingTerms = Array.isArray(support.missing_terms) ? support.missing_terms.slice(0, 12).filter((term) => term !== null && typeof term === "object") : [];
|
|
99184
100050
|
if (missingHardTerms.length === 0 && missingContentTerms.length === 0 && missingTerms.length === 0)
|
|
99185
100051
|
return;
|
|
@@ -99288,11 +100154,11 @@ function withPayloadMeta2(value, payload) {
|
|
|
99288
100154
|
})
|
|
99289
100155
|
};
|
|
99290
100156
|
}
|
|
99291
|
-
function
|
|
100157
|
+
function stringArray12(value) {
|
|
99292
100158
|
return Array.isArray(value) ? value.filter((entry) => typeof entry === "string") : [];
|
|
99293
100159
|
}
|
|
99294
100160
|
function narrowingSuggestionRemovedCount(context) {
|
|
99295
|
-
return (context.agent_hints ?? []).filter((hint) => hint.code === "compile-source-refs-narrowing-suggested").reduce((sum, hint) => sum +
|
|
100161
|
+
return (context.agent_hints ?? []).filter((hint) => hint.code === "compile-source-refs-narrowing-suggested").reduce((sum, hint) => sum + stringArray12(hint.diagnostics?.removed_source_refs).length, 0);
|
|
99296
100162
|
}
|
|
99297
100163
|
function prepareEnvelopeOutput(input) {
|
|
99298
100164
|
const warnings = (input.context.agent_hints ?? []).filter((hint) => hint.severity === "warning" || hint.severity === "error");
|
|
@@ -99386,27 +100252,12 @@ async function prepareCompileDraftWorkflow(input) {
|
|
|
99386
100252
|
}
|
|
99387
100253
|
|
|
99388
100254
|
// src/commands/compileDraftCommand.ts
|
|
99389
|
-
function
|
|
100255
|
+
function isRecord43(value) {
|
|
99390
100256
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
99391
100257
|
}
|
|
99392
|
-
function draftActionCounts(draft) {
|
|
99393
|
-
return {
|
|
99394
|
-
total: draft.actions.length,
|
|
99395
|
-
add: draft.actions.filter((action) => action.op === "add").length,
|
|
99396
|
-
update: draft.actions.filter((action) => action.op === "update").length,
|
|
99397
|
-
supersede: draft.actions.filter((action) => action.op === "supersede").length,
|
|
99398
|
-
deprecate: draft.actions.filter((action) => action.op === "deprecate").length,
|
|
99399
|
-
skip: draft.actions.filter((action) => action.op === "skip").length,
|
|
99400
|
-
structure_challenge: draft.actions.filter((action) => action.op === "structure_challenge").length,
|
|
99401
|
-
pending_ownership_challenge: draft.actions.filter((action) => action.op === "pending_ownership_challenge").length
|
|
99402
|
-
};
|
|
99403
|
-
}
|
|
99404
100258
|
function compileCycleInputCommand(slug) {
|
|
99405
100259
|
return `context compile cycle ${shellQuote(slug)} --input - --format json`;
|
|
99406
100260
|
}
|
|
99407
|
-
function compileCycleContinueCommand2(slug) {
|
|
99408
|
-
return `context compile cycle ${shellQuote(slug)} --continue --format json`;
|
|
99409
|
-
}
|
|
99410
100261
|
function compileDraftInputRequiredError(slug) {
|
|
99411
100262
|
const reasonCode = "compile-draft-input-required";
|
|
99412
100263
|
const message = "context compile draft requires --input - unless --prepare is used to load the saved draft session";
|
|
@@ -99443,6 +100294,44 @@ function compileDraftInputRequiredError(slug) {
|
|
|
99443
100294
|
}]
|
|
99444
100295
|
});
|
|
99445
100296
|
}
|
|
100297
|
+
function compileDraftPatchCommandError(slug) {
|
|
100298
|
+
const reasonCode = "compile-draft-patch-cycle-required";
|
|
100299
|
+
const command = compileCycleInputCommand(slug);
|
|
100300
|
+
const message = "submit compile draft patches through context compile cycle";
|
|
100301
|
+
const envelope = createNextActionEnvelope({
|
|
100302
|
+
allowed_actions: ["patch_payload", "show_view"],
|
|
100303
|
+
next_action: {
|
|
100304
|
+
kind: "patch_compile_draft",
|
|
100305
|
+
command,
|
|
100306
|
+
input_schema: "compile-draft-patch",
|
|
100307
|
+
reason_code: reasonCode,
|
|
100308
|
+
blocking: true
|
|
100309
|
+
},
|
|
100310
|
+
diagnostics: {
|
|
100311
|
+
summary: { reason_code: reasonCode, issue_count: 1 },
|
|
100312
|
+
warnings: [{
|
|
100313
|
+
code: reasonCode,
|
|
100314
|
+
severity: "error",
|
|
100315
|
+
message,
|
|
100316
|
+
reason_code: reasonCode
|
|
100317
|
+
}]
|
|
100318
|
+
},
|
|
100319
|
+
strict: false
|
|
100320
|
+
});
|
|
100321
|
+
return new ContextError(ExitCode.UserError, message, {
|
|
100322
|
+
category: ErrorCategory.UserInputInvalid,
|
|
100323
|
+
...envelope,
|
|
100324
|
+
agent_hints: [{
|
|
100325
|
+
code: reasonCode,
|
|
100326
|
+
severity: "error",
|
|
100327
|
+
message,
|
|
100328
|
+
next_action: "Submit the same compile-draft-patch payload to the compile cycle command.",
|
|
100329
|
+
command,
|
|
100330
|
+
schema: "compile-draft-patch",
|
|
100331
|
+
schema_version: "compile.draft-patch.v2"
|
|
100332
|
+
}]
|
|
100333
|
+
});
|
|
100334
|
+
}
|
|
99446
100335
|
async function writeCompileDraftChallengePayloads2(input) {
|
|
99447
100336
|
const payloads = await compileDraftChallengePayloads({
|
|
99448
100337
|
ctxDir: input.ctxDir,
|
|
@@ -99470,16 +100359,16 @@ async function writeCompileDraftChallengePayloads2(input) {
|
|
|
99470
100359
|
});
|
|
99471
100360
|
}
|
|
99472
100361
|
}
|
|
99473
|
-
function
|
|
100362
|
+
function stringArray13(value) {
|
|
99474
100363
|
return Array.isArray(value) ? value.filter((entry) => typeof entry === "string") : [];
|
|
99475
100364
|
}
|
|
99476
100365
|
function preparedSourceSupportStatus(value) {
|
|
99477
|
-
if (!
|
|
100366
|
+
if (!isRecord43(value) || typeof value.verdict !== "string")
|
|
99478
100367
|
return;
|
|
99479
100368
|
if (value.verdict === "supported")
|
|
99480
100369
|
return { verdict: value.verdict };
|
|
99481
|
-
const missingHardTerms =
|
|
99482
|
-
const missingContentTerms =
|
|
100370
|
+
const missingHardTerms = stringArray13(value.missing_hard_terms);
|
|
100371
|
+
const missingContentTerms = stringArray13(value.missing_content_terms);
|
|
99483
100372
|
const missingTerms = Array.isArray(value.missing_terms) ? value.missing_terms.slice(0, 12).filter((term) => term !== null && typeof term === "object") : [];
|
|
99484
100373
|
return {
|
|
99485
100374
|
verdict: value.verdict,
|
|
@@ -99489,15 +100378,15 @@ function preparedSourceSupportStatus(value) {
|
|
|
99489
100378
|
};
|
|
99490
100379
|
}
|
|
99491
100380
|
function preparedReconcileStatus(value, slug) {
|
|
99492
|
-
const agentHints =
|
|
99493
|
-
if (!
|
|
100381
|
+
const agentHints = isRecord43(value) && Array.isArray(value.agent_hints) ? value.agent_hints.filter(isRecord43) : [];
|
|
100382
|
+
if (!isRecord43(value) || !Array.isArray(value.items))
|
|
99494
100383
|
return { items: [], agentHints };
|
|
99495
|
-
const target =
|
|
100384
|
+
const target = isRecord43(value.target) ? value.target : undefined;
|
|
99496
100385
|
if (target !== undefined && target.node !== slug)
|
|
99497
100386
|
return { items: [], agentHints };
|
|
99498
100387
|
return {
|
|
99499
100388
|
agentHints,
|
|
99500
|
-
items: value.items.filter(
|
|
100389
|
+
items: value.items.filter(isRecord43).flatMap((item) => {
|
|
99501
100390
|
if (typeof item.item_id !== "string")
|
|
99502
100391
|
return [];
|
|
99503
100392
|
const sourceSupport = preparedSourceSupportStatus(item.source_support);
|
|
@@ -99546,125 +100435,7 @@ async function runDraftStatus(input) {
|
|
|
99546
100435
|
});
|
|
99547
100436
|
}
|
|
99548
100437
|
async function runDraftPatch(input) {
|
|
99549
|
-
|
|
99550
|
-
if (current.family !== "compile") {
|
|
99551
|
-
throw new ContextError(ExitCode.UserError, "compile draft patch requires an active compile workflow", {
|
|
99552
|
-
category: ErrorCategory.UserInputInvalid
|
|
99553
|
-
});
|
|
99554
|
-
}
|
|
99555
|
-
const payload = await readWorkflowPayloadByDigest({
|
|
99556
|
-
ctxDir: input.ctxDir,
|
|
99557
|
-
workflowId: current.workflow_id,
|
|
99558
|
-
scopeId: nodeRunIdForSlug(input.slug),
|
|
99559
|
-
payload: "compile-draft",
|
|
99560
|
-
...typeof input.options.payloadDigest === "string" ? { digest: input.options.payloadDigest } : {},
|
|
99561
|
-
fallbackToUniqueScope: true
|
|
99562
|
-
});
|
|
99563
|
-
const session = parseCompileDraftSession(payload.value);
|
|
99564
|
-
assertCompileDraftSessionNode(session, input.slug);
|
|
99565
|
-
const patchInput = await readStructuredInput2(resolveStdinOnlyInput(input.options.input, "--input"));
|
|
99566
|
-
const patch = parseCompileDraftPatch(patchInput);
|
|
99567
|
-
const patched = applyCompileDraftPatch({
|
|
99568
|
-
session,
|
|
99569
|
-
patch,
|
|
99570
|
-
expectedDigest: payload.digest
|
|
99571
|
-
});
|
|
99572
|
-
rejectRetiredDraftPatchFields(patchInput, input.slug);
|
|
99573
|
-
const result = await compileDraft({
|
|
99574
|
-
ctxDir: input.ctxDir,
|
|
99575
|
-
slug: input.slug,
|
|
99576
|
-
mode: "plan",
|
|
99577
|
-
inputMode: "internal",
|
|
99578
|
-
stdout: { write: () => true },
|
|
99579
|
-
draftProvider: async () => patched.draft
|
|
99580
|
-
});
|
|
99581
|
-
const normalizedDraft = result.plan ?? patched.draft;
|
|
99582
|
-
const nextSession = createCompileDraftSession({
|
|
99583
|
-
node: input.slug,
|
|
99584
|
-
draft: normalizedDraft,
|
|
99585
|
-
...result.agent_hints !== undefined ? { agentHints: result.agent_hints } : {}
|
|
99586
|
-
});
|
|
99587
|
-
const nextPayload = await writeWorkflowPayloadWithDigest({
|
|
99588
|
-
ctxDir: input.ctxDir,
|
|
99589
|
-
workflowId: current.workflow_id,
|
|
99590
|
-
scopeId: nodeRunIdForSlug(input.slug),
|
|
99591
|
-
payload: "compile-draft",
|
|
99592
|
-
value: nextSession,
|
|
99593
|
-
format: "yaml"
|
|
99594
|
-
});
|
|
99595
|
-
await writeCompileDraftChallengePayloads2({
|
|
99596
|
-
ctxDir: input.ctxDir,
|
|
99597
|
-
workflowId: current.workflow_id,
|
|
99598
|
-
scopeId: nodeRunIdForSlug(input.slug),
|
|
99599
|
-
draft: normalizedDraft
|
|
99600
|
-
});
|
|
99601
|
-
const continueCommand = compileCycleContinueCommand2(result.slug);
|
|
99602
|
-
const envelope = createNextActionEnvelope({
|
|
99603
|
-
workflow: {
|
|
99604
|
-
id: current.workflow_id,
|
|
99605
|
-
workflow_id: current.workflow_id,
|
|
99606
|
-
family: current.family,
|
|
99607
|
-
stage: current.stage,
|
|
99608
|
-
terminal: false,
|
|
99609
|
-
scope_id: workflowScope(current)
|
|
99610
|
-
},
|
|
99611
|
-
allowed_actions: ["continue_compile_cycle", "show_view"],
|
|
99612
|
-
next_action: {
|
|
99613
|
-
kind: "continue_compile_cycle",
|
|
99614
|
-
command: continueCommand,
|
|
99615
|
-
reason_code: "compile-draft-patched"
|
|
99616
|
-
},
|
|
99617
|
-
views: [{
|
|
99618
|
-
id: "draft-status",
|
|
99619
|
-
purpose: "Inspect the patched saved draft before continuing cycle if needed.",
|
|
99620
|
-
evidence_role: "diagnostic",
|
|
99621
|
-
expected: false,
|
|
99622
|
-
budget_safety: "compact",
|
|
99623
|
-
command: `context compile draft-status ${shellQuote(result.slug)} --format json`
|
|
99624
|
-
}]
|
|
99625
|
-
});
|
|
99626
|
-
const outputHints = [...patch.agent_hints ?? [], ...result.agent_hints ?? []];
|
|
99627
|
-
if (compileChangesFormat(input.options.format) === "json") {
|
|
99628
|
-
writeJson5({
|
|
99629
|
-
action: "patched",
|
|
99630
|
-
status: "planned",
|
|
99631
|
-
node: input.slug,
|
|
99632
|
-
schema_version: envelope.schema_version,
|
|
99633
|
-
allowed_actions: envelope.allowed_actions,
|
|
99634
|
-
next_action: envelope.next_action,
|
|
99635
|
-
views: envelope.views,
|
|
99636
|
-
workflow: workflowMetadata(current),
|
|
99637
|
-
draft: {
|
|
99638
|
-
payload: nextPayload.payload,
|
|
99639
|
-
scope_id: nextPayload.scope_id,
|
|
99640
|
-
digest: nextPayload.digest,
|
|
99641
|
-
format: nextPayload.format,
|
|
99642
|
-
show_command: workflowPayloadShowCommand(nextPayload)
|
|
99643
|
-
},
|
|
99644
|
-
action_counts: draftActionCounts(normalizedDraft),
|
|
99645
|
-
agent_hints: outputHints,
|
|
99646
|
-
next_command: continueCommand
|
|
99647
|
-
});
|
|
99648
|
-
return;
|
|
99649
|
-
}
|
|
99650
|
-
process.stdout.write(formatFeedback({
|
|
99651
|
-
symbol: outputHints.some((hint) => hint.severity === "warning" || hint.severity === "error") ? "⚠" : "✓",
|
|
99652
|
-
action: "patched",
|
|
99653
|
-
subject: input.slug,
|
|
99654
|
-
headline: formatDraftPatchHeadline(result),
|
|
99655
|
-
body: [
|
|
99656
|
-
workflowSummaryLine(current),
|
|
99657
|
-
...draftPlanBody({
|
|
99658
|
-
ctxDir: input.ctxDir,
|
|
99659
|
-
slug: result.slug,
|
|
99660
|
-
saved: false,
|
|
99661
|
-
...outputHints.length > 0 ? { hints: outputHints } : {},
|
|
99662
|
-
draftDigest: nextPayload.digest,
|
|
99663
|
-
result
|
|
99664
|
-
})
|
|
99665
|
-
],
|
|
99666
|
-
next: continueCommand
|
|
99667
|
-
}));
|
|
100438
|
+
throw compileDraftPatchCommandError(input.slug);
|
|
99668
100439
|
}
|
|
99669
100440
|
async function draftFromSavedSession(input) {
|
|
99670
100441
|
const current = requireCurrentWorkflow(await readCurrentWorkflow(input.ctxDir));
|
|
@@ -100178,7 +100949,7 @@ function registerCompileWorkflowSubcommands(command, run2) {
|
|
|
100178
100949
|
command.command("draft-status <slug>").description("Print the current compile draft session summary").option("--view <view>", "output view: summary | detail | narrowing-detail").option("--format <format>", "output format: json | table", "json").action(async (slug, options) => {
|
|
100179
100950
|
await run2(mergeOptions(options, { draftStatus: slug }));
|
|
100180
100951
|
});
|
|
100181
|
-
command.command("draft-patch <slug>").description("
|
|
100952
|
+
command.command("draft-patch <slug>", { hidden: true }).description("Use context compile cycle <slug> --input - --format json").option("--input <-|stdin>", "compile draft patch JSON/YAML document; only '-' is accepted; use shell redirect or heredoc").option("--payload-digest <digest>", "optional compile draft payload digest stale guard").option("--format <format>", "output format: json | table", "json").action(async (slug, options) => {
|
|
100182
100953
|
await run2(mergeOptions(options, { draftPatch: slug, plan: true }));
|
|
100183
100954
|
});
|
|
100184
100955
|
command.command("coverage <slug>").description("Resolve coverage candidates for one node").option("--input <-|stdin>", "coverage disposition patch JSON/YAML document; only '-' is accepted; use shell redirect or heredoc").option("--skip <candidate-id>", "skip one or more coverage candidates; repeat for multiple", collectCoverageSkip, []).option("--skip-unresolved", "skip every unresolved coverage candidate for this node").option("--reason <text>", "reason for coverage skip shortcuts").option("--replace", "replace existing dispositions for patched candidates").option("--payload-digest <digest>", "optional workflow payload digest stale guard").option("--format <format>", "output format: json | table", "json").action(async (slug, options) => {
|
|
@@ -100251,11 +101022,6 @@ var COMPILE_MODE_COMMANDS = [
|
|
|
100251
101022
|
command: "context compile draft-status <slug> --format json",
|
|
100252
101023
|
description: "Inspect a saved compile draft session."
|
|
100253
101024
|
},
|
|
100254
|
-
{
|
|
100255
|
-
mode: "draft-patch",
|
|
100256
|
-
command: "context compile draft-patch <slug> --input -",
|
|
100257
|
-
description: "Patch a saved compile draft session."
|
|
100258
|
-
},
|
|
100259
101025
|
{
|
|
100260
101026
|
mode: "coverage-status",
|
|
100261
101027
|
command: "context compile coverage <slug> --format json",
|
|
@@ -101660,11 +102426,6 @@ function assertDraftOptions(options) {
|
|
|
101660
102426
|
if (typeof options.draftPatch === "string" && options.plan !== true) {
|
|
101661
102427
|
options.plan = true;
|
|
101662
102428
|
}
|
|
101663
|
-
if (typeof options.draftPatch === "string" && typeof options.input !== "string") {
|
|
101664
|
-
throw new ContextError(ExitCode.UserError, "context compile draft-patch requires --input", {
|
|
101665
|
-
category: ErrorCategory.UserInputInvalid
|
|
101666
|
-
});
|
|
101667
|
-
}
|
|
101668
102429
|
}
|
|
101669
102430
|
function assertAspectCompileOptions(options, flags2) {
|
|
101670
102431
|
if (flags2.wantsCode && (options.plan === true || options.delegated === true)) {
|
|
@@ -102485,6 +103246,13 @@ var AGENT_HINT_EMITTER_WORKFLOW_INVENTORY = [
|
|
|
102485
103246
|
handles: ["node_ref", "block_id", "ownership_role"],
|
|
102486
103247
|
notes: "Shared align payload diagnostics expose semantic ids and ownership roles; normal authoring remains intent-first."
|
|
102487
103248
|
},
|
|
103249
|
+
{
|
|
103250
|
+
source: "src/workflow/alignStructureIntent.ts",
|
|
103251
|
+
family: "align structure intent compiler",
|
|
103252
|
+
policy: "semantic",
|
|
103253
|
+
handles: ["block_id", "node_slug", "ownership_role", "schema_version"],
|
|
103254
|
+
notes: "Intent compile diagnostics expose semantic block, node, role, and schema handles while keeping canonical decision expansion mechanical."
|
|
103255
|
+
},
|
|
102488
103256
|
{
|
|
102489
103257
|
source: "src/workflow/alignWorkflowSchemas.ts",
|
|
102490
103258
|
family: "align schema example",
|
|
@@ -102754,8 +103522,8 @@ var COMMAND_MATRIX = [
|
|
|
102754
103522
|
{ command: "compile context", view: "production-semantic", handles: ["node_slug", "source_ref", "block_id", "payload"], notes: "Prepares one node context or source-ref view before drafting." },
|
|
102755
103523
|
{ command: "compile cycle", view: "production-semantic", handles: ["node_slug", "review_id", "workflow_id"], notes: "Runs one node through draft validation, prepare, safe review, and apply." },
|
|
102756
103524
|
{ command: "compile draft", view: "production-semantic", handles: ["node_slug", "source_ref", "payload"], notes: "Validates one compile draft from stdin in plan mode." },
|
|
103525
|
+
{ command: "compile draft-patch", view: "production-semantic", handles: ["node_slug", "action_id", "operation"], notes: "Patches a saved compile draft session through semantic operations." },
|
|
102757
103526
|
{ command: "compile draft-status", view: "production-semantic", handles: ["node_slug", "payload"], notes: "Shows the current draft session for one node." },
|
|
102758
|
-
{ command: "compile draft-patch", view: "production-semantic", handles: ["node_slug", "payload"], notes: "Patches the current draft session for one node." },
|
|
102759
103527
|
{ command: "compile coverage", view: "production-semantic", handles: ["node_slug", "candidate_id", "payload"], notes: "Resolves coverage candidates through one node-scoped command." },
|
|
102760
103528
|
{ command: "compile close", view: "production-semantic", handles: ["workflow_id", "node_slug", "section_id"], notes: "Closes compile workflow after pending node work is settled." },
|
|
102761
103529
|
{ command: "reconcile", view: "production-semantic", handles: ["prepare_digest", "review_id", "scope_id"], notes: "Semantic reconciliation namespace." },
|
|
@@ -102941,6 +103709,13 @@ var AGENT_HINT_EMITTER_INVENTORY = [
|
|
|
102941
103709
|
handles: ["workflow_payload", "prepare_digest", "review_id"],
|
|
102942
103710
|
notes: "Reconcile errors route to previous semantic workflow step or schema."
|
|
102943
103711
|
},
|
|
103712
|
+
{
|
|
103713
|
+
source: "src/commands/reconcilePrepareCandidateViews.ts",
|
|
103714
|
+
family: "reconcile prepare candidate views",
|
|
103715
|
+
policy: "semantic",
|
|
103716
|
+
handles: ["item_id", "candidate_id", "candidate_count"],
|
|
103717
|
+
notes: "Candidate index hints route agents from prepare item ids to scoped candidate detail views before semantic judgment."
|
|
103718
|
+
},
|
|
102944
103719
|
{
|
|
102945
103720
|
source: "src/commands/reconcilePrepareRefresh.ts",
|
|
102946
103721
|
family: "reconcile stale prepare refresh",
|
|
@@ -105220,9 +105995,7 @@ function compileSchemaExample(name) {
|
|
|
105220
105995
|
schema: "compile-draft-patch",
|
|
105221
105996
|
schema_version: COMPILE_DRAFT_PATCH_SCHEMA_VERSION,
|
|
105222
105997
|
consumed_by: [
|
|
105223
|
-
"context compile
|
|
105224
|
-
"context compile cycle <slug> --input -",
|
|
105225
|
-
"context compile cycle <slug> --continue --format json"
|
|
105998
|
+
"context compile cycle <slug> --input -"
|
|
105226
105999
|
],
|
|
105227
106000
|
required: ["operations"],
|
|
105228
106001
|
enums: {
|
|
@@ -105234,7 +106007,7 @@ function compileSchemaExample(name) {
|
|
|
105234
106007
|
"The CLI reads the current draft session by default; add --payload-digest only when an explicit stale guard is needed.",
|
|
105235
106008
|
"This is not the align finalize patch shape: do not use op/path/value JSON Pointer operations here.",
|
|
105236
106009
|
"replace_action keeps the same action_id; add_action receives a new CLI-owned action_id.",
|
|
105237
|
-
"When node-cycle returns partial-applied or review-required,
|
|
106010
|
+
"When node-cycle returns partial-applied or review-required, submit this patch shape on stdin to context compile cycle <slug> --input - --format json to patch the saved draft and continue the safe-default review/apply loop.",
|
|
105238
106011
|
"The CLI validates the whole patched draft before saving it, so failed patches do not corrupt the current draft session."
|
|
105239
106012
|
],
|
|
105240
106013
|
example: {
|