@mohan-cao/jev-trajectory 0.1.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/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,97 @@
1
+ # @mohan-cao/jev-trajectory
2
+
3
+ The progress signal: **two orthogonal Jev judgments per settled turn** — did it
4
+ advance the work, did it reopen something — composed into four outcomes, plus
5
+ pure arithmetic over a series of them.
6
+
7
+ ```bash
8
+ npm install @mohan-cao/jev-trajectory
9
+ ```
10
+
11
+ ```ts
12
+ import { judgeTrajectory, progressOf, summarizeProgress } from "@mohan-cao/jev-trajectory";
13
+
14
+ const judgment = await judgeTrajectory(turns, apiKey, jevConfig);
15
+ // { advanceConfidence: 0.9, regressConfidence: 0.8 }
16
+ progressOf(judgment); // "mixed"
17
+
18
+ summarizeProgress(series, 0.7);
19
+ // { counted: 8, advanced: 4, regressed: 3, mixed: 2,
20
+ // advancedRate: 0.5, regressedRate: 0.375, mixedRate: 0.25,
21
+ // net: 0.125, oscillation: 2, longestStall: 3 }
22
+ ```
23
+
24
+ A judgment carries **only the two answers**. The composed label is derived by
25
+ `progressOf`, so it cannot drift out of step with the confidences it came from.
26
+
27
+ ## Two questions, not one scale
28
+
29
+ | `advance?` | `regress?` | outcome |
30
+ | --- | --- | --- |
31
+ | no | no | `held` |
32
+ | yes | no | `advanced` |
33
+ | no | yes | `regressed` |
34
+ | yes | yes | `mixed` |
35
+
36
+ A turn can genuinely do both — settle the API shape and reopen the storage
37
+ choice — and a single axis cannot say so. **This is the same reason
38
+ classification asks two Nouls rather than one Choice**: a single axis makes the
39
+ residual compete in an argmax. Forcing a two-dimensional turn onto one line is
40
+ the same mistake.
41
+
42
+ `mixed` is not a failure state. Neither is `regressed`: reopening a detail that
43
+ turned out to rest on a false premise is how a wrong premise gets caught.
44
+
45
+ ## There is no `stuck` value
46
+
47
+ An earlier version classified turns as `converging | stuck_detail | stuck_framing
48
+ | early`. The objection that killed it is worth keeping: *if something is in
49
+ progress and not converging, is it stuck?* That vocabulary answered yes by
50
+ omission — it had no place for a turn that neither advanced nor revisited, and
51
+ both `stuck` labels were **verdicts rather than observations**.
52
+
53
+ Divergence is therefore *recorded, not named*. The reader decides whether a
54
+ series is a correction cycle or a spiral; naming it would be the same overreach
55
+ as recommending a model.
56
+
57
+ ## The aggregates
58
+
59
+ | aggregate | reading |
60
+ | --- | --- |
61
+ | `net` | mean of the −1/0/+1 series, with `mixed` cancelling to zero. Positive means progressing, *even with much still open* |
62
+ | `oscillation` | direction reversals. `held` and `mixed` are pauses, not reversals |
63
+ | `longestStall` | longest run that did not net forward — `mixed` counts as not netting forward |
64
+ | `advancedRate`, `regressedRate` | **marginals**, so they overlap on `mixed`. The gap between `mixedRate` and what independence would predict is the interesting part |
65
+
66
+ Percentiles and variance are deliberately absent. Over a window this short they
67
+ are noise, and over a three-valued series spread is nearly redundant with the
68
+ proportions.
69
+
70
+ ## Where the pieces live
71
+
72
+ - **This package** — the questions, the judge, and pure aggregation. No I/O, no
73
+ state, no rendering.
74
+ - **The host** — the window, the reset point, and the wording. The tally is
75
+ cumulative from the last **state transition** and resets to `0/0` there, which
76
+ the host decides because a phase change is not this package's concern.
77
+
78
+ ## Caveats
79
+
80
+ - **No eval baselines.** The old cases — `detail-spiral`, `framing-loop`,
81
+ `design-open` — were labelled against the retired categories. Until they are
82
+ re-baselined against the rates, this signal is **unvalidated**.
83
+ - **A turn counts only when both answers are decisive enough.** The gate is on
84
+ **decisiveness** — distance from the midpoint — not on the raw probability. A
85
+ clear advance has `P(regress) ≈ 0.1`, so gating on the probability would exclude
86
+ every one-sided turn and leave the signal inert. The weaker of the two decides,
87
+ which keeps one denominator and makes the rates comparable. Below it the turn is
88
+ excluded, not forced to `held`.
89
+ - **Sensitivity falls as the stretch lengthens.** A three-turn spiral inside a
90
+ forty-turn stretch barely moves the rates. If that becomes a problem the fix is
91
+ a second, shorter measure alongside this one.
92
+ - **Never used in a real session.** Like everything here, it is younger than the
93
+ problem it is meant to observe.
94
+
95
+ ## License
96
+
97
+ Apache-2.0.
@@ -0,0 +1,43 @@
1
+ /**
2
+ * The progress signal.
3
+ *
4
+ * Two orthogonal Noul judgments per settled turn — did it advance the work, did
5
+ * it reopen something — composed into four outcomes, plus pure arithmetic over a
6
+ * series of them. It reports rates rather than a verdict: nothing here decides
7
+ * whether the work is "stuck", because the reader is the one who can tell a
8
+ * spiral from a correction.
9
+ *
10
+ * Read the README before relying on it. The tally's reset point is the host's
11
+ * business, and there are no eval baselines for this signal yet.
12
+ */
13
+ import { type HistoryTurn, type JevConfig } from "@mohan-cao/jev-classifier";
14
+ import { ADVANCE_QUESTION, REGRESS_QUESTION } from "./questions.js";
15
+ import { PROGRESS, PROGRESS_VALUE, progressFrom, type Progress, type ProgressSummary, type TrajectoryJudgment } from "./types.js";
16
+ export { ADVANCE_QUESTION, REGRESS_QUESTION };
17
+ export { PROGRESS, PROGRESS_VALUE, progressFrom };
18
+ export type { Progress, ProgressSummary, TrajectoryConfig, TrajectoryJudgment, } from "./types.js";
19
+ /**
20
+ * The composed outcome of a judgment, at the Noul midpoint.
21
+ *
22
+ * The only place the cutoff appears, so nothing else has to know it.
23
+ */
24
+ export declare function progressOf(judgment: TrajectoryJudgment): Progress;
25
+ /**
26
+ * Its own call, not shared with verification, classification, or the phase
27
+ * judgment. They read different state and are conceptually independent — and
28
+ * questions sharing a call can perturb each other.
29
+ */
30
+ export declare function judgeTrajectory(turns: HistoryTurn[], apiKey: string, config: JevConfig, parentSignal?: AbortSignal): Promise<TrajectoryJudgment>;
31
+ /**
32
+ * Pure arithmetic over a series of judgments, in order.
33
+ *
34
+ * A turn counts only when **both** answers are decisive enough. Turns below the
35
+ * gate are excluded rather than forced to `held`: a turn the judge could not read
36
+ * should not inflate the denominator, and one denominator is what makes the
37
+ * rates comparable.
38
+ *
39
+ * `oscillation` counts direction reversals, not pauses — `held` and `mixed` both
40
+ * net to zero, so neither changes direction.
41
+ */
42
+ export declare function summarizeProgress(judgments: TrajectoryJudgment[], minConfidence: number): ProgressSummary;
43
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAGL,KAAK,WAAW,EAChB,KAAK,SAAS,EACf,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AACpE,OAAO,EACL,QAAQ,EACR,cAAc,EACd,YAAY,EACZ,KAAK,QAAQ,EACb,KAAK,eAAe,EACpB,KAAK,kBAAkB,EACxB,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,YAAY,EAAE,CAAC;AAClD,YAAY,EACV,QAAQ,EACR,eAAe,EACf,gBAAgB,EAChB,kBAAkB,GACnB,MAAM,YAAY,CAAC;AAYpB;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,QAAQ,EAAE,kBAAkB,GAAG,QAAQ,CAKjE;AAED;;;;GAIG;AACH,wBAAsB,eAAe,CACnC,KAAK,EAAE,WAAW,EAAE,EACpB,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,SAAS,EACjB,YAAY,CAAC,EAAE,WAAW,GACzB,OAAO,CAAC,kBAAkB,CAAC,CAc7B;AAeD;;;;;;;;;;GAUG;AACH,wBAAgB,iBAAiB,CAC/B,SAAS,EAAE,kBAAkB,EAAE,EAC/B,aAAa,EAAE,MAAM,GACpB,eAAe,CAsEjB"}
package/dist/index.js ADDED
@@ -0,0 +1,134 @@
1
+ /**
2
+ * The progress signal.
3
+ *
4
+ * Two orthogonal Noul judgments per settled turn — did it advance the work, did
5
+ * it reopen something — composed into four outcomes, plus pure arithmetic over a
6
+ * series of them. It reports rates rather than a verdict: nothing here decides
7
+ * whether the work is "stuck", because the reader is the one who can tell a
8
+ * spiral from a correction.
9
+ *
10
+ * Read the README before relying on it. The tally's reset point is the host's
11
+ * business, and there are no eval baselines for this signal yet.
12
+ */
13
+ import { callSystemOne, parseNoulAnswer, } from "@mohan-cao/jev-classifier";
14
+ import { ADVANCE_QUESTION, REGRESS_QUESTION } from "./questions.js";
15
+ import { PROGRESS, PROGRESS_VALUE, progressFrom, } from "./types.js";
16
+ export { ADVANCE_QUESTION, REGRESS_QUESTION };
17
+ export { PROGRESS, PROGRESS_VALUE, progressFrom };
18
+ const ADVANCE_ID = "advanced";
19
+ const REGRESS_ID = "regressed";
20
+ /**
21
+ * A Noul is a probability, so composing it into a boolean needs a midpoint.
22
+ * The reliability gate is separate and lives in `TrajectoryConfig`: 0.51 is
23
+ * enough to *call* it advancing, but not enough to count it.
24
+ */
25
+ const NOUL_CUTOFF = 0.5;
26
+ /**
27
+ * The composed outcome of a judgment, at the Noul midpoint.
28
+ *
29
+ * The only place the cutoff appears, so nothing else has to know it.
30
+ */
31
+ export function progressOf(judgment) {
32
+ return progressFrom(judgment.advanceConfidence >= NOUL_CUTOFF, judgment.regressConfidence >= NOUL_CUTOFF);
33
+ }
34
+ /**
35
+ * Its own call, not shared with verification, classification, or the phase
36
+ * judgment. They read different state and are conceptually independent — and
37
+ * questions sharing a call can perturb each other.
38
+ */
39
+ export async function judgeTrajectory(turns, apiKey, config, parentSignal) {
40
+ const payload = await callSystemOne({ recent_conversation: turns.map((turn) => `${turn.role}: ${turn.text}`) }, { [ADVANCE_ID]: ADVANCE_QUESTION, [REGRESS_ID]: REGRESS_QUESTION }, apiKey, config, parentSignal);
41
+ const advanceConfidence = parseNoulAnswer(payload, ADVANCE_ID);
42
+ const regressConfidence = parseNoulAnswer(payload, REGRESS_ID);
43
+ const judgment = { advanceConfidence, regressConfidence };
44
+ return payload.model ? { ...judgment, model: payload.model } : judgment;
45
+ }
46
+ /**
47
+ * How decisive a Noul answer is: its distance from the midpoint, as 0.5–1.
48
+ *
49
+ * A Noul carries P(true), so a *confidently false* answer has a **low**
50
+ * probability. Gating on the raw probability would therefore exclude every
51
+ * one-sided turn — a clear advance has `P(regress) ≈ 0.1`, and the minimum of the
52
+ * two would sit below any sensible threshold. What the gate wants is how far
53
+ * each answer is from a coin flip.
54
+ */
55
+ function decisiveness(probability) {
56
+ return Math.max(probability, 1 - probability);
57
+ }
58
+ /**
59
+ * Pure arithmetic over a series of judgments, in order.
60
+ *
61
+ * A turn counts only when **both** answers are decisive enough. Turns below the
62
+ * gate are excluded rather than forced to `held`: a turn the judge could not read
63
+ * should not inflate the denominator, and one denominator is what makes the
64
+ * rates comparable.
65
+ *
66
+ * `oscillation` counts direction reversals, not pauses — `held` and `mixed` both
67
+ * net to zero, so neither changes direction.
68
+ */
69
+ export function summarizeProgress(judgments, minConfidence) {
70
+ const counted = judgments.filter((judgment) => Math.min(decisiveness(judgment.advanceConfidence), decisiveness(judgment.regressConfidence)) >=
71
+ minConfidence);
72
+ if (counted.length === 0) {
73
+ return {
74
+ counted: 0,
75
+ advanced: 0,
76
+ regressed: 0,
77
+ mixed: 0,
78
+ advancedRate: 0,
79
+ regressedRate: 0,
80
+ mixedRate: 0,
81
+ net: 0,
82
+ oscillation: 0,
83
+ longestStall: 0,
84
+ };
85
+ }
86
+ let advanced = 0;
87
+ let regressed = 0;
88
+ let mixed = 0;
89
+ let oscillation = 0;
90
+ let longestStall = 0;
91
+ let stall = 0;
92
+ let lastSign = 0;
93
+ let sum = 0;
94
+ for (const judgment of counted) {
95
+ const progress = progressOf(judgment);
96
+ // Marginals of the two questions, so `mixed` counts toward both.
97
+ if (progress === "advanced" || progress === "mixed")
98
+ advanced += 1;
99
+ if (progress === "regressed" || progress === "mixed")
100
+ regressed += 1;
101
+ if (progress === "mixed")
102
+ mixed += 1;
103
+ const value = PROGRESS_VALUE[progress];
104
+ sum += value;
105
+ // A stall is any turn that did not net forward — `regressed` is no more
106
+ // progress than `held` is, and `mixed` cancels itself out.
107
+ if (value > 0) {
108
+ stall = 0;
109
+ }
110
+ else {
111
+ stall += 1;
112
+ }
113
+ longestStall = Math.max(longestStall, stall);
114
+ const sign = Math.sign(value);
115
+ if (sign !== 0) {
116
+ if (lastSign !== 0 && sign !== lastSign)
117
+ oscillation += 1;
118
+ lastSign = sign;
119
+ }
120
+ }
121
+ return {
122
+ counted: counted.length,
123
+ advanced,
124
+ regressed,
125
+ mixed,
126
+ advancedRate: advanced / counted.length,
127
+ regressedRate: regressed / counted.length,
128
+ mixedRate: mixed / counted.length,
129
+ net: sum / counted.length,
130
+ oscillation,
131
+ longestStall,
132
+ };
133
+ }
134
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EACL,aAAa,EACb,eAAe,GAGhB,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AACpE,OAAO,EACL,QAAQ,EACR,cAAc,EACd,YAAY,GAIb,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,YAAY,EAAE,CAAC;AAQlD,MAAM,UAAU,GAAG,UAAU,CAAC;AAC9B,MAAM,UAAU,GAAG,WAAW,CAAC;AAE/B;;;;GAIG;AACH,MAAM,WAAW,GAAG,GAAG,CAAC;AAExB;;;;GAIG;AACH,MAAM,UAAU,UAAU,CAAC,QAA4B;IACrD,OAAO,YAAY,CACjB,QAAQ,CAAC,iBAAiB,IAAI,WAAW,EACzC,QAAQ,CAAC,iBAAiB,IAAI,WAAW,CAC1C,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,C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AAK,CAAC,CAAC;QAE7C,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC9B,IAAI,IAAI,KAAK,CAAC,EAAE,CAAC;YACf,IAAI,QAAQ,KAAK,CAAC,IAAI,IAAI,KAAK,QAAQ;gBAAE,WAAW,IAAI,CAAC,CAAC;YAC1D,QAAQ,GAAG,IAAI,CAAC;QAClB,CAAC;IACH,CAAC;IAED,OAAO;QACL,OAAO,EAAE,OAAO,CAAC,MAAM;QACvB,QAAQ;QACR,SAAS;QACT,KAAK;QACL,YAAY,EAAE,QAAQ,GAAG,OAAO,CAAC,MAAM;QACvC,aAAa,EAAE,SAAS,GAAG,OAAO,CAAC,MAAM;QACzC,SAAS,EAAE,KAAK,GAAG,OAAO,CAAC,MAAM;QACjC,GAAG,EAAE,GAAG,GAAG,OAAO,CAAC,MAAM;QACzB,WAAW;QACX,YAAY;KACb,CAAC;AACJ,CAAC"}
@@ -0,0 +1,15 @@
1
+ import type { NoulQuestionSpec } from "@mohan-cao/jev-classifier";
2
+ /**
3
+ * The progress questions — two orthogonal Nouls, asked in one call.
4
+ *
5
+ * Deliberately **not** one ordinal scale. A turn can advance one thing and
6
+ * reopen another, and a single axis cannot say so; two independent answers
7
+ * compose into four outcomes in code, the same way classification keeps
8
+ * `normal` as a residual instead of a competing argmax candidate.
9
+ *
10
+ * Phase-agnostic on purpose: the same answers read correctly in build as in
11
+ * design, and converging on agreement counts as advancing.
12
+ */
13
+ export declare const ADVANCE_QUESTION: NoulQuestionSpec;
14
+ export declare const REGRESS_QUESTION: NoulQuestionSpec;
15
+ //# sourceMappingURL=questions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"questions.d.ts","sourceRoot":"","sources":["../src/questions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAElE;;;;;;;;;;GAUG;AAEH,eAAO,MAAM,gBAAgB,EAAE,gBAQ9B,CAAC;AAEF,eAAO,MAAM,gBAAgB,EAAE,gBAQ9B,CAAC"}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * The progress questions — two orthogonal Nouls, asked in one call.
3
+ *
4
+ * Deliberately **not** one ordinal scale. A turn can advance one thing and
5
+ * reopen another, and a single axis cannot say so; two independent answers
6
+ * compose into four outcomes in code, the same way classification keeps
7
+ * `normal` as a residual instead of a competing argmax candidate.
8
+ *
9
+ * Phase-agnostic on purpose: the same answers read correctly in build as in
10
+ * design, and converging on agreement counts as advancing.
11
+ */
12
+ export const ADVANCE_QUESTION = {
13
+ type: "noul",
14
+ instructions: "Did this turn move the work forward? Judge the effect on the work itself, not how smoothly the conversation went, and judge it for any kind of work: a decision settled by agreement advances the work as much as a newly resolved detail does.",
15
+ criteria: {
16
+ true: "The turn settled something, moved the work forward, or converged on agreement.",
17
+ false: "The turn neither settled anything nor moved the work forward.",
18
+ },
19
+ };
20
+ export const REGRESS_QUESTION = {
21
+ type: "noul",
22
+ instructions: "Did this turn reopen or undo something previously settled? A detail that turned out to rest on a false premise counts — catching a wrong premise is the point, but it is still a reopening. Answer this independently of whether the turn also advanced something; both can be true of the same turn.",
23
+ criteria: {
24
+ true: "Something previously settled was reopened, revised, or undone.",
25
+ false: "Nothing previously settled was reopened or undone.",
26
+ },
27
+ };
28
+ //# sourceMappingURL=questions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"questions.js","sourceRoot":"","sources":["../src/questions.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AAEH,MAAM,CAAC,MAAM,gBAAgB,GAAqB;IAChD,IAAI,EAAE,MAAM;IACZ,YAAY,EACV,iPAAiP;IACnP,QAAQ,EAAE;QACR,IAAI,EAAE,gFAAgF;QACtF,KAAK,EAAE,+DAA+D;KACvE;CACF,CAAC;AAEF,MAAM,CAAC,MAAM,gBAAgB,GAAqB;IAChD,IAAI,EAAE,MAAM;IACZ,YAAY,EACV,uSAAuS;IACzS,QAAQ,EAAE;QACR,IAAI,EAAE,gEAAgE;QACtE,KAAK,EAAE,oDAAoD;KAC5D;CACF,CAAC"}
@@ -0,0 +1,94 @@
1
+ import type { JevConfig } from "@mohan-cao/jev-classifier";
2
+ /**
3
+ * What a single turn did to the work.
4
+ *
5
+ * Four outcomes composed from two orthogonal questions, not one ordinal scale.
6
+ * A turn can genuinely do both — settle the API shape and reopen the storage
7
+ * choice — and forcing that onto a single axis loses exactly the information
8
+ * that matters. This is the same reason classification asks two Nouls rather
9
+ * than one Choice: a single axis makes the residual compete in an argmax.
10
+ */
11
+ export declare const PROGRESS: readonly ["held", "advanced", "regressed", "mixed"];
12
+ export type Progress = (typeof PROGRESS)[number];
13
+ /** Composed from the two answers. `mixed` is not a failure state: it is both. */
14
+ export declare function progressFrom(advance: boolean, regress: boolean): Progress;
15
+ /**
16
+ * −1, 0, +1 — the series the trend aggregates operate on.
17
+ *
18
+ * `mixed` nets to zero, because one thing moved each way. That is deliberate: a
19
+ * run of mixed turns keeps changing things without netting forward, which is a
20
+ * stall in the only sense this signal claims.
21
+ */
22
+ export declare const PROGRESS_VALUE: {
23
+ regressed: number;
24
+ held: number;
25
+ mixed: number;
26
+ advanced: number;
27
+ };
28
+ /**
29
+ * What the progress judge observed on one settled turn.
30
+ *
31
+ * Deliberately carries **only the two answers**, not a composed label. A label
32
+ * here would be derived state that the type cannot keep consistent with its
33
+ * inputs, and anything reading it would have to trust that they agree. Compose
34
+ * with `progressOf` instead.
35
+ */
36
+ export interface TrajectoryJudgment {
37
+ /** P(the turn advanced the work). */
38
+ advanceConfidence: number;
39
+ /** P(the turn reopened or undid something). */
40
+ regressConfidence: number;
41
+ model?: string;
42
+ }
43
+ /** Transport settings plus this component's settings. */
44
+ export interface TrajectoryConfig extends JevConfig {
45
+ /** Conversation turns supplied to the progress judge. */
46
+ historyTurns: number;
47
+ /**
48
+ * Minimum **decisiveness** for both answers before a turn counts at all.
49
+ *
50
+ * A Noul carries P(true), so decisiveness is its distance from the midpoint —
51
+ * 0.7 means each answer is at least 70% sure of itself. Gating on the raw
52
+ * probability instead would exclude every one-sided turn, since a clear advance
53
+ * has `P(regress) ≈ 0.1`.
54
+ *
55
+ * Gating on the weaker of the two keeps a single denominator, which is what
56
+ * makes the rates comparable with one another. Below it the turn is excluded
57
+ * rather than forced to `held`, which would inflate the denominator with turns
58
+ * the judge could not read.
59
+ */
60
+ progressConfidenceThreshold: number;
61
+ }
62
+ /**
63
+ * The aggregates, all pure arithmetic over the counted turns.
64
+ *
65
+ * Nothing here decides whether the work is "stuck". That judgement belongs to
66
+ * the reader, and the point of reporting rates rather than a verdict is to give
67
+ * them what they need to make it.
68
+ */
69
+ export interface ProgressSummary {
70
+ /** Turns where both answers cleared the confidence gate. */
71
+ counted: number;
72
+ /**
73
+ * Turns where *something* advanced — `mixed` included.
74
+ *
75
+ * The rates are marginals of the two questions, so `advancedRate` and
76
+ * `regressedRate` overlap on `mixed` turns. The gap between `mixedRate` and
77
+ * what independence would predict is the interesting part.
78
+ */
79
+ advanced: number;
80
+ /** Turns where something was reopened — `mixed` included. */
81
+ regressed: number;
82
+ /** Turns that did both. */
83
+ mixed: number;
84
+ advancedRate: number;
85
+ regressedRate: number;
86
+ mixedRate: number;
87
+ /** Mean of the −1/0/+1 series. Positive means the work is progressing, even with much still open. */
88
+ net: number;
89
+ /** Sign changes in the series — thrashing, whatever it is about. */
90
+ oscillation: number;
91
+ /** Longest run that did not net forward. `held` and `mixed` both count as not netting forward. */
92
+ longestStall: number;
93
+ }
94
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAE3D;;;;;;;;GAQG;AACH,eAAO,MAAM,QAAQ,qDAAsD,CAAC;AAC5E,MAAM,MAAM,QAAQ,GAAG,CAAC,OAAO,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC;AAEjD,iFAAiF;AACjF,wBAAgB,YAAY,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,GAAG,QAAQ,CAKzE;AAED;;;;;;GAMG;AACH,eAAO,MAAM,cAAc;;;;;CAKS,CAAC;AAErC;;;;;;;GAOG;AACH,MAAM,WAAW,kBAAkB;IACjC,qCAAqC;IACrC,iBAAiB,EAAE,MAAM,CAAC;IAC1B,+CAA+C;IAC/C,iBAAiB,EAAE,MAAM,CAAC;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,yDAAyD;AACzD,MAAM,WAAW,gBAAiB,SAAQ,SAAS;IACjD,yDAAyD;IACzD,YAAY,EAAE,MAAM,CAAC;IACrB;;;;;;;;;;;;OAYG;IACH,2BAA2B,EAAE,MAAM,CAAC;CACrC;AAED;;;;;;GAMG;AACH,MAAM,WAAW,eAAe;IAC9B,4DAA4D;IAC5D,OAAO,EAAE,MAAM,CAAC;IAChB;;;;;;OAMG;IACH,QAAQ,EAAE,MAAM,CAAC;IACjB,6DAA6D;IAC7D,SAAS,EAAE,MAAM,CAAC;IAClB,2BAA2B;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,qGAAqG;IACrG,GAAG,EAAE,MAAM,CAAC;IACZ,oEAAoE;IACpE,WAAW,EAAE,MAAM,CAAC;IACpB,kGAAkG;IAClG,YAAY,EAAE,MAAM,CAAC;CACtB"}
package/dist/types.js ADDED
@@ -0,0 +1,34 @@
1
+ /**
2
+ * What a single turn did to the work.
3
+ *
4
+ * Four outcomes composed from two orthogonal questions, not one ordinal scale.
5
+ * A turn can genuinely do both — settle the API shape and reopen the storage
6
+ * choice — and forcing that onto a single axis loses exactly the information
7
+ * that matters. This is the same reason classification asks two Nouls rather
8
+ * than one Choice: a single axis makes the residual compete in an argmax.
9
+ */
10
+ export const PROGRESS = ["held", "advanced", "regressed", "mixed"];
11
+ /** Composed from the two answers. `mixed` is not a failure state: it is both. */
12
+ export function progressFrom(advance, regress) {
13
+ if (advance && regress)
14
+ return "mixed";
15
+ if (advance)
16
+ return "advanced";
17
+ if (regress)
18
+ return "regressed";
19
+ return "held";
20
+ }
21
+ /**
22
+ * −1, 0, +1 — the series the trend aggregates operate on.
23
+ *
24
+ * `mixed` nets to zero, because one thing moved each way. That is deliberate: a
25
+ * run of mixed turns keeps changing things without netting forward, which is a
26
+ * stall in the only sense this signal claims.
27
+ */
28
+ export const PROGRESS_VALUE = {
29
+ regressed: -1,
30
+ held: 0,
31
+ mixed: 0,
32
+ advanced: 1,
33
+ };
34
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,MAAM,EAAE,UAAU,EAAE,WAAW,EAAE,OAAO,CAAU,CAAC;AAG5E,iFAAiF;AACjF,MAAM,UAAU,YAAY,CAAC,OAAgB,EAAE,OAAgB;IAC7D,IAAI,OAAO,IAAI,OAAO;QAAE,OAAO,OAAO,CAAC;IACvC,IAAI,OAAO;QAAE,OAAO,UAAU,CAAC;IAC/B,IAAI,OAAO;QAAE,OAAO,WAAW,CAAC;IAChC,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,SAAS,EAAE,CAAC,CAAC;IACb,IAAI,EAAE,CAAC;IACP,KAAK,EAAE,CAAC;IACR,QAAQ,EAAE,CAAC;CACuB,CAAC"}
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "@mohan-cao/jev-trajectory",
3
+ "version": "0.1.0",
4
+ "description": "Jev progress signal: one signed per-turn judgment of whether the work advanced, held, or was reopened.",
5
+ "type": "module",
6
+ "license": "Apache-2.0",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/mohan-cao/pi-extensions.git",
10
+ "directory": "packages/jev-trajectory"
11
+ },
12
+ "keywords": [
13
+ "jev",
14
+ "typesafe-ai",
15
+ "system-one",
16
+ "classifier",
17
+ "llm"
18
+ ],
19
+ "engines": {
20
+ "node": ">=20"
21
+ },
22
+ "files": [
23
+ "dist",
24
+ "README.md",
25
+ "LICENSE",
26
+ "CHANGELOG.md"
27
+ ],
28
+ "exports": {
29
+ ".": {
30
+ "types": "./dist/index.d.ts",
31
+ "default": "./dist/index.js"
32
+ }
33
+ },
34
+ "publishConfig": {
35
+ "access": "public"
36
+ },
37
+ "dependencies": {
38
+ "@mohan-cao/jev-classifier": "^0.2.0"
39
+ },
40
+ "scripts": {
41
+ "clean": "rm -rf dist",
42
+ "build": "tsc -p tsconfig.json",
43
+ "build:unchecked": "tsc -p tsconfig.json --noCheck",
44
+ "test": "node --test test/*.test.mjs"
45
+ }
46
+ }