mandrel 2.80.0 → 2.81.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.agents/audit-checklists/security.md +15 -1
- package/.agents/docs/agentrc-reference.json +1 -0
- package/.agents/docs/configuration.md +3 -2
- package/.agents/docs/execution-reference.md +25 -5
- package/.agents/docs/workflows.md +1 -1
- package/.agents/schemas/agentrc.schema.json +12 -2
- package/.agents/schemas/audit-rules.json +10 -1
- package/.agents/scripts/deliver-run.js +43 -8
- package/.agents/scripts/lib/baselines/duplication-scanner.js +7 -1
- package/.agents/scripts/lib/baselines/refresh-service.js +6 -0
- package/.agents/scripts/lib/cli-args.js +16 -2
- package/.agents/scripts/lib/config/gates/duplication.schema.js +10 -2
- package/.agents/scripts/lib/generated/agentrc-validator.js +1 -1
- package/.agents/scripts/lib/observability/close-telemetry.js +17 -2
- package/.agents/scripts/lib/orchestration/complexity-gate.js +58 -11
- package/.agents/scripts/lib/orchestration/plan-persist/run-plan-persist.js +51 -6
- package/.agents/scripts/lib/orchestration/plan-persist/source-rewrite.js +177 -0
- package/.agents/scripts/lib/orchestration/plan-persist/story-ops.js +174 -43
- package/.agents/scripts/lib/orchestration/plan-persist/supersede-ops.js +57 -15
- package/.agents/scripts/lib/orchestration/resolve-stories.js +12 -3
- package/.agents/scripts/lib/orchestration/resume-effort.js +121 -0
- package/.agents/scripts/lib/orchestration/single-story-close/phases/options.js +13 -2
- package/.agents/scripts/lib/orchestration/single-story-close/runner.js +10 -2
- package/.agents/scripts/lib/orchestration/ticketing/reads.js +3 -0
- package/.agents/scripts/plan-persist.js +20 -6
- package/.agents/scripts/providers/github/tickets.js +2 -1
- package/.agents/scripts/resolve-stories.js +8 -2
- package/.agents/scripts/single-story-close.js +11 -3
- package/.agents/workflows/audit-security.md +136 -49
- package/.agents/workflows/helpers/deliver-reference.md +7 -2
- package/.agents/workflows/helpers/deliver-story.md +5 -3
- package/.agents/workflows/helpers/plan-reference.md +42 -2
- package/.agents/workflows/mandrel-deliver.md +9 -4
- package/.agents/workflows/mandrel-plan.md +7 -1
- package/docs/CHANGELOG.md +16 -0
- package/package.json +2 -1
|
@@ -29,6 +29,7 @@ import {
|
|
|
29
29
|
externalDependencyId,
|
|
30
30
|
isExternalDependencyRef,
|
|
31
31
|
} from './external-deps.js';
|
|
32
|
+
import { rewriteSourceTicket } from './source-rewrite.js';
|
|
32
33
|
import {
|
|
33
34
|
normalizeSupersedes,
|
|
34
35
|
resolveSupersedePartition,
|
|
@@ -722,11 +723,167 @@ async function ensurePersistLabel({
|
|
|
722
723
|
}
|
|
723
724
|
}
|
|
724
725
|
|
|
726
|
+
/**
|
|
727
|
+
* Label mutations for a rewritten source: the Story's labels on, and every
|
|
728
|
+
* `agent::*` plus any earlier run's cohort label off — the source now belongs
|
|
729
|
+
* to this run and is not deliverable until the terminal ready flip.
|
|
730
|
+
*
|
|
731
|
+
* @param {string[]} currentLabels
|
|
732
|
+
* @param {string[]} add
|
|
733
|
+
* @returns {{ add: string[], remove: string[] }}
|
|
734
|
+
*/
|
|
735
|
+
function rewriteLabelMutations(currentLabels, add) {
|
|
736
|
+
const agentLabels = Object.values(AGENT_LABELS);
|
|
737
|
+
const remove = (currentLabels ?? []).filter(
|
|
738
|
+
(label) =>
|
|
739
|
+
!add.includes(label) &&
|
|
740
|
+
(agentLabels.includes(label) || label.startsWith(PLAN_RUN_LABEL_PREFIX)),
|
|
741
|
+
);
|
|
742
|
+
return { add, remove };
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
/**
|
|
746
|
+
* Dry-run receipts: placeholder ids, or the source's id for a rewrite.
|
|
747
|
+
*
|
|
748
|
+
* @param {object[]} list
|
|
749
|
+
* @param {{ id: number }|null} rewriting
|
|
750
|
+
* @returns {object[]}
|
|
751
|
+
*/
|
|
752
|
+
function dryRunEntries(list, rewriting) {
|
|
753
|
+
if (rewriting) {
|
|
754
|
+
return list.map((s) => ({
|
|
755
|
+
slug: s.slug,
|
|
756
|
+
id: rewriting.id,
|
|
757
|
+
title: s.title,
|
|
758
|
+
url: undefined,
|
|
759
|
+
adopted: false,
|
|
760
|
+
rewritten: true,
|
|
761
|
+
}));
|
|
762
|
+
}
|
|
763
|
+
return list.map((s, i) => ({
|
|
764
|
+
slug: s.slug,
|
|
765
|
+
id: -(i + 1),
|
|
766
|
+
title: s.title,
|
|
767
|
+
url: undefined,
|
|
768
|
+
adopted: false,
|
|
769
|
+
}));
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
/**
|
|
773
|
+
* A resumed Story; when it is the rewrite target, the source already carries
|
|
774
|
+
* this Story, so it stays `rewritten`.
|
|
775
|
+
*
|
|
776
|
+
* @param {{ slug: string, title: string }} story
|
|
777
|
+
* @param {{ id: number, url?: string }} already
|
|
778
|
+
* @param {{ id: number }|null} rewriting
|
|
779
|
+
* @returns {object}
|
|
780
|
+
*/
|
|
781
|
+
function adoptedEntry(story, already, rewriting) {
|
|
782
|
+
const entry = {
|
|
783
|
+
slug: story.slug,
|
|
784
|
+
id: already.id,
|
|
785
|
+
title: story.title,
|
|
786
|
+
url: already.url,
|
|
787
|
+
adopted: true,
|
|
788
|
+
};
|
|
789
|
+
if (already.id === rewriting?.id) entry.rewritten = true;
|
|
790
|
+
return entry;
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
/**
|
|
794
|
+
* @param {object} args
|
|
795
|
+
* @param {object} args.provider
|
|
796
|
+
* @param {object} args.story
|
|
797
|
+
* @param {{ id: number, ticket: object }} args.rewriting
|
|
798
|
+
* @param {string[]} args.labels
|
|
799
|
+
* @param {Map<string, number>} args.idBySlug
|
|
800
|
+
* @returns {Promise<object>} The `created[]` entry.
|
|
801
|
+
*/
|
|
802
|
+
async function rewriteInPlace({
|
|
803
|
+
provider,
|
|
804
|
+
story,
|
|
805
|
+
rewriting,
|
|
806
|
+
labels,
|
|
807
|
+
idBySlug,
|
|
808
|
+
}) {
|
|
809
|
+
await rewriteSourceTicket({
|
|
810
|
+
provider,
|
|
811
|
+
target: rewriting,
|
|
812
|
+
title: story.title,
|
|
813
|
+
body: renderStoryBodyForCreate(story, idBySlug),
|
|
814
|
+
labels: rewriteLabelMutations(rewriting.ticket.labels, labels),
|
|
815
|
+
});
|
|
816
|
+
Logger.info(
|
|
817
|
+
`[plan-persist] rewrote source ticket #${rewriting.id} in place as ` +
|
|
818
|
+
`Story "${story.slug}" — no new issue filed.`,
|
|
819
|
+
);
|
|
820
|
+
return {
|
|
821
|
+
slug: story.slug,
|
|
822
|
+
id: rewriting.id,
|
|
823
|
+
title: story.title,
|
|
824
|
+
url: rewriting.ticket.url,
|
|
825
|
+
internalId: rewriting.ticket.internalId,
|
|
826
|
+
adopted: false,
|
|
827
|
+
rewritten: true,
|
|
828
|
+
};
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
/**
|
|
832
|
+
* POST one Story, adopting a lost-response first attempt by fingerprint.
|
|
833
|
+
*
|
|
834
|
+
* @param {object} args
|
|
835
|
+
* @param {object} args.provider
|
|
836
|
+
* @param {object} args.story
|
|
837
|
+
* @param {string[]} args.labels
|
|
838
|
+
* @param {Map<string, number>} args.idBySlug
|
|
839
|
+
* @param {Map<string, number[]>} args.idsByTitle
|
|
840
|
+
* @returns {Promise<object>} The `created[]` entry.
|
|
841
|
+
*/
|
|
842
|
+
async function createOneStory({
|
|
843
|
+
provider,
|
|
844
|
+
story,
|
|
845
|
+
labels,
|
|
846
|
+
idBySlug,
|
|
847
|
+
idsByTitle,
|
|
848
|
+
}) {
|
|
849
|
+
warnOnDivergentSameTitleStory(story, idsByTitle);
|
|
850
|
+
const result = await provider.createIssue({
|
|
851
|
+
title: story.title,
|
|
852
|
+
body: renderStoryBodyForCreate(story, idBySlug),
|
|
853
|
+
labels,
|
|
854
|
+
findExisting: () =>
|
|
855
|
+
findOpenStoryByPlanFingerprint({
|
|
856
|
+
provider,
|
|
857
|
+
fingerprint: story.fingerprint,
|
|
858
|
+
}),
|
|
859
|
+
});
|
|
860
|
+
const id = result?.id ?? result?.number;
|
|
861
|
+
if (!Number.isInteger(id)) {
|
|
862
|
+
throw new Error(
|
|
863
|
+
`[plan-persist] createIssue for slug "${story.slug}" did not return a numeric id`,
|
|
864
|
+
);
|
|
865
|
+
}
|
|
866
|
+
return {
|
|
867
|
+
slug: story.slug,
|
|
868
|
+
id,
|
|
869
|
+
title: story.title,
|
|
870
|
+
url: result.url,
|
|
871
|
+
// The database id — the only id the native sub-issue write accepts.
|
|
872
|
+
internalId: result.internalId,
|
|
873
|
+
// True when the retry probe adopted a lost-response first attempt.
|
|
874
|
+
adopted: result.adopted === true,
|
|
875
|
+
};
|
|
876
|
+
}
|
|
877
|
+
|
|
725
878
|
/**
|
|
726
879
|
* Create Story issues resumably, adopting any open Story whose fingerprint
|
|
727
880
|
* matches. Stories are born without `agent::ready`; `markStoriesReady` flips
|
|
728
881
|
* it last, once every plan comment is on the ticket.
|
|
729
882
|
*
|
|
883
|
+
* With `opts.rewriteTarget` (a one-for-one plan), the single Story is written
|
|
884
|
+
* over that source ticket instead of POSTed; its entry carries
|
|
885
|
+
* `rewritten: true` and the source's id.
|
|
886
|
+
*
|
|
730
887
|
* The loop stays serial: `idBySlug` is filled in loop order by the POSTs, and
|
|
731
888
|
* a concurrent create would render `#undefined` dependency refs.
|
|
732
889
|
*
|
|
@@ -735,8 +892,9 @@ async function ensurePersistLabel({
|
|
|
735
892
|
* @param {ReturnType<typeof assemblePlanStories>['stories']} args.stories
|
|
736
893
|
* @param {object} [args.opts]
|
|
737
894
|
* @param {boolean} [args.opts.dryRun=false]
|
|
895
|
+
* @param {{ id: number, ticket: object }|null} [args.opts.rewriteTarget=null]
|
|
738
896
|
* @returns {Promise<{
|
|
739
|
-
* created: Array<{ slug: string, id: number, url?: string, title: string, adopted: boolean }>,
|
|
897
|
+
* created: Array<{ slug: string, id: number, url?: string, title: string, adopted: boolean, rewritten?: boolean }>,
|
|
740
898
|
* dependencyEdges: { edgesAdded: number, edgesSkipped: number, edgesFailed: number, storiesProcessed: number }|null,
|
|
741
899
|
* planRunLabel: string,
|
|
742
900
|
* planRunLabelApplied: boolean,
|
|
@@ -750,6 +908,7 @@ export async function createStoryIssues({ provider, stories, opts = {} }) {
|
|
|
750
908
|
}
|
|
751
909
|
|
|
752
910
|
const list = Array.isArray(stories) ? stories : [];
|
|
911
|
+
const rewriting = list.length === 1 ? (opts.rewriteTarget ?? null) : null;
|
|
753
912
|
|
|
754
913
|
const cohortLabel = planRunLabel(
|
|
755
914
|
derivePlanRunId(list.map((story) => story.fingerprint)),
|
|
@@ -757,13 +916,7 @@ export async function createStoryIssues({ provider, stories, opts = {} }) {
|
|
|
757
916
|
|
|
758
917
|
if (opts.dryRun) {
|
|
759
918
|
return {
|
|
760
|
-
created: list
|
|
761
|
-
slug: s.slug,
|
|
762
|
-
id: -(i + 1),
|
|
763
|
-
title: s.title,
|
|
764
|
-
url: undefined,
|
|
765
|
-
adopted: false,
|
|
766
|
-
})),
|
|
919
|
+
created: dryRunEntries(list, rewriting),
|
|
767
920
|
dependencyEdges: null,
|
|
768
921
|
planRunLabel: cohortLabel,
|
|
769
922
|
planRunLabelApplied: false,
|
|
@@ -782,55 +935,33 @@ export async function createStoryIssues({ provider, stories, opts = {} }) {
|
|
|
782
935
|
const { byFingerprint, idsByTitle } = await indexExistingStories(provider);
|
|
783
936
|
const created = [];
|
|
784
937
|
const idBySlug = new Map();
|
|
938
|
+
const cohortLabels = applyCohortLabel ? [cohortLabel] : [];
|
|
785
939
|
|
|
786
940
|
// Already dependency-ordered; re-sorting would disagree on the primary.
|
|
787
941
|
for (const story of list) {
|
|
788
942
|
const already = byFingerprint.get(story.fingerprint);
|
|
789
|
-
if (!already) warnOnDivergentSameTitleStory(story, idsByTitle);
|
|
790
943
|
if (already) {
|
|
791
944
|
Logger.info(
|
|
792
945
|
`[plan-persist] resuming: Story "${story.slug}" already exists as ` +
|
|
793
946
|
`#${already.id} with byte-identical authored content ` +
|
|
794
947
|
`(plan fingerprint ${story.fingerprint}) — skipping create.`,
|
|
795
948
|
);
|
|
796
|
-
created.push(
|
|
797
|
-
slug: story.slug,
|
|
798
|
-
id: already.id,
|
|
799
|
-
title: story.title,
|
|
800
|
-
url: already.url,
|
|
801
|
-
adopted: true,
|
|
802
|
-
});
|
|
949
|
+
created.push(adoptedEntry(story, already, rewriting));
|
|
803
950
|
idBySlug.set(story.slug, already.id);
|
|
804
951
|
continue;
|
|
805
952
|
}
|
|
806
953
|
|
|
807
|
-
const
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
labels: [...story.labels, ...
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
if (!Number.isInteger(id)) {
|
|
819
|
-
throw new Error(
|
|
820
|
-
`[plan-persist] createIssue for slug "${story.slug}" did not return a numeric id`,
|
|
821
|
-
);
|
|
822
|
-
}
|
|
823
|
-
created.push({
|
|
824
|
-
slug: story.slug,
|
|
825
|
-
id,
|
|
826
|
-
title: story.title,
|
|
827
|
-
url: result.url,
|
|
828
|
-
// The database id — the only id the native sub-issue write accepts.
|
|
829
|
-
internalId: result.internalId,
|
|
830
|
-
// True when the retry probe adopted a lost-response first attempt.
|
|
831
|
-
adopted: result.adopted === true,
|
|
832
|
-
});
|
|
833
|
-
idBySlug.set(story.slug, id);
|
|
954
|
+
const args = {
|
|
955
|
+
provider,
|
|
956
|
+
story,
|
|
957
|
+
labels: [...story.labels, ...cohortLabels],
|
|
958
|
+
idBySlug,
|
|
959
|
+
};
|
|
960
|
+
const entry = rewriting
|
|
961
|
+
? await rewriteInPlace({ ...args, rewriting })
|
|
962
|
+
: await createOneStory({ ...args, idsByTitle });
|
|
963
|
+
created.push(entry);
|
|
964
|
+
idBySlug.set(story.slug, entry.id);
|
|
834
965
|
}
|
|
835
966
|
|
|
836
967
|
// Includes adopted ids, so a resume mirrors the whole cohort (idempotent).
|
|
@@ -379,6 +379,8 @@ async function closeOneSupersededTicket({
|
|
|
379
379
|
* @property {string|null} reason Why the phase was skipped wholesale.
|
|
380
380
|
* @property {'flag'|'envelope'|'none'} [sourceTicketOrigin] Stamped by `runPlanPersist`.
|
|
381
381
|
* @property {number[]} closed
|
|
382
|
+
* @property {number[]} rewritten Sources rewritten in place as their Story —
|
|
383
|
+
* never commented on or closed (dry runs list the planned rewrite).
|
|
382
384
|
* @property {Array<{ ticket: number, storySlug: string }>} planned Dry-run
|
|
383
385
|
* only; keyed by slug because dry-run Story ids are placeholders.
|
|
384
386
|
* @property {Array<{ ticket: number, reason: string }>} skipped
|
|
@@ -392,6 +394,7 @@ function emptyReport(overrides) {
|
|
|
392
394
|
dryRun: false,
|
|
393
395
|
reason: null,
|
|
394
396
|
closed: [],
|
|
397
|
+
rewritten: [],
|
|
395
398
|
planned: [],
|
|
396
399
|
skipped: [],
|
|
397
400
|
failed: [],
|
|
@@ -471,19 +474,7 @@ export async function closeSupersededTickets({
|
|
|
471
474
|
// the probe → comment → close sequence stays strictly ordered.
|
|
472
475
|
const outcomes = await concurrentMap(
|
|
473
476
|
units,
|
|
474
|
-
({
|
|
475
|
-
if (!createdStory) {
|
|
476
|
-
return { outcome: 'skipped', reason: 'story-not-created' };
|
|
477
|
-
}
|
|
478
|
-
if (dryRun) return { outcome: 'planned' };
|
|
479
|
-
return closeOneSupersededTicket({
|
|
480
|
-
provider,
|
|
481
|
-
id,
|
|
482
|
-
note,
|
|
483
|
-
story: createdStory,
|
|
484
|
-
sourceTicketIds: sources,
|
|
485
|
-
});
|
|
486
|
-
},
|
|
477
|
+
(unit) => supersedeUnit(unit, { provider, dryRun, sources }),
|
|
487
478
|
{ concurrency: FANOUT_CONCURRENCY },
|
|
488
479
|
);
|
|
489
480
|
|
|
@@ -520,6 +511,45 @@ function collectSupersedeUnits(stories, createdBySlug) {
|
|
|
520
511
|
return units;
|
|
521
512
|
}
|
|
522
513
|
|
|
514
|
+
/**
|
|
515
|
+
* One unit's outcome. Never throws.
|
|
516
|
+
*
|
|
517
|
+
* @param {{ id: number, note: string|null, createdStory: object|undefined }} unit
|
|
518
|
+
* @param {{ provider: object, dryRun: boolean, sources: number[] }} ctx
|
|
519
|
+
* @returns {Promise<{ outcome: string, reason?: string }>|{ outcome: string, reason?: string }}
|
|
520
|
+
*/
|
|
521
|
+
function supersedeUnit(
|
|
522
|
+
{ id, note, createdStory },
|
|
523
|
+
{ provider, dryRun, sources },
|
|
524
|
+
) {
|
|
525
|
+
if (!createdStory) {
|
|
526
|
+
return { outcome: 'skipped', reason: 'story-not-created' };
|
|
527
|
+
}
|
|
528
|
+
if (isRewrittenSource(createdStory, id)) return { outcome: 'rewritten' };
|
|
529
|
+
if (dryRun) return { outcome: 'planned' };
|
|
530
|
+
return closeOneSupersededTicket({
|
|
531
|
+
provider,
|
|
532
|
+
id,
|
|
533
|
+
note,
|
|
534
|
+
story: createdStory,
|
|
535
|
+
sourceTicketIds: sources,
|
|
536
|
+
});
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
/**
|
|
540
|
+
* The source IS the Story now; closing it would close the work.
|
|
541
|
+
*
|
|
542
|
+
* @param {{ id: number, rewritten?: boolean }} createdStory
|
|
543
|
+
* @param {number} id
|
|
544
|
+
* @returns {boolean}
|
|
545
|
+
*/
|
|
546
|
+
function isRewrittenSource(createdStory, id) {
|
|
547
|
+
return createdStory.rewritten === true && createdStory.id === id;
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
/** Outcomes recorded as a bare ticket id. */
|
|
551
|
+
const ID_OUTCOMES = new Set(['closed', 'rewritten']);
|
|
552
|
+
|
|
523
553
|
/**
|
|
524
554
|
* @param {SupersedeReport} report
|
|
525
555
|
* @param {{ id: number, createdStory: object|undefined }} unit
|
|
@@ -527,8 +557,8 @@ function collectSupersedeUnits(stories, createdBySlug) {
|
|
|
527
557
|
* @returns {void}
|
|
528
558
|
*/
|
|
529
559
|
function recordSupersedeOutcome(report, unit, result) {
|
|
530
|
-
if (result.outcome
|
|
531
|
-
report.
|
|
560
|
+
if (ID_OUTCOMES.has(result.outcome)) {
|
|
561
|
+
report[result.outcome].push(unit.id);
|
|
532
562
|
return;
|
|
533
563
|
}
|
|
534
564
|
if (result.outcome === 'planned') {
|
|
@@ -545,10 +575,22 @@ function recordSupersedeOutcome(report, unit, result) {
|
|
|
545
575
|
report.failed.push({ ticket: unit.id, reason: result.reason });
|
|
546
576
|
}
|
|
547
577
|
|
|
578
|
+
/**
|
|
579
|
+
* @param {SupersedeReport} report
|
|
580
|
+
*/
|
|
581
|
+
function logRewrittenSources(report) {
|
|
582
|
+
const line = report.dryRun
|
|
583
|
+
? (id) =>
|
|
584
|
+
`[plan-persist] dry-run: would rewrite #${id} in place as its Story.`
|
|
585
|
+
: (id) => `[plan-persist] #${id} was rewritten in place — not closed.`;
|
|
586
|
+
for (const id of report.rewritten) Logger.info(line(id));
|
|
587
|
+
}
|
|
588
|
+
|
|
548
589
|
/**
|
|
549
590
|
* @param {SupersedeReport} report
|
|
550
591
|
*/
|
|
551
592
|
function logSupersedeReport(report) {
|
|
593
|
+
logRewrittenSources(report);
|
|
552
594
|
if (report.dryRun) {
|
|
553
595
|
for (const { ticket, storySlug } of report.planned) {
|
|
554
596
|
Logger.info(
|
|
@@ -278,6 +278,9 @@ export async function readNativeBlockedBy({
|
|
|
278
278
|
* @param {Map<number, number[]>} nativeEdges
|
|
279
279
|
* @param {number[]} foreignDone Ids outside the set already satisfied.
|
|
280
280
|
* @param {(msg: string) => void} [warn]
|
|
281
|
+
* @param {Map<number, number>} [priorBlocksById] Local prior-block count per
|
|
282
|
+
* Story; absent counts 0.
|
|
283
|
+
* @param {boolean} [roleScopedAgents] `delivery.routing.roleScopedAgents`.
|
|
281
284
|
* @returns {{ kind: string, stories: object[], dag: object[], done: number[] }}
|
|
282
285
|
*/
|
|
283
286
|
export function buildStoriesEnvelope({
|
|
@@ -285,13 +288,16 @@ export function buildStoriesEnvelope({
|
|
|
285
288
|
nativeEdges = new Map(),
|
|
286
289
|
foreignDone = [],
|
|
287
290
|
warn,
|
|
291
|
+
priorBlocksById = new Map(),
|
|
292
|
+
roleScopedAgents = false,
|
|
288
293
|
}) {
|
|
289
294
|
const sorted = [...stories].sort((a, b) => a.id - b.id);
|
|
290
295
|
const inSetDone = sorted.filter(isSatisfiedBlocker).map((s) => s.id);
|
|
291
296
|
return {
|
|
292
297
|
kind: 'stories',
|
|
293
298
|
// `inline` (the router's own session) only for a single-Story set, so no
|
|
294
|
-
// sibling can claim that session
|
|
299
|
+
// sibling can claim that session — unless a one-Story resume needs a
|
|
300
|
+
// spawn for its per-call effort. Decided on the resolved set size, not
|
|
295
301
|
// the undelivered remainder, so the mode never changes mid-run.
|
|
296
302
|
stories: sorted.map(({ id, title, url, labels, state }) => ({
|
|
297
303
|
id,
|
|
@@ -299,8 +305,11 @@ export function buildStoriesEnvelope({
|
|
|
299
305
|
url,
|
|
300
306
|
labels,
|
|
301
307
|
state,
|
|
302
|
-
dispatchMode: resolveStoryDispatchMode({
|
|
303
|
-
.
|
|
308
|
+
dispatchMode: resolveStoryDispatchMode({
|
|
309
|
+
storyCount: sorted.length,
|
|
310
|
+
priorBlocks: priorBlocksById.get(id) ?? 0,
|
|
311
|
+
roleScopedAgents,
|
|
312
|
+
}).mode,
|
|
304
313
|
})),
|
|
305
314
|
dag: storiesToDag(sorted, nativeEdges, warn),
|
|
306
315
|
done: [...new Set([...inSetDone, ...foreignDone])].sort((a, b) => a - b),
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-call story-worker effort for a resumed blocked Story, from its local
|
|
3
|
+
* signals only.
|
|
4
|
+
*
|
|
5
|
+
* @module lib/orchestration/resume-effort
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { getDeliveryRouting } from '../config/delivery-routing.js';
|
|
9
|
+
import { Logger } from '../Logger.js';
|
|
10
|
+
import { RUNTIME_FRICTION_CATEGORIES } from '../observability/runtime-friction.js';
|
|
11
|
+
import { forEachLine } from '../observability/signals-writer.js';
|
|
12
|
+
import { EVENT_KINDS } from '../signals/schema.js';
|
|
13
|
+
|
|
14
|
+
const AGENT_EFFORT_LEVELS = Object.freeze([
|
|
15
|
+
'low',
|
|
16
|
+
'medium',
|
|
17
|
+
'high',
|
|
18
|
+
'xhigh',
|
|
19
|
+
'max',
|
|
20
|
+
]);
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @param {unknown} value
|
|
24
|
+
* @returns {{ effort: string|null, warning: string|null }}
|
|
25
|
+
*/
|
|
26
|
+
export function parseWorkerEffort(value) {
|
|
27
|
+
if (value == null) return { effort: null, warning: null };
|
|
28
|
+
const raw = String(value).trim();
|
|
29
|
+
if (AGENT_EFFORT_LEVELS.includes(raw)) {
|
|
30
|
+
return { effort: raw, warning: null };
|
|
31
|
+
}
|
|
32
|
+
return {
|
|
33
|
+
effort: null,
|
|
34
|
+
warning: `--worker-effort must be one of ${AGENT_EFFORT_LEVELS.join('|')} (got ${JSON.stringify(value)}); telemetry.workerEffort records null.`,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* @param {unknown} record
|
|
40
|
+
* @returns {boolean}
|
|
41
|
+
*/
|
|
42
|
+
function isPriorBlockRecord(record) {
|
|
43
|
+
return (
|
|
44
|
+
record !== null &&
|
|
45
|
+
typeof record === 'object' &&
|
|
46
|
+
record.kind === EVENT_KINDS.FRICTION &&
|
|
47
|
+
record.category === RUNTIME_FRICTION_CATEGORIES.STORY_BLOCKED &&
|
|
48
|
+
record.details?.recovered !== true
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* The ladder's single source; absolute, not relative to session effort.
|
|
54
|
+
*
|
|
55
|
+
* @param {number} priorBlocks
|
|
56
|
+
* @returns {'high'|'xhigh'|null}
|
|
57
|
+
*/
|
|
58
|
+
function resumeEffortFor(priorBlocks) {
|
|
59
|
+
if (priorBlocks < 1) return null;
|
|
60
|
+
return priorBlocks === 1 ? 'high' : 'xhigh';
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* @param {number} storyId
|
|
65
|
+
* @param {{ config?: object, readFn?: typeof forEachLine }} [opts]
|
|
66
|
+
* @returns {Promise<number>}
|
|
67
|
+
*/
|
|
68
|
+
async function countPriorBlocks(
|
|
69
|
+
storyId,
|
|
70
|
+
{ config, readFn = forEachLine } = {},
|
|
71
|
+
) {
|
|
72
|
+
let count = 0;
|
|
73
|
+
try {
|
|
74
|
+
await readFn(
|
|
75
|
+
null,
|
|
76
|
+
storyId,
|
|
77
|
+
(record) => {
|
|
78
|
+
if (isPriorBlockRecord(record)) count += 1;
|
|
79
|
+
},
|
|
80
|
+
config,
|
|
81
|
+
);
|
|
82
|
+
} catch (err) {
|
|
83
|
+
Logger.warn(
|
|
84
|
+
`[resume-effort] signal read failed for Story #${storyId}: ${
|
|
85
|
+
err instanceof Error ? err.message : String(err)
|
|
86
|
+
} — counting 0 prior blocks.`,
|
|
87
|
+
);
|
|
88
|
+
return 0;
|
|
89
|
+
}
|
|
90
|
+
return count;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* @param {number} storyId
|
|
95
|
+
* @param {{ config?: object, readFn?: typeof forEachLine }} [opts]
|
|
96
|
+
* @returns {Promise<'high'|'xhigh'|null>}
|
|
97
|
+
*/
|
|
98
|
+
export async function resolveResumeEffort(storyId, opts) {
|
|
99
|
+
return resumeEffortFor(await countPriorBlocks(storyId, opts));
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* @param {Array<{ id: number }>} stories
|
|
104
|
+
* @param {{ config?: object, countFn?: typeof countPriorBlocks }} [opts]
|
|
105
|
+
* @returns {Promise<{ priorBlocksById: Map<number, number>,
|
|
106
|
+
* roleScopedAgents: boolean }>}
|
|
107
|
+
*/
|
|
108
|
+
export async function resolveRunDispatchInputs(
|
|
109
|
+
stories,
|
|
110
|
+
{ config, countFn = countPriorBlocks } = {},
|
|
111
|
+
) {
|
|
112
|
+
const priorBlocksById = new Map();
|
|
113
|
+
if (stories.length === 1) {
|
|
114
|
+
const [{ id }] = stories;
|
|
115
|
+
priorBlocksById.set(id, await countFn(id, { config }));
|
|
116
|
+
}
|
|
117
|
+
return {
|
|
118
|
+
priorBlocksById,
|
|
119
|
+
roleScopedAgents: getDeliveryRouting(config).roleScopedAgents,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
@@ -126,11 +126,20 @@ function workerFlags(tokensParam, modelParam, parsed) {
|
|
|
126
126
|
};
|
|
127
127
|
}
|
|
128
128
|
|
|
129
|
+
/**
|
|
130
|
+
* @param {unknown} effortParam
|
|
131
|
+
* @param {{ workerEffort?: unknown }} parsed
|
|
132
|
+
* @returns {unknown}
|
|
133
|
+
*/
|
|
134
|
+
function workerEffortFlag(effortParam, parsed) {
|
|
135
|
+
return resolveFlag(effortParam, parsed.workerEffort);
|
|
136
|
+
}
|
|
137
|
+
|
|
129
138
|
/**
|
|
130
139
|
* Returns raw wait-for-merge intent; the runner resolves it after the arm.
|
|
131
140
|
*
|
|
132
|
-
* @param {{ storyIdParam, cwdParam, skipValidationParam, skipSyncParam, noAutoMergeParam, waitForMergeParam, noWaitForMergeParam, maxWaitSecondsParam, mergeWatchModeParam, rerunAdvisoryParam, overrideReviewBlockParam, workerTokensParam, workerModelParam }} raw
|
|
133
|
-
* @returns {{ storyId, cwd, skipValidation, skipSync, noAutoMerge, waitForMergeExplicit, noWaitForMerge, maxWaitSeconds, mergeWatchMode, rerunAdvisory, overrideReviewBlock, workerTokens, workerModel }}
|
|
141
|
+
* @param {{ storyIdParam, cwdParam, skipValidationParam, skipSyncParam, noAutoMergeParam, waitForMergeParam, noWaitForMergeParam, maxWaitSecondsParam, mergeWatchModeParam, rerunAdvisoryParam, overrideReviewBlockParam, workerTokensParam, workerModelParam, workerEffortParam }} raw
|
|
142
|
+
* @returns {{ storyId, cwd, skipValidation, skipSync, noAutoMerge, waitForMergeExplicit, noWaitForMerge, maxWaitSeconds, mergeWatchMode, rerunAdvisory, overrideReviewBlock, workerTokens, workerModel, workerEffort }}
|
|
134
143
|
*/
|
|
135
144
|
export function parseCloseOptions({
|
|
136
145
|
storyIdParam,
|
|
@@ -146,6 +155,7 @@ export function parseCloseOptions({
|
|
|
146
155
|
overrideReviewBlockParam,
|
|
147
156
|
workerTokensParam,
|
|
148
157
|
workerModelParam,
|
|
158
|
+
workerEffortParam,
|
|
149
159
|
}) {
|
|
150
160
|
// An injecting caller never reads argv (the host's flags are not its
|
|
151
161
|
// business), so `parsed` stays empty and the retired-flag guard is skipped.
|
|
@@ -187,5 +197,6 @@ export function parseCloseOptions({
|
|
|
187
197
|
resolveFlag(overrideReviewBlockParam, parsed.overrideReviewBlock),
|
|
188
198
|
),
|
|
189
199
|
...workerFlags(workerTokensParam, workerModelParam, parsed),
|
|
200
|
+
workerEffort: workerEffortFlag(workerEffortParam, parsed),
|
|
190
201
|
};
|
|
191
202
|
}
|
|
@@ -12,6 +12,7 @@ import { Logger } from '../../Logger.js';
|
|
|
12
12
|
import {
|
|
13
13
|
emitReviewBlockedFriction,
|
|
14
14
|
recordCloseTelemetry,
|
|
15
|
+
resolveWorkerEffort,
|
|
15
16
|
resolveWorkerModel,
|
|
16
17
|
resolveWorkerTokens,
|
|
17
18
|
} from '../../observability/close-telemetry.js';
|
|
@@ -104,7 +105,11 @@ function createPhaseTimer(nowMs = Date.now) {
|
|
|
104
105
|
const UNTIMED = Object.freeze({ stamp() {} });
|
|
105
106
|
|
|
106
107
|
/** No worker figures: an inline close, or an ending before they resolve. */
|
|
107
|
-
const NO_WORKER = Object.freeze({
|
|
108
|
+
const NO_WORKER = Object.freeze({
|
|
109
|
+
workerTokens: null,
|
|
110
|
+
workerModel: null,
|
|
111
|
+
workerEffort: null,
|
|
112
|
+
});
|
|
108
113
|
|
|
109
114
|
/**
|
|
110
115
|
* The single terminal writer: the retry signal, the result summary (with its
|
|
@@ -600,6 +605,7 @@ export async function runSingleStoryClose({
|
|
|
600
605
|
overrideReviewBlock: overrideReviewBlockParam,
|
|
601
606
|
workerTokens: workerTokensParam,
|
|
602
607
|
workerModel: workerModelParam,
|
|
608
|
+
workerEffort: workerEffortParam,
|
|
603
609
|
...injected
|
|
604
610
|
} = {}) {
|
|
605
611
|
const options = parseCloseOptions({
|
|
@@ -616,10 +622,11 @@ export async function runSingleStoryClose({
|
|
|
616
622
|
overrideReviewBlockParam,
|
|
617
623
|
workerTokensParam,
|
|
618
624
|
workerModelParam,
|
|
625
|
+
workerEffortParam,
|
|
619
626
|
});
|
|
620
627
|
if (!options.storyId) {
|
|
621
628
|
throw new Error(
|
|
622
|
-
'Usage: node single-story-close.js --story <STORY_ID> [--cwd <main-repo>] [--skip-validation] [--skip-sync] [--no-auto-merge] [--wait-merge|--no-wait-merge] [--max-wait-seconds <n>] [--merge-watch-mode <sync|async>] [--rerun-advisory <n>] [--override-review-block <reason>] [--worker-tokens <n>] [--worker-model <model>]',
|
|
629
|
+
'Usage: node single-story-close.js --story <STORY_ID> [--cwd <main-repo>] [--skip-validation] [--skip-sync] [--no-auto-merge] [--wait-merge|--no-wait-merge] [--max-wait-seconds <n>] [--merge-watch-mode <sync|async>] [--rerun-advisory <n>] [--override-review-block <reason>] [--worker-tokens <n>] [--worker-model <model>] [--worker-effort <level>]',
|
|
623
630
|
);
|
|
624
631
|
}
|
|
625
632
|
|
|
@@ -1212,6 +1219,7 @@ async function runClosePipeline(run, deps) {
|
|
|
1212
1219
|
worker: {
|
|
1213
1220
|
workerTokens: resolveWorkerTokens(run.options.workerTokens),
|
|
1214
1221
|
workerModel: resolveWorkerModel(run.options.workerModel),
|
|
1222
|
+
workerEffort: resolveWorkerEffort(run.options.workerEffort),
|
|
1215
1223
|
},
|
|
1216
1224
|
};
|
|
1217
1225
|
for (const phase of CLOSE_PIPELINE) {
|
|
@@ -60,6 +60,9 @@ export const STRUCTURED_COMMENT_TYPES = Object.freeze([
|
|
|
60
60
|
// Posted before closing a superseded source issue; the marker keeps
|
|
61
61
|
// re-runs from double-commenting.
|
|
62
62
|
'superseded-by',
|
|
63
|
+
// The source ticket's pre-plan title and body, posted once before a
|
|
64
|
+
// one-for-one rewrite; first write wins, so re-plans keep the original.
|
|
65
|
+
'plan-rewrite',
|
|
63
66
|
]);
|
|
64
67
|
|
|
65
68
|
export const WAVE_TYPE_PATTERN = WAVE_MARKER_RE;
|