@mohan-cao/jev-phase 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 +201 -0
- package/README.md +60 -0
- package/dist/index.d.ts +72 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +78 -0
- package/dist/index.js.map +1 -0
- package/package.json +47 -0
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,60 @@
|
|
|
1
|
+
# @mohan-cao/jev-phase
|
|
2
|
+
|
|
3
|
+
The phase signal, extracted from `@mohan-cao/jev-classifier`: one Jev Choice
|
|
4
|
+
judgment answering *what kind of work does this conversation need next* —
|
|
5
|
+
`build`, `design`, or `general`.
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @mohan-cao/jev-phase
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
import { judgePhase, NEXT_PHASE_QUESTION, PHASES } from "@mohan-cao/jev-phase";
|
|
13
|
+
|
|
14
|
+
const judgment = await judgePhase(turns, apiKey, routerConfig);
|
|
15
|
+
// { phase: "design", phaseConfidence: 0.83, model: "jev-1.13.0" }
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Scope: an indicator, not a router
|
|
19
|
+
|
|
20
|
+
This is deliberately a small component. It reports where a session sits; it does
|
|
21
|
+
not decide what you should do about it.
|
|
22
|
+
|
|
23
|
+
That is not modesty, it is the design. The reader of the signal — the human in
|
|
24
|
+
the loop — is the one who knows whether a session is advancing toward its goal
|
|
25
|
+
or circling one part of the problem. Reading `design` makes that judgement
|
|
26
|
+
explicit; no internal measurement can make it for them. A component that
|
|
27
|
+
recommended a model instead would be substituting for a preference the user
|
|
28
|
+
already holds, and the inputs that would justify it (risk, verification cost,
|
|
29
|
+
tolerance for a wrong path) are local knowledge a session does not have.
|
|
30
|
+
|
|
31
|
+
So the supported use is the status indicator. `PhaseConfig.routes`,
|
|
32
|
+
`phaseRecommendation`, and `formatPhaseNudge` are the earlier routing experiment,
|
|
33
|
+
kept because they are harmless and the data is interesting — but nothing here
|
|
34
|
+
should be treated as advice about which model to run.
|
|
35
|
+
|
|
36
|
+
See `docs/design/classifier-scope.md` in the repository for the rule this
|
|
37
|
+
follows and the verdicts on the other signals.
|
|
38
|
+
|
|
39
|
+
## API
|
|
40
|
+
|
|
41
|
+
| export | purpose |
|
|
42
|
+
| --- | --- |
|
|
43
|
+
| `judgePhase(turns, apiKey, config, signal?)` | one Jev Choice call → `PhaseJudgment` |
|
|
44
|
+
| `NEXT_PHASE_QUESTION` | the question spec, for reuse or inspection |
|
|
45
|
+
| `PHASES`, `Phase` | the vocabulary |
|
|
46
|
+
| `phaseRecommendation(judgment, currentModelId, config)` | the routing experiment |
|
|
47
|
+
| `formatPhaseNudge(recommendation, mode)` | status string, or `undefined` to clear |
|
|
48
|
+
|
|
49
|
+
## Notes
|
|
50
|
+
|
|
51
|
+
- **Its own call.** Not shared with verification or the trajectory judgment.
|
|
52
|
+
Questions sharing a call can perturb each other.
|
|
53
|
+
- **`general` is a residual, not a category.** It means "neither implementation
|
|
54
|
+
nor design specifically describes this", which includes prose and mixed work.
|
|
55
|
+
- **A `phaseConfidence` below the configured threshold means no nudge**, not a
|
|
56
|
+
low-quality judgment. Near-ties are reported as such rather than resolved.
|
|
57
|
+
|
|
58
|
+
## License
|
|
59
|
+
|
|
60
|
+
Apache-2.0.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The phase signal.
|
|
3
|
+
*
|
|
4
|
+
* Judges what kind of work a conversation needs next — implementation, design,
|
|
5
|
+
* or general — and reports it as an **indicator**. It is not a routing input:
|
|
6
|
+
* its consumer is the reader's own sense of whether a session is advancing
|
|
7
|
+
* toward its goal or circling one part of the problem. No internal measurement
|
|
8
|
+
* can make that judgement, and this package does not attempt to.
|
|
9
|
+
*
|
|
10
|
+
* See `docs/design/classifier-scope.md` for why that distinction is the whole
|
|
11
|
+
* scope of this component.
|
|
12
|
+
*/
|
|
13
|
+
import { type ChoiceQuestionSpec, type FooterMode, type HistoryTurn, type RouterConfig } from "@mohan-cao/jev-classifier";
|
|
14
|
+
export declare const PHASES: readonly ["build", "design", "general"];
|
|
15
|
+
export type Phase = (typeof PHASES)[number];
|
|
16
|
+
/** What the phase judge observed. */
|
|
17
|
+
export interface PhaseJudgment {
|
|
18
|
+
/** The phase the next work should be in. Never `stay` — that is a policy decision. */
|
|
19
|
+
phase: Phase;
|
|
20
|
+
phaseConfidence: number;
|
|
21
|
+
model?: string;
|
|
22
|
+
}
|
|
23
|
+
export interface PhaseRoute {
|
|
24
|
+
model: string;
|
|
25
|
+
thinking?: string;
|
|
26
|
+
steering?: string;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Model policy for the phase nudge.
|
|
30
|
+
*
|
|
31
|
+
* Retained for the routing experiment, but see the README: the package's
|
|
32
|
+
* supported use is the indicator, not the recommendation.
|
|
33
|
+
*/
|
|
34
|
+
export interface PhaseConfig {
|
|
35
|
+
/** phase → the model that serves it. Empty means the nudge is inert. */
|
|
36
|
+
routes: Partial<Record<Phase, PhaseRoute>>;
|
|
37
|
+
/** Minimum Choice confidence before a nudge is shown. */
|
|
38
|
+
phaseConfidenceThreshold: number;
|
|
39
|
+
/** Conversation turns supplied to the phase judge. */
|
|
40
|
+
historyTurns: number;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Present only when the running model is known to serve a different phase than
|
|
44
|
+
* the work is moving into. An unmapped current model yields no nudge — we cannot
|
|
45
|
+
* say it is wrong.
|
|
46
|
+
*/
|
|
47
|
+
export interface PhaseRecommendation {
|
|
48
|
+
phase: Phase;
|
|
49
|
+
/** The model configured for that phase, when the routes map has one. */
|
|
50
|
+
model?: string;
|
|
51
|
+
/** The phase the running model serves. */
|
|
52
|
+
currentPhase: Phase;
|
|
53
|
+
}
|
|
54
|
+
export declare const NEXT_PHASE_QUESTION: ChoiceQuestionSpec;
|
|
55
|
+
/**
|
|
56
|
+
* Post-generation phase judgment.
|
|
57
|
+
*
|
|
58
|
+
* Its own call, not shared with verification or the trajectory judgment. They
|
|
59
|
+
* read different state (the last exchange vs the conversation) and are
|
|
60
|
+
* conceptually independent — and questions sharing a call can perturb each
|
|
61
|
+
* other, which is how `implementation_ready` ended up flipping another answer.
|
|
62
|
+
*/
|
|
63
|
+
export declare function judgePhase(turns: HistoryTurn[], apiKey: string, config: RouterConfig, parentSignal?: AbortSignal): Promise<PhaseJudgment>;
|
|
64
|
+
/**
|
|
65
|
+
* Deterministic. Recommends only when the running model is *known* to serve a
|
|
66
|
+
* different phase — an unmapped model yields no nudge, because we cannot say it
|
|
67
|
+
* is wrong and "surface deviations" means staying quiet otherwise.
|
|
68
|
+
*/
|
|
69
|
+
export declare function phaseRecommendation(judgment: PhaseJudgment, currentModelId: string | undefined, config: PhaseConfig): PhaseRecommendation | undefined;
|
|
70
|
+
/** `undefined` clears the status indicator. */
|
|
71
|
+
export declare function formatPhaseNudge(recommendation: PhaseRecommendation | undefined, mode?: FooterMode): string | undefined;
|
|
72
|
+
//# 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,kBAAkB,EACvB,KAAK,UAAU,EACf,KAAK,WAAW,EAChB,KAAK,YAAY,EAClB,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/C,wBAAgB,gBAAgB,CAC9B,cAAc,EAAE,mBAAmB,GAAG,SAAS,EAC/C,IAAI,GAAE,UAAsB,GAC3B,MAAM,GAAG,SAAS,CAMpB"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The phase signal.
|
|
3
|
+
*
|
|
4
|
+
* Judges what kind of work a conversation needs next — implementation, design,
|
|
5
|
+
* or general — and reports it as an **indicator**. It is not a routing input:
|
|
6
|
+
* its consumer is the reader's own sense of whether a session is advancing
|
|
7
|
+
* toward its goal or circling one part of the problem. No internal measurement
|
|
8
|
+
* can make that judgement, and this package does not attempt to.
|
|
9
|
+
*
|
|
10
|
+
* See `docs/design/classifier-scope.md` for why that distinction is the whole
|
|
11
|
+
* scope of this component.
|
|
12
|
+
*/
|
|
13
|
+
import { callSystemOne, parseChoiceAnswer, } from "@mohan-cao/jev-classifier";
|
|
14
|
+
export const PHASES = ["build", "design", "general"];
|
|
15
|
+
export const NEXT_PHASE_QUESTION = {
|
|
16
|
+
type: "choice",
|
|
17
|
+
instructions: "What kind of work does this conversation need next? Judge the subject matter — what has been settled and what is still open — not how smoothly the conversation has been going.",
|
|
18
|
+
criteria: {
|
|
19
|
+
build: "Implementation, tests, mechanical debugging, or straightforward code changes. The decisions needed to act are already settled.",
|
|
20
|
+
design: "Architecture, ambiguous requirements, nuanced tradeoffs, adversarial review, or difficult debugging. Something material is still unresolved.",
|
|
21
|
+
general: "General conversation, investigation, or mixed work that neither implementation nor design specifically describes.",
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
const PHASE_ID = "next_phase";
|
|
25
|
+
/**
|
|
26
|
+
* Post-generation phase judgment.
|
|
27
|
+
*
|
|
28
|
+
* Its own call, not shared with verification or the trajectory judgment. They
|
|
29
|
+
* read different state (the last exchange vs the conversation) and are
|
|
30
|
+
* conceptually independent — and questions sharing a call can perturb each
|
|
31
|
+
* other, which is how `implementation_ready` ended up flipping another answer.
|
|
32
|
+
*/
|
|
33
|
+
export async function judgePhase(turns, apiKey, config, parentSignal) {
|
|
34
|
+
const payload = await callSystemOne({ recent_conversation: turns.map((turn) => `${turn.role}: ${turn.text}`) }, { [PHASE_ID]: NEXT_PHASE_QUESTION }, apiKey, config, parentSignal);
|
|
35
|
+
const phase = parseChoiceAnswer(payload, PHASE_ID, PHASES);
|
|
36
|
+
const judgment = { phase: phase.choice, phaseConfidence: phase.confidence };
|
|
37
|
+
return payload.model ? { ...judgment, model: payload.model } : judgment;
|
|
38
|
+
}
|
|
39
|
+
function modelForPhase(phase, config) {
|
|
40
|
+
return config.routes[phase]?.model;
|
|
41
|
+
}
|
|
42
|
+
function phaseForModel(modelId, config) {
|
|
43
|
+
if (!modelId)
|
|
44
|
+
return undefined;
|
|
45
|
+
for (const phase of PHASES) {
|
|
46
|
+
if (config.routes[phase]?.model === modelId)
|
|
47
|
+
return phase;
|
|
48
|
+
}
|
|
49
|
+
return undefined;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Deterministic. Recommends only when the running model is *known* to serve a
|
|
53
|
+
* different phase — an unmapped model yields no nudge, because we cannot say it
|
|
54
|
+
* is wrong and "surface deviations" means staying quiet otherwise.
|
|
55
|
+
*/
|
|
56
|
+
export function phaseRecommendation(judgment, currentModelId, config) {
|
|
57
|
+
if (judgment.phaseConfidence < config.phaseConfidenceThreshold)
|
|
58
|
+
return undefined;
|
|
59
|
+
const currentPhase = phaseForModel(currentModelId, config);
|
|
60
|
+
if (!currentPhase || currentPhase === judgment.phase)
|
|
61
|
+
return undefined;
|
|
62
|
+
const model = modelForPhase(judgment.phase, config);
|
|
63
|
+
if (!model)
|
|
64
|
+
return undefined;
|
|
65
|
+
return { phase: judgment.phase, model, currentPhase };
|
|
66
|
+
}
|
|
67
|
+
const PHASE_GLYPH = { build: "🔨", design: "📐", general: "💬" };
|
|
68
|
+
/** `undefined` clears the status indicator. */
|
|
69
|
+
export function formatPhaseNudge(recommendation, mode = "compact") {
|
|
70
|
+
if (!recommendation || mode === "off")
|
|
71
|
+
return undefined;
|
|
72
|
+
if (mode === "icons")
|
|
73
|
+
return `↪${PHASE_GLYPH[recommendation.phase]}`;
|
|
74
|
+
return recommendation.model
|
|
75
|
+
? `↪ ${recommendation.phase} · ${recommendation.model}`
|
|
76
|
+
: `↪ ${recommendation.phase}`;
|
|
77
|
+
}
|
|
78
|
+
//# 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,iBAAiB,GAKlB,MAAM,2BAA2B,CAAC;AAEnC,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,OAAO,EAAE,QAAQ,EAAE,SAAS,CAAU,CAAC;AA6C9D,MAAM,CAAC,MAAM,mBAAmB,GAAuB;IACrD,IAAI,EAAE,QAAQ;IACd,YAAY,EACV,iLAAiL;IACnL,QAAQ,EAAE;QACR,KAAK,EACH,gIAAgI;QAClI,MAAM,EACJ,8IAA8I;QAChJ,OAAO,EACL,mHAAmH;KACtH;CACF,CAAC;AAEF,MAAM,QAAQ,GAAG,YAAY,CAAC;AAE9B;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAC9B,KAAoB,EACpB,MAAc,EACd,MAAoB,EACpB,YAA0B;IAE1B,MAAM,OAAO,GAAG,MAAM,aAAa,CACjC,EAAE,mBAAmB,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,GAAG,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,EAAE,CAAC,EAAE,EAC1E,EAAE,CAAC,QAAQ,CAAC,EAAE,mBAAmB,EAAE,EACnC,MAAM,EACN,MAAM,EACN,YAAY,CACb,CAAC;IAEF,MAAM,KAAK,GAAG,iBAAiB,CAAC,OAAO,EAAE,QAAQ,EAAE,MAAM,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,MAAM,WAAW,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAkC,CAAC;AAEjG,+CAA+C;AAC/C,MAAM,UAAU,gBAAgB,CAC9B,cAA+C,EAC/C,OAAmB,SAAS;IAE5B,IAAI,CAAC,cAAc,IAAI,IAAI,KAAK,KAAK;QAAE,OAAO,SAAS,CAAC;IACxD,IAAI,IAAI,KAAK,OAAO;QAAE,OAAO,IAAI,WAAW,CAAC,cAAc,CAAC,KAAK,CAAC,EAAE,CAAC;IACrE,OAAO,cAAc,CAAC,KAAK;QACzB,CAAC,CAAC,KAAK,cAAc,CAAC,KAAK,MAAM,cAAc,CAAC,KAAK,EAAE;QACvD,CAAC,CAAC,KAAK,cAAc,CAAC,KAAK,EAAE,CAAC;AAClC,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mohan-cao/jev-phase",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Jev phase signal: what kind of work a conversation needs next, reported as an indicator.",
|
|
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-phase"
|
|
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
|
+
"scripts": {
|
|
35
|
+
"clean": "rm -rf dist",
|
|
36
|
+
"build": "tsc -p tsconfig.json",
|
|
37
|
+
"build:unchecked": "tsc -p tsconfig.json --noCheck",
|
|
38
|
+
"test": "node --test test/*.test.mjs",
|
|
39
|
+
"prepack": "npm run build"
|
|
40
|
+
},
|
|
41
|
+
"publishConfig": {
|
|
42
|
+
"access": "public"
|
|
43
|
+
},
|
|
44
|
+
"dependencies": {
|
|
45
|
+
"@mohan-cao/jev-classifier": "workspace:^"
|
|
46
|
+
}
|
|
47
|
+
}
|