@h1r-ai/croche 0.5.0 → 0.5.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.
Files changed (36) hide show
  1. package/README.md +23 -15
  2. package/dist/core-bindgen.js +18 -18
  3. package/dist/core-runtime.d.ts +1 -1
  4. package/dist/core-runtime.js +1 -1
  5. package/dist/core-wasm-bytes.d.ts +3 -3
  6. package/dist/core-wasm-bytes.js +3 -3
  7. package/dist/project-types.d.ts +2 -2
  8. package/dist/types.d.ts +6 -8
  9. package/docs/CODING-AGENT.md +11 -7
  10. package/docs/SKILL.md +309 -265
  11. package/docs/skills/croche/agents/openai.yaml +4 -0
  12. package/docs/skills/croche/references/agents.md +78 -0
  13. package/docs/skills/croche/references/first-turn.md +74 -0
  14. package/docs/skills/croche/references/tools.md +43 -0
  15. package/docs/skills/croche/references/web-search.md +85 -0
  16. package/docs/skills/croche-cli/SKILL.md +158 -0
  17. package/docs/skills/croche-cli/agents/openai.yaml +4 -0
  18. package/docs/skills/croche-cli/references/powershell.md +47 -0
  19. package/docs/skills/croche-config/SKILL.md +153 -0
  20. package/docs/skills/croche-config/agents/openai.yaml +4 -0
  21. package/docs/skills/croche-config/references/models.md +12 -0
  22. package/docs/skills/croche-platforms/SKILL.md +55 -0
  23. package/docs/skills/croche-platforms/agents/openai.yaml +4 -0
  24. package/docs/skills/croche-platforms/references/android.md +185 -0
  25. package/docs/skills/croche-platforms/references/ios.md +165 -0
  26. package/docs/skills/croche-platforms/references/react-native.md +50 -0
  27. package/docs/skills/croche-platforms/references/web-backend.md +58 -0
  28. package/docs/skills/croche-troubleshoot/SKILL.md +72 -0
  29. package/docs/skills/croche-troubleshoot/agents/openai.yaml +4 -0
  30. package/docs/skills/croche-troubleshoot/references/recovery.md +31 -0
  31. package/package.json +1 -1
  32. package/src/core-bindgen.ts +18 -18
  33. package/src/core-runtime.ts +1 -1
  34. package/src/core-wasm-bytes.ts +3 -3
  35. package/src/project-types.ts +2 -2
  36. package/src/types.ts +6 -8
package/docs/SKILL.md CHANGED
@@ -1,295 +1,339 @@
1
1
  ---
2
2
  name: croche
3
- description: Add a scoped AI agent (character, companion, assistant, NPC, tutor) to an app with the Croche SDK, and manage its Croche project and drafts, and inspect keys, attestation and usage with the croche CLI. Use when the user builds on Croche, mentions @h1r-ai/croche or @h1r-ai/croche-react-native, or asks to add AI behaviour to an app that uses Croche. Not for generic LLM integrations.
3
+ description: Build an app with Croche from requests such as "use Croche", "build this with Croche", or "Croche로 개발해줘", in an empty or existing app repository. Own onboarding, CLI project/debug-key setup, SDK integration and first-turn verification; combine missing app purpose and unresolved platform choice with signup, one account key and user-run croche login. Not for unrelated AI integrations.
4
4
  ---
5
5
 
6
- # Croche
6
+ # Build with Croche
7
7
 
8
- Croche gives an app a **scoped agent**: an AI with a clear purpose that acts through the app's
9
- own commands. The Runtime (a Rust Core inside the SDK) already does the hard, generic part:
10
- conversation history, long-term memory, the model and how it is called, the tool loop,
11
- spending limits and reporting. **You write only
12
- what is specific to this app.** This page is enough for most apps. Do not read the SDK
13
- sources or its `.d.ts` files; open a reference only when a step below points to it.
8
+ Croche helps developers put useful AI into their apps. The app supplies the agent's purpose,
9
+ its actions and UI; Croche handles running the agent and remembering conversations.
10
+ Do the code and checks yourself. Guide the user through the few steps that need their
11
+ Studio account or secrets, rather than handing them a manual.
14
12
 
15
- ## Do not build these (the Runtime does them)
13
+ ## Plugin installation, only if needed
16
14
 
17
- History, windowing, summaries, memory files, retries of model calls, a tool loop, a model
18
- client, provider choice, prompt caching. Every one of them is already correct in the Runtime,
19
- and a second copy costs tokens on every call. Never call the model provider yourself.
15
+ If the user asks how to install this plugin, give the matching terminal commands below.
16
+ Use only the public `H1R-AI/croche` marketplace. If this skill is already loaded from the plugin,
17
+ continue the app task; do not reinstall or add another onboarding step. Public marketplace
18
+ availability still needs verification before claiming installation works.
20
19
 
21
- ## What you need first
20
+ **Claude Code**, in your terminal:
22
21
 
23
- Ask for anything you do not have; never invent a value.
22
+ ```sh
23
+ claude plugin marketplace add H1R-AI/croche
24
+ claude plugin install croche@croche
25
+ ```
24
26
 
