@onthink/prompt-observer 0.1.0 → 0.2.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.
@@ -7,9 +7,11 @@ Follow this contract after every user-requested task. Complete the task first, t
7
7
  1. Use only information visible in the conversation, tool results, file changes, and verification output.
8
8
  2. Never store the full user prompt, the full assistant response, system instructions, private reasoning, chain-of-thought, credentials, access tokens, or other secrets.
9
9
  3. `prompt_summary` must be a short, redacted description of the request, not a quotation or close reproduction.
10
- 4. Do not invent the model name, token counts, or cost. Use `null` values with `source: "unavailable"` unless the platform explicitly reports them. Use `source: "estimated"` only when a deterministic tokenizer or pricing tool produced the value, and name that tool in `estimation_method`.
10
+ 4. Prefer platform-reported usage. When it is unavailable, estimate token counts only from the visible user input and final response with the deterministic heuristic below. Never guess a model name. The logger calculates estimated cost only for an exact model match in `.prompt-observer/pricing.json`.
11
11
  5. Base execution signals only on observed results. Do not claim a file changed or a test passed without evidence.
12
- 6. Use schema version `1.0` and conform to `.prompt-observer/event.schema.json`.
12
+ 6. Use schema version `1.1` and conform to `.prompt-observer/event.schema.json`.
13
+ 7. Do not manufacture criticism. If the prompt is clear and sufficient for the task, keep `weaknesses` and `improvement_suggestions` empty.
14
+ 8. Evaluate against objective task requirements, not personal preferences about wording, tone, verbosity, formatting, workflow, or technology choices.
13
15
 
14
16
  ## Required workflow
15
17
 
@@ -30,7 +32,7 @@ After completing a task:
30
32
  ```text
31
33
  Prompt Insight: <average>/10 — <short strength>
32
34
  Main weakness: <highest-impact weakness, or "No material weakness detected">
33
- Next time: <one actionable improvement>
35
+ Next time: <one actionable improvement, or "No change needed">
34
36
  ```
35
37
 
36
38
  Do not paste the complete JSON event into the user-facing response when persistence succeeds.
@@ -51,35 +53,64 @@ If writing files or running the logger is unavailable, do not pretend the event
51
53
 
52
54
  Score only prompt quality. Do not lower a score because implementation was difficult when the request itself was clear.
53
55
 
56
+ ## Structured insights
57
+
58
+ In schema `1.1`, every strength and improvement suggestion is an object with:
59
+
60
+ - `category`: one of `intent_clarity`, `context_sufficiency`, `scope_definition`, `constraints_quality`, `acceptance_criteria`, `verification_plan`, `output_format`, or `other`
61
+ - `message`: one concise, evidence-based observation
62
+
63
+ Legacy schema `1.0` events with string arrays remain readable, but all new events must use the structured `1.1` form.
64
+
65
+ ## Usage precedence and estimation
66
+
67
+ 1. If the platform reports any model, token, or cost metrics, record only those reported metrics, keep unreported metrics `null`, use `source: "platform_reported"`, and keep `estimation_method: null`.
68
+ 2. Otherwise, if the Agent can inspect the complete visible user input and its final response, estimate each side independently using `agent_text_heuristic_v1`:
69
+ - Ignore whitespace.
70
+ - Count ASCII letters and digits as `characters / 4`.
71
+ - Count non-ASCII letters, digits, and combining marks as `characters / 2`.
72
+ - Count punctuation and symbols as `characters / 2`.
73
+ - Add the three values and round up to the next integer.
74
+ 3. Store the two counts with `source: "estimated"` and `estimation_method: "agent_text_heuristic_v1"`.
75
+ 4. Set `model` only when the runtime explicitly identifies it. Never infer a model from the product name.
76
+ 5. Leave `cost_usd: null`. During `log`, the CLI fills it only when both token counts exist and `model` exactly matches `.prompt-observer/pricing.json`; the pricing snapshot identifier is then appended to `estimation_method`.
77
+ 6. If neither reported nor safely estimated usage is available, keep all metrics `null`, use `source: "unavailable"`, and keep `estimation_method: null`.
78
+
79
+ Estimated usage is directional, not billing data. Never include hidden system instructions, tool payloads, cached-token adjustments, subscription fees, or guessed reasoning tokens in the estimate.
80
+
81
+ ## Evidence threshold and neutrality
82
+
83
+ - Record a weakness only when a concrete omission, ambiguity, contradiction, or constraint creates a meaningful risk of wrong execution, wasted work, or unverifiable completion.
84
+ - Do not require context, constraints, acceptance criteria, output formatting, or tests when they are unnecessary for the specific task.
85
+ - Do not criticize a prompt merely because it could be longer, more formal, more structured, or written in a style you prefer.
86
+ - Do not turn optional enhancements into weaknesses.
87
+ - When no material weakness exists, use an empty `weaknesses` array, an empty `improvement_suggestions` array, `Main weakness: No material weakness detected`, and `Next time: No change needed`.
88
+ - Positive scores must reflect the prompt as written; do not lower them just to create variation or appear critical.
89
+
54
90
  ## Event example
