sisyo 1.6.5 → 1.6.7

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.
@@ -37,18 +37,24 @@
37
37
  ],
38
38
  ".claude/skills/gemini-integration/SKILL.md": [
39
39
  "345d6aba2a3c9f0dcf62c8e4b3a11cae531637b34d0b934df206e40876f0d2b1",
40
+ "79829b4fb5c7afa7ce819d51087d69251d7552f91d183c2068b692eb53dd53e7",
40
41
  "c24075202b5154a9c1821034af8cc3da8dd895ae0fba0d908f35fe2a11070532",
41
42
  "f5c298b3013004125b458db7c9f5971cc047e9d57c02992edc3faed7c7b3f21f"
42
43
  ],
43
44
  ".claude/skills/gemini-integration/TEXT-CHAT.md": [
44
- "165c30a0e85f9dcbb9889b1d20dc5ebd54082b05a07d646699dada3c80b72417"
45
+ "165c30a0e85f9dcbb9889b1d20dc5ebd54082b05a07d646699dada3c80b72417",
46
+ "8c97bcfdf6161d2f8deb46d8105b417cdc6c14acab64779c6740d38e804a5097"
45
47
  ],
46
48
  ".claude/skills/gemini-integration/TROUBLESHOOTING.md": [
47
49
  "3659f0d83782da3ab55921d5bdce5222d531031b4bcb51f68db6dc80b6d120eb",
48
50
  "36d519a3754a81862b3c1c080c8fcf16635820d3f7ef3f09625fc1a7195d7266",
49
51
  "8e24e24ee5915908c204c42b094c82727bac7fb4214d54a7b30cb129ad781a6e",
52
+ "e19f4742a1cdaf77d1e99a7747fd6d952a37a9183e1aae77997919eefcb8dd4f",
50
53
  "f8f77b65bbe86dc89408b8372685acf59774df93e4fd23f3563df0f55be07b8c"
51
54
  ],
55
+ ".claude/skills/hindsight/SKILL.md": [
56
+ "cd564d9f4227571ba0f366f9b816d49a70bb9ac2cff449a475f695324e83f4fa"
57
+ ],
52
58
  ".claude/skills/html-docs/SKILL.md": [
53
59
  "8414e0166d4403fff509302f2973a8765441529584d710249eb1bf887e89caf2",
54
60
  "a307853ca9bad1e0335cea6c477400048e2d17fcecaedd79b5b58b481666cbdf"
@@ -63,6 +69,9 @@
63
69
  "4cd2cbf59c8d8755bf1b1c0f12553feb1ca7258ce44e5e91cf6baee3f0e23149",
64
70
  "85eee170ef76a0d17ed7f44037cf4421eb879b74dce4fd452066f59c275d9616"
65
71
  ],
