@amaster.ai/pi-goal 0.1.2-beta.42
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 +120 -0
- package/dist/config.d.ts +36 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +46 -0
- package/dist/config.js.map +1 -0
- package/dist/derive.d.ts +17 -0
- package/dist/derive.d.ts.map +1 -0
- package/dist/derive.js +39 -0
- package/dist/derive.js.map +1 -0
- package/dist/evaluate.d.ts +28 -0
- package/dist/evaluate.d.ts.map +1 -0
- package/dist/evaluate.js +64 -0
- package/dist/evaluate.js.map +1 -0
- package/dist/extension.d.ts +28 -0
- package/dist/extension.d.ts.map +1 -0
- package/dist/extension.js +281 -0
- package/dist/extension.js.map +1 -0
- package/dist/goal-state.d.ts +46 -0
- package/dist/goal-state.d.ts.map +1 -0
- package/dist/goal-state.js +89 -0
- package/dist/goal-state.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/llm.d.ts +23 -0
- package/dist/llm.d.ts.map +1 -0
- package/dist/llm.js +79 -0
- package/dist/llm.js.map +1 -0
- package/dist/prompts.d.ts +35 -0
- package/dist/prompts.d.ts.map +1 -0
- package/dist/prompts.js +64 -0
- package/dist/prompts.js.map +1 -0
- package/dist/transcript.d.ts +20 -0
- package/dist/transcript.d.ts.map +1 -0
- package/dist/transcript.js +53 -0
- package/dist/transcript.js.map +1 -0
- package/package.json +85 -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,120 @@
|
|
|
1
|
+
# @amaster.ai/pi-goal
|
|
2
|
+
|
|
3
|
+
A Pi extension that lets Pi **keep working until a goal is met**. You don't have to write the completion condition yourself — run `/goal` with no argument and the extension derives a measurable condition from the conversation, shows it to you for a quick confirmation, then keeps the agent working (re-checking after each run) until the condition holds.
|
|
4
|
+
|
|
5
|
+
Modeled on Claude Code's stop-condition mechanism, with a token/iteration budget backstop borrowed from Codex's goal mode.
|
|
6
|
+
|
|
7
|
+
## How it works
|
|
8
|
+
|
|
9
|
+
1. **Set a goal.** Either give an explicit condition (`/goal all tests pass and lint is clean`) or let the extension derive one from the conversation (`/goal` with no argument).
|
|
10
|
+
2. **Derived goals are confirmed** in interactive (TUI) mode before they start, so a mis-derived goal can't run off on its own. Non-interactive modes skip the confirmation.
|
|
11
|
+
3. **After each agent run** (`agent_end`), a small evaluator model judges whether the condition is met:
|
|
12
|
+
- **Met** → the goal is marked achieved and cleared. Pi stops.
|
|
13
|
+
- **Not yet** → Pi is nudged to continue, told what still remains.
|
|
14
|
+
- **Impossible** → Pi stops and tells you why.
|
|
15
|
+
4. **Backstops.** Continuation stops after `maxIterations` rounds or once an optional `tokenBudget` is exceeded, so a bad goal can't loop forever.
|
|
16
|
+
|
|
17
|
+
Goal state is session-scoped and held in memory (no cross-session persistence), matching Claude Code's behavior.
|
|
18
|
+
|
|
19
|
+
## Pi lifecycle (how the engine hooks in)
|
|
20
|
+
|
|
21
|
+
The goal engine is driven by Pi's lifecycle events. For one `pi -p '<prompt>'`
|
|
22
|
+
run (non-interactive), events fire in this order:
|
|
23
|
+
|
|
24
|
+
```
|
|
25
|
+
session_start ← session-level, once
|
|
26
|
+
│ pi-goal: load config, read the --goal flag
|
|
27
|
+
▼
|
|
28
|
+
[ per user prompt — the "agent-level" block below repeats ]
|
|
29
|
+
│
|
|
30
|
+
before_agent_start { prompt, systemPrompt } ← carries the user's input for this turn, once per prompt
|
|
31
|
+
│
|
|
32
|
+
agent_start { }
|
|
33
|
+
│
|
|
34
|
+
├─ [ per turn, may repeat ]
|
|
35
|
+
│ turn_start { turnIndex }
|
|
36
|
+
│ message_start { message (user) }
|
|
37
|
+
│ message_end { message (user) }
|
|
38
|
+
│ message_start { message (assistant) }
|
|
39
|
+
│ message_end { message (assistant) }
|
|
40
|
+
│ turn_end { turnIndex, message, toolResults }
|
|
41
|
+
│
|
|
42
|
+
agent_end { messages: [...] } ← engine evaluates + stops/continues, once per prompt
|
|
43
|
+
│ If a goal is active: build a transcript from `messages`, ask the
|
|
44
|
+
│ evaluator ok / impossible / not-yet. Not-yet → sendUserMessage(continue)
|
|
45
|
+
│ → triggers a new agent run (back to before_agent_start).
|
|
46
|
+
│
|
|
47
|
+
agent_settled { } ← this prompt is fully done
|
|
48
|
+
▼
|
|
49
|
+
[ interactive: wait for next input · print mode: process exits here ]
|
|
50
|
+
|
|
51
|
+
session_shutdown ← on exit/switch; pi-goal clears state
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Events pi-goal uses:
|
|
55
|
+
|
|
56
|
+
| Event | What pi-goal does | Notes |
|
|
57
|
+
|-------|-------------------|-------|
|
|
58
|
+
| `session_start` | Load config; read the `--goal` flag | Session-level, fires once |
|
|
59
|
+
| `before_agent_start` | If a `--goal` derivation is pending, derive the condition from `event.prompt` (this turn's user input), then set the goal | Fires once per prompt; the right anchor for auto-derivation since no transcript exists yet at `session_start` |
|
|
60
|
+
| `agent_end` | If a goal is active, run the engine on `event.messages`: evaluate → mark achieved/impossible or `sendUserMessage` to continue | Engine core. `event.messages` is the full conversation, so no separate buffering is needed |
|
|
61
|
+
| `session_shutdown` | Clear the goal | Cleanup |
|
|
62
|
+
|
|
63
|
+
The interactive `/goal` command (no argument) derives from the session's own
|
|
64
|
+
history, read via `ctx.sessionManager` — not a buffer this extension maintains.
|
|
65
|
+
|
|
66
|
+
Note on derivation timing: a condition can only be derived once there is
|
|
67
|
+
conversation to derive from. `session_start` is too early (no transcript
|
|
68
|
+
yet); `before_agent_start` is the first point that carries the user's prompt
|
|
69
|
+
for the turn, so auto-derivation keys off it rather than firing at startup.
|
|
70
|
+
|
|
71
|
+
## Usage
|
|
72
|
+
|
|
73
|
+
```
|
|
74
|
+
/goal <condition> Set an explicit completion condition.
|
|
75
|
+
/goal No active goal → derive one from the conversation (with confirmation).
|
|
76
|
+
Active goal → show its status.
|
|
77
|
+
/goal clear Clear the active goal (also: stop, off, reset, none, cancel).
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
The slash command is for interactive (TUI) use; print mode can't dispatch it.
|
|
81
|
+
For the CLI / non-interactive runs, use the `--goal` flag instead:
|
|
82
|
+
|
|
83
|
+
```
|
|
84
|
+
pi --goal '<condition>' -p '<prompt>' Set an explicit goal, then run the prompt.
|
|
85
|
+
pi --goal '' -p '<prompt>' Derive the goal from the prompt (at before_agent_start).
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## Configuration
|
|
89
|
+
|
|
90
|
+
Settings key: `pi-goal` (in `~/.pi/agent/settings.json`, agent dir, or project `.pi/settings.json`).
|
|
91
|
+
|
|
92
|
+
```json
|
|
93
|
+
{
|
|
94
|
+
"pi-goal": {
|
|
95
|
+
"model": { "provider": "anthropic", "model": "claude-haiku-4-5-20251001" },
|
|
96
|
+
"maxIterations": 10,
|
|
97
|
+
"tokenBudget": 200000,
|
|
98
|
+
"transcriptMaxChars": 8000,
|
|
99
|
+
"requireConfirmForDerived": true
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
| Key | Default | Purpose |
|
|
105
|
+
|-----|---------|---------|
|
|
106
|
+
| `model` | — | Provider/model for deriving and evaluating conditions. **Omit to disable the automatic engine** — `/goal <condition>` still sets a goal, but nothing auto-derives or auto-continues. |
|
|
107
|
+
| `maxIterations` | `10` | Max continuation rounds before Pi stops pushing. |
|
|
108
|
+
| `tokenBudget` | — | Optional hard token ceiling; the goal is paused (`budget_limited`) once exceeded. |
|
|
109
|
+
| `transcriptMaxChars` | `8000` | Max transcript chars fed to derive/evaluate. |
|
|
110
|
+
| `requireConfirmForDerived` | `true` | Ask before starting a derived goal (TUI only). |
|
|
111
|
+
|
|
112
|
+
Prefer a small, cheap model for `model` — the evaluator runs after every agent run.
|
|
113
|
+
|
|
114
|
+
## Relationship to Claude Code / Codex
|
|
115
|
+
|
|
116
|
+
- **Engine (from Claude Code):** goal = a stop condition; Pi keeps going until an evaluator judges it met. Passive — it drives continuation off `agent_end`, not a background scheduler.
|
|
117
|
+
- **Prompts (from Claude Code):** the evaluator and activation prompts are adapted almost verbatim from Claude Code's own stop-hook prompts — including the quote-the-evidence requirement, the "insufficient evidence in transcript" fallback, the impossible-judgment discipline (the assistant's claim is *evidence, not proof*), and the truncated-transcript note.
|
|
118
|
+
- **Auto-derivation:** you don't have to phrase the condition; it's inferred and confirmed. (No CC analogue — CC always takes an explicit condition.)
|
|
119
|
+
- **Budget backstop (from Codex):** token + iteration limits prevent runaway loops.
|
|
120
|
+
- **Not included:** Codex's idle auto-resume, pause/resume dialogs, file-backed objectives, and cross-session persistence.
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/** Model used for deriving and evaluating goal conditions. */
|
|
2
|
+
export type GoalModelConfig = {
|
|
3
|
+
provider: string;
|
|
4
|
+
model: string;
|
|
5
|
+
};
|
|
6
|
+
export type PiGoalConfig = {
|
|
7
|
+
/**
|
|
8
|
+
* Model for deriving conditions and evaluating whether they are met.
|
|
9
|
+
* Omit to disable the automatic engine — `/goal <condition>` still works
|
|
10
|
+
* for setting a goal, but nothing auto-derives or auto-evaluates.
|
|
11
|
+
*/
|
|
12
|
+
model?: GoalModelConfig;
|
|
13
|
+
/** Max continuation rounds before the engine stops pushing. Default 10. */
|
|
14
|
+
maxIterations?: number;
|
|
15
|
+
/** Optional hard token budget; goal becomes budget_limited once exceeded. Omit for no limit. */
|
|
16
|
+
tokenBudget?: number;
|
|
17
|
+
/** Max chars of transcript fed to derive/evaluate. Default 8000. */
|
|
18
|
+
transcriptMaxChars?: number;
|
|
19
|
+
/** Ask the user to confirm a derived condition in TUI mode. Default true. */
|
|
20
|
+
requireConfirmForDerived?: boolean;
|
|
21
|
+
};
|
|
22
|
+
export type ResolvedGoalConfig = {
|
|
23
|
+
model?: GoalModelConfig;
|
|
24
|
+
maxIterations: number;
|
|
25
|
+
tokenBudget?: number;
|
|
26
|
+
transcriptMaxChars: number;
|
|
27
|
+
requireConfirmForDerived: boolean;
|
|
28
|
+
};
|
|
29
|
+
export declare const DEFAULTS: {
|
|
30
|
+
readonly maxIterations: 10;
|
|
31
|
+
readonly transcriptMaxChars: 8000;
|
|
32
|
+
readonly requireConfirmForDerived: true;
|
|
33
|
+
};
|
|
34
|
+
export declare function resolveConfig(raw?: PiGoalConfig): ResolvedGoalConfig;
|
|
35
|
+
export declare function loadSettings(cwd: string): PiGoalConfig | undefined;
|
|
36
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAIA,8DAA8D;AAC9D,MAAM,MAAM,eAAe,GAAG;IAC5B,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;IACzB;;;;OAIG;IACH,KAAK,CAAC,EAAE,eAAe,CAAC;IACxB,2EAA2E;IAC3E,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,gGAAgG;IAChG,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,oEAAoE;IACpE,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,6EAA6E;IAC7E,wBAAwB,CAAC,EAAE,OAAO,CAAC;CACpC,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,KAAK,CAAC,EAAE,eAAe,CAAC;IACxB,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,wBAAwB,EAAE,OAAO,CAAC;CACnC,CAAC;AAEF,eAAO,MAAM,QAAQ;;;;CAIX,CAAC;AAEX,wBAAgB,aAAa,CAAC,GAAG,CAAC,EAAE,YAAY,GAAG,kBAAkB,CAiBpE;AAED,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS,CAOlE"}
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { loadPiSettings } from '@amaster.ai/pi-shared/settings';
|
|
2
|
+
const SETTINGS_KEY = 'pi-goal';
|
|
3
|
+
export const DEFAULTS = {
|
|
4
|
+
maxIterations: 10,
|
|
5
|
+
transcriptMaxChars: 8000,
|
|
6
|
+
requireConfirmForDerived: true,
|
|
7
|
+
};
|
|
8
|
+
export function resolveConfig(raw) {
|
|
9
|
+
const resolved = {
|
|
10
|
+
maxIterations: sanitizePositiveInt(raw?.maxIterations, DEFAULTS.maxIterations),
|
|
11
|
+
transcriptMaxChars: sanitizePositiveInt(raw?.transcriptMaxChars, DEFAULTS.transcriptMaxChars),
|
|
12
|
+
requireConfirmForDerived: raw?.requireConfirmForDerived ?? DEFAULTS.requireConfirmForDerived,
|
|
13
|
+
};
|
|
14
|
+
if (isValidModel(raw?.model)) {
|
|
15
|
+
resolved.model = { provider: raw.model.provider, model: raw.model.model };
|
|
16
|
+
}
|
|
17
|
+
if (typeof raw?.tokenBudget === 'number' &&
|
|
18
|
+
Number.isFinite(raw.tokenBudget) &&
|
|
19
|
+
raw.tokenBudget > 0) {
|
|
20
|
+
resolved.tokenBudget = Math.floor(raw.tokenBudget);
|
|
21
|
+
}
|
|
22
|
+
return resolved;
|
|
23
|
+
}
|
|
24
|
+
export function loadSettings(cwd) {
|
|
25
|
+
try {
|
|
26
|
+
const config = loadPiSettings(SETTINGS_KEY, { cwd });
|
|
27
|
+
return Object.keys(config).length > 0 ? config : undefined;
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
function isValidModel(model) {
|
|
34
|
+
return (!!model &&
|
|
35
|
+
typeof model.provider === 'string' &&
|
|
36
|
+
model.provider.trim().length > 0 &&
|
|
37
|
+
typeof model.model === 'string' &&
|
|
38
|
+
model.model.trim().length > 0);
|
|
39
|
+
}
|
|
40
|
+
function sanitizePositiveInt(value, fallback) {
|
|
41
|
+
if (typeof value === 'number' && Number.isFinite(value) && value > 0) {
|
|
42
|
+
return Math.floor(value);
|
|
43
|
+
}
|
|
44
|
+
return fallback;
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAEhE,MAAM,YAAY,GAAG,SAAS,CAAC;AAiC/B,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtB,aAAa,EAAE,EAAE;IACjB,kBAAkB,EAAE,IAAI;IACxB,wBAAwB,EAAE,IAAI;CACtB,CAAC;AAEX,MAAM,UAAU,aAAa,CAAC,GAAkB;IAC9C,MAAM,QAAQ,GAAuB;QACnC,aAAa,EAAE,mBAAmB,CAAC,GAAG,EAAE,aAAa,EAAE,QAAQ,CAAC,aAAa,CAAC;QAC9E,kBAAkB,EAAE,mBAAmB,CAAC,GAAG,EAAE,kBAAkB,EAAE,QAAQ,CAAC,kBAAkB,CAAC;QAC7F,wBAAwB,EAAE,GAAG,EAAE,wBAAwB,IAAI,QAAQ,CAAC,wBAAwB;KAC7F,CAAC;IACF,IAAI,YAAY,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,CAAC;QAC7B,QAAQ,CAAC,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rE,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IAC3B,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
package/dist/derive.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Derive a measurable completion condition from recent conversation.
|
|
3
|
+
*/
|
|
4
|
+
import type { GoalModelConfig } from './config.js';
|
|
5
|
+
import { type GoalModelRegistry } from './llm.js';
|
|
6
|
+
export interface DeriveOptions {
|
|
7
|
+
registry: GoalModelRegistry;
|
|
8
|
+
modelConfig: GoalModelConfig;
|
|
9
|
+
transcript: string;
|
|
10
|
+
signal?: AbortSignal;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Returns a one-line condition, or null if the model is unavailable, the call
|
|
14
|
+
* fails, or no actionable objective could be inferred (model returned NONE).
|
|
15
|
+
*/
|
|
16
|
+
export declare function deriveCondition(opts: DeriveOptions): Promise<string | null>;
|
|
17
|
+
//# sourceMappingURL=derive.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"derive.d.ts","sourceRoot":"","sources":["../src/derive.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAgB,KAAK,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAGhE,MAAM,WAAW,aAAa;IAC5B,QAAQ,EAAE,iBAAiB,CAAC;IAC5B,WAAW,EAAE,eAAe,CAAC;IAC7B,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED;;;GAGG;AACH,wBAAsB,eAAe,CAAC,IAAI,EAAE,aAAa,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CA0BjF"}
|
package/dist/derive.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Derive a measurable completion condition from recent conversation.
|
|
3
|
+
*/
|
|
4
|
+
import { completeOnce } from './llm.js';
|
|
5
|
+
import { buildDeriveUserPrompt, DERIVE_SYSTEM_PROMPT } from './prompts.js';
|
|
6
|
+
/**
|
|
7
|
+
* Returns a one-line condition, or null if the model is unavailable, the call
|
|
8
|
+
* fails, or no actionable objective could be inferred (model returned NONE).
|
|
9
|
+
*/
|
|
10
|
+
export async function deriveCondition(opts) {
|
|
11
|
+
const { registry, modelConfig, transcript, signal } = opts;
|
|
12
|
+
if (!transcript.trim()) {
|
|
13
|
+
console.error('[pi-goal] derive: empty transcript, nothing to derive from');
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
const raw = await completeOnce(registry, modelConfig, DERIVE_SYSTEM_PROMPT, buildDeriveUserPrompt(transcript), signal);
|
|
17
|
+
if (raw === null) {
|
|
18
|
+
console.error('[pi-goal] derive: model unavailable or call failed');
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
const condition = normalizeCondition(raw);
|
|
22
|
+
if (!condition || condition.toUpperCase() === 'NONE') {
|
|
23
|
+
console.error('[pi-goal] derive: no actionable objective inferred (NONE)');
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
console.error(`[pi-goal] derived condition: ${condition}`);
|
|
27
|
+
return condition;
|
|
28
|
+
}
|
|
29
|
+
function normalizeCondition(raw) {
|
|
30
|
+
// Take the first non-empty line, strip stray wrapping quotes/backticks.
|
|
31
|
+
const firstLine = raw
|
|
32
|
+
.split('\n')
|
|
33
|
+
.map((line) => line.trim())
|
|
34
|
+
.find((line) => line.length > 0);
|
|
35
|
+
if (!firstLine)
|
|
36
|
+
return '';
|
|
37
|
+
return firstLine.replace(/^["'`]+|["'`]+$/g, '').trim();
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=derive.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"derive.js","sourceRoot":"","sources":["../src/derive.ts"],"names":[],"mappings":"AAAA;;GAE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,GAAG,CAAC,CAAC,CAAC;IACnC,IAAI,CAAC,SAAS;QAAE,OAAO,EAAE,CAAC;IAC1B,OAAO,SAAS,CAAC,OAAO,CAAC,kBAAkB,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;AAC1D,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Evaluate whether a goal condition is satisfied, given the conversation so far.
|
|
3
|
+
*/
|
|
4
|
+
import type { GoalModelConfig } from './config.js';
|
|
5
|
+
import { type GoalModelRegistry } from './llm.js';
|
|
6
|
+
export interface GoalVerdict {
|
|
7
|
+
ok: boolean;
|
|
8
|
+
impossible: boolean;
|
|
9
|
+
reason: string;
|
|
10
|
+
}
|
|
11
|
+
export interface EvaluateOptions {
|
|
12
|
+
registry: GoalModelRegistry;
|
|
13
|
+
modelConfig: GoalModelConfig;
|
|
14
|
+
condition: string;
|
|
15
|
+
transcript: string;
|
|
16
|
+
/** Text-bearing messages dropped to fit the cap; surfaced to the evaluator. */
|
|
17
|
+
omittedCount?: number;
|
|
18
|
+
signal?: AbortSignal;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Returns a verdict, or null if the model is unavailable / the call failed.
|
|
22
|
+
* A malformed model response is treated conservatively as "not yet met" rather
|
|
23
|
+
* than null, so the engine keeps working instead of silently giving up.
|
|
24
|
+
*/
|
|
25
|
+
export declare function evaluateCondition(opts: EvaluateOptions): Promise<GoalVerdict | null>;
|
|
26
|
+
/** Parse the JSON verdict leniently; unparseable output → conservative "not yet". */
|
|
27
|
+
export declare function parseVerdict(raw: string): GoalVerdict;
|
|
28
|
+
//# sourceMappingURL=evaluate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"evaluate.d.ts","sourceRoot":"","sources":["../src/evaluate.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAgB,KAAK,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAGhE,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,OAAO,CAAC;IACZ,UAAU,EAAE,OAAO,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,eAAe;IAC9B,QAAQ,EAAE,iBAAiB,CAAC;IAC5B,WAAW,EAAE,eAAe,CAAC;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,+EAA+E;IAC/E,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED;;;;GAIG;AACH,wBAAsB,iBAAiB,CAAC,IAAI,EAAE,eAAe,GAAG,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC,CAoB1F;AAED,qFAAqF;AACrF,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,WAAW,CAkBrD"}
|
package/dist/evaluate.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Evaluate whether a goal condition is satisfied, given the conversation so far.
|
|
3
|
+
*/
|
|
4
|
+
import { completeOnce } from './llm.js';
|
|
5
|
+
import { buildEvaluateUserPrompt, EVALUATE_SYSTEM_PROMPT } from './prompts.js';
|
|
6
|
+
/**
|
|
7
|
+
* Returns a verdict, or null if the model is unavailable / the call failed.
|
|
8
|
+
* A malformed model response is treated conservatively as "not yet met" rather
|
|
9
|
+
* than null, so the engine keeps working instead of silently giving up.
|
|
10
|
+
*/
|
|
11
|
+
export async function evaluateCondition(opts) {
|
|
12
|
+
const { registry, modelConfig, condition, transcript, omittedCount, signal } = opts;
|
|
13
|
+
const raw = await completeOnce(registry, modelConfig, EVALUATE_SYSTEM_PROMPT, buildEvaluateUserPrompt(condition, transcript, omittedCount ?? 0), signal);
|
|
14
|
+
if (raw === null) {
|
|
15
|
+
console.error('[pi-goal] evaluate: model unavailable or call failed');
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
const verdict = parseVerdict(raw);
|
|
19
|
+
console.error(`[pi-goal] evaluation: ok=${verdict.ok} impossible=${verdict.impossible} reason=${verdict.reason}`);
|
|
20
|
+
return verdict;
|
|
21
|
+
}
|
|
22
|
+
/** Parse the JSON verdict leniently; unparseable output → conservative "not yet". */
|
|
23
|
+
export function parseVerdict(raw) {
|
|
24
|
+
const parsed = extractJsonObject(raw);
|
|
25
|
+
if (!parsed) {
|
|
26
|
+
return {
|
|
27
|
+
ok: false,
|
|
28
|
+
impossible: false,
|
|
29
|
+
reason: 'insufficient evidence in transcript (unparseable evaluation)',
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
const ok = parsed.ok === true;
|
|
33
|
+
const impossible = parsed.impossible === true && !ok;
|
|
34
|
+
const reason = typeof parsed.reason === 'string' && parsed.reason.trim()
|
|
35
|
+
? parsed.reason.trim()
|
|
36
|
+
: ok
|
|
37
|
+
? 'Condition satisfied.'
|
|
38
|
+
: 'Condition not yet satisfied.';
|
|
39
|
+
return { ok, impossible, reason };
|
|
40
|
+
}
|
|
41
|
+
function extractJsonObject(raw) {
|
|
42
|
+
const text = raw.trim();
|
|
43
|
+
// Fast path: whole string is JSON.
|
|
44
|
+
const direct = tryParse(text);
|
|
45
|
+
if (direct)
|
|
46
|
+
return direct;
|
|
47
|
+
// Fallback: first {...} block (handles code fences / surrounding prose).
|
|
48
|
+
const start = text.indexOf('{');
|
|
49
|
+
const end = text.lastIndexOf('}');
|
|
50
|
+
if (start >= 0 && end > start) {
|
|
51
|
+
return tryParse(text.slice(start, end + 1));
|
|
52
|
+
}
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
function tryParse(text) {
|
|
56
|
+
try {
|
|
57
|
+
const value = JSON.parse(text);
|
|
58
|
+
return value && typeof value === 'object' ? value : null;
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
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O,IAAI,CAAC;IACd,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type ExtensionAPI } from '@earendil-works/pi-coding-agent';
|
|
2
|
+
import { type PiGoalConfig, type ResolvedGoalConfig } from './config.js';
|
|
3
|
+
import { GoalState } from './goal-state.js';
|
|
4
|
+
import type { GoalModelRegistry } from './llm.js';
|
|
5
|
+
export type PiGoalExtensionConfig = PiGoalConfig;
|
|
6
|
+
/**
|
|
7
|
+
* Dependencies for the goal engine — extracted so the engine is unit-testable
|
|
8
|
+
* without a live ExtensionAPI.
|
|
9
|
+
*/
|
|
10
|
+
export interface GoalEngineDeps {
|
|
11
|
+
state: GoalState;
|
|
12
|
+
config: ResolvedGoalConfig;
|
|
13
|
+
registry: GoalModelRegistry;
|
|
14
|
+
sendUserMessage: (content: string) => void;
|
|
15
|
+
notify: (message: string, level: 'info' | 'warning' | 'error') => void;
|
|
16
|
+
setStatus: (text: string) => void;
|
|
17
|
+
signal?: AbortSignal;
|
|
18
|
+
/** Rough token accounting; defaults to a char-based estimate of the transcript. */
|
|
19
|
+
estimateTokens?: (transcript: string) => number;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Evaluate the active goal against the transcript and either stop (achieved /
|
|
23
|
+
* impossible / limited) or inject a continuation message. Idempotent guard: the
|
|
24
|
+
* caller must ensure only one invocation runs at a time (see extension wiring).
|
|
25
|
+
*/
|
|
26
|
+
export declare function runGoalEngine(deps: GoalEngineDeps, messages: unknown[]): Promise<'achieved' | 'impossible' | 'continued' | 'budget_limited' | 'iteration_limited' | 'skipped'>;
|
|
27
|
+
export default function goalExtension(pi: ExtensionAPI, injectedConfig?: PiGoalExtensionConfig): void;
|
|
28
|
+
//# sourceMappingURL=extension.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extension.d.ts","sourceRoot":"","sources":["../src/extension.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,YAAY,EAElB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAEL,KAAK,YAAY,EACjB,KAAK,kBAAkB,EAExB,MAAM,aAAa,CAAC;AAGrB,OAAO,EAAmB,SAAS,EAAwC,MAAM,iBAAiB,CAAC;AACnG,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAMlD,MAAM,MAAM,qBAAqB,GAAG,YAAY,CAAC;AAEjD;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,SAAS,CAAC;IACjB,MAAM,EAAE,kBAAkB,CAAC;IAC3B,QAAQ,EAAE,iBAAiB,CAAC;IAC5B,eAAe,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IAC3C,MAAM,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,KAAK,IAAI,CAAC;IACvE,SAAS,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,mFAAmF;IACnF,cAAc,CAAC,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,MAAM,CAAC;CACjD;AAED;;;;GAIG;AACH,wBAAsB,aAAa,CACjC,IAAI,EAAE,cAAc,EACpB,QAAQ,EAAE,OAAO,EAAE,GAClB,OAAO,CACR,UAAU,GAAG,YAAY,GAAG,WAAW,GAAG,gBAAgB,GAAG,mBAAmB,GAAG,SAAS,CAC7F,CAgEA;AAED,MAAM,CAAC,OAAO,UAAU,aAAa,CACnC,EAAE,EAAE,YAAY,EAChB,cAAc,CAAC,EAAE,qBAAqB,GACrC,IAAI,CA2NN"}
|