@takeokunn/gbrainx 0.1.0 → 0.1.2

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/README.md CHANGED
@@ -1,39 +1,45 @@
1
1
  # @takeokunn/gbrainx
2
2
 
3
- GbrainX runs a local app for searching and using knowledge packs. It can import purchased packs into a GBrain folder.
3
+ The local app and command line for GbrainX, a marketplace for verified, secret-scrubbed [GBrain](https://github.com/garrytan/gbrain) memory packs. It serves the compile gates that turn exported GBrain pages into packs, serves packs to Claude Code through [`@takeokunn/gbrainx-mcp`](https://www.npmjs.com/package/@takeokunn/gbrainx-mcp), and imports purchased packs into a GBrain folder.
4
4
 
5
- ## Start
5
+ ## Quick start
6
6
 
7
- Requires Node.js 22 or later. Run:
7
+ Requires Node.js 22.13 or later.
8
8
 
9
9
  ```sh
10
- npx @takeokunn/gbrainx
10
+ npx -y @takeokunn/gbrainx [brain-directory]
11
11
  ```
12
12
 
13
- Open <http://127.0.0.1:4747> in your browser.
13
+ Open <http://127.0.0.1:4747/app>. The optional `brain-directory` is a folder of exported Markdown pages (for example from `gbrain export --dir ./my-brain-export`). It only seeds a store that does not exist yet.
14
14
 
15
- ## Import a purchased pack
16
-
17
- First start the local app to initialize its store and purchase a pack. Replace `example-pack` with the purchased pack ID.
15
+ To let Claude Code search, buy and load packs from the running app:
18
16
 
19
17
  ```sh
20
- npx @takeokunn/gbrainx import example-pack --to ~/brain
18
+ claude mcp add gbrainx -- npx -y @takeokunn/gbrainx-mcp
21
19
  ```
22
20
 
23
- The destination defaults to `~/brain` when `--to` is omitted. Import stops if a file would conflict with an existing file. Add `--force` to overwrite conflicting files.
21
+ ## Commands
24
22
 
25
- ## Clear the cache
23
+ | Command | What it does |
24
+ | --- | --- |
25
+ | `npx -y @takeokunn/gbrainx [brain-directory]` | Start the app and its local API on `127.0.0.1:4747`. |
26
+ | `npx -y @takeokunn/gbrainx import <packId> [--to <dir>] [--force]` | Write a purchased pack into `<dir>` (default `~/brain`) as Markdown with front matter, keeping `[[wikilinks]]`. It stops on an existing file unless `--force` is given, and prints the `gbrain import` command to run next. It never writes into GBrain itself. |
27
+ | `npx -y @takeokunn/gbrainx cache clear` | Delete `~/.gbrainx/cache`. |
26
28
 
27
- The MCP server caches loaded pack content under `~/.gbrainx/cache/`. To clear it, run:
29
+ `import` reads the store, so start the app and buy the pack first. Imported pages carry `source: gbrainx` and are left out when you compile your own packs.
28
30
 
29
- ```sh
30
- npx @takeokunn/gbrainx cache clear
31
- ```
31
+ ## Data
32
+
33
+ - `~/.gbrainx/store.json` holds pages, packs, wallet and purchases. `GBRAINX_STORE_DIR` selects another folder.
34
+ - `~/.gbrainx/cache/` holds content the MCP server has loaded.
32
35
 
33
- ## MCP server
36
+ ## Limits
34
37
 
35
- The separate `@takeokunn/gbrainx-mcp` package connects an MCP client to the local app. Start the local app before using the MCP server.
38
+ - The app listens on `127.0.0.1:4747` only.
39
+ - Purchases move a balance inside the local store; no real payment is made. A purchase is refused when the match score is below 0.5, or when it exceeds the per-purchase cap, the session cap or the balance.
40
+ - The `/api/claude/*` gate endpoints run `claude -p`: they need a logged-in Claude Code and send page text to the model. `GBRAINX_CLAUDE_EXECUTABLE` selects another executable.
41
+ - The `/app` screen keeps its data in browser storage. It does not call those endpoints or share data with the local store.
36
42
 
37
- ## License
43
+ ## Links
38
44
 
39
- MIT
45
+ [Source and issues](https://github.com/takeokunn/gbrainx) · [MCP server](https://www.npmjs.com/package/@takeokunn/gbrainx-mcp) · MIT
package/dist/core.mjs CHANGED
@@ -741,6 +741,50 @@ function evaluateKeywords(markdown, keywords) {
741
741
  missing
742
742
  };
743
743
  }
744
+ // ../core/src/double-charge-seed.ts
745
+ var doubleChargeSeed = {
746
+ "id": "stripe-double-charge-prevention",
747
+ "title": "Stripe Double-Charge Prevention",
748
+ "version": "v1",
749
+ "domain": "payments",
750
+ "errorSignatures": [
751
+ "double charge",
752
+ "charged twice",
753
+ "idempotency",
754
+ "orderKey",
755
+ "stripe double charge on retry"
756
+ ],
757
+ "nodes": [
758
+ "stripe-idempotency",
759
+ "payment-retries",
760
+ "webhook-dedupe"
761
+ ],
762
+ "markdown": "## [[stripe-idempotency]]\n\n# Stripe idempotency\n\nImport `orderKey` from `./pay-client.mjs` and use `payClient.charge(order, { orderKey: orderKey(order) })`. The key is derived from `order.merchantId`, `order.id`, and `order.revision`. Retry the same operation with the same values. A new revision represents a new operation. The client does not use `Idempotency-Key` for deduplication.\n\nSee [[payment-retries]] for retry handling and [[webhook-dedupe]] for duplicate events.\n\n\n## [[payment-retries]]\n\n# Payment retries\n\nRetry the same checkout operation with the same `order.merchantId`, `order.id`, and `order.revision`. Import `orderKey` from `./pay-client.mjs` and pass `orderKey(order)` as the `orderKey` option to `payClient.charge`. Generating a new key for each attempt can create a duplicate charge.\n\nSee [[stripe-idempotency]] and [[webhook-dedupe]] for the charge and event boundaries.\n\n\n## [[webhook-dedupe]]\n\n# Webhook deduplication\n\nUse the webhook event ID to detect duplicate deliveries before applying the event's effects. Record the ID only when processing succeeds, so a failed delivery can be retried.\n\nSee [[stripe-idempotency]] for checkout keys and [[payment-retries]] for retries.\n\n\n## Sources\n\n- [[stripe-idempotency]]\n- [[payment-retries]]\n- [[webhook-dedupe]]",
763
+ "summary": "## symptom\n\nRetries can produce a duplicate charge. [payment-retries#2]\n\n## cause\n\nA new key on each attempt creates separate operations. [payment-retries#2]\n\n## fix\n\nImport orderKey from ./pay-client.mjs and pass orderKey(order) as the orderKey option to payClient.charge. [stripe-idempotency#2]\n\n## avoid\n\nDo not generate a new key for retries. [payment-retries#2]\n\n## verify\n\nDeduplicate webhook deliveries using the event ID after successful processing. [webhook-dedupe#2]",
764
+ "pages": [
765
+ {
766
+ "id": "stripe-idempotency",
767
+ "markdown": "# Stripe idempotency\n\nImport `orderKey` from `./pay-client.mjs` and use `payClient.charge(order, { orderKey: orderKey(order) })`. The key is derived from `order.merchantId`, `order.id`, and `order.revision`. Retry the same operation with the same values. A new revision represents a new operation. The client does not use `Idempotency-Key` for deduplication.\n\nSee [[payment-retries]] for retry handling and [[webhook-dedupe]] for duplicate events.\n"
768
+ },
769
+ {
770
+ "id": "payment-retries",
771
+ "markdown": "# Payment retries\n\nRetry the same checkout operation with the same `order.merchantId`, `order.id`, and `order.revision`. Import `orderKey` from `./pay-client.mjs` and pass `orderKey(order)` as the `orderKey` option to `payClient.charge`. Generating a new key for each attempt can create a duplicate charge.\n\nSee [[stripe-idempotency]] and [[webhook-dedupe]] for the charge and event boundaries.\n"
772
+ },
773
+ {
774
+ "id": "webhook-dedupe",
775
+ "markdown": "# Webhook deduplication\n\nUse the webhook event ID to detect duplicate deliveries before applying the event's effects. Record the ID only when processing succeeds, so a failed delivery can be retried.\n\nSee [[stripe-idempotency]] for checkout keys and [[payment-retries]] for retries.\n"
776
+ }
777
+ ],
778
+ "scrubbed": [],
779
+ "eval": {
780
+ "without": "Not recorded",
781
+ "with": "Not recorded",
782
+ "recorded": true
783
+ },
784
+ "priceUsd": .5,
785
+ "author": "seed",
786
+ "createdAt": "2026-01-01T00:00:00.000Z"
787
+ };
744
788
  // ../core/src/import-files.ts
745
789
  function safeSegment(value) {
746
790
  return typeof value === "string" && value.length > 0 && value !== "." && value !== ".." && !Array.from(value).some((char) => char.charCodeAt(0) < 32 || char.charCodeAt(0) === 127 || "<>:\"/\\|?*[]".includes(char)) && !/[. ]$/.test(value) && !/^(?:con|prn|aux|nul|com[1-9]|lpt[1-9])(?:\.|$)/i.test(value);
@@ -1237,40 +1281,44 @@ function createInitialStore() {
1237
1281
  },
1238
1282
  ledger: [],
1239
1283
  sessions: [],
1240
- packs: [{
1241
- ...common,
1242
- id: "stripe-webhook-signature-errors",
1243
- title: "Stripe Webhook Signature Errors",
1244
- version: "v3",
1245
- domain: "payments",
1246
- errorSignatures: ["webhook signature verification failed", "raw body parsing"],
1247
- nodes: ["stripe-webhook-signature", "raw-body-parsing"],
1248
- markdown: "Verify the webhook signature against the raw request body.",
1249
- summary: "Verify the webhook signature against the raw request body.",
1250
- pages: [{
1251
- id: "stripe-webhook-signature",
1252
- markdown: "Verify the webhook signature against the raw request body."
1253
- }, {
1254
- id: "raw-body-parsing",
1255
- markdown: "Keep the raw request body for verification."
1256
- }],
1257
- priceUsd: .5
1258
- }, {
1259
- ...common,
1260
- id: "postgres-zero-downtime-migrations",
1261
- title: "Postgres Zero-Downtime Migrations",
1262
- version: "v2",
1263
- domain: "data",
1264
- errorSignatures: ["database migration downtime", "add column safely"],
1265
- nodes: ["pg-add-column-safely"],
1266
- markdown: "Add columns in stages and migrate data before enforcing constraints.",
1267
- summary: "Add columns in stages and migrate data before enforcing constraints.",
1268
- pages: [{
1269
- id: "pg-add-column-safely",
1270
- markdown: "Add columns in stages and migrate data before enforcing constraints."
1271
- }],
1272
- priceUsd: .8
1273
- }]
1284
+ packs: [
1285
+ {
1286
+ ...common,
1287
+ id: "stripe-webhook-signature-errors",
1288
+ title: "Stripe Webhook Signature Errors",
1289
+ version: "v3",
1290
+ domain: "payments",
1291
+ errorSignatures: ["webhook signature verification failed", "raw body parsing"],
1292
+ nodes: ["stripe-webhook-signature", "raw-body-parsing"],
1293
+ markdown: "Verify the webhook signature against the raw request body.",
1294
+ summary: "Verify the webhook signature against the raw request body.",
1295
+ pages: [{
1296
+ id: "stripe-webhook-signature",
1297
+ markdown: "Verify the webhook signature against the raw request body."
1298
+ }, {
1299
+ id: "raw-body-parsing",
1300
+ markdown: "Keep the raw request body for verification."
1301
+ }],
1302
+ priceUsd: .5
1303
+ },
1304
+ {
1305
+ ...common,
1306
+ id: "postgres-zero-downtime-migrations",
1307
+ title: "Postgres Zero-Downtime Migrations",
1308
+ version: "v2",
1309
+ domain: "data",
1310
+ errorSignatures: ["database migration downtime", "add column safely"],
1311
+ nodes: ["pg-add-column-safely"],
1312
+ markdown: "Add columns in stages and migrate data before enforcing constraints.",
1313
+ summary: "Add columns in stages and migrate data before enforcing constraints.",
1314
+ pages: [{
1315
+ id: "pg-add-column-safely",
1316
+ markdown: "Add columns in stages and migrate data before enforcing constraints."
1317
+ }],
1318
+ priceUsd: .8
1319
+ },
1320
+ structuredClone(doubleChargeSeed)
1321
+ ]
1274
1322
  };
1275
1323
  }
