sisyo 1.5.1 → 1.6.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +16 -16
- package/README.md +161 -139
- package/bin/known-hashes.json +71 -0
- package/bin/sisyo.js +200 -78
- package/package.json +30 -26
- package/templates/.claude/rules/docs.md +19 -19
- package/templates/.claude/skills/gemini-integration/GENERATE.md +111 -0
- package/templates/.claude/skills/gemini-integration/LIVE-VOICE.md +242 -0
- package/templates/.claude/skills/gemini-integration/RAG-EMBEDDING.md +93 -0
- package/templates/.claude/skills/gemini-integration/SKILL.md +157 -0
- package/templates/.claude/skills/gemini-integration/TEXT-CHAT.md +133 -0
- package/templates/.claude/skills/gemini-integration/TROUBLESHOOTING.md +67 -0
- package/templates/.claude/skills/html-docs/SKILL.md +207 -207
- package/templates/.claude/skills/terraform-best-practices/SKILL.md +341 -341
- package/templates/.claude/skills/typesafe-jev/SKILL.md +149 -0
- package/templates/.claude/skills/vibe-docs/SKILL.md +242 -242
- package/templates/SISYO.md +37 -37
- package/templates/docs/99_progress/features.md +7 -7
- package/templates/docs/99_progress/handoff.md +19 -19
- package/templates/docs/99_progress/todo.md +15 -15
- package/templates/docs/MAP.md +26 -26
package/bin/sisyo.js
CHANGED
|
@@ -2,10 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
const fs = require("fs");
|
|
4
4
|
const path = require("path");
|
|
5
|
+
const crypto = require("crypto");
|
|
5
6
|
|
|
6
7
|
const RESET = "\x1b[0m";
|
|
7
8
|
const GREEN = "\x1b[32m";
|
|
8
9
|
const YELLOW = "\x1b[33m";
|
|
10
|
+
const RED = "\x1b[31m";
|
|
9
11
|
const CYAN = "\x1b[36m";
|
|
10
12
|
const BOLD = "\x1b[1m";
|
|
11
13
|
const DIM = "\x1b[2m";
|
|
@@ -13,70 +15,136 @@ const DIM = "\x1b[2m";
|
|
|
13
15
|
function log(msg) { console.log(msg); }
|
|
14
16
|
function ok(msg) { log(`${GREEN}+${RESET} ${msg}`); }
|
|
15
17
|
function up(msg) { log(`${YELLOW}~${RESET} ${msg}`); }
|
|
18
|
+
function warn(msg) { log(`${RED}!${RESET} ${msg}`); }
|
|
16
19
|
function info(msg) { log(`${DIM} ${msg}${RESET}`); }
|
|
17
20
|
|
|
18
|
-
|
|
19
|
-
const SYSTEM_FILES = [
|
|
20
|
-
"SISYO.md",
|
|
21
|
-
".claude/rules/docs.md",
|
|
22
|
-
".claude/skills/vibe-docs/SKILL.md",
|
|
23
|
-
];
|
|
21
|
+
const PKG = require(path.join(__dirname, "..", "package.json"));
|
|
24
22
|
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
// ---------------------------------------------------------------------------
|
|
24
|
+
// Ownership model
|
|
25
|
+
//
|
|
26
|
+
// MANAGED (sisyo-owned) — everything under .claude/ that ships in templates/
|
|
27
|
+
// (rules/docs.md, skills/*). Replaced on --update, but ONLY
|
|
28
|
+
// when the local copy is byte-identical to what sisyo last
|
|
29
|
+
// installed (tracked by hash in the manifest). A locally
|
|
30
|
+
// edited managed file is never overwritten: the new version
|
|
31
|
+
// is written next to it as <file>.sisyo-new instead.
|
|
32
|
+
//
|
|
33
|
+
// USER-OWNED — SISYO.md, CLAUDE.md, docs/**. Created once if missing,
|
|
34
|
+
// never touched again, not even with --force.
|
|
35
|
+
//
|
|
36
|
+
// The manifest (.claude/sisyo.json) records the installed sisyo version and the hash
|
|
37
|
+
// of every managed file as sisyo wrote it.
|
|
38
|
+
// ---------------------------------------------------------------------------
|
|
39
|
+
|
|
40
|
+
const MANIFEST_REL = ".claude/sisyo.json";
|
|
41
|
+
const NEW_SUFFIX = ".sisyo-new";
|
|
42
|
+
|
|
43
|
+
function toPosix(p) { return p.split(path.sep).join("/"); }
|
|
44
|
+
function isManaged(rel) { return rel.startsWith(".claude/") && rel !== MANIFEST_REL; }
|
|
45
|
+
// Hash with line endings normalized: git autocrlf rewrites LF <-> CRLF on checkout, and
|
|
46
|
+
// that must not make an untouched file look "modified locally".
|
|
47
|
+
function sha256(buf) {
|
|
48
|
+
const text = buf.toString("utf8").replace(/\r\n/g, "\n");
|
|
49
|
+
return crypto.createHash("sha256").update(text).digest("hex");
|
|
50
|
+
}
|
|
51
|
+
function hashFile(p) { return sha256(fs.readFileSync(p)); }
|
|
52
|
+
|
|
53
|
+
// Hashes of every version of each managed file sisyo has ever shipped (from git history).
|
|
54
|
+
// Lets an install that predates the manifest (< v1.6) be recognised as untouched.
|
|
55
|
+
function readKnownHashes() {
|
|
56
|
+
try { return require(path.join(__dirname, "known-hashes.json")); } catch { return {}; }
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function readManifest(target) {
|
|
60
|
+
const p = path.join(target, MANIFEST_REL);
|
|
61
|
+
if (!fs.existsSync(p)) return null;
|
|
62
|
+
try {
|
|
63
|
+
const m = JSON.parse(fs.readFileSync(p, "utf8"));
|
|
64
|
+
return { version: m.version || "unknown", files: m.files || {} };
|
|
65
|
+
} catch {
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
27
68
|
}
|
|
28
69
|
|
|
29
|
-
function
|
|
70
|
+
function writeManifest(target, files) {
|
|
71
|
+
const p = path.join(target, MANIFEST_REL);
|
|
72
|
+
fs.mkdirSync(path.dirname(p), { recursive: true });
|
|
73
|
+
const sorted = {};
|
|
74
|
+
for (const k of Object.keys(files).sort()) sorted[k] = files[k];
|
|
75
|
+
fs.writeFileSync(p, JSON.stringify({ version: PKG.version, files: sorted }, null, 2) + "\n");
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function listTemplateFiles(dir, base = dir) {
|
|
79
|
+
const out = [];
|
|
80
|
+
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
81
|
+
const full = path.join(dir, entry.name);
|
|
82
|
+
if (entry.isDirectory()) out.push(...listTemplateFiles(full, base));
|
|
83
|
+
else out.push({ rel: toPosix(path.relative(base, full)), src: full });
|
|
84
|
+
}
|
|
85
|
+
return out;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function ensureClaudeMdImport(target, dryRun) {
|
|
30
89
|
const claudePath = path.join(target, "CLAUDE.md");
|
|
31
90
|
const importLine = "@SISYO.md";
|
|
32
91
|
if (fs.existsSync(claudePath)) {
|
|
33
92
|
const content = fs.readFileSync(claudePath, "utf8");
|
|
34
93
|
if (!content.includes(importLine)) {
|
|
35
|
-
fs.appendFileSync(claudePath, `\n${importLine}\n`);
|
|
94
|
+
if (!dryRun) fs.appendFileSync(claudePath, `\n${importLine}\n`);
|
|
36
95
|
up("CLAUDE.md (added @SISYO.md import)");
|
|
37
96
|
}
|
|
38
97
|
} else {
|
|
39
|
-
fs.writeFileSync(claudePath, `${importLine}\n`);
|
|
98
|
+
if (!dryRun) fs.writeFileSync(claudePath, `${importLine}\n`);
|
|
40
99
|
ok("CLAUDE.md");
|
|
41
100
|
}
|
|
42
101
|
}
|
|
43
102
|
|
|
44
|
-
function
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
continue;
|
|
61
|
-
}
|
|
62
|
-
fs.copyFileSync(srcPath, destPath);
|
|
63
|
-
ok(rel);
|
|
103
|
+
function fillDates(target, onlyRels) {
|
|
104
|
+
const today = new Date().toISOString().split("T")[0];
|
|
105
|
+
const files = [
|
|
106
|
+
"docs/MAP.md",
|
|
107
|
+
"docs/99_progress/handoff.md",
|
|
108
|
+
"docs/99_progress/todo.md",
|
|
109
|
+
"docs/99_progress/features.md",
|
|
110
|
+
];
|
|
111
|
+
for (const rel of files) {
|
|
112
|
+
if (!onlyRels.has(rel)) continue; // never rewrite docs that already existed
|
|
113
|
+
const p = path.join(target, rel);
|
|
114
|
+
if (!fs.existsSync(p)) continue;
|
|
115
|
+
const content = fs.readFileSync(p, "utf8");
|
|
116
|
+
if (content.includes("YYYY-MM-DD")) {
|
|
117
|
+
fs.writeFileSync(p, content.replace(/YYYY-MM-DD/g, today));
|
|
64
118
|
}
|
|
65
119
|
}
|
|
66
120
|
}
|
|
67
121
|
|
|
122
|
+
function ensureGitignore(target, dryRun) {
|
|
123
|
+
const gitignorePath = path.join(target, ".gitignore");
|
|
124
|
+
if (!fs.existsSync(gitignorePath)) return;
|
|
125
|
+
const gitignore = fs.readFileSync(gitignorePath, "utf8");
|
|
126
|
+
const lines = [];
|
|
127
|
+
if (!gitignore.includes("CLAUDE.local.md")) lines.push("CLAUDE.local.md", ".claude/settings.local.json");
|
|
128
|
+
if (!gitignore.includes(NEW_SUFFIX)) lines.push(`*${NEW_SUFFIX}`);
|
|
129
|
+
if (lines.length === 0) return;
|
|
130
|
+
if (!dryRun) fs.appendFileSync(gitignorePath, "\n# Claude Code local\n" + lines.join("\n") + "\n");
|
|
131
|
+
ok(".gitignore updated");
|
|
132
|
+
}
|
|
133
|
+
|
|
68
134
|
function main() {
|
|
69
135
|
const args = process.argv.slice(2);
|
|
70
136
|
const updateMode = args.includes("--update");
|
|
137
|
+
const force = args.includes("--force");
|
|
138
|
+
const dryRun = args.includes("--dry-run");
|
|
71
139
|
const targetDir = args.find(a => !a.startsWith("-")) || ".";
|
|
72
140
|
const target = path.resolve(targetDir);
|
|
73
141
|
const templatesDir = path.join(__dirname, "..", "templates");
|
|
74
142
|
|
|
75
143
|
log("");
|
|
76
144
|
if (updateMode) {
|
|
77
|
-
log(`${BOLD}${CYAN}sisyo${RESET} ${DIM}
|
|
145
|
+
log(`${BOLD}${CYAN}sisyo${RESET} ${DIM}v${PKG.version} — updating managed files${force ? " (force)" : ""}${dryRun ? " (dry-run)" : ""}${RESET}`);
|
|
78
146
|
} else {
|
|
79
|
-
log(`${BOLD}${CYAN}sisyo${RESET} ${DIM}Smart docs for Claude Code${RESET}`);
|
|
147
|
+
log(`${BOLD}${CYAN}sisyo${RESET} ${DIM}v${PKG.version} — Smart docs for Claude Code${dryRun ? " (dry-run)" : ""}${RESET}`);
|
|
80
148
|
}
|
|
81
149
|
log("");
|
|
82
150
|
|
|
@@ -85,69 +153,114 @@ function main() {
|
|
|
85
153
|
process.exit(1);
|
|
86
154
|
}
|
|
87
155
|
|
|
88
|
-
|
|
89
|
-
|
|
156
|
+
const manifest = readManifest(target);
|
|
157
|
+
const prevFiles = manifest ? manifest.files : {};
|
|
158
|
+
const nextFiles = {};
|
|
159
|
+
const conflicts = [];
|
|
160
|
+
const known = readKnownHashes();
|
|
161
|
+
const addedRels = new Set();
|
|
162
|
+
let updated = 0, added = 0, unchanged = 0;
|
|
90
163
|
|
|
91
|
-
|
|
92
|
-
|
|
164
|
+
if (updateMode && manifest) info(`installed: v${manifest.version} → v${PKG.version}`);
|
|
165
|
+
if (updateMode && !manifest) {
|
|
166
|
+
info("no manifest found (installed before v1.6). Files identical to an older sisyo");
|
|
167
|
+
info("release are updated; anything else is treated as locally modified.");
|
|
168
|
+
}
|
|
93
169
|
|
|
94
|
-
|
|
95
|
-
|
|
170
|
+
const templates = listTemplateFiles(templatesDir);
|
|
171
|
+
|
|
172
|
+
for (const { rel, src } of templates) {
|
|
173
|
+
const dest = path.join(target, rel);
|
|
174
|
+
const managed = isManaged(rel);
|
|
175
|
+
const srcBuf = fs.readFileSync(src);
|
|
176
|
+
const srcHash = sha256(srcBuf);
|
|
96
177
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
let mapContent = fs.readFileSync(mapPath, "utf8");
|
|
102
|
-
if (mapContent.includes("YYYY-MM-DD")) {
|
|
103
|
-
mapContent = mapContent.replace(/YYYY-MM-DD/g, today);
|
|
104
|
-
fs.writeFileSync(mapPath, mapContent);
|
|
178
|
+
if (!fs.existsSync(dest)) {
|
|
179
|
+
if (!dryRun) {
|
|
180
|
+
fs.mkdirSync(path.dirname(dest), { recursive: true });
|
|
181
|
+
fs.writeFileSync(dest, srcBuf);
|
|
105
182
|
}
|
|
183
|
+
if (managed) nextFiles[rel] = srcHash;
|
|
184
|
+
ok(rel);
|
|
185
|
+
addedRels.add(rel);
|
|
186
|
+
added++;
|
|
187
|
+
continue;
|
|
106
188
|
}
|
|
107
189
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
if (content.includes("YYYY-MM-DD")) {
|
|
112
|
-
content = content.replace(/YYYY-MM-DD/g, today);
|
|
113
|
-
fs.writeFileSync(handoffPath, content);
|
|
114
|
-
}
|
|
190
|
+
if (!managed) {
|
|
191
|
+
info(`skip ${rel} (yours)`);
|
|
192
|
+
continue;
|
|
115
193
|
}
|
|
116
194
|
|
|
117
|
-
const
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
195
|
+
const curHash = hashFile(dest);
|
|
196
|
+
const newPath = dest + NEW_SUFFIX;
|
|
197
|
+
|
|
198
|
+
if (curHash === srcHash) {
|
|
199
|
+
nextFiles[rel] = srcHash;
|
|
200
|
+
unchanged++;
|
|
201
|
+
if (fs.existsSync(newPath) && !dryRun) fs.unlinkSync(newPath); // resolved by hand
|
|
202
|
+
continue;
|
|
124
203
|
}
|
|
125
204
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
205
|
+
if (!updateMode) {
|
|
206
|
+
info(`skip ${rel} (exists — run with --update)`);
|
|
207
|
+
nextFiles[rel] = prevFiles[rel] || curHash;
|
|
208
|
+
continue;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// Untouched = identical to what the manifest says sisyo installed, or (no manifest
|
|
212
|
+
// entry, i.e. installed before v1.6) identical to some version sisyo once shipped.
|
|
213
|
+
const pristine = prevFiles[rel] !== undefined
|
|
214
|
+
? prevFiles[rel] === curHash
|
|
215
|
+
: (known[rel] || []).includes(curHash);
|
|
216
|
+
if (pristine || force) {
|
|
217
|
+
if (!dryRun) {
|
|
218
|
+
fs.writeFileSync(dest, srcBuf);
|
|
219
|
+
if (fs.existsSync(newPath)) fs.unlinkSync(newPath);
|
|
132
220
|
}
|
|
221
|
+
nextFiles[rel] = srcHash;
|
|
222
|
+
up(`${rel} (updated${force && !pristine ? ", overwrote local edits" : ""})`);
|
|
223
|
+
updated++;
|
|
224
|
+
continue;
|
|
133
225
|
}
|
|
226
|
+
|
|
227
|
+
// Locally modified → keep theirs, drop the new version next to it.
|
|
228
|
+
if (!dryRun) fs.writeFileSync(newPath, srcBuf);
|
|
229
|
+
nextFiles[rel] = prevFiles[rel] || curHash;
|
|
230
|
+
warn(`${rel} modified locally — kept yours, new version at ${rel}${NEW_SUFFIX}`);
|
|
231
|
+
conflicts.push(rel);
|
|
134
232
|
}
|
|
135
233
|
|
|
136
|
-
//
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
const
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
)
|
|
144
|
-
|
|
234
|
+
// Managed files sisyo no longer ships: remove only if still pristine.
|
|
235
|
+
if (updateMode) {
|
|
236
|
+
const shipped = new Set(templates.map(t => t.rel));
|
|
237
|
+
for (const rel of Object.keys(prevFiles)) {
|
|
238
|
+
if (shipped.has(rel)) continue;
|
|
239
|
+
const dest = path.join(target, rel);
|
|
240
|
+
if (!fs.existsSync(dest)) continue;
|
|
241
|
+
if (hashFile(dest) === prevFiles[rel]) {
|
|
242
|
+
if (!dryRun) {
|
|
243
|
+
fs.unlinkSync(dest);
|
|
244
|
+
try { fs.rmdirSync(path.dirname(dest)); } catch { /* not empty — keep */ }
|
|
245
|
+
}
|
|
246
|
+
up(`${rel} (removed — no longer shipped)`);
|
|
247
|
+
} else {
|
|
248
|
+
warn(`${rel} no longer shipped by sisyo but modified locally — left in place`);
|
|
249
|
+
nextFiles[rel] = prevFiles[rel];
|
|
250
|
+
}
|
|
145
251
|
}
|
|
146
252
|
}
|
|
147
253
|
|
|
254
|
+
ensureClaudeMdImport(target, dryRun);
|
|
255
|
+
if (!dryRun) fillDates(target, addedRels);
|
|
256
|
+
ensureGitignore(target, dryRun);
|
|
257
|
+
if (!dryRun) writeManifest(target, nextFiles);
|
|
258
|
+
|
|
148
259
|
log("");
|
|
149
|
-
if (
|
|
150
|
-
log(`${BOLD}
|
|
260
|
+
if (dryRun) {
|
|
261
|
+
log(`${BOLD}Dry run.${RESET} +${added} added, ~${updated} updated, ${unchanged} unchanged, ${conflicts.length} conflicts. Nothing written.`);
|
|
262
|
+
} else if (updateMode) {
|
|
263
|
+
log(`${BOLD}Done!${RESET} +${added} added, ~${updated} updated, ${unchanged} unchanged. Your SISYO.md, CLAUDE.md and docs/ are untouched.`);
|
|
151
264
|
} else {
|
|
152
265
|
log(`${BOLD}Done!${RESET} Next steps:`);
|
|
153
266
|
log("");
|
|
@@ -155,6 +268,15 @@ function main() {
|
|
|
155
268
|
log(` 2. Open Claude Code and start building`);
|
|
156
269
|
log(` 3. Docs auto-update as you work`);
|
|
157
270
|
}
|
|
271
|
+
if (conflicts.length > 0) {
|
|
272
|
+
log("");
|
|
273
|
+
log(`${RED}${conflicts.length} file(s) were modified locally and NOT overwritten:${RESET}`);
|
|
274
|
+
for (const rel of conflicts) log(` ${rel} → ${rel}${NEW_SUFFIX}`);
|
|
275
|
+
log("");
|
|
276
|
+
log(` Review: git diff --no-index <file> <file>${NEW_SUFFIX}`);
|
|
277
|
+
log(` Accept: move the ${NEW_SUFFIX} file over the original, or rerun with ${CYAN}--force${RESET}`);
|
|
278
|
+
log(` Keep: delete the ${NEW_SUFFIX} file (sisyo will offer it again next update)`);
|
|
279
|
+
}
|
|
158
280
|
log("");
|
|
159
281
|
log(`${DIM}Docs system: SISYO.md -> docs/MAP.md -> _summary.md -> detail files${RESET}`);
|
|
160
282
|
log("");
|
package/package.json
CHANGED
|
@@ -1,26 +1,30 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "sisyo",
|
|
3
|
-
"version": "1.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
|
-
"
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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,19 +1,19 @@
|
|
|
1
|
-
# Doc Management Rule
|
|
2
|
-
|
|
3
|
-
3-level routing: MAP.md → _summary.md → detail files.
|
|
4
|
-
|
|
5
|
-
When changing code that affects project structure or behavior:
|
|
6
|
-
1. Read docs/MAP.md to find relevant folder
|
|
7
|
-
2. Read _summary.md of that folder (if exists)
|
|
8
|
-
3. Update detail file (or create if new)
|
|
9
|
-
4. Update _summary.md table
|
|
10
|
-
5. Update MAP.md summary line
|
|
11
|
-
|
|
12
|
-
When a feature is completed or added:
|
|
13
|
-
- Log it in docs/99_progress/features.md (date, name, status, link to spec)
|
|
14
|
-
|
|
15
|
-
Before ending session or when context gets large:
|
|
16
|
-
- Write docs/99_progress/handoff.md
|
|
17
|
-
|
|
18
|
-
At session start:
|
|
19
|
-
- Read docs/MAP.md then docs/99_progress/handoff.md
|
|
1
|
+
# Doc Management Rule
|
|
2
|
+
|
|
3
|
+
3-level routing: MAP.md → _summary.md → detail files.
|
|
4
|
+
|
|
5
|
+
When changing code that affects project structure or behavior:
|
|
6
|
+
1. Read docs/MAP.md to find relevant folder
|
|
7
|
+
2. Read _summary.md of that folder (if exists)
|
|
8
|
+
3. Update detail file (or create if new)
|
|
9
|
+
4. Update _summary.md table
|
|
10
|
+
5. Update MAP.md summary line
|
|
11
|
+
|
|
12
|
+
When a feature is completed or added:
|
|
13
|
+
- Log it in docs/99_progress/features.md (date, name, status, link to spec)
|
|
14
|
+
|
|
15
|
+
Before ending session or when context gets large:
|
|
16
|
+
- Write docs/99_progress/handoff.md
|
|
17
|
+
|
|
18
|
+
At session start:
|
|
19
|
+
- Read docs/MAP.md then docs/99_progress/handoff.md
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
# One-shot Generate (JSON, grounding, PDF, TTS)
|
|
2
|
+
|
|
3
|
+
Use `client.models.generate_content` on `GEMINI_GENERATE_MODEL` for offline / admin work
|
|
4
|
+
(config generation, Q&A generation, document extraction). Never on the interactive chat path.
|
|
5
|
+
|
|
6
|
+
## JSON output
|
|
7
|
+
|
|
8
|
+
```python
|
|
9
|
+
resp = client.models.generate_content(
|
|
10
|
+
model=settings.GEMINI_GENERATE_MODEL,
|
|
11
|
+
contents=prompt,
|
|
12
|
+
config={
|
|
13
|
+
"system_instruction": SYS,
|
|
14
|
+
"response_mime_type": "application/json",
|
|
15
|
+
"thinking_config": {"thinking_level": "low"},
|
|
16
|
+
},
|
|
17
|
+
)
|
|
18
|
+
data = _parse_json(resp.text or "")
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
```python
|
|
22
|
+
def _parse_json(text: str) -> dict:
|
|
23
|
+
text = text.strip()
|
|
24
|
+
try:
|
|
25
|
+
return json.loads(text)
|
|
26
|
+
except Exception:
|
|
27
|
+
pass
|
|
28
|
+
m = re.search(r"\{.*\}", text, flags=re.DOTALL) # tolerate ```json fences / prose
|
|
29
|
+
if m:
|
|
30
|
+
try:
|
|
31
|
+
return json.loads(m.group(0))
|
|
32
|
+
except Exception:
|
|
33
|
+
pass
|
|
34
|
+
return {}
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Always parse defensively and have a fallback (empty dict, original order, etc.).
|
|
38
|
+
|
|
39
|
+
## Grounding: Google Search + URL context
|
|
40
|
+
|
|
41
|
+
For "generate an agent config from this business URL" style tasks:
|
|
42
|
+
|
|
43
|
+
```python
|
|
44
|
+
from google.genai import types
|
|
45
|
+
|
|
46
|
+
resp = client.models.generate_content(
|
|
47
|
+
model=settings.GEMINI_GENERATE_MODEL,
|
|
48
|
+
contents=prompt_with_urls,
|
|
49
|
+
config={
|
|
50
|
+
"system_instruction": GENERATE_PROMPT,
|
|
51
|
+
"tools": [
|
|
52
|
+
types.Tool(google_search=types.GoogleSearch()),
|
|
53
|
+
types.Tool(url_context=types.UrlContext()),
|
|
54
|
+
],
|
|
55
|
+
},
|
|
56
|
+
)
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
- Tell the model in the system prompt to browse the URLs first and search for the business
|
|
60
|
+
before generating; otherwise it invents data.
|
|
61
|
+
- When regenerating (e.g. "10 more Q&A"), pass the existing items and say "do NOT duplicate".
|
|
62
|
+
- Grounded calls are slow (seconds) — run them from admin endpoints / background jobs only.
|
|
63
|
+
|
|
64
|
+
## PDF / document extraction
|
|
65
|
+
|
|
66
|
+
Send the file bytes inline and ask for Markdown. Cap size (~19 MB inline limit).
|
|
67
|
+
|
|
68
|
+
```python
|
|
69
|
+
from google.genai import types
|
|
70
|
+
|
|
71
|
+
resp = client.models.generate_content(
|
|
72
|
+
model=settings.GEMINI_GENERATE_MODEL,
|
|
73
|
+
contents=[
|
|
74
|
+
types.Part.from_bytes(data=pdf_bytes, mime_type="application/pdf"),
|
|
75
|
+
"Extract ALL text from this document as clean Markdown. Preserve tables as Markdown "
|
|
76
|
+
"tables and keep headings in reading order. Output only the extracted content.",
|
|
77
|
+
],
|
|
78
|
+
)
|
|
79
|
+
text = (resp.text or "").strip()
|
|
80
|
+
if not text:
|
|
81
|
+
raise ValueError("PDF text extraction returned no text (scanned/empty document?)")
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Raise a `ValueError` with a short message on failure so the upload UI can show it.
|
|
85
|
+
|
|
86
|
+
## TTS (voice sample clips)
|
|
87
|
+
|
|
88
|
+
```python
|
|
89
|
+
resp = client.models.generate_content(
|
|
90
|
+
model=settings.GEMINI_TTS_MODEL,
|
|
91
|
+
contents=text,
|
|
92
|
+
config={
|
|
93
|
+
"response_modalities": ["AUDIO"],
|
|
94
|
+
"speech_config": {"voice_config": {"prebuilt_voice_config": {"voice_name": voice_name}}},
|
|
95
|
+
},
|
|
96
|
+
)
|
|
97
|
+
pcm = b"".join(p.inline_data.data for p in resp.candidates[0].content.parts
|
|
98
|
+
if p.inline_data and p.inline_data.data)
|
|
99
|
+
# → wrap as WAV: mono, 16-bit, 24000 Hz
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Rules for TTS previews:
|
|
103
|
+
|
|
104
|
+
- **Pre-generate and cache** (S3 / disk) every voice × language at startup in a background
|
|
105
|
+
thread; the play button must be a URL lookup, never a live TTS wait.
|
|
106
|
+
- Key clips by a version string (`voice-samples/v1/{voice}_{lang}.wav`). Bump the version when
|
|
107
|
+
the sample text or TTS model changes; provide a `--force` regenerate script.
|
|
108
|
+
- Pace calls (`sleep 1s` between, `5s` after a failure) to stay under rate limits; one bad clip
|
|
109
|
+
must not stop the batch.
|
|
110
|
+
- Voice ids: Live API subset (`Kore, Puck, Charon, Aoede, Fenrir, Leda, Orus, Zephyr`).
|
|
111
|
+
Store the Gemini id; show friendly names in the UI. Unknown id → default `Kore`.
|