55
91
 
56
92
  ```json
57
93
  {
58
- "schema_version": "1.0",
94
+ "schema_version": "1.1",
59
95
  "event_id": "evt-20260901-7f3a92c1",
60
96
  "timestamp": "2026-09-01T12:00:00.000Z",
61
97
  "task_type": "coding",
62
98
  "prompt_summary": "Implement a dependency-free prompt observation kit with structured local logging.",
63
- "intent_clarity": 9,
64
- "context_sufficiency": 8,
65
- "scope_definition": 9,
66
- "constraints_quality": 9,
67
- "acceptance_criteria": 8,
68
- "verification_plan": 7,
99
+ "intent_clarity": 10,
100
+ "context_sufficiency": 10,
101
+ "scope_definition": 10,
102
+ "constraints_quality": 10,
103
+ "acceptance_criteria": 9,
104
+ "verification_plan": 9,
69
105
  "ambiguity_risk": "low",
70
106
  "strengths": [
71
- "The requested deliverables and runtime constraints are explicit."
72
- ],
73
- "weaknesses": [
74
107
  {
75
- "category": "missing_verification",
76
- "severity": "low",
77
- "message": "The exact expected report contents were not fully enumerated."
108
+ "category": "constraints_quality",
109
+ "message": "The requested deliverables and runtime constraints are explicit."
78
110
  }
79
111
  ],
80
- "improvement_suggestions": [
81
- "List the required report sections and one expected example."
82
- ],
112
+ "weaknesses": [],
113
+ "improvement_suggestions": [],
83
114
  "execution_signals": {
84
115
  "result_status": "completed",
85
116
  "files_changed": [
@@ -94,11 +125,11 @@ Score only prompt quality. Do not lower a score because implementation was diffi
94
125
  },
95
126
  "usage": {
96
127
  "model": null,
97
- "input_tokens": null,
98
- "output_tokens": null,
128
+ "input_tokens": 280,
129
+ "output_tokens": 640,
99
130
  "cost_usd": null,
100
- "source": "unavailable",
101
- "estimation_method": null
131
+ "source": "estimated",
132
+ "estimation_method": "agent_text_heuristic_v1"
102
133
  }
103
134
  }
104
135
  ```
package/README.md CHANGED
@@ -4,15 +4,19 @@ Prompt Observer is a dependency-free observability kit for professional coding-a
4
4
 
5
5
  It is designed for Vibe Coding workflows and works without a browser extension, a local model, or an additional AI API. The agent already completing the task creates the observation.
6
6
 
