Skip to content

Commit c656869

Browse files
AgentLexclaude
andcommitted
v2.0: rebuild as a portable AI memory wallet
Reposition CodeCart from a DSL note console to a copy-paste memory wallet: card-based UI (preference / fact / status / boundary), a round-trip protocol where the AI emits fenced codecart blocks that merge back with supersede semantics, a first-run starter wizard, honest token counting, light/dark themes, and offline-first storage with file export, import and URL-hash transfer links (no account, no server). Four languages (en, zh-CN, zh-TW, ja) with auto-detect and manual switching; Chinese brand renamed to 思维卡. All docs rewritten; DEVELOPER_API is now the open protocol spec. Legacy v1.3 localStorage data migrates automatically. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 00430ba commit c656869

14 files changed

Lines changed: 1396 additions & 992 deletions

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.DS_Store
2+
_private/
3+
.claude/

DEVELOPER_API.ja.md

Lines changed: 64 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,85 @@
1-
# CodeCart デベロッパー API ガイド (v1.3)
1+
# CodeCart プロトコル仕様 (v2.0)
22

33
[English](DEVELOPER_API.md) | [简体中文](DEVELOPER_API.zh-CN.md) | [繁體中文](DEVELOPER_API.zh-TW.md) | **日本語**
44

55
## 目的
66

7-
このガイドは、ブラウザでの手動操作ではなく、APIコール、スクリプト、マルチエージェント(Multi-agent)フレームワーク、または CI/CD パイプラインを通じて CodeCart を利用する開発者や研究者を対象としています
7+
本書は CodeCart の「ラウンドトリップ・プロトコル」を定義し、あらゆる AI 製品・エージェントフレームワーク・ブラウザー拡張・スクリプトがユーザーのメモリーウォレットを読み書きし、互換性を保てるようにするものです。プロトコルは意図的に極小です:普通のチャット返信の中で、どの LLM でも確実に出力できなければなりません
88

9-
## コアアーキテクチャ
9+
## 3つの構成要素
1010

11-
CodeCart v1.3 は、結晶化された外部メモリレイヤーとして機能します。そのアーキテクチャは、人間向けのインターフェースとマシンリーダーブルな状態を分離しています。
11+
1. **キャリーブロック**——ユーザーが AI に貼り付ける内容:有効なカード+モデルに更新の出力を求める指示。
12+
2. **`codecart` ブロック**——モデルが返信の最後に付けるメモリー更新(フェンス付きコードブロック)。
13+
3. **ウォレットファイル**——全カードを保持するエクスポート JSON。ユーザーが持ち運べる正準ストア。
1214

13-
- **人間向け UI**: ポータブルな HTML ファイル(視覚化および手動調整用)。
14-
- **マシンメモリ**: エクスポートされた JSON カートリッジ(v1.3 形式)。
15-
- **プロンプトビルダー**: トークンコストを最小限に抑えるため、アクティブな(上書きされていない)ノードのみを抽出します。
16-
- **モデル契約**: LLM に対し、CodeCart DSL(`+CLAIM`, `>SUPERSEDE`, `+ANCHOR`)形式での出力を厳格に要求します。
15+
## 1. キャリーブロック
1716

18-
## 標準的な API ワークフロー
17+
```
18+
[これは私の個人メモリーです(CodeCart ウォレット、<日付>)。すべての回答をこれに基づいてパーソナライズしてください。]
19+
- (preference) 短く、結論から答える
20+
- (fact) ネットショップを運営している
21+
- (boundary) 月1万円の予算を超える提案はしない
22+
---
23+
<codecart ブロックの追加をモデルに求める指示——正準の文言はアプリ内を参照>
24+
```
1925