1276
1324
  function createSkillMarkdown(pack) {
package/dist/gbrainx.mjs CHANGED
@@ -5631,6 +5631,49 @@ function classifyParagraphs(pages) {
5631
5631
  });
5632
5632
  });
5633
5633
  }
5634
+ var doubleChargeSeed = {
5635
+ "id": "stripe-double-charge-prevention",
5636
+ "title": "Stripe Double-Charge Prevention",
5637
+ "version": "v1",
5638
+ "domain": "payments",
5639
+ "errorSignatures": [
5640
+ "double charge",
5641
+ "charged twice",
5642
+ "idempotency",
5643
+ "orderKey",
5644
+ "stripe double charge on retry"
5645
+ ],
5646
+ "nodes": [
5647
+ "stripe-idempotency",
5648
+ "payment-retries",
5649
+ "webhook-dedupe"
5650
+ ],
5651
+ "markdown": "## [[stripe-idempotency]]\n\n# Stripe idempotency\n\nImport `orderKey` from `./pay-client.mjs` and use `payClient.charge(order, { orderKey: orderKey(order) })`. The key is derived from `order.merchantId`, `order.id`, and `order.revision`. Retry the same operation with the same values. A new revision represents a new operation. The client does not use `Idempotency-Key` for deduplication.\n\nSee [[payment-retries]] for retry handling and [[webhook-dedupe]] for duplicate events.\n\n\n## [[payment-retries]]\n\n# Payment retries\n\nRetry the same checkout operation with the same `order.merchantId`, `order.id`, and `order.revision`. Import `orderKey` from `./pay-client.mjs` and pass `orderKey(order)` as the `orderKey` option to `payClient.charge`. Generating a new key for each attempt can create a duplicate charge.\n\nSee [[stripe-idempotency]] and [[webhook-dedupe]] for the charge and event boundaries.\n\n\n## [[webhook-dedupe]]\n\n# Webhook deduplication\n\nUse the webhook event ID to detect duplicate deliveries before applying the event's effects. Record the ID only when processing succeeds, so a failed delivery can be retried.\n\nSee [[stripe-idempotency]] for checkout keys and [[payment-retries]] for retries.\n\n\n## Sources\n\n- [[stripe-idempotency]]\n- [[payment-retries]]\n- [[webhook-dedupe]]",
5652
+ "summary": "## symptom\n\nRetries can produce a duplicate charge. [payment-retries#2]\n\n## cause\n\nA new key on each attempt creates separate operations. [payment-retries#2]\n\n## fix\n\nImport orderKey from ./pay-client.mjs and pass orderKey(order) as the orderKey option to payClient.charge. [stripe-idempotency#2]\n\n## avoid\n\nDo not generate a new key for retries. [payment-retries#2]\n\n## verify\n\nDeduplicate webhook deliveries using the event ID after successful processing. [webhook-dedupe#2]",
5653
+ "pages": [
5654
+ {
5655
+ "id": "stripe-idempotency",
5656
+ "markdown": "# Stripe idempotency\n\nImport `orderKey` from `./pay-client.mjs` and use `payClient.charge(order, { orderKey: orderKey(order) })`. The key is derived from `order.merchantId`, `order.id`, and `order.revision`. Retry the same operation with the same values. A new revision represents a new operation. The client does not use `Idempotency-Key` for deduplication.\n\nSee [[payment-retries]] for retry handling and [[webhook-dedupe]] for duplicate events.\n"
5657
+ },
5658
+ {
5659
+ "id": "payment-retries",
5660
+ "markdown": "# Payment retries\n\nRetry the same checkout operation with the same `order.merchantId`, `order.id`, and `order.revision`. Import `orderKey` from `./pay-client.mjs` and pass `orderKey(order)` as the `orderKey` option to `payClient.charge`. Generating a new key for each attempt can create a duplicate charge.\n\nSee [[stripe-idempotency]] and [[webhook-dedupe]] for the charge and event boundaries.\n"
5661
+ },
5662
+ {
5663
+ "id": "webhook-dedupe",
5664
+ "markdown": "# Webhook deduplication\n\nUse the webhook event ID to detect duplicate deliveries before applying the event's effects. Record the ID only when processing succeeds, so a failed delivery can be retried.\n\nSee [[stripe-idempotency]] for checkout keys and [[payment-retries]] for retries.\n"
5665
+ }
5666
+ ],
5667
+ "scrubbed": [],
5668
+ "eval": {
5669
+ "without": "Not recorded",
5670
+ "with": "Not recorded",
5671
+ "recorded": true
5672
+ },
5673
+ "priceUsd": .5,
5674
+ "author": "seed",
5675
+ "createdAt": "2026-01-01T00:00:00.000Z"
5676
+ };
5634
5677
  function safeSegment(value) {
5635
5678
  return typeof value === "string" && value.length > 0 && value !== "." && value !== ".." && !Array.from(value).some((char) => char.charCodeAt(0) < 32 || char.charCodeAt(0) === 127 || "<>:\"/\\|?*[]".includes(char)) && !/[. ]$/.test(value) && !/^(?:con|prn|aux|nul|com[1-9]|lpt[1-9])(?:\.|$)/i.test(value);
5636
5679
  }