7
+ [View the package on npm](https://www.npmjs.com/package/@onthink/prompt-observer)
8
+
7
9
  ## What it records
8
10
 
9
11
  - Prompt-quality dimensions: clarity, context, scope, constraints, acceptance criteria, and verification plan
10
- - Actionable weaknesses and improvement suggestions
12
+ - Structured strengths, actionable weaknesses, and improvement suggestions
11
13
  - Observed execution signals: result status, changed files, and test outcomes
12
- - Model, token, and cost information only when the platform explicitly provides it
14
+ - Exact platform usage when available, otherwise clearly labeled token estimates and model-matched cost estimates
13
15
 
14
16
  Raw prompts, raw responses, private reasoning, system instructions, and secrets are prohibited from the event format.
15
17
 
18
+ Prompt Observer does not force criticism. A clear, sufficient prompt receives no fabricated weakness or subjective style advice; its `weaknesses` and `improvement_suggestions` arrays remain empty.
19
+
16
20
  ## Requirements
17
21
 
18
22
  - Node.js 20 or newer
@@ -21,14 +25,15 @@ Raw prompts, raw responses, private reasoning, system instructions, and secrets
21
25
 
22
26
  ## Quick start
23
27
 
24
- Clone this repository and initialize Prompt Observer in a target project:
28
+ Initialize Prompt Observer in any target project:
25
29
 
26
30
  ```powershell
27
- git clone <your-repository-url>
28
- cd prompt-observer
29
- node bin/prompt-observer.mjs init "E:\path\to\your-project"
31
+ cd "E:\path\to\your-project"
32
+ npx @onthink/prompt-observer init .
30
33
  ```
31
34
 
35
+ `init` adds a portable local CLI under `.prompt-observer`, so the target project can log events and generate reports without a global installation.
36
+
32
37
  Then add the following one-line instruction to the target project's existing agent-instruction file:
33
38
 
34
39
  ```md
@@ -52,43 +57,75 @@ Each initialized project receives:
52
57
  event.schema.json Versioned event schema
53
58
  prompt-observer.mjs Portable local CLI
54
59
  events.jsonl Generated append-only event log
55
- report.md Generated analysis report
60
+ pricing.json Versioned model-pricing snapshot
61
+ report.md Compact GitHub-friendly report
62
+ report.html Interactive offline dashboard
56
63
  ```
57
64
 
58
- The generated log and report are excluded by the local `.prompt-observer/.gitignore`; the contract and schema can safely be committed.
65
+ The generated log and reports are excluded by the local `.prompt-observer/.gitignore`; the contract, schema, and pricing snapshot can safely be committed.
59
66
 
60
- ## Commands
67
+ ## Automatic behavior
61
68
 
62
- Run these commands inside an initialized project:
69
+ After the project instruction is added, the coding agent handles event creation and logging after each task. You do **not** need to run `validate` or `log` yourself during normal use.
63
70
 
64
- ```powershell
65
- # Check an event before saving it
66
- node .prompt-observer/prompt-observer.mjs validate .prompt-observer/pending/example.json
71
+ The agent creates a temporary event, validates it, appends it to `.prompt-observer/events.jsonl`, and removes the temporary file after a successful save.
72
+
73
+ ## View reports
67
74
 
68
- # Validate and append an event to the local JSONL log
69
- node .prompt-observer/prompt-observer.mjs log .prompt-observer/pending/example.json
75
+ Generate reports from the latest 50 events:
70
76
 
71
- # Generate the aggregate Markdown report
77
+ ```powershell
72
78
  node .prompt-observer/prompt-observer.mjs report .
73
79
  ```
74
80
 
75
- The report includes average prompt health, recurring weaknesses, ambiguity risk, execution outcomes, verification trends, and platform-reported usage totals.
81
+ This creates `.prompt-observer/report.md` and `.prompt-observer/report.html`. The Markdown report is a compact repository-friendly summary. The self-contained HTML dashboard adds KPI cards, quality and trend charts, filters, recurring strengths, weaknesses, improvement suggestions, verification results, and usage coverage. It embeds only the selected window's already-redacted analytical fields, not changed-file lists or test names.
82
+
83
+ Choose another bounded window or explicitly analyze all events:
84
+
85
+ ```powershell
86
+ node .prompt-observer/prompt-observer.mjs report . --limit 100
87
+ node .prompt-observer/prompt-observer.mjs report . --all
88
+ ```
89
+
90
+ The default reader streams the JSONL history and retains only the latest 50 events plus the previous 50-event comparison window. The complete append-only log remains available without making the generated reports grow forever.
91
+
92
+ ## Usage accuracy and estimates
93
+
94
+ Prompt Observer uses this precedence:
95
+
96
+ 1. Metrics explicitly reported by the Agent platform are stored as `platform_reported`.
97
+ 2. When the platform exposes no usage but the Agent can see the input and final response, token counts are estimated with the documented `agent_text_heuristic_v1` method.
98
+ 3. Estimated cost is calculated only when the runtime reports an exact model ID that exists in the local versioned `pricing.json` snapshot.
99
+ 4. Unknown values remain `null` and are reported as unavailable.
100
+
101
+ The dashboard always separates exact, estimated, and unavailable values. Cost estimates exclude cached tokens, tools, subscription pricing, discounts, long-context premiums, and provider-specific charges, so they must not be treated as invoices.
102
+
103
+ ## Manual event troubleshooting (advanced)
104
+
105
+ `validate` and `log` are diagnostic commands for a temporary event that an agent has already created. They are not part of the normal setup or daily workflow, and `example.json` is not created by `init`.
106
+
107
+ Use them only when inspecting a real pending event before it is logged:
108
+
109
+ ```powershell
110
+ node .prompt-observer/prompt-observer.mjs validate .prompt-observer/pending/<event-id>.json
111
+ node .prompt-observer/prompt-observer.mjs log .prompt-observer/pending/<event-id>.json
112
+ ```
76
113
 
77
114
  ## No-filesystem fallback
78
115
 
79
116
  When an agent cannot write files, the contract requires it to show the three-line insight and return a complete valid JSON event in a fenced `json` block. It must state that the event was not persisted. A later extension or integration can capture that output automatically.
80
117
 
81
- ## npm package — coming soon
118
+ ## npm package
82
119
 
83
- The project is configured for npm packaging, but it is **not published yet**. The final package name will be chosen before release, preferably as a scoped name such as `@your-npm-username/prompt-observer`.
120
+ Prompt Observer is published as [`@onthink/prompt-observer`](https://www.npmjs.com/package/@onthink/prompt-observer).
84
121
 
85
- After publication, the intended installation flow will be:
122
+ Use it without installing it globally:
86
123
 
87
124
  ```powershell
88
- npx @your-npm-username/prompt-observer init .
125
+ npx @onthink/prompt-observer init .
89
126
  ```
90
127
 
91
- Before publishing, replace `@your-npm-username` with your real npm scope and configure the repository URL in `package.json`.
128
+ Running `init` again is safe: it preserves existing Prompt Observer files and adds only missing files.
92
129
 
93
130
  ## Development
94
131
 
@@ -97,7 +134,7 @@ npm run check
97
134
  npm test
98
135
  ```
99
136
 
100
- `prepublishOnly` runs both checks automatically before `npm publish`. The package uses only Node.js built-ins; JSONL is the source of truth for v1, while SQLite export is intentionally deferred to a later release.
137
+ `prepublishOnly` runs both checks automatically before `npm publish`. The package is published publicly under the `@onthink` scope. The project uses only Node.js built-ins; JSONL remains the source of truth, while SQLite export is intentionally deferred.
101
138
 
102
139
  ## License
103
140