sisyo 1.7.0 → 1.9.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 (61) hide show
  1. package/LICENSE +16 -16
  2. package/README.md +177 -166
  3. package/bin/known-hashes.json +8 -1
  4. package/bin/sisyo.js +285 -285
  5. package/package.json +30 -30
  6. package/templates/.claude/rules/agents-and-tests.md +32 -24
  7. package/templates/.claude/rules/docs.md +39 -19
  8. package/templates/.claude/skills/fastapi-best-practices/ASYNC-PATTERNS.md +121 -121
  9. package/templates/.claude/skills/fastapi-best-practices/DATABASE.md +153 -153
  10. package/templates/.claude/skills/fastapi-best-practices/DEPENDENCIES.md +140 -140
  11. package/templates/.claude/skills/fastapi-best-practices/PROJECT-STRUCTURE.md +90 -90
  12. package/templates/.claude/skills/fastapi-best-practices/PYDANTIC-GUIDE.md +155 -155
  13. package/templates/.claude/skills/fastapi-best-practices/SKILL.md +123 -123
  14. package/templates/.claude/skills/g6-style/SKILL.md +125 -125
  15. package/templates/.claude/skills/g6-style/references/checks.md +58 -58
  16. package/templates/.claude/skills/g6-style/references/imagery.md +103 -103
  17. package/templates/.claude/skills/g6-style/references/motion.md +121 -121
  18. package/templates/.claude/skills/g6-style/references/sections.md +263 -263
  19. package/templates/.claude/skills/g6-style/references/tokens.md +197 -197
  20. package/templates/.claude/skills/hindsight/SKILL.md +175 -175
  21. package/templates/.claude/skills/hoang-auth/SKILL.md +188 -0
  22. package/templates/.claude/skills/html-docs/SKILL.md +207 -207
  23. package/templates/.claude/skills/i18n-multilang/SKILL.md +153 -153
  24. package/templates/.claude/skills/i18n-multilang/assets/languages.json +47 -47
  25. package/templates/.claude/skills/i18n-multilang/assets/plural-vectors.json +46 -46
  26. package/templates/.claude/skills/i18n-multilang/assets/project/README.md +17 -17
  27. package/templates/.claude/skills/i18n-multilang/assets/project/gitattributes.txt +6 -6
  28. package/templates/.claude/skills/i18n-multilang/assets/project/gitignore.txt +4 -4
  29. package/templates/.claude/skills/i18n-multilang/assets/project/glossary.json +6 -6
  30. package/templates/.claude/skills/i18n-multilang/assets/project/i18n.config.json +22 -22
  31. package/templates/.claude/skills/i18n-multilang/assets/project/locales/__source__/common.json +10 -10
  32. package/templates/.claude/skills/i18n-multilang/assets/project/notes/common.json +5 -5
  33. package/templates/.claude/skills/i18n-multilang/assets/project/style.md +20 -20
  34. package/templates/.claude/skills/i18n-multilang/references/format.md +100 -100
  35. package/templates/.claude/skills/i18n-multilang/references/languages.md +97 -97
  36. package/templates/.claude/skills/i18n-multilang/references/layout-and-versioning.md +256 -256
  37. package/templates/.claude/skills/i18n-multilang/references/numbers.md +161 -161
  38. package/templates/.claude/skills/i18n-multilang/references/platform-unity.md +142 -142
  39. package/templates/.claude/skills/i18n-multilang/references/platform-web.md +107 -107
  40. package/templates/.claude/skills/i18n-multilang/references/translation.md +143 -143
  41. package/templates/.claude/skills/i18n-multilang/references/voice.md +271 -271
  42. package/templates/.claude/skills/i18n-multilang/scripts/i18n.py +1041 -1041
  43. package/templates/.claude/skills/i18n-multilang/scripts/numwords.py +1013 -1013
  44. package/templates/.claude/skills/i18n-multilang/scripts/voice.py +478 -478
  45. package/templates/.claude/skills/neon-game-ui-ux-skill/COMPONENTS.md +490 -490
  46. package/templates/.claude/skills/neon-game-ui-ux-skill/GAMIFICATION.md +246 -246
  47. package/templates/.claude/skills/neon-game-ui-ux-skill/ICONS.md +249 -249
  48. package/templates/.claude/skills/neon-game-ui-ux-skill/LAYOUT-NAV.md +362 -362
  49. package/templates/.claude/skills/neon-game-ui-ux-skill/MOTION-A11Y.md +168 -168
  50. package/templates/.claude/skills/neon-game-ui-ux-skill/SKILL.md +137 -137
  51. package/templates/.claude/skills/neon-game-ui-ux-skill/TOKENS.md +323 -323
  52. package/templates/.claude/skills/react-page-oriented/SKILL.md +407 -407
  53. package/templates/.claude/skills/react-page-oriented/triggers.md +12 -12
  54. package/templates/.claude/skills/terraform-best-practices/SKILL.md +341 -341
  55. package/templates/.claude/skills/typesafe-jev/SKILL.md +148 -148
  56. package/templates/.claude/skills/vibe-docs/SKILL.md +139 -242
  57. package/templates/SISYO.md +39 -37
  58. package/templates/docs/99_progress/features.md +7 -7
  59. package/templates/docs/99_progress/handoff.md +19 -19
  60. package/templates/docs/99_progress/todo.md +15 -15
  61. package/templates/docs/MAP.md +26 -26
