user-habit-pipeline 0.4.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.
Files changed (44) hide show
  1. package/CHANGELOG.md +52 -0
  2. package/README.md +499 -0
  3. package/data/.gitkeep +1 -0
  4. package/docs/api-reference.md +362 -0
  5. package/docs/codex-current-session-contract.md +328 -0
  6. package/docs/codex-skill-integration.md +114 -0
  7. package/docs/confidence-scoring.md +342 -0
  8. package/docs/cross-repo-release-checklist.md +95 -0
  9. package/docs/cross-repo-release-runbook.md +153 -0
  10. package/docs/editor-integration.md +48 -0
  11. package/docs/examples.md +172 -0
  12. package/docs/freeze-assessment-0.1.0.md +65 -0
  13. package/docs/manual-e2e-acceptance.md +316 -0
  14. package/docs/mvp-spec.md +304 -0
  15. package/docs/project-principles.md +313 -0
  16. package/docs/registry-authoring.md +209 -0
  17. package/docs/registry.schema.json +74 -0
  18. package/docs/release-checklist.md +50 -0
  19. package/docs/release-notes-v0.3.0.md +74 -0
  20. package/docs/release-notes-v0.4.0.md +80 -0
  21. package/docs/session-habit-suggestions.md +214 -0
  22. package/docs/user-habit-management.md +363 -0
  23. package/docs/versioning.md +61 -0
  24. package/package.json +80 -0
  25. package/scripts/manual-e2e-smoke.ps1 +252 -0
  26. package/src/adapters/growth_hub/adapter.js +13 -0
  27. package/src/cli.js +118 -0
  28. package/src/codex-session-habits-cli.js +572 -0
  29. package/src/demo.js +42 -0
  30. package/src/generate-examples-doc.js +118 -0
  31. package/src/habit_core/context_rules.js +56 -0
  32. package/src/habit_core/interpreter.js +149 -0
  33. package/src/habit_core/scoring.js +75 -0
  34. package/src/habit_core/types.js +39 -0
  35. package/src/habit_registry/default_habits.json +124 -0
  36. package/src/habit_registry/management_prompt.js +291 -0
  37. package/src/habit_registry/user_registry.js +236 -0
  38. package/src/habit_registry/validate_registry.js +81 -0
  39. package/src/index.js +71 -0
  40. package/src/manage-habits-cli.js +746 -0
  41. package/src/runtime_paths.js +57 -0
  42. package/src/session_suggestions/cache.js +36 -0
  43. package/src/session_suggestions/extract_candidates.js +559 -0
  44. package/src/validate-registry-cli.js +41 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,52 @@
