pi-harness-runtime 1.1.463 → 1.1.465
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/CHANGELOG.md +83 -0
- package/harness/honcho-init.ts +132 -0
- package/index.ts +87 -5
- package/package.json +1 -1
- package/packages/agent-policy/package.json +1 -1
- package/packages/auth/package.json +1 -1
- package/packages/autonomous-runtime/package.json +1 -1
- package/packages/checkpoint/package.json +1 -1
- package/packages/clipboard/package.json +1 -1
- package/packages/codex-watcher/package.json +1 -1
- package/packages/config-capture/package.json +1 -1
- package/packages/contracts/package.json +1 -1
- package/packages/cookie-sanitizer/package.json +1 -1
- package/packages/evaluation-engine/package.json +1 -1
- package/packages/event-bus/package.json +1 -1
- package/packages/event-store/package.json +1 -1
- package/packages/experience-replay/package.json +1 -1
- package/packages/file-copy-helper/package.json +1 -1
- package/packages/intent-analyzer/package.json +1 -1
- package/packages/jev-judge/dist/decision-context.d.ts +12 -2
- package/packages/jev-judge/dist/decision-context.d.ts.map +1 -1
- package/packages/jev-judge/dist/decision-context.js +157 -35
- package/packages/jev-judge/dist/decision-context.js.map +1 -1
- package/packages/jev-judge/package.json +1 -1
- package/packages/jev-judge/src/decision-context.ts +181 -40
- package/packages/knowledge-retrieval/package.json +1 -1
- package/packages/learning-engine/package.json +1 -1
- package/packages/logging/package.json +1 -1
- package/packages/memory-engine/package.json +1 -1
- package/packages/notification/package.json +1 -1
- package/packages/paperclip-integration/package.json +1 -1
- package/packages/performance-optimizer/package.json +1 -1
- package/packages/privilege-broker/package.json +1 -1
- package/packages/prompt-compiler/package.json +1 -1
- package/packages/providers/package.json +1 -1
- package/packages/qdrant-skills/package.json +1 -1
- package/packages/quota-manager/package.json +1 -1
- package/packages/relay/package.json +1 -1
- package/packages/skill-mcp-client/package.json +1 -1
- package/packages/skills/package.json +1 -1
- package/packages/todo-bd-sync/package.json +1 -1
- package/packages/token-estimation/package.json +1 -1
- package/packages/tooling-preference/package.json +1 -1
- package/packages/trajectory/package.json +1 -1
- package/packages/tui/package.json +1 -1
- package/packages/two-phase-review/package.json +1 -1
- package/packages/types/package.json +1 -1
- package/packages/webmcp-tester/package.json +1 -1
- package/packages/wiki/package.json +1 -1
- package/packages/write-review/package.json +1 -1
|
@@ -80,7 +80,7 @@ export interface ChoiceDecisionContext {
|
|
|
80
80
|
truncated: boolean;
|
|
81
81
|
/** What the evaluation does not see. */
|
|
82
82
|
omittedInformation: string[];
|
|
83
|
-
/** Where the facts came from. */
|
|
83
|
+
/** Where the facts came from: the structure, the message, or both. */
|
|
84
84
|
derived: "structured" | "extracted" | "mixed";
|
|
85
85
|
/** Whether every option carries its meaning. */
|
|
86
86
|
complete: boolean;
|
|
@@ -90,7 +90,8 @@ export interface ChoiceDecisionContext {
|
|
|
90
90
|
/** One option as the agent supplied it. */
|
|
91
91
|
type StructuredOption = NonNullable<StructuredChoiceFacts["options"]>[number];
|
|
92
92
|
|
|
93
|
-
/** The facts the agent supplied itself. They
|
|
93
|
+
/** The facts the agent supplied itself. They come first; the facts of the
|
|
94
|
+
* message are merged with them. */
|
|
94
95
|
export interface StructuredChoiceFacts {
|
|
95
96
|
/** The problem the choice is about. */
|
|
96
97
|
problem?: string;
|
|
@@ -141,6 +142,15 @@ export interface ExtractedOption {
|
|
|
141
142
|
found: boolean;
|
|
142
143
|
/** The line of the header the facts were found at, -1 when there was none. */
|
|
143
144
|
headerIndex: number;
|
|
145
|
+
/**
|
|
146
|
+
* Whether the description of the option states a restriction.
|
|
147
|
+
*
|
|
148
|
+
* The wording of the source for an option can carry the caveat of that
|
|
149
|
+
* option ("it must actually connect"). When another wording is supplied
|
|
150
|
+
* for the option, this tells the caller which list the source wording
|
|
151
|
+
* belongs to.
|
|
152
|
+
*/
|
|
153
|
+
descriptionConstraint: boolean;
|
|
144
154
|
}
|
|
145
155
|
|
|
146
156
|
/** What the extraction needs to know about one option. */
|
|
@@ -365,6 +375,17 @@ function mentionsAny(text: string, anchors: string[]): boolean {
|
|
|
365
375
|
return anchors.some((anchor) => mentionsAnchor(text, anchor));
|
|
366
376
|
}
|
|
367
377
|
|
|
378
|
+
/**
|
|
379
|
+
* The offset of a line in the source message.
|
|
380
|
+
*/
|
|
381
|
+
function lineOffset(lines: string[], index: number): number {
|
|
382
|
+
let offset = 0;
|
|
383
|
+
for (let position = 0; position < index; position += 1) {
|
|
384
|
+
offset += (lines[position] as string).length + 1;
|
|
385
|
+
}
|
|
386
|
+
return offset;
|
|
387
|
+
}
|
|
388
|
+
|
|
368
389
|
/**
|
|
369
390
|
* Whether a paragraph is a fact of one option.
|
|
370
391
|
*
|
|
@@ -433,6 +454,7 @@ export function extractOptionFacts(
|
|
|
433
454
|
constraints: [],
|
|
434
455
|
found: false,
|
|
435
456
|
headerIndex: -1,
|
|
457
|
+
descriptionConstraint: false,
|
|
436
458
|
};
|
|
437
459
|
if (headerCandidates.length === 0 || source.length === 0) return empty;
|
|
438
460
|
|
|
@@ -442,12 +464,17 @@ export function extractOptionFacts(
|
|
|
442
464
|
const paragraphs = splitParagraphs(source);
|
|
443
465
|
let description = "";
|
|
444
466
|
let region: Paragraph[] = [];
|
|
467
|
+
// The range of the section of the option in the source message.
|
|
468
|
+
let sectionRange: { start: number; end: number } | null = null;
|
|
469
|
+
// The paragraphs of the source that the section of the option covers.
|
|
470
|
+
const covered = new Set<number>();
|
|
445
471
|
|
|
446
472
|
if (headerIndex >= 0) {
|
|
447
473
|
// The region of the option ends at the next option header, at the
|
|
448
474
|
// next heading of the message, or at the question itself.
|
|
449
475
|
const regionLines: string[] = [];
|
|
450
476
|
const questionMarker = question.trim().slice(0, 40);
|
|
477
|
+
let lastIndex = headerIndex;
|
|
451
478
|
for (let index = headerIndex; index < lines.length; index += 1) {
|
|
452
479
|
const line = lines[index] as string;
|
|
453
480
|
if (index > headerIndex) {
|
|
@@ -462,7 +489,14 @@ export function extractOptionFacts(
|
|
|
462
489
|
}
|
|
463
490
|
}
|
|
464
491
|
regionLines.push(line);
|
|
492
|
+
lastIndex = index;
|
|
465
493
|
}
|
|
494
|
+
sectionRange = {
|
|
495
|
+
start: lineOffset(lines, headerIndex),
|
|
496
|
+
end:
|
|
497
|
+
lineOffset(lines, lastIndex) +
|
|
498
|
+
(lines[lastIndex] as string).length,
|
|
499
|
+
};
|
|
466
500
|
region = splitParagraphs(regionLines.join("\n"));
|
|
467
501
|
if (region.length > 0) {
|
|
468
502
|
const anchor =
|
|
@@ -476,30 +510,45 @@ export function extractOptionFacts(
|
|
|
476
510
|
} else {
|
|
477
511
|
// No header: the first paragraph that names the option and no other
|
|
478
512
|
// one carries its meaning.
|
|
479
|
-
const
|
|
480
|
-
const candidate = paragraphs.find((paragraph) =>
|
|
513
|
+
const candidateIndex = paragraphs.findIndex((paragraph) =>
|
|
481
514
|
belongsToOption(
|
|
482
515
|
paragraph.text,
|
|
483
516
|
mentionAnchors,
|
|
484
517
|
otherMentionAnchors,
|
|
485
518
|
),
|
|
486
519
|
);
|
|
520
|
+
const candidate =
|
|
521
|
+
candidateIndex >= 0
|
|
522
|
+
? (paragraphs[candidateIndex] as Paragraph)
|
|
523
|
+
: undefined;
|
|
487
524
|
if (candidate) {
|
|
488
525
|
const anchor =
|
|
489
526
|
mentionAnchors.find((token) =>
|
|
490
527
|
mentionsAnchor(candidate.text.slice(0, MENTION_WINDOW_CHARS), token),
|
|
491
528
|
) ?? (mentionAnchors[0] as string);
|
|
492
529
|
description = stripMarkdown(stripLeadingAnchor(candidate.text, anchor));
|
|
493
|
-
|
|
530
|
+
covered.add(candidateIndex);
|
|
494
531
|
}
|
|
495
532
|
}
|
|
496
533
|
|
|
534
|
+
// The paragraphs that the section of the option covers: they belong to
|
|
535
|
+
// the option, and they are not looked at a second time.
|
|
536
|
+
if (sectionRange) {
|
|
537
|
+
paragraphs.forEach((paragraph, paragraphIndex) => {
|
|
538
|
+
const paragraphEnd = paragraph.start + paragraph.text.length;
|
|
539
|
+
if (
|
|
540
|
+
paragraph.start < sectionRange.end &&
|
|
541
|
+
paragraphEnd > sectionRange.start
|
|
542
|
+
) {
|
|
543
|
+
covered.add(paragraphIndex);
|
|
544
|
+
}
|
|
545
|
+
});
|
|
546
|
+
}
|
|
547
|
+
|
|
497
548
|
const tradeoffs: string[] = [];
|
|
498
549
|
const constraints: string[] = [];
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
if (value.length === 0) return;
|
|
502
|
-
if (!belongsToOption(value, mentionAnchors, otherMentionAnchors)) return;
|
|
550
|
+
/** Remember a fact, as a constraint when it states a restriction. */
|
|
551
|
+
const recordFact = (value: string): void => {
|
|
503
552
|
if (statesConstraint(value)) {
|
|
504
553
|
if (!constraints.includes(value)) constraints.push(value);
|
|
505
554
|
} else if (!tradeoffs.includes(value)) {
|
|
@@ -507,17 +556,44 @@ export function extractOptionFacts(
|
|
|
507
556
|
}
|
|
508
557
|
};
|
|
509
558
|
|
|
510
|
-
|
|
559
|
+
/**
|
|
560
|
+
* A fact of the section of the option belongs to it by position: the
|
|
561
|
+
* section writes about that option, and a paragraph that names it with
|
|
562
|
+
* a pronoun ("it must actually connect") is still about it. A paragraph
|
|
563
|
+
* that names another option belongs to that one.
|
|
564
|
+
*/
|
|
565
|
+
const addSectionFact = (text: string): void => {
|
|
566
|
+
const value = stripMarkdown(text);
|
|
567
|
+
if (value.length === 0) return;
|
|
568
|
+
if (
|
|
569
|
+
mentionsAny(value.slice(0, MENTION_WINDOW_CHARS), otherMentionAnchors)
|
|
570
|
+
) {
|
|
571
|
+
return;
|
|
572
|
+
}
|
|
573
|
+
recordFact(value);
|
|
574
|
+
};
|
|
575
|
+
|
|
576
|
+
/**
|
|
577
|
+
* A fact from outside the section has to name the option, and it must
|
|
578
|
+
* not name another one: "Caveat for B: ..." is about B.
|
|
579
|
+
*/
|
|
580
|
+
const addNamedFact = (text: string): void => {
|
|
581
|
+
const value = stripMarkdown(text);
|
|
582
|
+
if (value.length === 0) return;
|
|
583
|
+
if (!belongsToOption(value, mentionAnchors, otherMentionAnchors)) return;
|
|
584
|
+
recordFact(value);
|
|
585
|
+
};
|
|
586
|
+
|
|
587
|
+
// The paragraphs of the section after the description.
|
|
511
588
|
for (const paragraph of region.slice(1)) {
|
|
512
|
-
|
|
589
|
+
addSectionFact(paragraph.text);
|
|
513
590
|
}
|
|
514
591
|
|
|
515
592
|
// A caveat that names the option belongs to the option, even when it
|
|
516
|
-
// stands outside the
|
|
517
|
-
const
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
addFact(paragraph.text);
|
|
593
|
+
// stands outside the section: "Caveat for B: ..." is about B.
|
|
594
|
+
for (const [paragraphIndex, paragraph] of paragraphs.entries()) {
|
|
595
|
+
if (covered.has(paragraphIndex)) continue;
|
|
596
|
+
addNamedFact(paragraph.text);
|
|
521
597
|
}
|
|
522
598
|
|
|
523
599
|
return {
|
|
@@ -526,6 +602,7 @@ export function extractOptionFacts(
|
|
|
526
602
|
constraints,
|
|
527
603
|
found: description.length > 0,
|
|
528
604
|
headerIndex,
|
|
605
|
+
descriptionConstraint: statesConstraint(description),
|
|
529
606
|
};
|
|
530
607
|
}
|
|
531
608
|
|
|
@@ -587,9 +664,17 @@ export function buildChoiceDecisionContext(
|
|
|
587
664
|
const primarySets = alternatives.map((alternative) =>
|
|
588
665
|
derivePrimaryAnchors(alternative),
|
|
589
666
|
);
|
|
590
|
-
const headerSets = alternatives.map((alternative) =>
|
|
591
|
-
|
|
592
|
-
|
|
667
|
+
const headerSets = alternatives.map((alternative, index) => {
|
|
668
|
+
// A token that is the primary label of another option belongs to
|
|
669
|
+
// that option and to no other: the header of "A+B" is not the header
|
|
670
|
+
// of the option "A", whatever the order of the alternatives is.
|
|
671
|
+
const otherPrimaries = primarySets
|
|
672
|
+
.flat()
|
|
673
|
+
.filter((token) => !primarySets[index]?.includes(token));
|
|
674
|
+
return deriveOptionAnchors(alternative).filter(
|
|
675
|
+
(token) => !otherPrimaries.includes(token),
|
|
676
|
+
);
|
|
677
|
+
});
|
|
593
678
|
// The mention anchors of every option: a part of a combination belongs
|
|
594
679
|
// to the option that names it and to no other.
|
|
595
680
|
const mentionSets = primarySets.map((primaries) =>
|
|
@@ -610,6 +695,7 @@ export function buildChoiceDecisionContext(
|
|
|
610
695
|
const claimed = new Set<number>();
|
|
611
696
|
let derivedFromStructured = 0;
|
|
612
697
|
let derivedFromMessage = 0;
|
|
698
|
+
let derivedFromBoth = 0;
|
|
613
699
|
let missingMeaning = false;
|
|
614
700
|
|
|
615
701
|
const readFacts = (
|
|
@@ -631,6 +717,32 @@ export function buildChoiceDecisionContext(
|
|
|
631
717
|
return { facts, cut: list.length > MAX_OPTION_FACTS };
|
|
632
718
|
};
|
|
633
719
|
|
|
720
|
+
/**
|
|
721
|
+
* The facts of an option: the supplied ones come first, the facts of the
|
|
722
|
+
* source follow. A fact that is in both lists is kept once.
|
|
723
|
+
*
|
|
724
|
+
* The result is undefined when the supplied facts are not a list: the
|
|
725
|
+
* facts of the source are then the only ones, and the caller reports
|
|
726
|
+
* the malformed facts itself.
|
|
727
|
+
*/
|
|
728
|
+
const mergeFacts = (
|
|
729
|
+
supplied: unknown,
|
|
730
|
+
sourceFacts: string[],
|
|
731
|
+
): string[] | undefined => {
|
|
732
|
+
if (!Array.isArray(supplied)) return undefined;
|
|
733
|
+
const merged: string[] = [];
|
|
734
|
+
for (const value of supplied) {
|
|
735
|
+
if (typeof value !== "string") continue;
|
|
736
|
+
const trimmed = value.trim();
|
|
737
|
+
if (trimmed.length === 0) continue;
|
|
738
|
+
if (!merged.includes(trimmed)) merged.push(trimmed);
|
|
739
|
+
}
|
|
740
|
+
for (const fact of sourceFacts) {
|
|
741
|
+
if (!merged.includes(fact)) merged.push(fact);
|
|
742
|
+
}
|
|
743
|
+
return merged;
|
|
744
|
+
};
|
|
745
|
+
|
|
634
746
|
for (const [index, alternative] of alternatives.entries()) {
|
|
635
747
|
const id = `option_${index + 1}`;
|
|
636
748
|
const label = alternative.trim();
|
|
@@ -666,26 +778,26 @@ export function buildChoiceDecisionContext(
|
|
|
666
778
|
);
|
|
667
779
|
}
|
|
668
780
|
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
if (extracted
|
|
781
|
+
// The extraction always runs. A supplied description is the meaning
|
|
782
|
+
// of the option, not a replacement for the facts of the message: a
|
|
783
|
+
// caveat that only the message carries has to survive it.
|
|
784
|
+
const extracted = extractOptionFacts({
|
|
785
|
+
source,
|
|
786
|
+
headerCandidates,
|
|
787
|
+
mentionAnchors,
|
|
788
|
+
otherHeaderCandidates,
|
|
789
|
+
otherMentionAnchors,
|
|
790
|
+
claimed,
|
|
791
|
+
question: input.question,
|
|
792
|
+
});
|
|
793
|
+
if (extracted.headerIndex >= 0) {
|
|
682
794
|
claimed.add(extracted.headerIndex);
|
|
683
795
|
}
|
|
684
796
|
|
|
685
797
|
let description =
|
|
686
798
|
suppliedDescription.length > 0
|
|
687
799
|
? suppliedDescription
|
|
688
|
-
:
|
|
800
|
+
: extracted.description;
|
|
689
801
|
if (description.length > MAX_OPTION_DESCRIPTION_CHARS) {
|
|
690
802
|
description = description.slice(0, MAX_OPTION_DESCRIPTION_CHARS);
|
|
691
803
|
omitted.push(
|
|
@@ -693,13 +805,37 @@ export function buildChoiceDecisionContext(
|
|
|
693
805
|
);
|
|
694
806
|
}
|
|
695
807
|
|
|
808
|
+
// The wording of the source for the option survives a supplied
|
|
809
|
+
// description: it can carry the caveat of the option ("it must
|
|
810
|
+
// actually connect").
|
|
811
|
+
const sourceWording =
|
|
812
|
+
suppliedDescription.length > 0 &&
|
|
813
|
+
extracted.description.length > 0 &&
|
|
814
|
+
extracted.description !== suppliedDescription
|
|
815
|
+
? extracted.description
|
|
816
|
+
: "";
|
|
817
|
+
const sourceConstraints = [
|
|
818
|
+
...(sourceWording.length > 0 && extracted.descriptionConstraint
|
|
819
|
+
? [sourceWording]
|
|
820
|
+
: []),
|
|
821
|
+
...extracted.constraints,
|
|
822
|
+
];
|
|
823
|
+
const sourceTradeoffs = [
|
|
824
|
+
...(sourceWording.length > 0 && !extracted.descriptionConstraint
|
|
825
|
+
? [sourceWording]
|
|
826
|
+
: []),
|
|
827
|
+
...extracted.tradeoffs,
|
|
828
|
+
];
|
|
829
|
+
const sourceFacts =
|
|
830
|
+
sourceConstraints.length > 0 || sourceTradeoffs.length > 0;
|
|
831
|
+
|
|
696
832
|
const tradeoffsResult = readFacts(
|
|
697
|
-
supplied?.tradeoffs,
|
|
698
|
-
|
|
833
|
+
mergeFacts(supplied?.tradeoffs, sourceTradeoffs),
|
|
834
|
+
sourceTradeoffs,
|
|
699
835
|
);
|
|
700
836
|
const constraintsResult = readFacts(
|
|
701
|
-
supplied?.constraints,
|
|
702
|
-
|
|
837
|
+
mergeFacts(supplied?.constraints, sourceConstraints),
|
|
838
|
+
sourceConstraints,
|
|
703
839
|
);
|
|
704
840
|
if (tradeoffsResult.cut || constraintsResult.cut) {
|
|
705
841
|
omitted.push(
|
|
@@ -719,9 +855,13 @@ export function buildChoiceDecisionContext(
|
|
|
719
855
|
);
|
|
720
856
|
}
|
|
721
857
|
|
|
722
|
-
if (suppliedDescription.length > 0) {
|
|
858
|
+
if (suppliedDescription.length > 0 && sourceFacts) {
|
|
859
|
+
// The meaning comes from the structure, the facts of the message
|
|
860
|
+
// are merged with it: the provenance is mixed.
|
|
861
|
+
derivedFromBoth += 1;
|
|
862
|
+
} else if (suppliedDescription.length > 0) {
|
|
723
863
|
derivedFromStructured += 1;
|
|
724
|
-
} else if (extracted
|
|
864
|
+
} else if (extracted.found) {
|
|
725
865
|
derivedFromMessage += 1;
|
|
726
866
|
} else {
|
|
727
867
|
missingMeaning = true;
|
|
@@ -804,7 +944,8 @@ export function buildChoiceDecisionContext(
|
|
|
804
944
|
}
|
|
805
945
|
|
|
806
946
|
const derived =
|
|
807
|
-
|
|
947
|
+
derivedFromBoth > 0 ||
|
|
948
|
+
(derivedFromStructured > 0 && derivedFromMessage > 0)
|
|
808
949
|
? "mixed"
|
|
809
950
|
: derivedFromStructured > 0
|
|
810
951
|
? "structured"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-harness/two-phase-review",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.465",
|
|
4
4
|
"description": "pi-harness-runtime — two-phase implementation and review workflow (queue review signals, gate the phase, scope the diff)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|