pi-system-one 1.1.4 → 1.2.1

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/README.md CHANGED
@@ -4,8 +4,47 @@ System One decisions for Pi. Plug in TypeSafe Jev, Reflex, or your own provider.
4
4
 
5
5
  ```bash
6
6
  pi install npm:pi-system-one
7
+ ```
8
+
9
+ For Oh My Pi (OMP), install the published package with:
10
+
11
+ ```bash
12
+ omp install npm:pi-system-one
13
+ ```
14
+
15
+ For a local checkout, install or load the package directory directly:
16
+
17
+ ```bash
18
+ omp install /path/to/pi-system-one
19
+ # or
20
+ omp --extension /path/to/pi-system-one
21
+ ```
22
+
23
+ Set `SYSTEM_ONE_BASE_URL` before launch, or run `/so config`; the `system_one` tool is registered after the endpoint is configured.
24
+
25
+ <img src="./demo.gif" alt="Description" width="640" >
26
+
27
+ ---
28
+
29
+ Setup Provider:
30
+ ##### locally hosted model e.g Reflex, von, laya etc, any model that supports `POST /v1/systemone`
31
+ ```bash
7
32
  export SYSTEM_ONE_BASE_URL=http://localhost:8008
8
33
  ```
34
+ or
35
+
36
+ ##### typesafe/JEV
37
+ ```bash
38
+ export SYSTEM_ONE_BASE_URL=https://api.typesafe.ai
39
+ export SYSTEM_ONE_MODEL=jev-latest
40
+ # Option 1: paste the key directly
41
+ export SYSTEM_ONE_API_KEY="..."
42
+ # Option 2: reuse an existing variable
43
+ export SYSTEM_ONE_API_KEY="$TYPESAFE_API_KEY"
44
+ ```
45
+
46
+
47
+ ---
9
48
 
10
49
  **Configuration**
11
50
 
@@ -18,12 +57,70 @@ The extension provides a `/so` command for configuring the System One client:
18
57
  When you run `/so config`, you can:
19
58
 
20
59
  - **Enter a new API key** – it is stored in memory only and will be lost when the session ends.
21
- - **Enter `-`** – forget the memory‑only key. If an `SYSTEM_ONE_API_KEY` environment variable is present, the client will fall back to it; otherwise the key becomes absent.
60
+ - **Enter `-`** – forget the memory‑only key. If a `SYSTEM_ONE_API_KEY` environment variable is present, the client will fall back to it; otherwise the key becomes absent.
22
61
  - **Leave the input empty** – keep the existing value.
23
62
 
24
63
  The current configuration can be inspected with `/so status`.
25
64
 
26
65
  ---
27
66
 