25
- - Croche Cloud URL and the project's **public project key**.
26
- - The SDK from npm: `npm install @h1r-ai/croche@{{SDK_VERSION}}`. For React Native, also
27
- `npm install @h1r-ai/croche-react-native@{{SDK_VERSION}}` (the native Core is inside;
28
- see the [SDK reference](references/sdk.md), React Native).
29
- - Native iOS (Swift) and Android (Kotlin) apps: the native SDKs are planned for 0.5.1, with the
30
- same `Croche.open` API. Until then, use React Native, or run the Runtime on a web backend.
31
- - In development (Node, simulator, browser): a **debug key** (`cdt_…`) passed as
32
- `debugKey`. Release builds on phones use platform attestation instead; web apps run the
33
- Runtime on their backend with a server key (`csk_…`). See [SDK reference](references/sdk.md)
34
- only if you are in one of those cases.
27
+ **Codex**, in your terminal:
35
28
 
36
- ## The recommended setup
29
+ ```sh
30
+ codex plugin marketplace add H1R-AI/croche
31
+ codex plugin add croche@croche
32
+ ```
37
33
 
38
- One `Croche` project per user, opened once for the app's lifetime, and its agents
39
- (Node shown; React Native is the same API):
34
+ ## Start from the request, not a questionnaire
35
+
36
+ For “use Croche”, “build this with Croche”, or “Croche로 개발해줘”, begin the integration.
37
+
38
+ **The CLI comes first.** Before any other Croche step (project, key file, SDK code), confirm the
39
+ CLI runs (`croche --version`) and install it if missing
40
+ (below). Croche keys reach the app only through the CLI. If it cannot be installed or run, stop
41
+ and report that release blocker. Never build with a key pasted into chat, an account key in app
42
+ code or a hand-written `.env` instead.
43
+
44
+ Inspect the repository, the user's request and active shell yourself. Preserve a platform
45
+ already stated by the user or revealed by the repository; **do not ask it again**.
46
+ Use these repository signals for the target app; an explicit platform in the prompt wins:
47
+
48
+ | Repository signal | Platform; do not ask again |
49
+ | --- | --- |
50
+ | `react-native` dependency | React Native |
51
+ | `*.xcodeproj` or `Package.swift` | Swift (iOS) |
52
+ | `build.gradle` or `build.gradle.kts` with the Android plugin | Kotlin (Android) |
53
+ | `vite`, `express` or `next` in `package.json` | Web (Node backend) |
54
+
55
+ If neither reveals the platform, ask **web (Node backend) / React Native / Swift (iOS) /
56
+ Kotlin (Android)**. Do not silently choose Node or rewrite an existing app into another stack.
57
+ In an empty repo, also obtain the app's purpose if missing; in an existing app, infer it.
58
+ Missing purpose/platform choices belong with the human login setup in **one question,
59
+ not a separate round**. If already logged in, the unresolved platform question may stand
60
+ alone. Asking when the prompt or repo already reveals it is a failure. Omit every part already answered. Do not ask for project name,
61
+ persona, tool list or credentials. Use the repo/app name for the project. Required tool/install
62
+ approvals remain separate permission boundaries, not another onboarding questionnaire.
63
+
64
+ Choose the matching path:
65
+
66
+ - **Node script or web backend:** `@h1r-ai/croche`, Node.js 22+ on macOS/Linux.
67
+ - **React Native:** `@h1r-ai/croche` + `@h1r-ai/croche-react-native`; same project/agent API.
68
+ - **Native Swift/Kotlin SDKs are published as 0.5.2**, including the shared `Croche.open` project API.
69
+ Read the `croche-platforms` iOS/Android reference for installation and the first turn.
70
+ Verify package resolution and native execution in the target app; publication is not a test pass.
71
+ If its exact release is unavailable, offer TypeScript/React Native as an alternative, not an
72
+ automatic rewrite of a native app. Never invent native snippets.
73
+ - **Windows:** verification pending; command forms are not a support claim. Use the
74
+ detected shell rather than assuming Bash; `croche-cli` has PowerShell guidance.
75
+
76
+ The TypeScript SDK, React Native SDK and CLI **0.5.2 are published on npm**. Use
77
+ `npm install @h1r-ai/croche` and `npm install -g @h1r-ai/croche-cli`; check the installed
78
+ version and command help. Publication alone does not prove the user's platform or first turn.
79
+ TODO verify: the matching release's first-turn and login workflows. The examples use
80
+ `debugKey`, Studio **Debug keys**, and automatic connection setup; do not substitute a
81
+ source build or guessed package. Native project API availability remains a separate gate.
82
+
83
+ Use a focused companion skill only when that task arises (if installed): `croche-cli` for
84
+ CLI commands, `croche-config` for drafts/language, `croche-platforms` for mobile/web setup,
85
+ `croche-troubleshoot` for errors. Without one, consult the matching public SDK/CLI docs or
86
+ installed package help; never guess an API.
87
+
88
+ ## Install the CLI, then make one combined request
89
+
90
+ Install a missing CLI yourself with appropriate permission: `npm install -g @h1r-ai/croche-cli`.
91
+ In PowerShell, use plain `croche` too. If it is refused because running scripts is disabled, that
92
+ is a human step: fold `Set-ExecutionPolicy -Scope CurrentUser RemoteSigned` (run once) into the
93
+ login request below; never change the policy yourself. See `croche-cli`'s PowerShell reference.
94
+ Use the host approval mechanism when required, not a setup questionnaire. Check `croche --help`
95
+ for the matching release. **Do not run `croche login`**, even to start a prompt for the user.
96
+ If account access is already configured, re-check with `croche auth whoami --json` and skip login.
97
+ Capture CLI JSON privately and show only the authentication result, never raw output or a key prefix.
98
+
99
+ Ask **once, in one combined request**, using the matching case below. Skip login when already
100
+ confirmed; still obtain missing app purpose or an unresolved platform in the same question.
101
+
102
+ ### Empty repo: missing purpose/platform + human setup, together
103
+
104
+ > What should this app do, and which platform: web (Node backend), React Native,
105
+ > Swift (iOS), or Kotlin (Android)? Sign up at https://studio.croche.ai, create one account key under
106
+ > **Account → Account keys** (under **Personal**), then run **`croche login` yourself in a private
107
+ > terminal on this machine and OS user account**. Paste the key only into its hidden prompt,
108
+ > never into chat. If PowerShell refuses `croche` because running scripts is disabled, run
109
+ > **`Set-ExecutionPolicy -Scope CurrentUser RemoteSigned`** once first.
110
+ > Tell me the missing app choices and when login is complete; I will handle the rest.
111
+
112
+ Omit the platform choice when already stated or visible in the repo; omit the purpose when
113
+ already supplied. These are parts of one request, not successive questions.
114
+
115
+ ### Existing app: human setup, plus platform only if unresolved
116
+
117
+ > Sign up at https://studio.croche.ai, create one account key under **Account → Account keys**
118
+ > (under **Personal**), then run **`croche login` yourself in a private terminal on this
119
+ > machine and OS user account**. Paste the key only into its hidden prompt, never into chat.
120
+ > If PowerShell refuses `croche` because running scripts is disabled, run
121
+ > **`Set-ExecutionPolicy -Scope CurrentUser RemoteSigned`** once first.
122
+ > Tell me when login is complete; I will handle the project, SDK and first-turn check.
123
+
124
+ If this existing repo and request do not reveal a platform, prepend the same four-way platform
125
+ choice to this request; otherwise ask only the human setup. An existing app already supplies its purpose.
126
+
127
+ ### Project: new or existing
128
+
129
+ The person picks the project by answering you; no key is part of this exchange.
130
+
131
+ - **Already logged in:** run `croche projects list --json` first (captured; use only names and
132
+ IDs). If projects exist, the combined request also asks:
133
+ > Should I create a new project **<app name>**, or use one of yours: **<name>**, **<name>**?
134
+
135
+ With no projects, say you will create **<app name>**.
136
+ - **Not logged in yet:** add one line to the combined request:
137
+ > If this app already has a Croche project, tell me its name; otherwise I'll create **<app name>**.
138
+
139
+ After “done”, list projects and use the named one. If it does not exist, or no name was given,
140
+ create **<app name>** and say so. Do not ask a second question.
141
+
142
+ Skip already-completed steps. The user redeems an invitation privately if needed. Do not ask
143
+ for a service endpoint, public project key, SDK debug key (`cdt_`), account key, shell export or
144
+ agent restart. The agent creates the project (or uses the one picked) and its debug key through
145
+ the CLI; no key is a user input.
146
+ Stored login works across terminals for that OS account. A remote/container agent has a different credential
147
+ context; explain that genuine mismatch without collecting or transporting the secret yourself.
148
+
149
+ **Login workflow — TODO verify:** hidden prompt, validation before storage and
150
+ cross-terminal reuse against the matching published CLI. Package `@h1r-ai/croche-cli` provides
151
+ the `croche` executable. If the command is unavailable, report the release blocker instead of
152
+ inventing a login command or asking for a key in chat. Do not invent an `npx` form. Login is
153
+ user-run only, accepts no key argument, and stores a protected credential; never read that file
154
+ into the transcript. `croche-cli` covers logout and the CI-only environment alternative.
155
+
156
+ Never print **any part of a key**: no prefixes, suffixes, masked substrings or previews.
157
+ For a key check, output only its variable name and presence/length. Never dump the environment,
158
+ print a private file or capture a secret screen. CLI identity/debug-key JSON can include prefixes:
159
+ capture that output in the subprocess and emit only allowlisted non-key fields (success, account
160
+ ID, project ID, destination path), never raw JSON/stderr. Do not log `.credential.prefix` or
161
+ `.debug_key.prefix`. The CLI and app may load secret files directly without showing them to you.
162
+
163
+ ## After the human says done: re-check and continue now
164
+
165
+ On “done”, “했어”, or equivalent, **re-check**, do not reuse an earlier missing-file/auth result.
166
+ Run `croche auth whoami --json` with captured, filtered output to confirm authentication. Then
167
+ check whether the selected private key file exists (`.env`, Debug `.xcconfig`, or `local.properties`)
168
+ and whether `CROCHE_DEBUG_KEY` is present/nonempty, without printing any value or substring.
169
+ Login authenticates the CLI; a missing app key file is work for **you**, not another human step.
170
+ Create/reuse the project and create the private key file if missing, then verify it again.
171
+
172
+ Continue installation, code/config, syntax/build checks and the **first live turn in the same
173
+ turn**, under the requested usage permission. Do not stop with “keys are missing”, `.env.example`
174
+ copy instructions or an offer to run the test later when the user just completed setup. A real
175
+ auth error, unavailable release, missing platform answer or required approval is a valid blocker:
176
+ report its safe error code/action instead of inventing success or requesting a secret.
177
+
178
+ ## The agent does the rest
179
+
180
+ Use the selected platform; infer stable user identity and storage from the app and purpose already given.
181
+ Do not ask a second setup/product question when the combined request is answered, or request another credential. Use `croche-cli` if
182
+ available for command details. After user-confirmed login, verify the intended account with
183
+ `croche auth whoami --json` with private output capture (success/account only). Before creating a debug key, verify the env-file
184
+ path is not already tracked by Git; do not expose it with a diff or file read. Then, within the
185
+ requested app setup, run these CLI operations with captured/filtered JSON rather than echoing
186
+ raw output into the transcript:
40
187
 