@@ -1,175 +1,175 @@
1
- ---
2
- name: hindsight
3
- description: >
4
- Add long-term memory to a project with the shared Hindsight server on the LAN
5
- (vectorize-io/hindsight), or operate or redeploy that server. Use when a
6
- project, app, agent system or coding setup should remember facts, decisions or
7
- user preferences across sessions; when asked to "integrate Hindsight",
8
- "add memory", "retain/recall/reflect"; or when the Hindsight stack in
9
- ~/Workspace/LanServer/Hindsight needs a restart, login, upgrade or rebuild.
10
- ---
11
-
12
- # Hindsight: long-term memory for any project
13
-
14
- One Hindsight server runs on an always-on LAN host and serves every project. A
15
- **bank** holds one project's memories, and banks never see each other. Integrating a new
16
- project means: pick a bank, decide what to retain, recall at the point of use.
17
- Do not stand up a second server unless the project must run somewhere else.
18
-
19
- Server details and the reasons behind its setup: `~/Workspace/LanServer/Hindsight/README.md`.
20
- `<hindsight-host>` below stands for that host's LAN address. This package is public,
21
- so the address is not written here: take it from the server README or the
22
- project's own `SISYO.md`.
23
- Paperclip's integration (capture plugin + per-run recall): the "Company memory
24
- (Hindsight)" section of `~/Workspace/Hoang/paperclip/DEPLOY-DORAEMON.md`.
25
-
26
- ## The shared server
27
-
28
- | | |
29
- |---|---|
30
- | API (and MCP) | `http://<hindsight-host>:26352` from the LAN; `http://host.docker.internal:26352` from a container on the host |
31
- | UI | `http://<hindsight-host>:26353` (browse, edit, invalidate memories) |
32
- | Auth | `Authorization: Bearer <HINDSIGHT_API_KEY>`; UI key `HINDSIGHT_UI_ACCESS_KEY` |
33
- | Keys | in `~/Workspace/LanServer/Hindsight/.env` (mode 600) |
34
- | LLM | Claude Sonnet 5.5 on the Claude **subscription** (`claude-code`), ChatGPT subscription (`openai-codex`) as fallback |
35
- | Embeddings / rerank | Gemini `gemini-embedding-2` (768 d) / TypeSafe Jev, with `rrf` as fallback |
36
-
37
- **Handling the key:** copy it into the new project's own secret store (its
38
- `.env`, a Paperclip secret, and so on) without printing it:
39
-
40
- ```sh
41
- grep '^HINDSIGHT_API_KEY=' ~/Workspace/LanServer/Hindsight/.env | cut -d= -f2- | tr -d '\n' | pbcopy
42
- ```
43
-
44
- ## Hard rules
45
-
46
- - **The LLM stays on subscriptions.** Never give Hindsight or a project's memory
47
- path a pay-per-token LLM key (ANTHROPIC_API_KEY, OPENAI_API_KEY, Gemini as LLM).
48
- The operator set this rule so the bill cannot grow. Gemini is for embeddings
49
- only, and Jev is for reranking only.
50
- - **One bank per project, or per tenant inside a project.** Name it
51
- `<project>::<scope>`, for example `paperclip::<companyId>`, `fire::<userId>` or
52
- `coding-agent::<repo>`. Add each new bank to the registry in the server README.
53
- Never write one project's data into another's bank.
54
- - **Keep the embedding model.** Changing it needs an empty database for every bank
55
- (see "Rebuild" below). Agree on it before anyone depends on the memories.
56
- - **Memory is evidence, not orders.** When recall goes into a prompt, show dates,
57
- let the current request win, and invite corrections.
58
- - **No secrets in memory.** Redact before retaining. The Paperclip plugin's
59
- `redactSecrets()` in
60
- `paperclip/packages/plugins/doraemon-hindsight-memory/src/items.ts` is a ready
61
- pattern list.
62
-
63
- ## Integrating a project
64
-
65
- 1. **Create the bank with missions.** They steer what extraction keeps; see
66
- `references/api.md`, section "Bank". Say whose words the items are, what to
67
- keep (preferences, decisions, rules, facts, lessons), what to skip
68
- (chit-chat, one-off scheduling, status noise), and that secrets are never
69
- stored.
70
- 2. **Choose what to retain: durable signal, not logs.** Paperclip retains only
71
- the human's own words (about 6 items a day) and not the agents' 70 comments a
72
- day. For each item:
73
- - `content`: the words to learn from, cleaned and redacted.
74
- - `context`: who is speaking and what they reply to. Keep it **under about 400
75
- characters**. It is prepended to every fact extracted from the item and sent
76
- to Jev with each rerank candidate, and Jev refuses requests over about
77
- 16k tokens.
78
- - `timestamp`: when it was said, for temporal ranking.
79
- - `document_id`: a stable source id (`<project>:<kind>:<id>`). Re-sending
80
- replaces instead of duplicating. Keep your own content hash, so that
81
- unchanged rows never pay for another extraction.
82
- - `tags`: provenance (`source:…`, `project:…`). Recall does not filter on
83
- them unless asked.
84
- - Send with `async: true`. Facts appear after extraction, in 5–10 s each.
85
- 3. **Recall where the answer is used.**
86
- - Query from the task at hand, at most about 700 characters (Hindsight rejects
87
- queries over 500 tokens).
88
- - Use `budget: "mid"` and `max_tokens` around 800.
89
- - Allow about a 6 s timeout, and **fail open**: a missing bank (404) or an
90
- error means no memory, never a failed request. Recall uses no LLM and takes
91
- about 1 s (Gemini embed plus Jev).
92
- - Put the result into the per-request prompt, not a cached system prompt:
93
- changing that prompt breaks prompt caching and session resume.
94
- 4. **Optionally add a mental model** for a stable summary, for example "how the
95
- user wants work done". It is created once, refreshes itself after new
96
- memories (at most every 30 min) and reads with a plain GET, with no LLM.
97
- While the first refresh runs, its content is `Generating content...`: treat
98
- that as empty.
99
- 5. **Use reflect only for deliberate questions** ("why did we drop X?"). It runs
100
- an LLM loop and takes up to minutes.
101
- 6. **Verify.** Retain one representative item synchronously into
102
- `zz-test-<project>` and read the extracted facts. Recall a query in the
103
- project's language (Vietnamese works), then delete the test bank.
104
-
105
- Client code for TypeScript and Python, and the exact endpoints, are in
106
- `references/api.md`.
107
-
108
- ## Coding agents (Claude Code, Codex)
109
-
110
- Use MCP: `claude mcp add --transport http hindsight http://<hindsight-host>:26352/mcp/<bank>/ --header "Authorization: Bearer <key>"`,
111
- with one bank per repo (`coding-agent::<repo>`).
112
-
113
- **Do not install Hindsight hooks globally** (`~/.claude/settings.json`) on the
114
- server or in WSL. Paperclip agents on those machines share `~/.claude`, so they would
115
- get the hooks too: a second injection of memory, and agent transcripts retained
116
- into the bank. Use MCP, or project-level hooks (`.claude/settings.json` in the
117
- repo).
118
-
119
- ## Operating the server
120
-
121
- All in `~/Workspace/LanServer/Hindsight`:
122
-
123
- | Task | Do |
124
- |---|---|
125
- | Restart or look | `docker compose up -d`, `docker compose logs -f hindsight`, `curl -s http://127.0.0.1:26352/health` |
126
- | Claude login expired (a year) | `./login-claude.sh` (or `--paste` with a `claude setup-token` token; the script strips the indentation and wrapping) |
127
- | ChatGPT fallback login invalid | `./login-codex.sh`. It uses its own `codex-home/`; never `~/.codex`, where rotating refresh tokens would log the codex agents out |
128
- | New Claude model or CLI | `docker compose build --no-cache hindsight && docker compose up -d`, then set `HINDSIGHT_LLM_MODEL` in `.env`. Look up model ids in the CLI binary: `docker exec hindsight sh -c 'grep -a -oE "claude-[a-z]+-[0-9-]+" /opt/claude/claude \| sort -u'` |
129
- | Backup | `docker exec hindsight-db pg_dump -U hindsight hindsight \| gzip > backups/hindsight-$(date +%Y%m%d%H%M).sql.gz` |
130
- | Upgrade Hindsight | bump `HINDSIGHT_VERSION` in `docker-compose.yml`, then `docker compose up -d --build`; migrations run on start |
131
- | Rebuild (embedding change) | back up, `docker compose down`, `docker volume rm hindsight_db_data`, `docker compose up -d`. Paperclip's plugin resends its history by itself when its bank is missing; other projects must re-send theirs |
132
-
133
- Health signals:
134
- - the startup log shows `LLM: claude-code / claude-sonnet-5-5`,
135
- `Claude Code connection verified`, `Codex LLM verified` and
136
- `google provider initialized ... dim: 768`;
137
- - recall takes about 1 s;
138
- - the API process uses about 360 MB of RAM.
139
-
140
- ## Deploying a separate instance
141
-
142
- Only when a project must run away from this host. Copy the directory (compose
143
- file, `Dockerfile`, `login-*.sh`, README); do not copy `.env`, `codex-home/` or
144
- `backups/`. Then:
145
-
146
- 1. **New secrets.** Create a new `.env` with fresh `HINDSIGHT_DB_PASSWORD`,
147
- `HINDSIGHT_API_KEY` and `HINDSIGHT_UI_ACCESS_KEY` (`openssl rand -hex 24`),
148
- plus the Gemini and Jev keys.
149
- 2. **A free subnet.** Pin `networks.default` to a free 10.x subnet. On the Mac it
150
- first ran on, an automatic pick lands on 192.168.0.0/20 and cuts containers off from the LAN.
151
- 3. **Build for the host's own architecture.** The Dockerfile copies the native
152
- Claude CLI binary for that platform.
153
- 4. **Log in** with `login-claude.sh`, then `login-codex.sh`.
154
- 5. **Verify** as in "Integrating a project", step 6.
155
-
156
- ## Traps already paid for
157
-
158
- - **Reranker.** A local cross-encoder reranker on the Mac's CPU took 36–97 s per
159
- recall. Jev over the API, with `RECALL_MAX_CANDIDATES_PER_SOURCE=15`, takes
160
- about 0.3 s. The recall budget does not bound the candidate pool; the
161
- per-source cap does.
162
- - **torch.** On arm64, the PyPI torch wheel pulls 3.3 GB of CUDA. Local models
163
- are gone now; if they ever come back, install torch from the CPU index.
164
- - **Codex models.** `gpt-5.4-mini` is refused on ChatGPT accounts; `gpt-6-luna`
165
- works.
166
- - **Reflect timeout.** It defaults to 30 s per LLM call, which is too short;
167
- `HINDSIGHT_API_REFLECT_LLM_TIMEOUT=120`.
168
- - **`HINDSIGHT_API_LLM_STRATEGY`.** It must be JSON (`{"mode": "failover"}`); a
169
- bare word crashes startup.
170
- - **Bank reads.** There is no GET for a single bank (405); list banks instead.
171
- - **Deleting memories.** No endpoint hard-deletes one memory. Invalidate it, in
172
- the UI or with `PATCH` `state: invalidated`, or delete its document.
173
- - **Plugin workers (Paperclip).** Background calls must run outside host
174
- invocations and name the company. The host expands array SQL parameters, so
175
- pass lists as JSON. Details are in DEPLOY-DORAEMON.md.
1
+ ---
2
+ name: hindsight
3
+ description: >
4
+ Add long-term memory to a project with the shared Hindsight server on the LAN
5
+ (vectorize-io/hindsight), or operate or redeploy that server. Use when a
6
+ project, app, agent system or coding setup should remember facts, decisions or
7
+ user preferences across sessions; when asked to "integrate Hindsight",
8
+ "add memory", "retain/recall/reflect"; or when the Hindsight stack in
9
+ ~/Workspace/LanServer/Hindsight needs a restart, login, upgrade or rebuild.
10
+ ---
11
+
12
+ # Hindsight: long-term memory for any project
13
+
14
+ One Hindsight server runs on an always-on LAN host and serves every project. A
15
+ **bank** holds one project's memories, and banks never see each other. Integrating a new
16
+ project means: pick a bank, decide what to retain, recall at the point of use.
17
+ Do not stand up a second server unless the project must run somewhere else.
18
+
19
+ Server details and the reasons behind its setup: `~/Workspace/LanServer/Hindsight/README.md`.
20
+ `<hindsight-host>` below stands for that host's LAN address. This package is public,
21
+ so the address is not written here: take it from the server README or the
22
+ project's own `SISYO.md`.
23
+ Paperclip's integration (capture plugin + per-run recall): the "Company memory
24
+ (Hindsight)" section of `~/Workspace/Hoang/paperclip/DEPLOY-DORAEMON.md`.
25
+
26
+ ## The shared server
27
+
28
+ | | |
29
+ |---|---|
30
+ | API (and MCP) | `http://<hindsight-host>:26352` from the LAN; `http://host.docker.internal:26352` from a container on the host |
31
+ | UI | `http://<hindsight-host>:26353` (browse, edit, invalidate memories) |
32
+ | Auth | `Authorization: Bearer <HINDSIGHT_API_KEY>`; UI key `HINDSIGHT_UI_ACCESS_KEY` |
33
+ | Keys | in `~/Workspace/LanServer/Hindsight/.env` (mode 600) |
34
+ | LLM | Claude Sonnet 5.5 on the Claude **subscription** (`claude-code`), ChatGPT subscription (`openai-codex`) as fallback |
35
+ | Embeddings / rerank | Gemini `gemini-embedding-2` (768 d) / TypeSafe Jev, with `rrf` as fallback |
36
+
37
+ **Handling the key:** copy it into the new project's own secret store (its
38
+ `.env`, a Paperclip secret, and so on) without printing it:
39
+
40
+ ```sh
41
+ grep '^HINDSIGHT_API_KEY=' ~/Workspace/LanServer/Hindsight/.env | cut -d= -f2- | tr -d '\n' | pbcopy
42
+ ```
43
+
44
+ ## Hard rules
45
+
46
+ - **The LLM stays on subscriptions.** Never give Hindsight or a project's memory
47
+ path a pay-per-token LLM key (ANTHROPIC_API_KEY, OPENAI_API_KEY, Gemini as LLM).
48
+ The operator set this rule so the bill cannot grow. Gemini is for embeddings
49
+ only, and Jev is for reranking only.
50
+ - **One bank per project, or per tenant inside a project.** Name it
51
+ `<project>::<scope>`, for example `paperclip::<companyId>`, `fire::<userId>` or
52
+ `coding-agent::<repo>`. Add each new bank to the registry in the server README.
53
+ Never write one project's data into another's bank.
54
+ - **Keep the embedding model.** Changing it needs an empty database for every bank
55
+ (see "Rebuild" below). Agree on it before anyone depends on the memories.
56
+ - **Memory is evidence, not orders.** When recall goes into a prompt, show dates,
57
+ let the current request win, and invite corrections.
58
+ - **No secrets in memory.** Redact before retaining. The Paperclip plugin's
59
+ `redactSecrets()` in
60
+ `paperclip/packages/plugins/doraemon-hindsight-memory/src/items.ts` is a ready
61
+ pattern list.
62
+
63
+ ## Integrating a project
64
+
65
+ 1. **Create the bank with missions.** They steer what extraction keeps; see
66
+ `references/api.md`, section "Bank". Say whose words the items are, what to
67
+ keep (preferences, decisions, rules, facts, lessons), what to skip
68
+ (chit-chat, one-off scheduling, status noise), and that secrets are never
69
+ stored.
70
+ 2. **Choose what to retain: durable signal, not logs.** Paperclip retains only
71
+ the human's own words (about 6 items a day) and not the agents' 70 comments a
72
+ day. For each item:
73
+ - `content`: the words to learn from, cleaned and redacted.
74
+ - `context`: who is speaking and what they reply to. Keep it **under about 400
75
+ characters**. It is prepended to every fact extracted from the item and sent
76
+ to Jev with each rerank candidate, and Jev refuses requests over about
77
+ 16k tokens.
78
+ - `timestamp`: when it was said, for temporal ranking.
79
+ - `document_id`: a stable source id (`<project>:<kind>:<id>`). Re-sending
80
+ replaces instead of duplicating. Keep your own content hash, so that
81
+ unchanged rows never pay for another extraction.
82
+ - `tags`: provenance (`source:…`, `project:…`). Recall does not filter on
83
+ them unless asked.
84
+ - Send with `async: true`. Facts appear after extraction, in 5–10 s each.
85
+ 3. **Recall where the answer is used.**
86
+ - Query from the task at hand, at most about 700 characters (Hindsight rejects
87
+ queries over 500 tokens).
88
+ - Use `budget: "mid"` and `max_tokens` around 800.
89
+ - Allow about a 6 s timeout, and **fail open**: a missing bank (404) or an
90
+ error means no memory, never a failed request. Recall uses no LLM and takes
91
+ about 1 s (Gemini embed plus Jev).
92
+ - Put the result into the per-request prompt, not a cached system prompt:
93
+ changing that prompt breaks prompt caching and session resume.
94
+ 4. **Optionally add a mental model** for a stable summary, for example "how the
95
+ user wants work done". It is created once, refreshes itself after new
96
+ memories (at most every 30 min) and reads with a plain GET, with no LLM.
97
+ While the first refresh runs, its content is `Generating content...`: treat
98
+ that as empty.
99
+ 5. **Use reflect only for deliberate questions** ("why did we drop X?"). It runs
100
+ an LLM loop and takes up to minutes.
101
+ 6. **Verify.** Retain one representative item synchronously into
102
+ `zz-test-<project>` and read the extracted facts. Recall a query in the
103
+ project's language (Vietnamese works), then delete the test bank.
104
+
105
+ Client code for TypeScript and Python, and the exact endpoints, are in
106
+ `references/api.md`.
107
+
108
+ ## Coding agents (Claude Code, Codex)
109
+
110
+ Use MCP: `claude mcp add --transport http hindsight http://<hindsight-host>:26352/mcp/<bank>/ --header "Authorization: Bearer <key>"`,
111
+ with one bank per repo (`coding-agent::<repo>`).
112
+
113
+ **Do not install Hindsight hooks globally** (`~/.claude/settings.json`) on the
114
+ server or in WSL. Paperclip agents on those machines share `~/.claude`, so they would
115
+ get the hooks too: a second injection of memory, and agent transcripts retained
116
+ into the bank. Use MCP, or project-level hooks (`.claude/settings.json` in the
117
+ repo).
118
+
119
+ ## Operating the server
120
+
121
+ All in `~/Workspace/LanServer/Hindsight`:
122
+
123
+ | Task | Do |
124
+ |---|---|
125
+ | Restart or look | `docker compose up -d`, `docker compose logs -f hindsight`, `curl -s http://127.0.0.1:26352/health` |
126
+ | Claude login expired (a year) | `./login-claude.sh` (or `--paste` with a `claude setup-token` token; the script strips the indentation and wrapping) |
127
+ | ChatGPT fallback login invalid | `./login-codex.sh`. It uses its own `codex-home/`; never `~/.codex`, where rotating refresh tokens would log the codex agents out |
128
+ | New Claude model or CLI | `docker compose build --no-cache hindsight && docker compose up -d`, then set `HINDSIGHT_LLM_MODEL` in `.env`. Look up model ids in the CLI binary: `docker exec hindsight sh -c 'grep -a -oE "claude-[a-z]+-[0-9-]+" /opt/claude/claude \| sort -u'` |
129
+ | Backup | `docker exec hindsight-db pg_dump -U hindsight hindsight \| gzip > backups/hindsight-$(date +%Y%m%d%H%M).sql.gz` |
130
+ | Upgrade Hindsight | bump `HINDSIGHT_VERSION` in `docker-compose.yml`, then `docker compose up -d --build`; migrations run on start |
131
+ | Rebuild (embedding change) | back up, `docker compose down`, `docker volume rm hindsight_db_data`, `docker compose up -d`. Paperclip's plugin resends its history by itself when its bank is missing; other projects must re-send theirs |
132
+
133
+ Health signals:
134
+ - the startup log shows `LLM: claude-code / claude-sonnet-5-5`,
135
+ `Claude Code connection verified`, `Codex LLM verified` and
136
+ `google provider initialized ... dim: 768`;
137
+ - recall takes about 1 s;
138
+ - the API process uses about 360 MB of RAM.
139
+
140
+ ## Deploying a separate instance
141
+
142
+ Only when a project must run away from this host. Copy the directory (compose
143
+ file, `Dockerfile`, `login-*.sh`, README); do not copy `.env`, `codex-home/` or
144
+ `backups/`. Then:
145
+
146
+ 1. **New secrets.** Create a new `.env` with fresh `HINDSIGHT_DB_PASSWORD`,
147
+ `HINDSIGHT_API_KEY` and `HINDSIGHT_UI_ACCESS_KEY` (`openssl rand -hex 24`),
148
+ plus the Gemini and Jev keys.
149
+ 2. **A free subnet.** Pin `networks.default` to a free 10.x subnet. On the Mac it
150
+ first ran on, an automatic pick lands on 192.168.0.0/20 and cuts containers off from the LAN.
151
+ 3. **Build for the host's own architecture.** The Dockerfile copies the native
152
+ Claude CLI binary for that platform.
153
+ 4. **Log in** with `login-claude.sh`, then `login-codex.sh`.
154
+ 5. **Verify** as in "Integrating a project", step 6.
155
+
156
+ ## Traps already paid for
157
+
158
+ - **Reranker.** A local cross-encoder reranker on the Mac's CPU took 36–97 s per
159
+ recall. Jev over the API, with `RECALL_MAX_CANDIDATES_PER_SOURCE=15`, takes
160
+ about 0.3 s. The recall budget does not bound the candidate pool; the
161
+ per-source cap does.
162
+ - **torch.** On arm64, the PyPI torch wheel pulls 3.3 GB of CUDA. Local models
163
+ are gone now; if they ever come back, install torch from the CPU index.
164
+ - **Codex models.** `gpt-5.4-mini` is refused on ChatGPT accounts; `gpt-6-luna`
165
+ works.
166
+ - **Reflect timeout.** It defaults to 30 s per LLM call, which is too short;
167
+ `HINDSIGHT_API_REFLECT_LLM_TIMEOUT=120`.
168
+ - **`HINDSIGHT_API_LLM_STRATEGY`.** It must be JSON (`{"mode": "failover"}`); a
169
+ bare word crashes startup.
170
+ - **Bank reads.** There is no GET for a single bank (405); list banks instead.
171
+ - **Deleting memories.** No endpoint hard-deletes one memory. Invalidate it, in
172
+ the UI or with `PATCH` `state: invalidated`, or delete its document.
173
+ - **Plugin workers (Paperclip).** Background calls must run outside host
174
+ invocations and name the company. The host expands array SQL parameters, so
175
+ pass lists as JSON. Details are in DEPLOY-DORAEMON.md.
@@ -0,0 +1,188 @@
1
+ ---
2
+ name: hoang-auth
3
+ description: >-
4
+ The one sign-in flow every Hoang app uses with Hoang Auth (Keycloak realm `hoang`, https://auth.hoang.jp): what
5
+ the app's own sign-in screen shows (Google, Apple, LINE, "Sign in with Hoang Account", "Create account"), how each
6
+ button opens the shared Hoang Auth page (code flow + PKCE, kc_idp_hint, login_hint, prompt=create, ui_locales),
7
+ what an app must never build itself (password fields, password grant, its own sign-up or reset mails, links to
8
+ Keycloak's account pages), the app's account screen (change or set password, passkey, two-factor, recovery codes,
9
+ link a provider, remove a credential, delete the account) through kc_action, server-side token checks, sign-out, and a test checklist.
10
+ Use for any sign-in, sign-up, sign-out or account-settings work in a Hoang web app, game (Unity) or mobile app,
11
+ and whenever someone says "Hoang Auth", "auth.hoang.jp", "đăng nhập", "đăng ký", "đổi mật khẩu", "liên kết tài
12
+ khoản", "2FA", "passkey", "ログイン", "新規登録", "連携", "sign in with Google / LINE / Apple", "OIDC" or "Keycloak"
13
+ for a Hoang app.
14
+ ---
15
+
16
+ # Hoang Auth: the sign-in flow for every app
17
+
18
+ One person has **one Hoang Account**, shared by every Hoang app. Passwords, passkeys, two-factor, Google / Apple /
19
+ LINE, sign-up, password reset and email verification happen **only on the shared Hoang Auth page**. The app draws
20
+ its own screen with buttons, and every button opens that page. There is one place to fix bugs and one place to keep
21
+ secure, and no app ever handles a password.
22
+
23
+ ## 1. The app's sign-in screen (the app's own design)
24
+
25
+ | Button | What it opens |
26
+ |---|---|
27
+ | Continue with Google | Hoang Auth with `kc_idp_hint=google`: straight on to Google |
28
+ | Continue with Apple | `kc_idp_hint=apple`. On iOS it is required as soon as any other social sign-in is offered (App Store guideline 4.8) |
29
+ | Continue with LINE | `kc_idp_hint=line` |
30
+ | Sign in with Hoang Account | The Hoang Auth sign-in page: email or username, then password or passkey. Optional: an email field in the app, sent as `login_hint` |
31
+ | Create account | The Hoang Auth sign-up page (`prompt=create`) |
32
+
33
+ - Offer only the providers Hoang Auth has turned on: today Google, Apple and LINE (Facebook is off). Use the same
34
+ order as the Hoang Auth page: Google, Apple, LINE.
35
+ - The app has no password field and no sign-up form.
36
+ - After a provider button the person sees no Hoang Auth page, with two exceptions: someone who turned two-factor on
37
+ gets a code step, and a first visit whose email already belongs to an account gets an "account already exists"
38
+ page (the accounts are joined only after a link sent to that mailbox is clicked).
39
+ - The Hoang Auth page shows the app's name (the client's name) at the top, so people know where they are signing in.
40
+
41
+ ## 2. Opening Hoang Auth (the authorize request)
42
+
43
+ ```
44
+ GET https://auth.hoang.jp/realms/hoang/protocol/openid-connect/auth
45
+ ?client_id=<the app's client> one client per app (section 8)
46
+ &response_type=code
47
+ &scope=openid add "email profile" if the app shows them
48
+ &redirect_uri=<exact registered URL>
49
+ &code_challenge=<BASE64URL(SHA-256(verifier))>&code_challenge_method=S256 PKCE, required
50
+ &state=<random, kept by the app>
51
+ &nonce=<random, checked in the ID token>
52
+ &ui_locales=<the app's language: vi | ja | en | ...>
53
+ [&kc_idp_hint=google | apple | line] provider buttons
54
+ [&login_hint=<email typed in the app>] an existing account opens at the password step; a new one at sign-up
55
+ [&prompt=create] Create account
56
+ [&prompt=login] "use another account"
57
+ [&kc_action=<action>] the account screen, section 5
58
+ ```
59
+
60
+ Where to open it:
61
+ - **Web**: a full-page redirect. No iframe (Hoang Auth refuses to be framed) and no popup. An app with a backend runs
62
+ the code flow on the server; a single-page app uses keycloak-js or oidc-client-ts with PKCE.
63
+ - **Native, Unity, mobile**: the system browser (iOS `ASWebAuthenticationSession`, Android Custom Tabs). Never an
64
+ embedded WebView: Google refuses sign-in there, and people cannot see that the page is really Hoang Auth's. The
65
+ redirect goes back to the app's own scheme, for example `<bundle id>:/oauth2redirect`.
66
+
67
+ Callback: check that `state` is unchanged. On `error=...` (such as `access_denied`), show the app's sign-in screen
68
+ again. Otherwise exchange `code` together with the `code_verifier` at the token endpoint; a code works only once.
69
+ Discovery (all endpoints): `https://auth.hoang.jp/realms/hoang/.well-known/openid-configuration`.
70
+
71
+ ## 3. What Hoang Auth already does (nothing for the app to build)
72
+
73
+ - Email or username first. An existing account goes to the password step (the provider buttons are there too); an
74
+ unknown one goes to sign-up with what was typed filled in.
75
+ - Passkeys (browser autofill and a "sign in with passkey" button), and two-factor for people who turned it on:
76
+ authenticator app, security key, recovery codes.
77
+ - Sign-up with email verification. Password rules: 8 to 128 characters, not the username.
78
+ - Forgot password by mail, without telling whether an account exists. Lockout after repeated wrong passwords.
79
+ - Asking to sign in again before account changes (password, passkey, two-factor, linking) when the last sign-in is
80
+ older than 5 minutes.
81
+ - 29 languages, following `ui_locales`.
82
+ - Accounts are never merged by email without proof.
83
+
84
+ ## 4. The app's server
85
+
86
+ - Verify the ID token: the signature (RS256, keys at `.../protocol/openid-connect/certs`), `iss` =
87
+ `https://auth.hoang.jp/realms/hoang`, `aud` and `azp` = the app's client, `exp`, and `nonce`.
88
+ - Key people by `sub`. Never key them by email, and never merge accounts by email.
89
+ - Trust `email` only when `email_verified` is true. Accounts made with LINE (and others) may have no email at all,
90
+ so the app must work with `sub` and a display name alone.
91
+ - Display name: `name` (or `given_name` / `family_name`). Accounts made through a provider have usernames like
92
+ `google-<uuid>`, so never show `preferred_username` to people.
93
+ - Keep the app's own session. Do not store the providers' tokens.
94
+
95
+ ## 5. The app's account screen
96
+
97
+ The app draws it. To show status (which providers are linked, whether there is a password, a passkey, two-factor),
98
+ the app's backend reads the account through Keycloak's Admin REST with a service-account client that the Hoang Auth
99
+ owner grants; the screen also works without status. Every action is a button that opens Hoang Auth: the same
100
+ authorize request as sign-in (section 2), plus `kc_action`.
101
+
102
+ | Button | `kc_action` | Credential type in the status |
103
+ |---|---|---|
104
+ | Change password / set a password | `UPDATE_PASSWORD` (it also gives a first password to an account made with Google, Apple or LINE) | `password` |
105
+ | Add a passkey | `webauthn-register-passwordless` | `webauthn-passwordless` |
106
+ | Turn on two-factor: authenticator app | `CONFIGURE_TOTP` | `otp` |
107
+ | Two-factor: security key | `webauthn-register` | `webauthn` |
108
+ | Recovery codes (offer them right after two-factor is turned on) | `CONFIGURE_RECOVERY_AUTHN_CODES` | `recovery-authn-codes` |
109
+ | Link Google / Apple / LINE | `idp_link:google`, `idp_link:apple`, `idp_link:line` | (a linked provider) |
110
+ | Remove a passkey or a two-factor method | `delete_credential:<credential id>` (Hoang Auth asks to confirm) | — |
111
+ | Delete my Hoang Account | `delete_account` (Hoang Auth warns that the account is every Hoang app's and asks to confirm) | — |
112
+
113
+ - The person comes back to `redirect_uri` with `code` and `kc_action_status=success`, `cancelled` or `error`.
114
+ Exchange the code as after a sign-in (or drop it), show a one-line result, then reload the status.
115
+ - If the last sign-in is older than 5 minutes, Hoang Auth asks to sign in again first. The app does nothing for this.
116
+ - Never offer removing the password, and never remove the last way in. Unlinking a provider is done by the app's
117
+ backend (Admin REST); there is no `kc_action` for it.
118
+ - Never link to Keycloak's own account pages (`/realms/hoang/account/...`): they look nothing like the apps.
119
+ - Deleting the Hoang Account (owner, 2026-11-30): the app first deletes its own data, then opens `kc_action=delete_account`.
120
+ After the deletion Hoang Auth does **not** return to the app (no `kc_action_status`): it shows "account deleted" with a
121
+ "Back to application" link to the client's **Base URL**. So every client needs a Base URL (section 8). A native app
122
+ either uses its own scheme as the Base URL or closes the system browser itself. Cancel returns with
123
+ `kc_action_status=cancelled`. The account is gone for every Hoang app; a later Google / Apple / LINE sign-in makes a
124
+ new account (new `sub`).
125
+ - Two-factor is opt-in. Apps do not add re-authentication of their own before sensitive actions (owner decision,
126
+ 2026-11-25).
127
+
128
+ ## 6. Sign-out
129
+
130
+ - `GET https://auth.hoang.jp/realms/hoang/protocol/openid-connect/logout?id_token_hint=<ID token>&post_logout_redirect_uri=<registered URL>&client_id=<client>`,
131
+ then clear the app's own session. This ends the Hoang Auth session for every app in that browser.
132
+ - "Use another account" (on mobile, for example): an authorize request with `prompt=login`. There is no need to clear
133
+ the browser's cookies.
134
+
135
+ ## 7. Never
136
+
137
+ - A password field or the password grant (`grant_type=password`). It fails for people with two-factor, passkeys
138
+ cannot work there, and the app would hold everyone's Hoang password.
139
+ - A sign-up of the app's own that writes users into Keycloak, or the app's own reset-password or verification mails.
140
+ - The implicit flow, tokens in URLs, WebViews, iframes.
141
+ - Matching or merging accounts by email.
142
+ - Links to Keycloak's account pages.
143
+ - The legacy linking endpoint `/realms/hoang/broker/<alias>/link`, which Keycloak 27 removes. Use
144
+ `kc_action=idp_link:<alias>`.
145
+
146
+ ## 8. A client for a new app (ask the Hoang Auth owner)
147
+
148
+ Send the owner:
149
+ - the app's name as people should see it on the page (for example "Shipper Battle");
150
+ - the platform (web, iOS, Android, Unity);
151
+ - the exact redirect URIs (the web callback, the native `<bundle id>:/oauth2redirect`, the dev URLs);
152
+ - the post-logout redirect URIs;
153
+ - the Base URL: where "Back to application" leads from Hoang Auth's own pages (after deleting the account, error pages):
154
+ the web home page, or the native app's scheme URL;
155
+ - whether a backend needs to read account status (a service account).
156
+
157
+ The owner creates a public client with only the standard flow, PKCE S256 and exact redirect URIs (no password
158
+ grant, no implicit flow). Its name is what the Hoang Auth page shows at the top.
159
+
160
+ ## 9. Test checklist (each app, before release)
161
+
162
+ 1. Google button: on to Google and back in the app. The second time, no Hoang Auth page at all.
163
+ 2. Hoang Account button: the page shows the app's name. The email of an existing account goes to the password step;
164
+ a new email goes to sign-up with the email filled in (`login_hint`).
165
+ 3. Create account: sign-up, verification mail, the link, back in the app signed in.
166
+ 4. Forgot password from the Hoang Auth page: mail, new password, back in the app.
167
+ 5. Authenticator app turned on from the account screen: after signing out, the next sign-in asks the code (both
168
+ with the password and with Google).
169
+ 6. Passkey added: after signing out, sign in with the passkey and no password.
170
+ 7. Link LINE: `kc_action_status=success`. Cancel: `cancelled`. A LINE account that belongs to someone else: Hoang
171
+ Auth's error page.
172
+ 8. Change password: works. Cancel: `cancelled`.
173
+ 9. Sign out: back in the app, and signing in again shows the page.
174
+ 10. Cancel at Google or close the system browser: the app shows its sign-in screen and does not crash.
175
+ 11. The app in Japanese: the page is in Japanese (`ui_locales`).
176
+ 12. Server: a tampered or expired ID token is refused, a wrong `nonce` is refused, and people are keyed by `sub`.
177
+ 13. Delete account: the app's data first, then `kc_action=delete_account`; "Back to application" leads back into the app;
178
+ signing in again with the same Google account makes a new account.
179
+
180
+ Hoang Auth has its own end-to-end suite for the shared page (sign-in, sign-up, passwords, passkeys, two-factor,
181
+ linking, sign-out, protocol security). An app tests its own side with this list.
182
+
183
+ ## 10. Moving an existing app to this flow
184
+
185
+ - It has its own password form or sign-up (password grant, users created through the admin API): replace them with
186
+ the buttons of section 1. Accounts stay the same (same `sub`).
187
+ - It opens Keycloak's account pages for linking or security: replace them with `kc_action` buttons (section 5).
188
+ - It links through `/broker/<alias>/link`: move to `kc_action=idp_link:<alias>` before Keycloak 27.