seed-hosted-c-data.mjs
sha256:65ccb454656ea5acdea0a10e559b78bcde1eb6ff753ecc2911bc99d1c3d7cadd
feat(calendar): enforce agent context tiers in retrieval AP…
Human
minor
⚠ breaking
2 days ago
| 1 | #!/usr/bin/env node |
| 2 | /** |
| 3 | * Seed recognizable C-related demo notes into a Hub backend (hosted gateway + canister). |
| 4 | * |
| 5 | * Usage: |
| 6 | * KNOWTATION_HUB_URL="https://knowtation-gateway.netlify.app" \ |
| 7 | * KNOWTATION_HUB_TOKEN="<JWT from Hub after login>" \ |
| 8 | * node scripts/seed-hosted-c-data.mjs |
| 9 | * |
| 10 | * For repo-default demo notes (inbox / projects / areas), prefer: |
| 11 | * npm run seed:hosted-showcase |
| 12 | * (uploads everything under vault/showcase/). See docs/SHOWCASE-VAULT.md. |
| 13 | * |
| 14 | * Notes: |
| 15 | * - Idempotent: writes fixed paths under seed/c-data/ (re-running overwrites). |
| 16 | * - Safe: everything is namespaced under seed/c-data/ so you can delete later. |
| 17 | */ |
| 18 | |
| 19 | const hubUrl = (process.env.KNOWTATION_HUB_URL || process.env.HUB_URL || '').replace(/\/$/, ''); |
| 20 | const token = process.env.KNOWTATION_HUB_TOKEN || process.env.HUB_TOKEN || ''; |
| 21 | |
| 22 | if (!hubUrl) { |
| 23 | console.error('Missing KNOWTATION_HUB_URL (e.g. https://knowtation-gateway.netlify.app)'); |
| 24 | process.exit(2); |
| 25 | } |
| 26 | if (!token) { |
| 27 | console.error('Missing KNOWTATION_HUB_TOKEN (JWT from Hub after login)'); |
| 28 | process.exit(2); |
| 29 | } |
| 30 | |
| 31 | function fm(obj) { |
| 32 | return `---\n${Object.entries(obj) |
| 33 | .filter(([, v]) => v !== undefined && v !== null && v !== '') |
| 34 | .map(([k, v]) => { |
| 35 | if (Array.isArray(v)) return `${k}: [${v.map((x) => JSON.stringify(String(x))).join(', ')}]`; |
| 36 | if (typeof v === 'number') return `${k}: ${v}`; |
| 37 | return `${k}: ${JSON.stringify(String(v))}`; |
| 38 | }) |
| 39 | .join('\n')}\n---\n`; |
| 40 | } |
| 41 | |
| 42 | const nowIso = new Date().toISOString(); |
| 43 | const notes = [ |
| 44 | { |
| 45 | path: 'seed/c-data/README.md', |
| 46 | title: 'C seed data (demo)', |
| 47 | tags: ['seed', 'c', 'demo'], |
| 48 | project: 'seed', |
| 49 | body: `# C seed data (demo)\n\nC_DATA_SEED\n\nThese notes are intentionally obvious and repeatable.\n\n- Purpose: quick visual check that the hosted canister-backed vault is reading/writing correctly.\n- Namespace: \`seed/c-data/\`\n- Regenerate: run \`node scripts/seed-hosted-c-data.mjs\`\n\nCreated at: ${nowIso}\n`, |
| 50 | }, |
| 51 | { |
| 52 | path: 'seed/c-data/pointers-and-arrays.md', |
| 53 | title: 'Pointers and arrays', |
| 54 | tags: ['seed', 'c', 'pointers'], |
| 55 | project: 'seed', |
| 56 | body: `# Pointers and arrays\n\nC_DATA_SEED\n\n## Pointer basics\n\n\`\`\`c\nint x = 42;\nint *p = &x;\nprintf(\"%d\\n\", *p);\n\`\`\`\n\n## Arrays decay to pointers\n\n\`\`\`c\nint a[3] = {1,2,3};\nint *p = a; // same as &a[0]\nprintf(\"%d\\n\", p[1]);\n\`\`\`\n`, |
| 57 | }, |
| 58 | { |
| 59 | path: 'seed/c-data/structs-and-offsetof.md', |
| 60 | title: 'Structs, padding, offsetof', |
| 61 | tags: ['seed', 'c', 'struct'], |
| 62 | project: 'seed', |
| 63 | body: `# Structs, padding, offsetof\n\nC_DATA_SEED\n\n\`\`\`c\n#include <stddef.h>\n\ntypedef struct {\n char tag;\n int value;\n} Item;\n\nsize_t off = offsetof(Item, value);\n\`\`\`\n\n- Padding depends on ABI; \`offsetof\` is the reliable way to compute member offsets.\n`, |
| 64 | }, |
| 65 | { |
| 66 | path: 'seed/c-data/malloc-free.md', |
| 67 | title: 'malloc/free checklist', |
| 68 | tags: ['seed', 'c', 'memory'], |
| 69 | project: 'seed', |
| 70 | body: `# malloc/free checklist\n\nC_DATA_SEED\n\n- Always check allocation result.\n- Initialize memory if needed (\`calloc\` or \`memset\`).\n- Pair every successful allocation with exactly one \`free\`.\n- Avoid use-after-free: set pointer to NULL after freeing.\n\n\`\`\`c\nchar *buf = malloc(1024);\nif (!buf) return -1;\nmemset(buf, 0, 1024);\n/* ... */\nfree(buf);\nbuf = NULL;\n\`\`\`\n`, |
| 71 | }, |
| 72 | { |
| 73 | path: 'seed/c-data/strings-and-buffers.md', |
| 74 | title: 'Strings and buffers', |
| 75 | tags: ['seed', 'c', 'strings'], |
| 76 | project: 'seed', |
| 77 | body: `# Strings and buffers\n\nC_DATA_SEED\n\nPrefer bounded operations:\n\n\`\`\`c\nsnprintf(out, out_cap, \"%s:%d\", name, port);\n\`\`\`\n\nKnow what null-termination guarantees apply for each function you use.\n`, |
| 78 | }, |
| 79 | { |
| 80 | path: 'seed/c-data/error-handling-patterns.md', |
| 81 | title: 'Error handling patterns (C)', |
| 82 | tags: ['seed', 'c', 'errors'], |
| 83 | project: 'seed', |
| 84 | body: `# Error handling patterns (C)\n\nC_DATA_SEED\n\nA common pattern is \`goto cleanup\` to keep resource release correct.\n\n\`\`\`c\nint rc = 0;\nFILE *f = fopen(path, \"rb\");\nif (!f) { rc = -1; goto cleanup; }\n\n/* ... */\n\ncleanup:\nif (f) fclose(f);\nreturn rc;\n\`\`\`\n`, |
| 85 | }, |
| 86 | ]; |
| 87 | |
| 88 | async function writeNote(n) { |
| 89 | const frontmatter = fm({ |
| 90 | title: n.title, |
| 91 | project: n.project, |
| 92 | tags: n.tags, |
| 93 | seed: true, |
| 94 | seed_kind: 'c-data', |
| 95 | created_at: nowIso, |
| 96 | }); |
| 97 | const body = frontmatter + '\n' + n.body; |
| 98 | |
| 99 | const r = await fetch(`${hubUrl}/api/v1/notes`, { |
| 100 | method: 'POST', |
| 101 | headers: { |
| 102 | Authorization: `Bearer ${token}`, |
| 103 | 'Content-Type': 'application/json', |
| 104 | }, |
| 105 | body: JSON.stringify({ path: n.path, body }), |
| 106 | }); |
| 107 | const text = await r.text(); |
| 108 | if (!r.ok) { |
| 109 | throw new Error(`POST /api/v1/notes failed (${r.status}): ${text}`); |
| 110 | } |
| 111 | return text; |
| 112 | } |
| 113 | |
| 114 | const results = []; |
| 115 | for (const n of notes) { |
| 116 | process.stdout.write(`Seeding ${n.path} ... `); |
| 117 | // eslint-disable-next-line no-await-in-loop |
| 118 | await writeNote(n); |
| 119 | process.stdout.write('ok\n'); |
| 120 | results.push(n.path); |
| 121 | } |
| 122 | |
| 123 | console.log(`\nSeed complete (${results.length} notes). Open Hub → Notes and look under seed/c-data/.`); |
File History
2 commits
sha256:65ccb454656ea5acdea0a10e559b78bcde1eb6ff753ecc2911bc99d1c3d7cadd
feat(calendar): enforce agent context tiers in retrieval AP…
Human
minor
⚠
2 days ago
sha256:9103f98c89257ed2b01c237cea895dabb3e85ea337dccb1161c175e4422355b6
docs: accept Calendar Events v0 spec with Phase 0 security …
Human
2 days ago