41
- ```ts
42
- import { Croche } from '@h1r-ai/croche';
43
- import { FileStorage } from '@h1r-ai/croche/node';
44
-
45
- const croche = await Croche.open({
46
- projectKey, debugKey, // from .env; never hard-code or log keys
47
- user: playerId, // your app's id for this person
48
- storage: new FileStorage(join(dataDir, 'croche')), // one directory for the whole project
49
- config: { instructions: PIP, tools: [shop] }, // who the agent is (short: paid on every call), and the app's actions, below
50
- handlers: { shop: runShop }, // one handler per tool, by tool name
51
- }); // leave every other option at its default
52
-
53
- const pip = await croche.agent(); // the project's agent
54
- const result = await pip.request({ id: messageId, text: userText, context: appState() });
188
+ ```sh
189
+ croche auth whoami --json
190
+ croche projects create --name "My app" --json
191
+ croche debug-keys create --project PROJECT_ID --json
55
192
  ```
56
193
 
57
- - **`request`** resolves when the input is answered, with its `messages`; the reply is the
58
- `message.end` among them. **`send`** returns at once with a receipt. To show replies as they
59
- stream, `subscribe({ onEvent })` once and render `message.delta` (provisional) and
60
- `message.end` (final) events.
61
- - **Several agents:** declare them under `config.agents` (`{ helper: { instructions: … } }`)
62
- and open each with `croche.agent('helper')`. A separate conversation of one agent, such as a
63
- save slot, is `croche.agent(id, { instance: 'save-2' })`; `{ fresh: true }` starts a new one.
64
- Each has its own history and memory.
65
- - `CrocheRuntime.create` (one agent, no project) still works and the
66
- [SDK reference](references/sdk.md) documents it. New apps use `Croche`.
67
-
68
- - **`instructions`:** the character only: who, voice, what they care about, in a few short
69
- paragraphs, in English (the persona's example lines may be in the user's language). No
70
- command list, no app state, no rules the tool set already enforces.
71
- - **Reply length and tone are yours.** The Runtime says nothing about how the agent talks. If
72
- replies should be short (a task app, a store), say it in `instructions` ("one to three short
73
- sentences unless asked for more"); a character may need more room. Measured: a brevity line
74
- halves reply length and cuts cost on task apps, but flattened an NPC's voice.
75
- - **`context`:** the current app state on **every** message: what most turns need to answer
76
- (cart, balance, open tasks, today's schedule, recent orders). Rich state here saves a lookup
77
- call on most turns and keeps the agent from answering without checking. Keep it bounded:
78
- cap long lists and add a hint such as `"more": "use orders list"`. Kept earlier turns are
79
- resent exactly as they were sent, earlier states included. Send the current state on every
80
- message, even when unchanged: Croche sends only what changed, and resends it in full after older turns are folded.
81
- - **Money:** per-user and project spending limits are the Runtime's and Cloud's; do not wrap or
82
- gate the SDK's `fetch` to meter calls. To show or record usage, use `onUsage`: one event for
83
- every paid call, including memory upkeep that belongs to no message.
84
- - **Storage:** durable, one per project; the Runtime keeps each agent's store inside it.
85
- Reopening with the same storage restores every conversation and memory.
86
- - **Time in context:** Core adds the permanent conversation number and short local
87
- time before the input channels, with a zone at the start and after reduction.
88
- Kept messages are never re-dated. Do not add a time channel or `timeContext`;
89
- that removed setting is refused by name.
90
- - **The Runtime's own behaviour is tuned by Croche,** not by the app. Set `memory.policy` only
91
- if this app must keep something specific.
92
- - **Clock:** the Node/web host schedules the Runtime's upkeep. Only with `CrocheRuntime` and
93
- an app clock of its own (tests, simulations): pass `clock` and call `runtime.maintain()` once
94
- `clock()` reaches `runtime.wakeAt()` (epoch ms, like the clock).
95
-
96
- ## Commands: the app's actions
97
-
98
- Each capability is a **command** of a grouped tool. Write per command: a one-line `summary`
99
- saying what it does **and when to use it**, with the allowed values when they are few; typed
100
- flags with `enum`, `minimum`/`maximum`, `required`.
101
-
102
- **Say when each state-changing command may run.** A Croche agent acts on its own judgement by
103
- default; limiting that is your app's call, and it takes one line. For every command that changes
104
- something, put in its `summary` (or in `toolGuide`) whether it runs only when the person asks for
105
- that change, e.g. "Change the cart only when the shopper asks for that change, not because an item
106
- seems suitable or while answering a question." Without it, a shop agent answering "would the
107
- notebook still fit?" may add the notebook (measured 2026-09-29: 17% of such questions changed the
108
- cart; with that one line 0%, and requested changes still ran).
109
-
110
- **Actions that need the person's agreement** (delete, refund, anything that spends or can't be
111
- undone) are approved in your app, not by Croche. Croche has no approval step: a command with a
112
- `confirm` field is refused (`invalid_configuration`). The tool's handler asks the person in your
113
- UI and returns a value the agent reads, such as `{ status: 'waiting_for_approval' }`; once they
114
- approve, a later call runs. Return a value, not an exception: an exception after the handler
115
- starts ends the turn. Don't return `{ ok: false }` for a wait either: it tells the agent the
116
- command failed. The SDK reference has the example ("Approval in your app").
117
-
118
- **Every command that only reads (list, get, search, status, menu) must have `reads: true`.** Not
119
- optional: the agent replies together with its commands, and without the mark a lookup can end
120
- the turn on "let me check" before the answer.
194
+ Project creation returns its ID and **public project key**. Replace `PROJECT_ID` with that ID;
195
+ put the public key into app configuration yourself. For a picked existing project, take its ID and
196
+ public key from `croche projects list --json`; do not create a duplicate. The account `dk_` key never goes into app code or the SDK's `debugKey`.
121
197
 
122
- ```ts
123
- import type { ToolDeclaration, ToolHandler } from '@h1r-ai/croche';
124
-
125
- const shop: ToolDeclaration = { // goes in config.tools
126
- name: 'shop',
127
- summary: 'The inn shop.',
128
- commands: [
129
- { key: 'shop_sell', name: 'sell', summary: 'Sell food or drink the player asks for: stew, bread, ale (evenings only).',
130
- flags: [{ name: 'item', type: 'string', enum: ['stew', 'bread', 'ale'], required: true },
131
- { name: 'qty', type: 'integer', minimum: 1, maximum: 5 }] },
132
- { key: 'shop_menu', name: 'menu', summary: 'List today\'s menu and prices.', reads: true },
133
- ],
134
- };
135
- const runShop: ToolHandler = ({ key, args }, context) => { // goes in handlers.shop
136
- // Enforce everything here: this is the real boundary, not the prompt.
137
- const out = app.run(key, args, context.user);
138
- return out.ok ? out.value : { status: 'rejected', reason: out.reason }; // return, never throw
139
- };
140
- ```
198
+ **CLI workflow — TODO verify:** debug-key commands are implemented; check the installed
199
+ release’s help and verify its behavior before use. If unavailable, report the release blocker; do not improvise a secret-
200
+ printing command or make the user paste another key. The command writes **`CROCHE_DEBUG_KEY`**
201
+ (`cdt_`) to **`./.env`**, returns key metadata and file location (filter out any prefix), creates the file with
202
+ **0600 permissions** for a new file on POSIX, and adds the destination to `.gitignore` in Git.
203
+ An existing file keeps its permissions; check those without displaying its contents.
204
+ `--env-file PATH` chooses another file; verify that path is ignored too. Windows protection is
205
+ unverified. An existing nonempty value is refused without `--force`: stop for explicit approval,
206
+ not an automatic overwrite. Never use a secret-print mode or display the file.
141
207
 
142
- - The declaration is data (a released config can replace it); the handler is code and stays in
143
- the app. `context` names the `agentId`, the `user` and what caused the call.
144
- - The model sees each command's usage line and `summary`. The tool's own `summary` (`'The inn
145
- shop.'`) appears only in `help` output, so put rules in command summaries or `toolGuide`,
146
- never only in the tool summary.
147
- - Summaries have no length limit of their own and are never cut. The whole tool list is capped
148
- at 256,000 bytes of JSON, and each `help` text at 32,000 bytes. Keep each summary to one line.
149
-
150
- - `key` is global across all tools (and becomes the function name under `functions`): prefix
151
- it with the tool name (`shop_sell`), never a bare `list` or `get`.
152
- - If the app already has JSON-schema tool specs, map each to one command (property ->
153
- flag, keeping `type`, `enum`, `minimum`, `maximum`, `required`, `description`) in a small
154
- loop. Do not hand-write them twice.
155
- - A rejected result teaches the model the rule at the moment it needs it; you do not need to
156
- describe every rule in prose. Say what to do instead, in plain words, and name arguments as
157
- the model writes them (`--order-id`).
158
-
159
- **Good commands, in one minute.** Croche renders the usage line, reads forgivingly and answers
160
- mistakes with the exact usage, so you only declare:
161
- - a group noun and short verbs: `tasks add|list|done|delete`, `shop search|add-to-cart`;
162
- - required arguments first: they may be written without their flag, in order
163
- (`tasks done t5`, `shop cart-add notebook 2`);
164
- - `enum` for allowed values. The usage line lists them only when there are at most 12 and they
165
- fit in 120 characters; otherwise it shows a placeholder (`--item ITEM`), so name the values
166
- in the summary or give a read command that lists them;
167
- - `list: true` for several values (`--tags work,home`); the handler gets an array;
168
- - `default` on a flag or positional: the handler's `args` has it filled in when the model omits
169
- the argument;
170
- - `aliases` for verbs a model may mix up (`update` also `edit`, `upgrade`), shown only in help.
171
- Do not handle spelling variants yourself: a missing group, `_` for `-`, or an unquoted multi-word
172
- value are accepted when unambiguous (and counted as `command.repaired` debug events).
173
- - Money, inventory and progress live in the app, never only in what the model was told.
174
- - The Runtime keeps a dated record of what each command did, for when the conversation has moved
175
- on. A handler may add `record: 'one line of what happened'` to its result; otherwise the command
176
- line is recorded.
177
-
178
- ## Tool interface
179
-
180
- A `setTools` filter never changes the system prompt. `toolGuide` is app text,
181
- verbatim at the start of `run_tool`'s **App tools:** section, after the compiled
182
- base guide and **Croche tools:** section. It is not in the system prompt. App
183
- command summaries are shown in full, within the registry's byte cap.
184
-
185
- Use project config `crocheTools` for the built-in library: `memory.save` is on
186
- when memory is on, `wiki` requires visible documents, and `schedule` defaults
187
- off. Set a switch to `false` to remove that tool from both the description and
188
- dispatch. These config fields are removed and refused at every layer (project,
189
- `agents.X`, `languages.Y`, `agents.X.languages.Y`): `memory.keys`,
190
- `memory.commands`, `memory.recall`, `memory.deltas`, `schedule.commands`,
191
- `memoryRecall`, `timeContext`, and `defaultLanguage` anywhere below the project
192
- root. All are refused by name except `memory.deltas` and a nested
193
- `defaultLanguage`, which are refused as unknown fields. The `crocheTools` switch `"memory.recall"` is not that field: it turns the
194
- model's `memory recall` command on or off. Only the model writes monotonic memory ids with `memory
195
- save` or `memory replace`; the app can list, export, delete by id or clear them,
196
- but cannot set keyed facts. A replacement retains its earlier version.
197
- `memory history <tN>` reads bounded archived-turn text and `memory recall <words>`
198
- searches every memory, each when enabled. Nothing is recalled automatically: the
199
- model reads only what it asks for. Conversation summaries are not memory items: deleting or
200
- clearing memories preserves the summary and does not rewrite kept or archived
201
- turns. `clearHistory()` or `Croche.deleteStore()` removes the summary.
202
-
203
- **Croche's own tools and modes, in config:**
208
+ ### Create a project
204
209
 
205
- ```ts
206
- config: {
207
- toolGuide: 'Phone effects are rare: use them only when the person asks.', // app text for run_tool
208
- crocheTools: { 'memory.save': true, 'memory.history': true, 'memory.recall': true, wiki: true, schedule: false },
209
- modes: {
210
- room: { tools: [room], toolGuide: 'In the room, place items only where the person says.' },
211
- },
212
- }
213
- // later: await agent.setMode('room'); … await agent.setMode(null);
214
- ```
210
+ `croche projects create --name "<app name>" --json` creates one (ID and public project key in
211
+ its output). In Studio the same is **Projects → New project**. Either way the agent then runs
212
+ `croche debug-keys create --project PROJECT_ID`, which writes the debug key (`CROCHE_DEBUG_KEY`) into `.env`.
213
+
214
+ ### Wire the private file into the actual stack
215
+
216
+ **Writing `.env` does not load it.** Node and React Native do not automatically put its values
217
+ in the app. `croche login` authenticates the CLI only; it does not supply the SDK's `debugKey`.
218
+
219
+ - **Node:** run `node --env-file=.env app.mjs` (the flag exists from Node 20.6; Croche requires
220
+ Node 22+), or use the project's **existing** dotenv setup before `Croche.open`. For our sample,
221
+ run `node --env-file=.env first-turn.mjs`, not plain `node first-turn.mjs`. Use the actual
222
+ selected env-file path. Fail locally if `CROCHE_DEBUG_KEY` is missing, without printing it.
223
+ - **Web:** load credentials only in the server process, including local development. Keep
224
+ `Croche.open` and `debugKey` on the backend; the browser calls your app endpoint. Never put
225
+ a secret into browser code, a public-prefixed variable or a client bundle.
226
+ - **React Native:** wire `CROCHE_DEBUG_KEY` through the app's existing **debug-only build config**
227
+ to `debugKey: __DEV__ ? developmentKey : undefined`. Neither `process.env` nor `.env` loads
228
+ it automatically. Refuse a missing value in a debug build; exclude the secret at build time
229
+ from release artifacts, not just at runtime. Read `croche-platforms` for the app-specific path.
230
+
231
+ Do this wiring yourself; do not ask for another key. Do not add a dotenv/build dependency
232
+ without permission, source the file into a shell, or display its contents. `croche-cli` also
233
+ covers `debug-keys list` and `debug-keys revoke`; check final arguments before acting.
215
234
 
216
- - `crocheTools` is a flat object with these five dotted keys and boolean values; a nested
217
- `{ memory: { save: true } }` is refused. Defaults: `memory.save`, `memory.history` and `wiki`
218
- on (memory tools only while memory is on; `wiki` only while the agent sees a document),
219
- `memory.recall` follows `memory.save`, `schedule` off. `memory replace` is on exactly when
220
- `memory.save` is.
221
- - `toolGuide` and `crocheTools` are allowed at every config layer, applied in this order:
222
- project → `languages.Y` → `agents.X` → `agents.X.languages.Y` → the `config` your code
223
- passes to `croche.agent(id, { config })` (this agent only), so an agent's value beats a
224
- project language's. `toolGuide` from a later layer replaces the
225
- earlier one. `crocheTools` merges per key: a later layer changes only the keys it names
226
- (project `{ wiki: false, schedule: true }` plus agent `{ schedule: false }` gives
227
- `{ wiki: false, schedule: false }`). Neither has its own size limit; the whole config is
228
- capped at 256 KiB.
229
- - `modes.<name>` takes only `tools` and `toolGuide`. While a mode is on, each one it sets
230
- **replaces** the agent's (no merge); what it leaves out stays. `setMode(null)` turns it off,
231
- and a `setTools` filter still applies on top.
232
-
233
- Tool-list changes are announced in the conversation. A changed app guide is
234
- also a tool-description change, applied at the next turn; it does not edit the
235
- system prompt. A changed description can prevent prefix reuse; this is not a
236
- promise about how much the provider will cache.
237
-
238
- The agent runs your commands as command lines. If your live check shows the same command
239
- rejected with `invalid_arguments` again and again, fix that command (required arguments,
240
- `enum`, `list`, `aliases`, a clearer summary).
241
-
242
- ## A store from an older build
243
-
244
- An agent store written by an older build with keyed memory is refused before any write:
245
- `croche.agent(id)` rejects with a `CrocheError` whose `code` is `memory_store_too_old`.
246
- `Croche.open` itself succeeds, and other agents open normally. To recover:
235
+ ## Choose the model in code
236
+
237
+ The app can choose its model through `Croche.open`'s `config.model`. Set it explicitly:
247
238
 
248
239
  ```ts