20-
### ステップ 1: カートリッジのエクスポート
21-
CodeCart UI の **詳細モード(Advanced Mode)** を使用して、現在のプロジェクト状態を JSON ファイルとしてエクスポートします。
26+
カードタイプ:`preference`(答え方の好み)、`fact`(安定した情報)、`status`(現在の関心事、変化する)、`boundary`(絶対ルール)。
27+
28+
## 2. `codecart` ブロックの文法
29+
30+
モデルは返信の最後にこう付けます:
31+
32+
```codecart
33+
+ <type> | <内容>
34+
~ <古いメモリー行からそのまま引用した断片> => <修正後の内容>
35+
- <退役させるメモリー行の断片>
36+
```
37+
38+
- `+` はカード追加。`<type>` は4タイプのいずれか。省略時(`+ <内容>`)は `fact` として扱う——ただし誤検出を避けるためフェンス内のみ。
39+
- `~` は置き換え:テキストに `<断片>` を含む有効カードを(大文字小文字を無視して)探し、アーカイブして修正カードを追加。これがウォレットを肥大化させず最新に保つ仕組みです。
40+
- `-` は置き換えなしの退役(フェンス内のみ)。
41+
- 推奨モデルルール(キャリー指示に含まれます):最大5行;持続的な個人情報のみ;ユーザーの言語で書く;該当なしならブロック自体を省略。
42+
43+
パーサーはフェンス外の行も受け付けてよいが、明示的な `<type> |` 接頭辞がある場合に限ります。
44+
45+
## 3. ウォレットファイル (JSON)
46+
47+
```json
48+
{
49+
"version": 2,
50+
"cards": [
51+
{
52+
"id": "m3k9x1ab2",
53+
"type": "preference",
54+
"text": "短く、結論から答える",
55+
"status": "active",
56+
"created": 1720300000000,
57+
"updated": 1720300000000
58+
}
59+
]
60+
}
61+
```
2262

23-
### ステップ 2: コンパクトなコンテキストブロックの構築
24-
プロンプトに注入するために必要な情報のみを抽出します。以下のロジックにより、廃棄されたノードにトークンを浪費しないようにします。
63+
`status``active``archived`。コンシューマーは active カードのみを持ち込み、インポート時は `text` の重複(大文字小文字・前後空白を無視)をスキップしてマージしなければなりません。
2564

26-
**Python 実装例:**
65+
## 参考:API パイプラインでウォレットを使う
2766

2867
```python
2968
import json
3069

31-
# v1.3 でエクスポートされたカートリッジファイルを読み込む
32-
with open('codecart_export.json', 'r', encoding='utf-8') as f:
33-
cart = json.load(f)
34-
35-
active_nodes = []
36-
for n in cart.get('nodes', []):
37-
# フィルタリング:すべてのアンカー(Anchor)と、アクティブな結論(Claim)のみを保持
38-
if n.get('type') == 'anchor' or not n.get('isSuperseded'):
39-
active_nodes.append(f"[{n['id']}] {n['content']}")
70+
with open("codecart-wallet.json", encoding="utf-8") as f:
71+
wallet = json.load(f)
4072

41-
context_block = "[CODECART CONTEXT]\n" + "\n".join(active_nodes)
42-
print(context_block)
43-
```
44-
45-
### ステップ 3: モデル呼び出しへの注入
46-
LLM にコンテキストを処理させ、更新内容を厳格に DSL 形式で返却するように強制します。
47-
48-
```python
49-
from openai import OpenAI
50-
51-
client = OpenAI()
52-
53-
system_prompt = (
54-
"あなたは CodeCart メモリカートリッジへのアクセス権を持つアシスタントです。"
55-
"分析後、安定した更新内容を CodeCart DSL のみを使用して要約してください。"
56-
"新しいロジックには +CLAIM(id, '内容') を、更新には >SUPERSEDE(旧ID, 新ID, '理由') を使用してください。"
73+
carry = "\n".join(
74+
f"- ({c['type']}) {c['text']}"
75+
for c in wallet["cards"] if c["status"] == "active"
5776
)
58-
59-
messages = [
60-
{"role": "system", "content": f"{system_prompt}\n\n{context_block}"},
61-
{"role": "user", "content": "現在のアーキテクチャをレビューし、スケーリング戦略を提案してください。"}
62-
]
63-
64-
resp = client.chat.completions.create(
65-
model="gpt-4o",
66-
messages=messages
67-
)
68-
69-
# モデルは生の DSL テキストを返します
70-
print(resp.choices[0].message.content)
77+
# carry を system prompt の先頭に付け、モデル出力中の
78+
# ```codecart``` ブロックを上記文法でパースしてマージする。
7179
```
7280