@@ -5813,40 +5856,44 @@ function createInitialStore() {
5813
5856
  },
5814
5857
  ledger: [],
5815
5858
  sessions: [],
5816
- packs: [{
5817
- ...common,
5818
- id: "stripe-webhook-signature-errors",
5819
- title: "Stripe Webhook Signature Errors",
5820
- version: "v3",
5821
- domain: "payments",
5822
- errorSignatures: ["webhook signature verification failed", "raw body parsing"],
5823
- nodes: ["stripe-webhook-signature", "raw-body-parsing"],
5824
- markdown: "Verify the webhook signature against the raw request body.",
5825
- summary: "Verify the webhook signature against the raw request body.",
5826
- pages: [{
5827
- id: "stripe-webhook-signature",
5828
- markdown: "Verify the webhook signature against the raw request body."
5829
- }, {
5830
- id: "raw-body-parsing",
5831
- markdown: "Keep the raw request body for verification."
5832
- }],
5833
- priceUsd: .5
5834
- }, {
5835
- ...common,
5836
- id: "postgres-zero-downtime-migrations",
5837
- title: "Postgres Zero-Downtime Migrations",
5838
- version: "v2",
5839
- domain: "data",
5840
- errorSignatures: ["database migration downtime", "add column safely"],
5841
- nodes: ["pg-add-column-safely"],
5842
- markdown: "Add columns in stages and migrate data before enforcing constraints.",
5843
- summary: "Add columns in stages and migrate data before enforcing constraints.",
5844
- pages: [{
5845
- id: "pg-add-column-safely",
5846
- markdown: "Add columns in stages and migrate data before enforcing constraints."
5847
- }],
5848
- priceUsd: .8
5849
- }]
5859
+ packs: [
5860
+ {
5861
+ ...common,
5862
+ id: "stripe-webhook-signature-errors",
5863
+ title: "Stripe Webhook Signature Errors",
5864
+ version: "v3",
5865
+ domain: "payments",
5866
+ errorSignatures: ["webhook signature verification failed", "raw body parsing"],
5867
+ nodes: ["stripe-webhook-signature", "raw-body-parsing"],
5868
+ markdown: "Verify the webhook signature against the raw request body.",
5869
+ summary: "Verify the webhook signature against the raw request body.",
5870
+ pages: [{
5871
+ id: "stripe-webhook-signature",
5872
+ markdown: "Verify the webhook signature against the raw request body."
5873
+ }, {
5874
+ id: "raw-body-parsing",
5875
+ markdown: "Keep the raw request body for verification."
5876
+ }],
5877
+ priceUsd: .5
5878
+ },
5879
+ {
5880
+ ...common,
5881
+ id: "postgres-zero-downtime-migrations",
5882
+ title: "Postgres Zero-Downtime Migrations",
5883
+ version: "v2",
5884
+ domain: "data",
5885
+ errorSignatures: ["database migration downtime", "add column safely"],
5886
+ nodes: ["pg-add-column-safely"],
5887
+ markdown: "Add columns in stages and migrate data before enforcing constraints.",
5888
+ summary: "Add columns in stages and migrate data before enforcing constraints.",
5889
+ pages: [{
5890
+ id: "pg-add-column-safely",
5891
+ markdown: "Add columns in stages and migrate data before enforcing constraints."
5892
+ }],
5893
+ priceUsd: .8
5894
+ },
5895
+ structuredClone(doubleChargeSeed)
5896
+ ]
5850
5897
  };
5851
5898
  }
5852
5899
  // startup-error.mjs