249
- let agent;
250
- try {
251
- agent = await croche.agent();
252
- } catch (error) {
253
- if ((error as CrocheError).code !== 'memory_store_too_old') throw error;
254
- await croche.close(); // simplest: delete with nothing open
255
- await Croche.deleteStore({ ...openOptions, agent: 'default' }); // the default agent's id
256
- croche = await Croche.open(openOptions);
257
- agent = await croche.agent();
258
- }
240
+ const config = { model: 'deepseek/deepseek-v4.1-flash', instructions: 'Help this user with the app.' };
241
+ // Pass config in Croche.open alongside the existing project/storage/credential options.
259
242
  ```
260
243
 
261
- This deletes that agent's conversation, memory, user wiki, archive and message log for
262
- that user; other agents and the project record stay. In the Core's words: "This agent's store
263
- was written by an older Croche build whose memory this Core cannot read or convert. Nothing was
264
- changed. To continue, delete this agent's store and reopen; this permanently loses this agent's
265
- conversation and memories for this user. Only an older build that still runs can export them
266
- first." After an app update the older build no longer runs, so tell the person before deleting.
267
- If your app tracks the input ids it sent (pending sends, a retry queue), drop the ones the old
268
- store accepted: their final status never comes. React Native has the same calls.
269
-
270
- ## Check it
244
+ Prefer `deepseek/deepseek-v4.1-flash` for text and images; `openai/gpt-6-luna` is an alternative.
245
+ Text-only apps may choose `deepseek/deepseek-v4-flash-0731` for cheaper output. Infer image use
246
+ from the requested app, and preserve an explicit user model choice.
271
247
 
272
- - One short live session is the check: a real command changed app state, a restart restores
273
- the conversation, and a refused action comes back as a rejection, not a crash. Test your own
274
- handlers as you would any app code; do not test the Runtime.
275
- - Report failures and costs as they are. Never fake an AI result, and never put a provider,
276
- development or server key in a bundle, a repository or a log.
248
+ `model` can appear at project, project-language, agent and agent-language levels; an omitted
249
+ override inherits its base. The unset default is
250
+ `deepseek/deepseek-v4.1-flash`, with `openai/gpt-6-luna` fallback only at reasoning `default` or
251
+ `off` (not `low`, `medium`, or `high`). Set the project model explicitly when you need a particular choice.
252
+ Read `croche-config` or the online [Models page](https://docs.croche.ai/models.md) for the full
253
+ allowed list and fallback limits. Use [llms.txt](https://docs.croche.ai/llms.txt) to discover public
254
+ Markdown docs. Do not tell the user model choice is unavailable.
277
255
 
278
- That is the whole integration. Stop there unless a measured problem sends you to
279
- [Coding-agent guidance](references/coding-agent.md) (why each default is what it is) or the
280
- [SDK reference](references/sdk.md) (streaming, several agents, markers, web backends, mobile).
256
+ ## Markers: expressions and scenes without a tool call
281
257
 
282
- ## CLI
258
+ The model can drive presentation from inside its reply. It writes a marker `:name:` (ASCII
259
+ letters, digits, `_` and `-`); Croche removes it from the text, and the app reacts: a character's
260
+ expression, a scene or background change, a sound. There is no tool call and no extra model
261
+ round trip. Markers never execute anything; actions that change app state stay tools.
283
262
 
284
- `croche --help` lists everything. The ones an integration usually needs:
263
+ - **Tell the model which markers exist** with `markerGuide` in the agent config: `config.markerGuide`
264
+ in `Croche.open`, per agent under `config.agents`, or in the project config in Studio.
265
+ - **Read them on `message.end`:** `event.markers` lists the names in reply order. Markers never
266
+ appear in `message.delta` or the message text. Every `:name:` that fits the syntax counts, so
267
+ ignore names the app does not know. Messages replayed before `snapshot` carry their markers too.
268
+ - Structured turns (`responseFormat`) produce no markers.
285
269
 
286
- ```sh
287
- croche projects list
288
- croche keys development list <project-id>
289
- croche keys server list <project-id>
290
- croche attestation get <project-id>
291
- croche projects usage <project-id> --period week
292
- croche debug # attach the local debugger
270
+ ```ts
271
+ const config = {
272
+ instructions: 'You are Mina, a cheerful guide.',
273
+ markerGuide: 'Show feelings with :happy: or :sad:. Change the scene with :scene-beach: or :scene-night:.',
274
+ };
275
+ // Pass config in Croche.open alongside the existing options; then, for the agent:
276
+ agent.subscribe({ onEvent(event) {
277
+ if (event.type !== 'message.end') return;
278
+ for (const name of event.markers as string[]) { // setExpression/setScene: app UI functions
279
+ if (name === 'happy' || name === 'sad') setExpression(name);
280
+ if (name.startsWith('scene-')) setScene(name.slice('scene-'.length));
281
+ }
282
+ } });
293
283
  ```