73-
### ステップ 4: マージ(反映)
74-
モデルが出力した DSL テキストを CodeCart の **詳細モード** コンソールに貼り付け、**⚡ 実行(EXECUTE)** をクリックして、視覚的なロジックツリーを更新します。
75-
76-
## 効果的な API 利用のガイドライン
81+
## 互換性の約束
7782

78-
1. **トークンの効率化**: 「デッド」ノード(置換済み/非アクティブ)をプロンプトに注入しないでください。
79-
2. **アンカーの安定性**: 変更不可のプロジェクトルールには `+ANCHOR` を使用し、「モデルのドリフト(脱線)」を防ぎます。
80-
3. **アトミックな結論**: LLM が1つの論理的結論に対して1つの独立したノードを生成するように調整してください。
81-
4. **自動スナップショット**: パイプラインの重要な意思決定ポイントで、スクリプトを使用して JSON スナップショットを自動保存することを推奨します。
83+
- ブロックタグは常にリテラル文字列 `codecart`
84+
- 未知のカードタイプは `fact` として扱い、未知の JSON フィールドはラウンドトリップで保持すること。
85+
- v1.3 レガシーエクスポート(`nodes` + `+CLAIM`/`+ANCHOR` セマンティクス)の対応:`anchor → boundary``claim → fact``isSuperseded → archived`

DEVELOPER_API.md

Lines changed: 64 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,85 @@
1-
# CodeCart Developer API Guide (v1.3)
1+
# CodeCart Protocol Specification (v2.0)
22

33
**English** | [简体中文](DEVELOPER_API.zh-CN.md) | [繁體中文](DEVELOPER_API.zh-TW.md) | [日本語](DEVELOPER_API.ja.md)
44

55
## Purpose
66

7-
This guide is for developers and researchers who work through API calls, scripts, multi-agent frameworks, or CI/CD pipelines rather than manually copying text in a browser.
7+
This document specifies the CodeCart round-trip protocol so that any AI product, agent framework, browser extension or script can read, write and stay compatible with a user's memory wallet. The protocol is deliberately tiny: it must survive being emitted by any LLM inside a plain chat reply.
88

9-
## Core Architecture
9+
## The three artifacts
1010

11-
CodeCart v1.3 functions as a crystallized external memory layer. The architecture separates the human interface from the machine-readable state:
11+
1. **Carry block** — what the user pastes *into* an AI chat: active cards + an instruction asking the model to emit updates.
12+
2. **`codecart` block** — what the model appends to its replies: memory updates in a fenced code block.
13+
3. **Wallet file** — the exported JSON that holds all cards; the user's canonical, portable store.
1214

13-
- **Human-facing UI**: The portable HTML file.
14-
- **Machine memory**: The exported JSON cartridge (v1.3 format).
15-
- **Prompt builder**: Extracts only active (non-superseded) nodes to minimize token costs.
16-
- **Model contract**: The LLM is instructed to output strictly in CodeCart DSL (`+CLAIM`, `>SUPERSEDE`, `+ANCHOR`).
15+
## 1. Carry block
1716

18-
## Standard API Workflow
17+
```
18+
[My personal memory — CodeCart wallet, <date>. Use it to personalize every answer.]
19+
- (preference) Answer concisely, conclusion first
20+
- (fact) I run a small online store
21+
- (boundary) Never suggest options over my $200/month budget
22+
---
23+
<instruction asking the model to append a codecart block — see the app for canonical wording>
24+
```
1925

20-
### Step 1: Export the Cartridge
21-
Export your current project state as a JSON file using the **Advanced Mode** in the CodeCart UI.
26+
Card types: `preference` (how to answer), `fact` (stable info), `status` (current focus, expected to change), `boundary` (hard rule).
27+
28+
## 2. `codecart` block grammar
29+
30+
The model appends, at the end of a reply:
31+
32+
```codecart
33+
+ <type> | <content>
34+
~ <fragment copied from an outdated memory line> => <corrected content>
35+
- <fragment of a memory line to retire>
36+
```
37+
38+
- `+` adds a card. `<type>` is one of the four types; if omitted (`+ <content>`), consumers should default to `fact` — but only inside a fenced block, to avoid false positives.
39+
- `~` supersedes: the consumer finds the active card whose text contains `<fragment>` (case-insensitive), archives it, and adds the corrected card. This is what keeps wallets current instead of ever-growing.
40+
- `-` retires a card without replacement (fenced block only).
41+
- Recommended model rules (already in the carry instruction): max 5 lines, only durable personal info, write contents in the user's language, omit the block when nothing qualifies.
42+
43+
Parsers should accept the lines outside a fence too, but only when an explicit `<type> |` prefix is present.
44+
45+
## 3. Wallet file (JSON)
46+
47+
```json
48+
{
49+
"version": 2,
50+
"cards": [
51+
{
52+
"id": "m3k9x1ab2",
53+
"type": "preference",
54+
"text": "Answer concisely, conclusion first",
55+
"status": "active",
56+
"created": 1720300000000,
57+
"updated": 1720300000000
58+
}
59+
]
60+
}
61+
```
2262