28
- For further details see the source code and comments in `src/commands.ts`.
29
- ```
67
+ ## `/judge`
68
+
69
+ The fastest way to use System One. A prompt shortcut that expands into
70
+ instructions calling the `system_one` tool explicitly, so routing
71
+ doesn't depend on inferring intent. For short, unstructured asks:
72
+
73
+ ```
74
+ /judge should I ship this? <paste diff plus test summary>
75
+ ```
76
+
77
+ ```
78
+ /judge which team should take this ticket? <paste ticket>
79
+ ```
80
+
81
+ ---
82
+
83
+ ## `system_one` skill
84
+
85
+ For everything else, the bundled skill teaches the agent when to call
86
+ `system_one`, which question type to use (`choice` / `noul` / `score`),
87
+ and how to read answers. It loads automatically — just ask for
88
+ quantified answers over material already in context. Probabilities and
89
+ confidence are the words that route to the tool. Retrieve facts first;
90
+ the judge weighs supplied state, it cannot recall facts.
91
+
92
+ See [SKILL.md](./skills/system-one/SKILL.md) for the full reference
93
+ and [use cases](./skills/system-one/references/use-cases.md) for
94
+ copy-pasteable recipes.
95
+
96
+ Examples — same decisions, quantified wording:
97
+
98
+ ```
99
+ Pick one: fix forward with a minimal patch, or revert and re-land
100
+ later. Give me the probability of each and your confidence.
101
+ <paste context>
102
+ ```
103
+
104
+ ```
105
+ This just landed in our support queue — which team is the most likely
106
+ owner: billing, technical, or sales? Give me the probability for each
107
+ and your confidence for the pick. Also, how urgent is it on a low /
108
+ medium / critical scale? And should I escalate (yes/no probability,
109
+ no confidence needed)?
110
+ <paste ticket>
111
+ ```
112
+
113
+ ```
114
+ Should I ship this or revert it? Give me the probability that shipping
115
+ causes a follow-up bug within a week (yes/no probability only — noul
116
+ has no confidence field). Also rate the test coverage — none, partial,
117
+ or full — with probabilities and confidence for the pick.
118
+ <paste diff plus test summary>
119
+ ```
120
+
121
+ Independent judgments over the same context should be batched into one
122
+ call, and answers should come back as calibrated, state-conditional
123
+ probabilities — with confidence for choice/score only (noul has no
124
+ confidence) — not prose guesses, and never as recalled facts.
125
+
126
+ Running your own backend? See the [system one core package](../system-one-core/README.md)
package/demo.gif ADDED
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-system-one",
3
- "version": "1.1.4",
3
+ "version": "1.2.1",
4
4
  "description": "System One decisions for Pi. Plug in TypeSafe Jev, Reflex, or your own provider.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -27,7 +27,7 @@
27
27
  "coding-agent"
28
28
  ],
29
29
  "dependencies": {
30
- "system-one-core": "^0.2.0"
30
+ "system-one-core": "^0.2.1"
31
31
  },
32
32
  "peerDependencies": {
33
33
  "@earendil-works/pi-coding-agent": "*",
@@ -37,5 +37,10 @@
37
37
  "extensions": [
38
38
  "./src/extension.ts"
39
39
  ]
40
+ },
41
+ "omp": {
42
+ "extensions": [
43
+ "./src/extension.ts"
44
+ ]
40
45
  }
41
46
  }
@@ -0,0 +1,29 @@
1
+ ---
2
+ description: Judge a decision with calibrated probabilities via System One
3
+ argument-hint: "<decision and context>"
4
+ ---
5
+ The user wants a calibrated judgment conditional on the supplied
6
+ state, not a prose opinion and not recalled facts. Retrieve any missing
7
+ factual evidence into the state first — then call the system_one tool
8
+ for the request below, do not answer it directly from priors.
9
+
10
+ Frame the request as one or more questions:
11
+
12
+ - exactly one option must be picked from several → a `choice`
13
+ question, with criteria keyed by option label (`null` values when
14
+ labels are self-explanatory),
15
+ - a yes/no must be estimated as a chance → a `noul` question (omit
16
+ criteria unless the yes/no outcomes need clarification),
17
+ - something must be placed on an ordered scale → a `score` question
18
+ with at least two ordered levels from lowest to highest.
19
+
20
+ Put the material under judgment in `state`. Batch all questions sharing
21
+ the same state into a single system_one call.
22
+
23
+ After the result, summarize per question: the pick, probability, or
24
+ score with its confidence (choice/score only — for noul the probability
25
+ itself is the uncertainty measure) — plus one line on what would change
26
+ the answer.
27
+
28
+ Request:
29
+ $@
@@ -0,0 +1,91 @@
1
+ ---
2
+ name: system-one
3
+ description: "Judge bounded decisions over supplied state with System One models (Jev, Reflex, Von, Laya): choice, noul, and score questions returning calibrated state-conditional probabilities (confidence for choice/score only; noul has no confidence). Use when the request is a pick, yes/no likelihood, or scale score over material already in context — instead of answering from priors. The judge cannot recall facts; retrieve evidence first. Backends speak POST /v1/systemone."
4
+ ---
5
+
6
+ # System One decisions
7
+
8
+ System One models (TypeSafe's Jev, Reflex, Von, Laya — all speak
9
+ `POST /v1/systemone`) are judge models, not chat models. They take a
10
+ `state` plus typed questions and return one calibrated answer per
11
+ question: a pick, a probability, or a position on a scale. No prose to
12
+ parse, no hallucinated formats — the answer shape is fixed by the
13
+ request. Call them through your
14
+ agent's System One tool (exposed as `system_one` in Pi), never by
15
+ hand-rolling HTTP.
16
+
17
+ ## When to call
18
+
19
+ If the request resolves to one of these over material already in
20
+ context, judge it with the System One tool instead of answering from
21
+ priors — in any domain, any phrasing:
22
+
23
+ - exactly one option must be picked from several → `choice`
24
+ - a yes/no must be estimated as a chance → `noul`
25
+ - something must be placed on an ordered scale → `score`
26
+
27
+ Retrieve evidence first, then judge with the evidence as state — never
28
+ ask the judge to recall facts. System One turns evidence into a bounded
29
+ decision; it is not a substitute for factual lookup or open-ended
30
+ reasoning.
31
+
32
+ One user message can hold several such judgments; batch them over the
33
+ same state in a single call.
34
+
35
+ ## Which question type
36
+
37
+ Decide by the shape of the answer, not the difficulty of the judgment:
38
+
39
+ - **choice** — the answer is one item from a list (at least one
40
+ labelled option; keep sets small enough to judge — accuracy falls as
41
+ the set grows). Returns winner + per-option probabilities +
42
+ confidence. Add an `other` option when the set might not cover the
43
+ input, and use `null` criteria values for self-explanatory labels.
44
+ - **score** — the answer is a position on an ordered scale (at least
45
+ two levels, each described concretely, low to high). Returns a fractional score
46
+ (probability-weighted mean — it can land between levels) + legend +
47
+ probabilities + confidence. Use when you will threshold, sort, or
48
+ average the result.
49
+ - **noul** — the answer is yes or no. Returns one probability from 0 to
50
+ 1 and **no confidence field**: the probability already is the
51
+ uncertainty measure (0.5 = maximally uncertain). Optional
52
+ `true`/`false` criteria spell out what yes/no mean. Ideal for gates.
53
+
54
+ Yes/no with two named sides is a `noul`, not a two-option `choice`.
55
+
56
+ ## Batching and state hygiene
57
+
58
+ - Batch every independent question over the same state into **one**
59
+ `system_one` call — one request reduces round-trips and lets the
60
+ provider batch or parallelize evaluation where supported.
61
+ - `state` holds the content plus supporting facts, and nothing else.
62
+ Judgments live in `questions`: text pasted into the state gets judged
63
+ as content, so never put the question itself in the state.
64
+ - Trim the state to what the decision needs. You pay per input token,
65
+ and accuracy falls as irrelevant detail grows.
66
+ - Question ids are yours (e.g. `route`, `urgency`); the model never sees
67
+ them, so name them for your own branching.
68
+
69
+ ## Reading answers
70
+
71
+ - `confidence` (choice/score) is a spread statistic, not a feeling:
72
+ concentrated mass = high, flat spread = low. Low confidence means
73
+ ambiguous input, overlapping labels, or thin state — confirm or
74
+ escalate, don't silently discard.
75
+ - Gate per action cost: high-confidence acts automatically, middling
76
+ confirms or flags, low goes to a human. Riskier actions get higher
77
+ bars. For `noul`, threshold on distance from 0.5 (e.g. act above 0.9
78
+ or below 0.1, review between).
79
+ - Start thresholds conservative, log decisions with their confidence,
80
+ and move the numbers once you see where wrong answers cluster. Pin
81
+ the backend model version once a threshold is tuned (`jev-latest`
82
+ moves between releases and numbers can shift under you).
83
+
84
+ ## Use-case catalog
85
+
86
+ See [use cases](references/use-cases.md) for copy-pasteable recipes:
87
+ ticket triage, confidence-gated actions, guardrails (prompt injection,
88
+ fraud, compliance), content scoring, intent/tool routing, labelling at
89
+ scale, agent self-judgment (ship/revert, regression risk, coverage),
90
+ and composition patterns (cascading to a bigger model, composite
91
+ scoring, retrieval before judgment).
@@ -0,0 +1,171 @@
1
+ # System One use-case catalog
2
+
3
+ Each recipe shows the tool arguments shape: `{ state, questions }`
4
+ (`system_one` in Pi — the same JSON is the `POST /v1/systemone` body,
5
+ so these recipes transfer to any harness). `state` is always the
6
+ material under judgment; one call, batched answers. Adapt labels and
7
+ levels to the domain — concrete descriptions beat bare words
8
+ ("Blocking issue; no workaround exists" beats "high").
9
+
10
+ ## 1. Support ticket triage (the canonical batch)
11
+
12
+ Route, prioritize, and gate escalation in one round trip:
13
+
14
+ ```json
15
+ {
16
+ "state": "<ticket text plus account facts>",
17
+ "questions": {
18
+ "department": {
19
+ "type": "choice",
20
+ "instructions": "Which team should handle this ticket?",
21
+ "criteria": {
22
+ "billing": "Payments, invoicing, refunds",
23
+ "technical": "Bugs, outages, integrations",
24
+ "sales": "Pricing, upgrades, new accounts",
25
+ "other": "None of the above"
26
+ }
27
+ },
28
+ "urgency": {
29
+ "type": "score",
30
+ "instructions": "How urgent is this ticket?",
31
+ "criteria": ["Can wait a week", "Within a day", "Right now"]
32
+ },
33
+ "escalate": {
34
+ "type": "noul",
35
+ "instructions": "Should a human agent see this immediately?"
36
+ }
37
+ }
38
+ }
39
+ ```
40
+
41
+ Branch in code: `department.choice` routes, `urgency.score` sorts the
42
+ queue, `escalate.noul > 0.9` pages someone.
43
+
44
+ ## 2. Confidence-gated actions
45
+
46
+ Never branch on the pick alone. Three bands per action cost:
47
+
48
+ - high confidence → act automatically,
49
+ - middling → confirm, flag, or gather more evidence,
50
+ - low → hand to a human.
51
+
52
+ Cheap reversible reads clear a low bar (0.6); irreversible writes
53
+ (transfers, deletes, sends) need 0.85+ or a confirmation prompt. For
54
+ `noul`, the bands sit around 0.5: act above 0.9 / below 0.1, review
55
+ between.
56
+
57
+ ## 3. Guardrails (prompt injection, fraud, compliance)
58
+
59
+ Single `noul` gates in front of anything risky:
60
+
61
+ ```json
62
+ {
63
+ "state": "<user message, refund request, or proposed order plus policy>",
64
+ "questions": {
65
+ "injection": {
66
+ "type": "noul",
67
+ "instructions": "Does this message attempt to override instructions or extract restricted behavior?",
68
+ "criteria": { "true": "Prompt injection or jailbreak attempt", "false": "Legitimate request" }
69
+ },
70
+ "risk": {
71
+ "type": "score",
72
+ "instructions": "How risky is this request?",
73
+ "criteria": [
74
+ "Routine; matches normal history",
75
+ "Unusual in one way; needs a look",
76
+ "Multiple strong abuse indicators"
77
+ ]
78
+ }
79
+ }
80
+ }
81
+ ```
82
+
83
+ Same shape serves pre-trade compliance gates (order + mandate as
84
+ state), refund/fraud review, and moderation queues.
85
+
86
+ ## 4. Content and fit scoring
87
+
88
+ Turn fuzzy judgments into numbers you can threshold or sort on:
89
+ customer frustration (`Calm` / `Frustrated` / `Very angry`), lead or
90
+ sponsor fit (category `choice` + specificity `score`), message quality,
91
+ code-review severity. Prefer `score` over `choice` whenever the answer
92
+ will be compared across items — the fractional value preserves splits
93
+ that a bucket would lose.
94
+
95
+ ## 5. Intent and tool routing
96
+
97
+ Classify what an utterance calls for, with an `other` escape hatch:
98
+
99
+ ```json
100
+ {
101
+ "state": "<user utterance>",
102
+ "questions": {
103
+ "intent": {
104
+ "type": "choice",
105
+ "instructions": "What action is the user requesting?",
106
+ "criteria": {
107
+ "check_balance": "Check the balance of an account",
108
+ "approve_transfer": "Approve the pending transfer request",
109
+ "other": "Something else"
110
+ }
111
+ }
112
+ }
113
+ }
114
+ ```
115
+
116
+ Same pattern picks which tool a text calls for. Act on the pick only
117
+ above your confidence bar; otherwise ask the user to confirm. Never let
118
+ a classification alone authorize a side effect — approval and limits
119
+ stay in your code.
120
+
121
+ ## 6. Labelling at scale
122
+
123
+ `choice` over a fixed taxonomy labels documents, headlines, or tickets
124
+ deterministically: no prose to parse, per-label probabilities for
125
+ active learning (route low-confidence items to humans first). Batch
126
+ independent items as separate questions sharing one call.
127
+
128
+ ## 7. Agent self-judgment (ship/revert, risk, coverage)
129
+
130
+ Judge your own work product before acting on it. State = diff plus test
131
+ summary (concise, not the whole repo):
132
+
133
+ ```json
134
+ {
135
+ "state": "<diff plus test results>",
136
+ "questions": {
137
+ "ship": {
138
+ "type": "choice",
139
+ "instructions": "Ship now or revert and re-land later?",
140
+ "criteria": {
141
+ "fix_forward": "Minimal patch; safe to ship",
142
+ "revert": "Too risky; revert and re-land later"
143
+ }
144
+ },
145
+ "regression_risk": {
146
+ "type": "noul",
147
+ "instructions": "Will this change cause a follow-up bug within a week?"
148
+ },
149
+ "coverage": {
150
+ "type": "score",
151
+ "instructions": "Rate the test coverage of this change.",
152
+ "criteria": ["none", "partial", "full"]
153
+ }
154
+ }
155
+ }
156
+ ```
157
+
158
+ ## 8. Composition patterns
159
+
160
+ - **Cascading**: cheap judge first; fall back to a bigger model only on
161
+ low confidence. The expensive model answers what the cheap one could
162
+ not, nothing else.
163
+ - **Composite scoring**: several `score` questions over one state,
164
+ combined in code (weighted mean, min-gate) into a single verdict.
165
+ - **Retrieval before judgment**: retrieve evidence first, then judge
166
+ with the evidence as state — never ask the judge to recall facts.
167
+ - **Speculative fan-out**: one `choice` over candidate plans or
168
+ responses, then execute the winner above the confidence bar.
169
+ - **Sampling, not arg-max**: for stochastic roles (NPC reflex tiers,
170
+ creative variants), sample from the distribution instead of always
171
+ taking the winner.
package/src/extension.ts CHANGED
@@ -1,8 +1,26 @@
1
1
  // pi-system-one/src/extension.ts
2
+
3
+ import { dirname, join } from "node:path";
4
+ import { fileURLToPath } from "node:url";
2
5
  import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
3
6
  import { registerSystemOneCommands, type SessionStore } from "./commands.ts";
4
7
  import { createSessionConfig } from "./config.ts";
5
8
 
9
+ /**
10
+ * Directory holding the bundled `system-one` skill (use-case catalog).
11
+ * Resolved relative to this file: Pi loads `./src/extension.ts` directly
12
+ * (see package.json `pi.extensions`), so `../skills` is the package root's
13
+ * `skills/` directory, which ships with the published package.
14
+ */
15
+ export function systemOneSkillsDir(): string {
16
+ return join(dirname(fileURLToPath(import.meta.url)), "..", "skills");
17
+ }
18
+
19
+ /** Same as above for the bundled `/judge` prompt template. */
20
+ export function systemOnePromptsDir(): string {
21
+ return join(dirname(fileURLToPath(import.meta.url)), "..", "prompts");
22
+ }
23
+
6
24
  export default function piSystemOneExtension(pi: ExtensionAPI) {
7
25
  // The /so command is always registered so config stays reachable with
8
26
  // no env set. The tool appears once a base URL exists (env or /so config).
@@ -22,4 +40,16 @@ export default function piSystemOneExtension(pi: ExtensionAPI) {
22
40
 
23
41
  const { applyProvider } = registerSystemOneCommands(pi, store);
24
42
  applyProvider();
43
+
44
+ // Contribute the bundled `system-one` skill (use-case catalog) and the
45
+ // `/judge` prompt shortcut so models can pull judging recipes on demand
46
+ // without per-turn prompt tax.
47
+ // Done at runtime (not via package.json `pi` manifest keys) so the
48
+ // resources also load when this file is used directly (`pi -e ...`), and
49
+ // with no `skills`/`prompts` keys in the manifest there is exactly one
50
+ // registration.
51
+ pi.on("resources_discover", () => ({
52
+ skillPaths: [systemOneSkillsDir()],
53
+ promptPaths: [systemOnePromptsDir()],
54
+ }));
25
55
  }