294
284
 
295
- Full reference: [CLI](references/cli.md).
285
+ ## Implement, then prove it
286
+
287
+ 1. Check installed versions and obtain required install permission. For Node, adapt
288
+ [first-turn.md](references/first-turn.md); for RN/web, use `croche-platforms`.
289
+ 2. Open one `Croche` project per user, then `croche.agent()`. Keep it open for the app session.
290
+ Use new input IDs for new messages; retain an ID and identical payload for delivery retries.
291
+ 3. When the app needs actions, read [tools.md](references/tools.md). Add declarations and
292
+ matching handlers; enforce permissions and user approval in the handler/UI.
293
+ For current web facts, turn on the built-in web search in the project's Studio config instead
294
+ of writing your own: [web-search.md](references/web-search.md).
295
+ 4. Write the app's code config and integration code yourself; do not hand the user a list of
296
+ implementation chores. For streaming, multiple agents or memory UI, read [agents.md](references/agents.md).
297
+ 5. Run local syntax/type checks first. With live-usage authorization, make one small request.
298
+ This is the first-turn check for the requested integration, not permission for repeated paid
299
+ experimentation. Confirm a completed reply, not merely a send receipt. Never manufacture a success transcript.
300
+ 6. Report the completed reply or real blocker, files changed and exact run command. Tell the
301
+ user how to verify in **Monitoring → Logs** (development filter if needed); reports can lag.
302
+ Development traffic does not appear in **Monitoring → Activity**. Reopen the same store and
303
+ subscribe to read the replayed history, not another paid message, to verify persistence. Test any app action once and
304
+ a refused action without an unintended state change.
305
+
306
+ The completion report covers files changed, checks actually run, completed reply/error status,
307
+ and this verification pointer: **Studio → select the project → Monitoring → Logs → development
308
+ filter**. Say whether a real turn ran; never claim a log was seen unless checked. Development
309
+ traffic is not in Monitoring → Activity. Do not end with only local run commands.
310
+ Do not silently spend repeatedly, raise budgets, release a config, or delete stored data to
311
+ make a check pass. Stop at the error and use `croche-troubleshoot`.
312
+
313
+ ## Watch it in Studio (development only)
314
+
315
+ The local debugger shows a running app's turns, tools and costs in Studio. It is off by default:
316
+ the app opts in, in a **development build only**, never a release build.
317
+
318
+ - **Collector:** `croche debug start` starts it on `127.0.0.1:8790`. Start it **before**
319
+ starting or restarting the app; events sent before the collector runs are lost. Delivery is best effort, with no retry.
320
+ - **Pairing token:** a local credential. Read it in the development host from
321
+ `croche debug token`, or from `pairingToken` in the connection file, never printed or
322
+ committed:
323
+ - macOS: `~/Library/Application Support/croche/debugger/connection.json`;
324
+ - Linux: `${XDG_STATE_HOME:-~/.local/state}/croche/debugger/connection.json`;
325
+ - Windows: `%LOCALAPPDATA%\croche\debugger\connection.json`.
326
+
327
+ Never put it in a browser bundle; a browser app needs a server-side relay (`DEBUGGER.md`).
328
+ - **Wiring, project agents:**
329
+
330
+ ```ts
331
+ import { createLocalDebugger } from '@h1r-ai/croche/debug';
332
+ const debug = createLocalDebugger({ token: pairingToken, appName: 'My app' });
333
+ const croche = await Croche.open({ /* existing options */ onDebugEvent: debug.onEvent });
334
+ ```
335
+
336
+ For a raw runtime: `runtime.setDebugObserver({ onDebugEvent: debug.onEvent, visibility: 'runtime' })`.
337
+ These entries are stamped `visibility: 'runtime'`, which is what Studio shows.
338
+ - **Open it:** `croche debug --studio-link` prints a fresh Studio link; open it. Counters at 0 after a turn mean the app is not wired, or
339
+ started before the collector.
@@ -0,0 +1,4 @@
1
+ interface:
2
+ display_name: "Croche"
3
+ short_description: "Guide an app to its first Croche reply"
4
+ default_prompt: "Use $croche to integrate Croche into my app and guide me through setup."