1
+ # Changelog
2
+
3
+ ## Unreleased
4
+
5
+ - Prepared the package for installable distribution by moving default user state to a user data directory with a compatibility fallback for older repo-local overlays.
6
+ - Added runtime path helpers and exported the user-home override constant so installed consumers can resolve or override package-managed state without hardcoded paths.
7
+ - Added a real package-install smoke test that packs, installs into a temporary consumer, validates installed bin shims, and verifies installed library imports before publish.
8
+ - Added a `prepublishOnly` gate so `npm publish` runs the full release check first.
9
+
10
+ ## 0.4.0 - 2026-04-05
11
+
12
+ - Added a formal Codex current-session contract document covering transcript input, bridge response fields, host responsibilities, and bridge error boundaries.
13
+ - Added realistic Codex session transcript fixtures and regression coverage for noisy current-thread scans through both the suggestion backend and the Codex bridge CLI.
14
+ - Added a formal confidence-scoring document that separates interpreter confidence from session-suggestion confidence and records the current runtime thresholds and bonuses.
15
+ - Added a formal project-principles document that captures the current interpretation-layer boundary, explicit-confirmation model, and the rule that install/config paths must stay configurable rather than hardcoded.
16
+ - Added persistent suggestion suppression so users can ignore a candidate with `忽略第1条`, `--ignore-candidate c1`, or suppress a noisy phrase with `以后别再建议这个短句`.
17
+ - Added `ignored_suggestions` to the user registry state so noisy phrases stay excluded from future suggestion scans without becoming active habits.
18
+ - Added a Codex-facing session bridge CLI so in-app skills can pass the current conversation transcript through `--thread-stdin` and reuse the existing prompt-based management flow.
19
+ - Added documentation for the installed Codex skill entry path and the current-session one-sentence flow inside the Codex app.
20
+ - Cached the latest session suggestion snapshot locally so follow-up apply actions can use `添加第1条` or `--apply-candidate c1` without an explicit suggestions file path.
21
+ - Added apply-time overrides for suggestion candidates so users can confirm with messages such as `把第1条加到 session_close 场景`, or provide `intent` when applying a review-only candidate.
22
+ - Added explicit suggestion-apply support so reviewed session candidates can be written into the user overlay through `--apply-candidate` or prompt requests such as `添加第1条`.
23
+ - Added read-only session habit suggestion scanning from transcript text, including prompt-triggered `suggest` requests through the manage-habits CLI.
24
+ - Added transcript parsing and candidate extraction for explicit add requests, explicit phrase definitions, and repeated short phrases that are not already registered.
25
+ - Added documentation for the Codex-oriented transcript-scan backend and clarified that the remaining app boundary is transcript injection from visible conversation context.
26
+ - Added `--request-stdin` to the habit management CLI so multiline prompt requests work reliably in PowerShell and other shell setups that do not preserve multiline `--request` arguments through `npm run`.
27
+ - Documented the PowerShell here-string testing flow and added regression coverage for stdin-based prompt requests.
28
+
29
+ ## 0.3.0 - 2026-04-01
30
+
31
+ - Added user overlay import/export support for persistent habit phrase customizations.
32
+ - Added `replace` and `merge` import modes for user registry state management.
33
+ - Expanded lightweight prompt parsing to better handle Chinese management phrasing and multiline add requests.
34
+ - Added CLI coverage and regression tests for import/export and more tolerant prompt parsing.
35
+
36
+ ## 0.2.0 - 2026-04-01
37
+
38
+ - Added a persistent user-habits overlay on top of the default registry.
39
+ - Added support for user-managed habit phrase add/remove/list operations.
40
+ - Added a lightweight prompt parser so users can manage habits with simple natural-language requests.
41
+ - Added a dedicated `manage-user-habits` CLI and `--user-registry` support on the main interpreter CLI.
42
+ - Added regression tests and documentation for user-managed habit phrases.
43
+
44
+ ## 0.1.0 - 2026-04-01
45
+
46
+ - Added a minimal habit interpreter with explicit phrase matching, scoring, and clarification rules.
47
+ - Added a `growth-hub` adapter that projects interpretation results into downstream hint fields.
48
+ - Added CLI entrypoints for interpretation and registry validation.
49
+ - Added runtime registry validation plus a formal JSON Schema artifact.
50
+ - Added fixture-driven examples and generated example documentation from a single source.
51
+ - Added workspace editor integration for registry schema hints in VS Code.
52
+ - Added API/reference, versioning, and release-check documentation plus a higher-level `release-check` script.
package/README.md ADDED
@@ -0,0 +1,499 @@
1
+ # User Habit Pipeline
2
+
3
+ A reusable user-habit interpretation layer that turns repeated shorthand expressions into structured, reviewable intent hints for downstream workflows.
4
+
5
+ ---
6
+
7
+ ## 1. Purpose
8
+
9
+ This project exists to reduce repeated interpretation cost for stable, high-frequency user expressions.
10
+
11
+ It is designed for cases where a user repeatedly uses short prompts such as:
12
+
13
+ - `继续`
14
+ - `下一条`
15
+ - `入板`
16
+ - `更新入板`
17
+ - `验收`
18
+ - `session-close`
19
+ - `收口`
20
+
21
+ Without a habit layer, downstream systems repeatedly spend effort re-inferring the same meaning.
22
+ This project aims to make that interpretation cheaper, more stable, and easier to review.
23
+ When a proposed next step becomes obviously low-return relative to the user's effort, the preferred behavior is to say so early and offer an easy stop/skip path rather than dragging the user through low-value follow-up work.
24
+
25
+ ---
26
+
27
+ ## 2. Product Position
28
+
29
+ This project is an **interpretation layer**.
30
+
31
+ It does:
32
+
33
+ - interpret repeated shorthand expressions
34
+ - normalize likely user intent
35
+ - return structured hints
36
+ - help downstream workflows reduce ambiguity
37
+
38
+ It does **not**:
39
+
40
+ - decide workflow actions
41
+ - write files
42
+ - update boards
43
+ - approve tasks
44
+ - switch roles
45
+ - replace explicit workflow rules
46
+
47
+ Core rule:
48
+
49
+ - this project explains
50
+ - downstream workflows decide
51
+
52
+ ---
53
+
54
+ ## 3. MVP Goal
55
+
56
+ The MVP should prove one thing:
57
+
58
+ > A small, explicit, inspectable habit layer can reduce misunderstanding of repeated user shorthand without taking over workflow decisions.
59
+
60
+ The MVP does **not** need to support broad coverage.
61
+ The MVP does **not** need to learn automatically.
62
+ The MVP does **not** need to be smart in a general sense.
63
+
64
+ It only needs to be useful, stable, and easy to inspect.
65
+
66
+ ---
67
+
68
+ ## 4. Hard Scope Boundary
69
+
70
+ The MVP must remain inside this boundary:
71
+
72
+ ### In scope
73
+
74
+ - interpret current user message
75
+ - use limited recent context when needed
76
+ - map repeated phrases to normalized intent hints
77
+ - return explicit, inspectable structured output
78
+ - recommend clarification when confidence is low
79
+
80
+ ### Out of scope
81
+
82
+ Anything that directly changes workflow state, files, approvals, or role behavior is out of scope for MVP.
83
+
84
+ Specifically, MVP must not:
85
+
86
+ - write status boards
87
+ - update files
88
+ - trigger execution
89
+ - choose reviewer vs executor behavior
90
+ - replace handoff or other explicit source-of-truth documents
91
+ - infer personality, emotion, hidden motives, or psychological traits
92
+ - require full-thread replay to work
93
+ - become a hidden rule engine
94
+
95
+ ---
96
+
97
+ ## 5. Input Contract
98
+
99
+ ### Required input
100
+
101
+ - `message: string`
102
+
103
+ ### Optional input
104
+
105
+ - `recent_context: string[]`
106
+ - `scenario: string | null`
107
+
108
+ ### Input guidance
109
+
110
+ - `message` is the main interpretation target
111
+ - `recent_context` should stay short
112
+ - `scenario` is only a bias hint, not a hard rule
113
+
114
+ Suggested `scenario` examples:
115
+
116
+ - `reviewer`
117
+ - `executor`
118
+ - `status_board`
119
+ - `session_close`
120
+ - `general`
121
+
122
+ ---
123
+
124
+ ## 6. Output Contract
125
+
126
+ The MVP must return a structured object with stable fields.
127
+
128
+ ### Required fields
129
+
130
+ - `normalized_intent`
131
+ - `habit_matches`
132
+ - `disambiguation_hints`
133
+ - `confidence`
134
+ - `should_ask_clarifying_question`
135
+
136
+ ### Optional fields
137
+
138
+ - `preferred_terms`
139
+ - `notes`
140
+
141
+ ### Field contract
142
+
143
+ #### `normalized_intent`
144
+ - type: `string`
145
+ - required
146
+ - may be `unknown`
147
+ - should stay generic enough to reuse across projects
148
+
149
+ Examples:
150
+ - `continue_current_track`
151
+ - `move_to_next_item`
152
+ - `add_or_update_board_item`
153
+ - `review_acceptance`
154
+ - `refresh_latest_board_state`
155
+ - `close_session`
156
+ - `draft_text_artifact`
157
+ - `unknown`
158
+
159
+ #### `habit_matches`
160
+ - type: `array`
161
+ - required
162
+ - each item should describe one matched phrase or rule
163
+
164
+ Each match item should contain:
165
+ - `phrase: string`
166
+ - `meaning: string`
167
+ - `confidence: number`
168
+
169
+ #### `disambiguation_hints`
170
+ - type: `array[string]`
171
+ - required
172
+ - empty array allowed
173
+
174
+ #### `confidence`
175
+ - type: `number`
176
+ - required
177
+ - range: `0.0` to `1.0`
178
+
179
+ #### `should_ask_clarifying_question`
180
+ - type: `boolean`
181
+ - required
182
+
183
+ #### `preferred_terms`
184
+ - type: `array[string]`
185
+ - optional
186
+
187
+ #### `notes`
188
+ - type: `array[string]`
189
+ - optional
190
+
191
+ ### Output example
192
+
193
+ ```json
194
+ {
195
+ "normalized_intent": "add_or_update_board_item",
196
+ "habit_matches": [
197
+ {
198
+ "phrase": "帮我入板",
199
+ "meaning": "add_or_update_board_item",
200
+ "confidence": 0.94
201
+ }
202
+ ],
203
+ "disambiguation_hints": [
204
+ "Prefer board action over general planning."
205
+ ],
206
+ "confidence": 0.94,
207
+ "should_ask_clarifying_question": false,
208
+ "preferred_terms": [
209
+ "status_board"
210
+ ],
211
+ "notes": [
212
+ "High-confidence shorthand mapping."
213
+ ]
214
+ }
215
+ ```
216
+
217
+ ---
218
+
219
+ ## 7. Usage
220
+
221
+ ### Install As A Package
222
+
223
+ If you want to consume this project from another local environment without treating the repository itself as the runtime home, use the packed tarball:
224
+
225
+ ```powershell
226
+ npm pack
227
+ npm install .\user-habit-pipeline-<version>.tgz
228
+ ```
229
+
230
+ After installation, prefer the installed bin commands instead of `npm run` wrappers:
231
+
232
+ ```powershell
233
+ user-habit-pipeline --message "继续" --scenario general
234
+ manage-user-habits --list
235
+ codex-session-habits --request "列出用户习惯短句"
236
+ ```
237
+
238
+ Runtime user state is stored in a user data directory by default, not in the installed package directory.
239
+ On existing repository-based setups, the runtime keeps using the legacy repo-local overlay file if that file already exists.
240
+ Repository releases also validate a real tarball install path through `npm run package-install-smoke`, so packaged bin commands and runtime-path behavior are checked before publish.
241
+
242
+ ### Library
243
+
244
+ ```js
245
+ const { interpretHabit, toGrowthHubHint } = require("./src");
246
+
247
+ const interpreted = interpretHabit({
248
+ message: "继续",
249
+ scenario: "general",
250
+ recent_context: ["继续当前评审", "review the next issue after this"]
251
+ });
252
+
253
+ const growthHubHint = toGrowthHubHint(interpreted);
254
+ ```
255
+
256
+ Use a different registry without changing the interpreter:
257
+
258
+ ```js
259
+ const { interpretHabit, loadHabitsFromFile } = require("./src");
260
+
261
+ const altRules = loadHabitsFromFile("./tests/fixtures/alt_habits.json");
262
+
263
+ const interpreted = interpretHabit(
264
+ { message: "归档一下", scenario: "session_close" },
265
+ { rules: altRules }
266
+ );
267
+ ```
268
+
269
+ ### CLI
270
+
271
+ Run the interpreter directly:
272
+
273
+ ```powershell
274
+ npm run interpret -- --message "更新入板" --scenario status_board
275
+ ```
276
+
277
+ Show CLI help:
278
+
279
+ ```powershell
280
+ npm run interpret -- --help
281
+ ```
282
+
283
+ Provide recent context by repeating `--context`:
284
+
285
+ ```powershell
286
+ npm run interpret -- --message "继续" --scenario general --context "继续当前评审" --context "review the next issue after this"
287
+ ```
288
+
289
+ Use a custom registry file:
290
+
291
+ ```powershell
292
+ npm run interpret -- --message "归档一下" --scenario session_close --registry .\tests\fixtures\alt_habits.json
293
+ ```
294
+
295
+ Use a custom user-habits overlay file:
296
+
297
+ ```powershell
298
+ npm run interpret -- --message "收尾一下" --scenario session_close --user-registry .\data\user_habits.json
299
+ ```
300
+
301
+ Validate a registry file before using it:
302
+
303
+ ```powershell
304
+ npm run validate-registry -- .\tests\fixtures\alt_habits.json
305
+ ```
306
+
307
+ Show validator help:
308
+
309
+ ```powershell
310
+ npm run validate-registry -- --help
311
+ ```
312
+
313
+ The registry format is also described by a JSON Schema artifact:
314
+
315
+ - [registry.schema.json](/E:/user-habit-pipeline/docs/registry.schema.json)
316
+ - [editor-integration.md](/E:/user-habit-pipeline/docs/editor-integration.md)
317
+ - [api-reference.md](/E:/user-habit-pipeline/docs/api-reference.md)
318
+ - [confidence-scoring.md](/E:/user-habit-pipeline/docs/confidence-scoring.md)
319
+ - [project-principles.md](/E:/user-habit-pipeline/docs/project-principles.md)
320
+ - [versioning.md](/E:/user-habit-pipeline/docs/versioning.md)
321
+ - [release-checklist.md](/E:/user-habit-pipeline/docs/release-checklist.md)
322
+ - [cross-repo-release-runbook.md](/E:/user-habit-pipeline/docs/cross-repo-release-runbook.md)
323
+ - [manual-e2e-acceptance.md](/E:/user-habit-pipeline/docs/manual-e2e-acceptance.md)
324
+ - [release-notes-v0.4.0.md](/E:/user-habit-pipeline/docs/release-notes-v0.4.0.md)
325
+ - [session-habit-suggestions.md](/E:/user-habit-pipeline/docs/session-habit-suggestions.md)
326
+ - [codex-current-session-contract.md](/E:/user-habit-pipeline/docs/codex-current-session-contract.md)
327
+ - [codex-skill-integration.md](/E:/user-habit-pipeline/docs/codex-skill-integration.md)
328
+ - [freeze-assessment-0.1.0.md](/E:/user-habit-pipeline/docs/freeze-assessment-0.1.0.md)
329
+ - [user-habit-management.md](/E:/user-habit-pipeline/docs/user-habit-management.md)
330
+
331
+ Regenerate the examples document after changing the example fixtures:
332
+
333
+ ```powershell
334
+ npm run generate-examples-doc
335
+ ```
336
+
337
+ Run the bundled end-to-end smoke script:
338
+
339
+ ```powershell
340
+ npm run manual-e2e-smoke
341
+ ```
342
+
343
+ Run a quick end-to-end demo of the current package scope:
344
+
345
+ ```powershell
346
+ npm run demo
347
+ ```
348
+
349
+ Project the output through the `growth-hub` adapter:
350
+
351
+ ```powershell
352
+ npm run interpret -- --message "验收" --scenario reviewer --adapter growth-hub
353
+ ```
354
+
355
+ ### User-Managed Habit Phrases
356
+
357
+ Add a user habit with structured flags:
358
+
359
+ ```powershell
360
+ npm run manage-habits -- --add --phrase "收尾一下" --intent close_session --scenario session_close --confidence 0.86
361
+ ```
362
+
363
+ Remove a phrase from the effective registry:
364
+
365
+ ```powershell
366
+ npm run manage-habits -- --remove --phrase "验收"
367
+ ```
368
+
369
+ Suppress a noisy suggestion phrase without making it an active habit:
370
+
371
+ ```powershell
372
+ npm run manage-habits -- --ignore-phrase "收工啦"
373
+ ```
374
+
375
+ List the current user-defined additions and removals:
376
+
377
+ ```powershell
378
+ npm run manage-habits -- --list
379
+ ```
380
+
381
+ Export your current user overlay:
382
+
383
+ ```powershell
384
+ npm run manage-habits -- --export .\backup\user_habits.json
385
+ ```
386
+
387
+ Import a saved overlay:
388
+
389
+ ```powershell
390
+ npm run manage-habits -- --import .\backup\user_habits.json
391
+ npm run manage-habits -- --import .\backup\user_habits.json --mode merge
392
+ ```
393
+
394
+ Use a lightweight prompt-like request instead of flags:
395
+
396
+ ```powershell
397
+ npm run manage-habits -- --request "添加用户习惯短句: phrase=收尾一下; intent=close_session; 场景=session_close; 置信度=0.86"
398
+ npm run manage-habits -- --request "删除用户习惯短句: 收尾一下"
399
+ npm run manage-habits -- --request "以后别再建议这个短句: 收工啦"
400
+ npm run manage-habits -- --request "列出用户习惯短句"
401
+ npm run manage-habits -- --request "导出用户习惯短句: path=.\backup\user_habits.json"
402
+ npm run manage-habits -- --request "导入习惯短句 路径=.\backup\user_habits.json; 模式=merge"
403
+ ```
404
+
405
+ For multiline prompt requests in PowerShell, prefer piping a here-string into `--request-stdin`:
406
+
407
+ ```powershell
408
+ @'
409
+ 新增习惯短句 phrase=收尾一下
410
+ intent=close_session
411
+ 场景=session_close
412
+ 置信度=0.86
413
+ '@ | npm run manage-habits -- --request-stdin
414
+ ```
415
+
416
+ This writes user-managed phrases into a separate overlay file and leaves the default registry untouched.
417
+
418
+ ### Session Habit Suggestions
419
+
420
+ Scan a current-thread transcript for habit candidates without writing anything to the overlay:
421
+
422
+ ```powershell
423
+ npm run manage-habits -- --suggest --transcript .\data\thread.txt
424
+ ```
425
+
426
+ You can also trigger the same scan through a natural-language request:
427
+
428
+ ```powershell
429
+ npm run manage-habits -- --request "扫描这次会话里的习惯候选" --transcript .\data\thread.txt
430
+ ```
431
+
432
+ For PowerShell here-string input:
433
+
434
+ ```powershell
435
+ @'
436
+ user: 以后我说“收尾一下”就是 close_session
437
+ assistant: 收到。
438
+ user: 收尾一下
439
+ '@ | npm run manage-habits -- --suggest --transcript-stdin
440
+ ```
441
+
442
+ For Codex-side in-app triggering, use the session bridge CLI so the current conversation can be piped in directly:
443
+
444
+ ```powershell
445
+ @'
446
+ user: 以后我说“收尾一下”就是 close_session
447
+ assistant: 收到。
448
+ user: 收尾一下
449
+ '@ | npm run codex-session-habits -- --request "扫描这次会话里的习惯候选" --thread-stdin
450
+ ```
451
+
452
+ The current host/skill integration boundary is documented separately in:
453
+
454
+ - [codex-current-session-contract.md](/E:/user-habit-pipeline/docs/codex-current-session-contract.md)
455
+
456
+ This suggestion flow is intentionally read-only.
457
+ It returns candidate phrases and evidence, but it does not automatically add them to the user overlay.
458
+ It also saves the latest suggestion snapshot into a local hidden cache so the next apply step does not need a manual file path.
459
+ Each returned candidate now also includes `confidence_details`, so a Codex skill or other host can explain why that score was assigned instead of only showing a bare number.
460
+
461
+ After reviewing the candidates, you can explicitly add one:
462
+
463
+ ```powershell
464
+ npm run manage-habits -- --apply-candidate c1
465
+ ```
466
+
467
+ Prompt-style confirmation is also supported:
468
+
469
+ ```powershell
470
+ npm run manage-habits -- --request "添加第1条"
471
+ npm run manage-habits -- --request "把第1条加到 session_close 场景"
472
+ npm run manage-habits -- --request "忽略第1条"
473
+ npm run codex-session-habits -- --request "添加第1条"
474
+ npm run codex-session-habits -- --request "把第1条加到 session_close 场景"
475
+ ```
476
+
477
+ If a candidate is review-only, you can still apply it by supplying an explicit intent:
478
+
479
+ ```powershell
480
+ npm run manage-habits -- --apply-candidate c1 --intent close_session --scenario session_close
481
+ ```
482
+
483
+ If a candidate is noisy and should not be suggested again, suppress it instead of adding it:
484
+
485
+ ```powershell
486
+ npm run manage-habits -- --ignore-candidate c1
487
+ npm run manage-habits -- --request "忽略第1条"
488
+ ```
489
+
490
+ ### CLI contract
491
+
492
+ - `--message` is required
493
+ - `--scenario` is optional
494
+ - repeat `--context` to supply short recent-context items
495
+ - `--adapter growth-hub` projects the interpretation into downstream hint fields
496
+ - `--registry <path>` loads a different habit registry file for this invocation
497
+ - `--user-registry <path>` loads a user-habits overlay file for this invocation
498
+
499
+ The CLI prints JSON only.
package/data/.gitkeep ADDED
@@ -0,0 +1 @@
1
+