23-
### Step 2: Build a Compact Context Block
24-
Extract only relevant information to inject into your prompt. The following logic ensures you don't waste tokens on superseded nodes.
63+
`status` is `active` or `archived`. Consumers must carry only active cards, and must merge imports by skipping duplicate `text` values (case-insensitive, trimmed).
2564

26-
**Python Example:**
65+
## Reference: consuming a wallet in an API pipeline
2766

2867
```python
2968
import json
3069

31-
# Load v1.3 exported cartridge
32-
with open('codecart_export.json', 'r', encoding='utf-8') as f:
33-
cart = json.load(f)
34-
35-
active_nodes = []
36-
for n in cart.get('nodes', []):
37-
# Filter: Keep all anchors and only active claims
38-
if n.get('type') == 'anchor' or not n.get('isSuperseded'):
39-
active_nodes.append(f"[{n['id']}] {n['content']}")
70+
with open("codecart-wallet.json", encoding="utf-8") as f:
71+
wallet = json.load(f)
4072

41-
context_block = "[CODECART CONTEXT]\n" + "\n".join(active_nodes)
42-
print(context_block)
43-
```
44-
45-
### Step 3: Inject into Your Model Call
46-
Force the LLM to process the context and return updates strictly in DSL format.
47-
48-
```python
49-
from openai import OpenAI
50-
51-
client = OpenAI()
52-
53-
system_prompt = (
54-
"You are an assistant with access to a CodeCart memory cartridge. "
55-
"After analysis, summarize stable updates using CodeCart DSL only. "
56-
"Use +CLAIM(id, 'content') for new logic and >SUPERSEDE(old, new, 'why') for updates."
73+
carry = "\n".join(
74+
f"- ({c['type']}) {c['text']}"
75+
for c in wallet["cards"] if c["status"] == "active"
5776
)
58-
59-
messages = [
60-
{"role": "system", "content": f"{system_prompt}\n\n{context_block}"},
61-
{"role": "user", "content": "Review the current architecture and propose a scaling strategy."}
62-
]
63-
64-
resp = client.chat.completions.create(
65-
model="gpt-4o",
66-
messages=messages
67-
)
68-
69-
# The model returns raw DSL
70-
print(resp.choices[0].message.content)
77+
# Prepend `carry` to your system prompt; parse ```codecart``` blocks
78+
# from model output with the grammar above and merge back.
7179
```
7280

73-
### Step 4: Merge Back
74-
Paste the model's DSL output back into the CodeCart **Advanced Mode** console and click **⚡ EXECUTE** to update your visual logic tree.
75-
76-
## Rules for Good API Usage
81+
## Compatibility promises
7782

78-
1. **Token Efficiency**: Never inject "dead" (superseded) nodes into the prompt.
79-
2. **Anchor Stability**: Use `+ANCHOR` for immutable project rules to prevent "model drift".
80-
3. **Atomic Claims**: Ensure the LLM generates one node per discrete logical conclusion.
81-
4. **Automated Snapshots**: Save JSON snapshots after major decision points in your pipeline.
83+
- The block tag is always the literal string `codecart`.
84+
- Unknown card types must be treated as `fact`, unknown JSON fields must be preserved on round-trip.
85+
- v1.3 legacy exports (`nodes` with `+CLAIM`/`+ANCHOR` semantics) map as: `anchor → boundary`, `claim → fact`, `isSuperseded → archived`.

0 commit comments

Comments
 (0)