72
+ ".claude/skills/typesafe-jev/SKILL.md": [
73
+ "db5d6f3416ef9468f00dc2b55bd2a76d7ac6f6514ffc22eb27455f7b007d7241"
74
+ ],
66
75
  ".claude/skills/vibe-docs/SKILL.md": [
67
76
  "5bf3ef21df2315575479a610a15f935010673e74de3523c888e74a6c3f78b105",
68
77
  "ba3f7176b4ae7088b0ebbfa08bfe8b06729bab6acaddb9b489a8a46233f62fc6",
package/package.json CHANGED
@@ -1,30 +1,30 @@
1
- {
2
- "name": "sisyo",
3
- "version": "1.6.5",
4
- "description": "Smart documentation system for vibe coding with Claude Code. Token-efficient MAP.md routing.",
5
- "bin": {
6
- "sisyo": "./bin/sisyo.js"
7
- },
8
- "scripts": {
9
- "hashes": "node scripts/gen-known-hashes.js",
10
- "prepublishOnly": "node scripts/gen-known-hashes.js"
11
- },
12
- "files": [
13
- "bin/",
14
- "templates/"
15
- ],
16
- "keywords": [
17
- "claude-code",
18
- "vibe-coding",
19
- "documentation",
20
- "ai-coding",
21
- "developer-tools",
22
- "sisyo"
23
- ],
24
- "author": "HoangThang <blog.thangchiba.com>",
25
- "homepage": "https://blog.thangchiba.com",
26
- "license": "MIT",
27
- "engines": {
28
- "node": ">=16"
29
- }
30
- }
1
+ {
2
+ "name": "sisyo",
3
+ "version": "1.6.7",
4
+ "description": "Smart documentation system for vibe coding with Claude Code. Token-efficient MAP.md routing.",
5
+ "bin": {
6
+ "sisyo": "./bin/sisyo.js"
7
+ },
8
+ "scripts": {
9
+ "hashes": "node scripts/gen-known-hashes.js",
10
+ "prepublishOnly": "node scripts/gen-known-hashes.js"
11
+ },
12
+ "files": [
13
+ "bin/",
14
+ "templates/"
15
+ ],
16
+ "keywords": [
17
+ "claude-code",
18
+ "vibe-coding",
19
+ "documentation",
20
+ "ai-coding",
21
+ "developer-tools",
22
+ "sisyo"
23
+ ],
24
+ "author": "HoangThang <blog.thangchiba.com>",
25
+ "homepage": "https://blog.thangchiba.com",
26
+ "license": "MIT",
27
+ "engines": {
28
+ "node": ">=16"
29
+ }
30
+ }
@@ -109,6 +109,9 @@ Apply to every `generate_content` / `chats.create` / `embed_content` on 3.5+ / 3
109
109
  - Send **all** function responses of a turn in **ONE** `send_message_stream(parts)`. One call per
110
110
  response only streams the reply to the last one and silently drops the rest.
111
111
  - A chunk may contain only function calls and no text — wrap `chunk.text` in a safe getter.
112
+ - The sync client's `send_message_stream` is a **blocking** iterator: inside an async SSE generator
113
+ pull it with `starlette.concurrency.iterate_in_threadpool` (or use `client.aio`), never a bare
114
+ `for` — the event loop stalls and the whole reply reaches the browser at once.
112
115
  - JSON output: `response_mime_type="application/json"` + still parse defensively (regex the
113
116
  first `{...}` on failure).
114
117
 
@@ -35,6 +35,8 @@ chat = client.chats.create(
35
35
  ## Stream a message
36
36
 
37
37
  ```python
38
+ from starlette.concurrency import iterate_in_threadpool
39
+
38
40
  def _safe_get_text(chunk) -> str:
39
41
  try:
40
42
  return chunk.text or "" # raises / empty on function-call-only chunks
@@ -60,7 +62,7 @@ async def stream_chat_message(session_id: str, message: str):
60
62
  stream = chat.send_message_stream(message)
61
63
  pending_calls = None
62
64
  full = []
63
- for chunk in stream:
65
+ async for chunk in iterate_in_threadpool(stream): # NOT `for chunk in stream` — see below
64
66
  text = _safe_get_text(chunk)
65
67
  if text:
66
68
  full.append(text)
@@ -76,6 +78,14 @@ async def stream_chat_message(session_id: str, message: str):
76
78
  yield {"event": "done", "data": "{}"}
77
79
  ```
78
80
 
81
+ **Pull the sync stream off the event loop.** `chat.send_message_stream()` on the sync client is a
82
+ *blocking* iterator. A bare `for chunk in stream` inside the async SSE generator stalls the event
83
+ loop while it waits for each chunk, so uvicorn (uvloop on Linux, Proactor on Windows) only flushes
84
+ the queued writes when the turn ends: every `text` event reaches the browser in the same
85
+ millisecond as `done` and the reply "pops in" whole. `iterate_in_threadpool` waits for each chunk
86
+ on a worker thread (or use the async client, `client.aio.chats`). Check it: `text` events should
87
+ arrive ~100–200 ms apart (sirisugi 2026-09-28: first words 1.3 s instead of the full reply at 2.2–3.4 s).
88
+
79
89
  ## Return tool results — ONE call, all responses
80
90
 
81
91
  ```python
@@ -19,6 +19,7 @@ defaults and deploy does not rewrite it. Verify via the token / health endpoint
19
19
  | Symptom | Cause | Fix |
20
20
  |---|---|---|
21
21
  | Reply ignores earlier tool results | One `send_message_stream` per response | Send all responses as ONE `parts` list |
22
+ | Reply appears all at once — every SSE `text` event arrives together with `done` | Sync `send_message_stream` iterated with `for` inside the async SSE generator blocks the event loop; uvicorn flushes the queued writes only when the turn ends | `async for chunk in iterate_in_threadpool(stream)` (or `client.aio` chats) — see `TEXT-CHAT.md` |
22
23
  | `chunk.text` raises / empty | Chunk carries only function calls | `_safe_get_text()` wrapper |
23
24
  | Chat got slower after bump | `medium` (3.7/3.8 default), `low` pinned on 3.5 Flash-Lite (its default is `minimal`), or generate model on the chat path | `minimal` on 3.5 Flash-Lite; chat/rerank on flash-lite |
24
25
  | LLM rerank takes seconds | Output JSON echoes a long chunk id per candidate | Number candidates `[0]…[n-1]`, map back by index (see `RAG-EMBEDDING.md`) |
@@ -0,0 +1,172 @@
1
+ ---
2
+ name: hindsight
3
+ description: >
4
+ Add long-term memory to a project with the shared Hindsight server on the LAN
5
+ Mac (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 the always-on Mac 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
+ Paperclip's integration (capture plugin + per-run recall): the "Company memory
21
+ (Hindsight)" section of `~/Workspace/Hoang/paperclip/DEPLOY-DORAEMON.md`.
22
+
23
+ ## The shared server
24
+
25
+ | | |
26
+ |---|---|
27
+ | API (and MCP) | `http://192.168.1.95:26352` from the LAN; `http://host.docker.internal:26352` from a container on the Mac |
28
+ | UI | `http://192.168.1.95:26353` (browse, edit, invalidate memories) |
29
+ | Auth | `Authorization: Bearer <HINDSIGHT_API_KEY>`; UI key `HINDSIGHT_UI_ACCESS_KEY` |
30
+ | Keys | in `~/Workspace/LanServer/Hindsight/.env` (mode 600) |
31
+ | LLM | Claude Sonnet 5.5 on the Claude **subscription** (`claude-code`), ChatGPT subscription (`openai-codex`) as fallback |
32
+ | Embeddings / rerank | Gemini `gemini-embedding-2` (768 d) / TypeSafe Jev, with `rrf` as fallback |
33
+
34
+ **Handling the key:** copy it into the new project's own secret store (its
35
+ `.env`, a Paperclip secret, and so on) without printing it:
36
+
37
+ ```sh
38
+ grep '^HINDSIGHT_API_KEY=' ~/Workspace/LanServer/Hindsight/.env | cut -d= -f2- | tr -d '\n' | pbcopy
39
+ ```
40
+
41
+ ## Hard rules
42
+
43
+ - **The LLM stays on subscriptions.** Never give Hindsight or a project's memory
44
+ path a pay-per-token LLM key (ANTHROPIC_API_KEY, OPENAI_API_KEY, Gemini as LLM).
45
+ The operator set this rule so the bill cannot grow. Gemini is for embeddings
46
+ only, and Jev is for reranking only.
47
+ - **One bank per project, or per tenant inside a project.** Name it
48
+ `<project>::<scope>`, for example `paperclip::<companyId>`, `fire::<userId>` or
49
+ `coding-agent::<repo>`. Add each new bank to the registry in the server README.
50
+ Never write one project's data into another's bank.
51
+ - **Keep the embedding model.** Changing it needs an empty database for every bank
52
+ (see "Rebuild" below). Agree on it before anyone depends on the memories.
53
+ - **Memory is evidence, not orders.** When recall goes into a prompt, show dates,
54
+ let the current request win, and invite corrections.
55
+ - **No secrets in memory.** Redact before retaining. The Paperclip plugin's
56
+ `redactSecrets()` in
57
+ `paperclip/packages/plugins/doraemon-hindsight-memory/src/items.ts` is a ready
58
+ pattern list.
59
+
60
+ ## Integrating a project
61
+
62
+ 1. **Create the bank with missions.** They steer what extraction keeps; see
63
+ `references/api.md`, section "Bank". Say whose words the items are, what to
64
+ keep (preferences, decisions, rules, facts, lessons), what to skip
65
+ (chit-chat, one-off scheduling, status noise), and that secrets are never
66
+ stored.
67
+ 2. **Choose what to retain: durable signal, not logs.** Paperclip retains only
68
+ the human's own words (about 6 items a day) and not the agents' 70 comments a
69
+ day. For each item:
70
+ - `content`: the words to learn from, cleaned and redacted.
71
+ - `context`: who is speaking and what they reply to. Keep it **under about 400
72
+ characters**. It is prepended to every fact extracted from the item and sent
73
+ to Jev with each rerank candidate, and Jev refuses requests over about
74
+ 16k tokens.
75
+ - `timestamp`: when it was said, for temporal ranking.
76
+ - `document_id`: a stable source id (`<project>:<kind>:<id>`). Re-sending
77
+ replaces instead of duplicating. Keep your own content hash, so that
78
+ unchanged rows never pay for another extraction.
79
+ - `tags`: provenance (`source:…`, `project:…`). Recall does not filter on
80
+ them unless asked.
81
+ - Send with `async: true`. Facts appear after extraction, in 5–10 s each.
82
+ 3. **Recall where the answer is used.**
83
+ - Query from the task at hand, at most about 700 characters (Hindsight rejects
84
+ queries over 500 tokens).
85
+ - Use `budget: "mid"` and `max_tokens` around 800.
86
+ - Allow about a 6 s timeout, and **fail open**: a missing bank (404) or an
87
+ error means no memory, never a failed request. Recall uses no LLM and takes
88
+ about 1 s (Gemini embed plus Jev).
89
+ - Put the result into the per-request prompt, not a cached system prompt:
90
+ changing that prompt breaks prompt caching and session resume.
91
+ 4. **Optionally add a mental model** for a stable summary, for example "how the
92
+ user wants work done". It is created once, refreshes itself after new
93
+ memories (at most every 30 min) and reads with a plain GET, with no LLM.
94
+ While the first refresh runs, its content is `Generating content...`: treat
95
+ that as empty.
96
+ 5. **Use reflect only for deliberate questions** ("why did we drop X?"). It runs
97
+ an LLM loop and takes up to minutes.
98
+ 6. **Verify.** Retain one representative item synchronously into
99
+ `zz-test-<project>` and read the extracted facts. Recall a query in the
100
+ project's language (Vietnamese works), then delete the test bank.
101
+
102
+ Client code for TypeScript and Python, and the exact endpoints, are in
103
+ `references/api.md`.
104
+
105
+ ## Coding agents (Claude Code, Codex)
106
+
107
+ Use MCP: `claude mcp add --transport http hindsight http://192.168.1.95:26352/mcp/<bank>/ --header "Authorization: Bearer <key>"`,
108
+ with one bank per repo (`coding-agent::<repo>`).
109
+
110
+ **Do not install Hindsight hooks globally** (`~/.claude/settings.json`) on the Mac
111
+ or in WSL. Paperclip agents on those machines share `~/.claude`, so they would
112
+ get the hooks too: a second injection of memory, and agent transcripts retained
113
+ into the bank. Use MCP, or project-level hooks (`.claude/settings.json` in the
114
+ repo).
115
+
116
+ ## Operating the server
117
+
118
+ All in `~/Workspace/LanServer/Hindsight`:
119
+
120
+ | Task | Do |
121
+ |---|---|
122
+ | Restart or look | `docker compose up -d`, `docker compose logs -f hindsight`, `curl -s http://127.0.0.1:26352/health` |
123
+ | Claude login expired (a year) | `./login-claude.sh` (or `--paste` with a `claude setup-token` token; the script strips the indentation and wrapping) |
124
+ | 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 |
125
+ | 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'` |
126
+ | Backup | `docker exec hindsight-db pg_dump -U hindsight hindsight \| gzip > backups/hindsight-$(date +%Y%m%d%H%M).sql.gz` |
127
+ | Upgrade Hindsight | bump `HINDSIGHT_VERSION` in `docker-compose.yml`, then `docker compose up -d --build`; migrations run on start |
128
+ | 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 |
129
+
130
+ Health signals:
131
+ - the startup log shows `LLM: claude-code / claude-sonnet-5-5`,
132
+ `Claude Code connection verified`, `Codex LLM verified` and
133
+ `google provider initialized ... dim: 768`;
134
+ - recall takes about 1 s;
135
+ - the API process uses about 360 MB of RAM.
136
+
137
+ ## Deploying a separate instance
138
+
139
+ Only when a project must run away from this Mac. Copy the directory (compose
140
+ file, `Dockerfile`, `login-*.sh`, README); do not copy `.env`, `codex-home/` or
141
+ `backups/`. Then:
142
+
143
+ 1. **New secrets.** Create a new `.env` with fresh `HINDSIGHT_DB_PASSWORD`,
144
+ `HINDSIGHT_API_KEY` and `HINDSIGHT_UI_ACCESS_KEY` (`openssl rand -hex 24`),
145
+ plus the Gemini and Jev keys.
146
+ 2. **A free subnet.** Pin `networks.default` to a free 10.x subnet. On this Mac,
147
+ an automatic pick lands on 192.168.0.0/20 and cuts containers off from the LAN.
148
+ 3. **Build for the host's own architecture.** The Dockerfile copies the native
149
+ Claude CLI binary for that platform.
150
+ 4. **Log in** with `login-claude.sh`, then `login-codex.sh`.
151
+ 5. **Verify** as in "Integrating a project", step 6.
152
+
153
+ ## Traps already paid for
154
+
155
+ - **Reranker.** A local cross-encoder reranker on the Mac's CPU took 36–97 s per
156
+ recall. Jev over the API, with `RECALL_MAX_CANDIDATES_PER_SOURCE=15`, takes
157
+ about 0.3 s. The recall budget does not bound the candidate pool; the
158
+ per-source cap does.
159
+ - **torch.** On arm64, the PyPI torch wheel pulls 3.3 GB of CUDA. Local models
160
+ are gone now; if they ever come back, install torch from the CPU index.
161
+ - **Codex models.** `gpt-5.4-mini` is refused on ChatGPT accounts; `gpt-6-luna`
162
+ works.
163
+ - **Reflect timeout.** It defaults to 30 s per LLM call, which is too short;
164
+ `HINDSIGHT_API_REFLECT_LLM_TIMEOUT=120`.
165
+ - **`HINDSIGHT_API_LLM_STRATEGY`.** It must be JSON (`{"mode": "failover"}`); a
166
+ bare word crashes startup.
167
+ - **Bank reads.** There is no GET for a single bank (405); list banks instead.
168
+ - **Deleting memories.** No endpoint hard-deletes one memory. Invalidate it, in
169
+ the UI or with `PATCH` `state: invalidated`, or delete its document.
170
+ - **Plugin workers (Paperclip).** Background calls must run outside host
171
+ invocations and name the company. The host expands array SQL parameters, so
172
+ pass lists as JSON. Details are in DEPLOY-DORAEMON.md.