@h1r-ai/croche 0.0.0-stage → 0.5.1
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 +32 -0
- package/README.md +1184 -2
- package/THIRD-PARTY-NOTICES +5824 -0
- package/dist/archive.d.ts +47 -0
- package/dist/archive.js +217 -0
- package/dist/atomic-replace.d.ts +18 -0
- package/dist/atomic-replace.js +39 -0
- package/dist/commands.d.ts +56 -0
- package/dist/commands.js +1 -0
- package/dist/control.d.ts +62 -0
- package/dist/control.js +269 -0
- package/dist/core-abi.d.ts +110 -0
- package/dist/core-abi.js +1 -0
- package/dist/core-bindgen.d.ts +413 -0
- package/dist/core-bindgen.js +1533 -0
- package/dist/core-runtime.d.ts +214 -0
- package/dist/core-runtime.js +837 -0
- package/dist/core-wasm-bytes.d.ts +4 -0
- package/dist/core-wasm-bytes.js +5 -0
- package/dist/core-wasm.d.ts +16 -0
- package/dist/core-wasm.js +63 -0
- package/dist/debug.d.ts +26 -0
- package/dist/debug.js +171 -0
- package/dist/file-lock.d.ts +46 -0
- package/dist/file-lock.js +300 -0
- package/dist/images.d.ts +53 -0
- package/dist/images.js +179 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +9 -0
- package/dist/markers.d.ts +1 -0
- package/dist/markers.js +1 -0
- package/dist/node.d.ts +46 -0
- package/dist/node.js +281 -0
- package/dist/project-core.d.ts +79 -0
- package/dist/project-core.js +261 -0
- package/dist/project-session.d.ts +44 -0
- package/dist/project-session.js +143 -0
- package/dist/project-types.d.ts +97 -0
- package/dist/project-types.js +1 -0
- package/dist/project-wire.d.ts +19 -0
- package/dist/project-wire.js +39 -0
- package/dist/sse.d.ts +19 -0
- package/dist/sse.js +53 -0
- package/dist/storage.d.ts +24 -0
- package/dist/storage.js +32 -0
- package/dist/stream-branch.d.ts +47 -0
- package/dist/stream-branch.js +107 -0
- package/dist/stream-hub.d.ts +207 -0
- package/dist/stream-hub.js +210 -0
- package/dist/stream.d.ts +3 -0
- package/dist/stream.js +5 -0
- package/dist/types.d.ts +928 -0
- package/dist/types.js +8 -0
- package/dist/wiki.d.ts +15 -0
- package/dist/wiki.js +25 -0
- package/docs/CODING-AGENT.md +96 -0
- package/docs/DEBUGGER.md +230 -0
- package/docs/S2-IMPLEMENTATION.md +585 -0
- package/docs/SKILL.md +337 -0
- package/docs/skills/croche/agents/openai.yaml +4 -0
- package/docs/skills/croche/references/agents.md +78 -0
- package/docs/skills/croche/references/first-turn.md +74 -0
- package/docs/skills/croche/references/tools.md +43 -0
- package/docs/skills/croche-cli/SKILL.md +158 -0
- package/docs/skills/croche-cli/agents/openai.yaml +4 -0
- package/docs/skills/croche-cli/references/powershell.md +47 -0
- package/docs/skills/croche-config/SKILL.md +152 -0
- package/docs/skills/croche-config/agents/openai.yaml +4 -0
- package/docs/skills/croche-config/references/models.md +12 -0
- package/docs/skills/croche-platforms/SKILL.md +55 -0
- package/docs/skills/croche-platforms/agents/openai.yaml +4 -0
- package/docs/skills/croche-platforms/references/android.md +185 -0
- package/docs/skills/croche-platforms/references/ios.md +165 -0
- package/docs/skills/croche-platforms/references/react-native.md +50 -0
- package/docs/skills/croche-platforms/references/web-backend.md +58 -0
- package/docs/skills/croche-troubleshoot/SKILL.md +72 -0
- package/docs/skills/croche-troubleshoot/agents/openai.yaml +4 -0
- package/docs/skills/croche-troubleshoot/references/recovery.md +31 -0
- package/package.json +52 -4
- package/src/archive.ts +188 -0
- package/src/atomic-replace.ts +43 -0
- package/src/commands.ts +62 -0
- package/src/control.ts +179 -0
- package/src/core-abi.ts +52 -0
- package/src/core-bindgen.ts +1557 -0
- package/src/core-runtime.ts +750 -0
- package/src/core-wasm-bytes.ts +5 -0
- package/src/core-wasm.ts +57 -0
- package/src/debug.ts +160 -0
- package/src/file-lock.ts +269 -0
- package/src/images.ts +174 -0
- package/src/index.ts +15 -0
- package/src/markers.ts +1 -0
- package/src/node.ts +194 -0
- package/src/project-core.ts +231 -0
- package/src/project-session.ts +118 -0
- package/src/project-types.ts +77 -0
- package/src/project-wire.ts +39 -0
- package/src/sse.ts +57 -0
- package/src/storage.ts +30 -0
- package/src/stream-branch.ts +112 -0
- package/src/stream-hub.ts +249 -0
- package/src/stream.ts +7 -0
- package/src/types.ts +838 -0
- package/src/wiki.ts +25 -0
package/docs/SKILL.md
ADDED
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: croche
|
|
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
|
+
---
|
|
5
|
+
|
|
6
|
+
# Build with Croche
|
|
7
|
+
|
|
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.
|
|
12
|
+
|
|
13
|
+
## Plugin installation, only if needed
|
|
14
|
+
|
|
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.
|
|
19
|
+
|
|
20
|
+
**Claude Code**, in your terminal:
|
|
21
|
+
|
|
22
|
+
```sh
|
|
23
|
+
claude plugin marketplace add H1R-AI/croche
|
|
24
|
+
claude plugin install croche@croche
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
**Codex**, in your terminal:
|
|
28
|
+
|
|
29
|
+
```sh
|
|
30
|
+
codex plugin marketplace add H1R-AI/croche
|
|
31
|
+
codex plugin add croche@croche
|
|
32
|
+
```
|
|
33
|
+
|
|
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 exist.** The shared `Croche.open` project API is coming in **0.5.1**;
|
|
69
|
+
Read the `croche-platforms` iOS/Android reference for the candidate install and first turn.
|
|
70
|
+
TODO verify: package resolution and native execution. Describe the pending project API, not absent SDKs.
|
|
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.1 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:
|
|
187
|
+
|
|
188
|
+
```sh
|
|
189
|
+
croche auth whoami --json
|
|
190
|
+
croche projects create --name "My app" --json
|
|
191
|
+
croche debug-keys create --project PROJECT_ID --json
|
|
192
|
+
```
|
|
193
|
+
|
|
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`.
|
|
197
|
+
|
|
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.
|
|
207
|
+
|
|
208
|
+
### Create a project
|
|
209
|
+
|
|
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.
|
|
234
|
+
|
|
235
|
+
## Choose the model in code
|
|
236
|
+
|
|
237
|
+
The app can choose its model through `Croche.open`'s `config.model`. Set it explicitly:
|
|
238
|
+
|
|
239
|
+
```ts
|
|
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.
|
|
242
|
+
```
|
|
243
|
+
|
|
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.
|
|
247
|
+
|
|
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.
|
|
255
|
+
|
|
256
|
+
## Markers: expressions and scenes without a tool call
|
|
257
|
+
|
|
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.
|
|
262
|
+
|
|
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.
|
|
269
|
+
|
|
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
|
+
} });
|
|
283
|
+
```
|
|
284
|
+
|
|
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
|
+
4. Write the app's code config and integration code yourself; do not hand the user a list of
|
|
294
|
+
implementation chores. For streaming, multiple agents or memory UI, read [agents.md](references/agents.md).
|
|
295
|
+
5. Run local syntax/type checks first. With live-usage authorization, make one small request.
|
|
296
|
+
This is the first-turn check for the requested integration, not permission for repeated paid
|
|
297
|
+
experimentation. Confirm a completed reply, not merely a send receipt. Never manufacture a success transcript.
|
|
298
|
+
6. Report the completed reply or real blocker, files changed and exact run command. Tell the
|
|
299
|
+
user how to verify in **Monitoring → Logs** (development filter if needed); reports can lag.
|
|
300
|
+
Development traffic does not appear in **Monitoring → Activity**. Reopen the same store and
|
|
301
|
+
subscribe to read the replayed history, not another paid message, to verify persistence. Test any app action once and
|
|
302
|
+
a refused action without an unintended state change.
|
|
303
|
+
|
|
304
|
+
The completion report covers files changed, checks actually run, completed reply/error status,
|
|
305
|
+
and this verification pointer: **Studio → select the project → Monitoring → Logs → development
|
|
306
|
+
filter**. Say whether a real turn ran; never claim a log was seen unless checked. Development
|
|
307
|
+
traffic is not in Monitoring → Activity. Do not end with only local run commands.
|
|
308
|
+
Do not silently spend repeatedly, raise budgets, release a config, or delete stored data to
|
|
309
|
+
make a check pass. Stop at the error and use `croche-troubleshoot`.
|
|
310
|
+
|
|
311
|
+
## Watch it in Studio (development only)
|
|
312
|
+
|
|
313
|
+
The local debugger shows a running app's turns, tools and costs in Studio. It is off by default:
|
|
314
|
+
the app opts in, in a **development build only**, never a release build.
|
|
315
|
+
|
|
316
|
+
- **Collector:** `croche debug start` starts it on `127.0.0.1:8790`. Start it **before**
|
|
317
|
+
starting or restarting the app; events sent before the collector runs are lost. Delivery is best effort, with no retry.
|
|
318
|
+
- **Pairing token:** a local credential. Read it in the development host from
|
|
319
|
+
`croche debug token`, or from `pairingToken` in the connection file, never printed or
|
|
320
|
+
committed:
|
|
321
|
+
- macOS: `~/Library/Application Support/croche/debugger/connection.json`;
|
|
322
|
+
- Linux: `${XDG_STATE_HOME:-~/.local/state}/croche/debugger/connection.json`;
|
|
323
|
+
- Windows: `%LOCALAPPDATA%\croche\debugger\connection.json`.
|
|
324
|
+
|
|
325
|
+
Never put it in a browser bundle; a browser app needs a server-side relay (`DEBUGGER.md`).
|
|
326
|
+
- **Wiring, project agents:**
|
|
327
|
+
|
|
328
|
+
```ts
|
|
329
|
+
import { createLocalDebugger } from '@h1r-ai/croche/debug';
|
|
330
|
+
const debug = createLocalDebugger({ token: pairingToken, appName: 'My app' });
|
|
331
|
+
const croche = await Croche.open({ /* existing options */ onDebugEvent: debug.onEvent });
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
For a raw runtime: `runtime.setDebugObserver({ onDebugEvent: debug.onEvent, visibility: 'runtime' })`.
|
|
335
|
+
These entries are stamped `visibility: 'runtime'`, which is what Studio shows.
|
|
336
|
+
- **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
|
|
337
|
+
started before the collector.
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# Messages, agents and memory
|
|
2
|
+
|
|
3
|
+
Use only for the relevant SDK task. The examples use an already-open `croche` project.
|
|
4
|
+
|
|
5
|
+
## Messages and UI
|
|
6
|
+
|
|
7
|
+
`const agent = await croche.agent()` opens the default agent. `agent.request(input)` waits
|
|
8
|
+
for the result and its final messages. `agent.send(input)` returns a receipt, not a reply.
|
|
9
|
+
For streaming, subscribe once and render messages by their IDs:
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
const subscription = agent.subscribe({ onEvent(event) {
|
|
13
|
+
// App UI functions, not Croche APIs. Delta text is provisional; end text is authoritative.
|
|
14
|
+
if (event.type === 'message.delta') appendText(event.id, event.text);
|
|
15
|
+
if (event.type === 'message.end') finishMessage(event.id, event.text, event.status);
|
|
16
|
+
} });
|
|
17
|
+
await agent.send({ id: messageId, text: userText });
|
|
18
|
+
// On UI teardown: subscription.close(); on app-session teardown: await croche.close();
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
A subscription replays the latest stored messages (`initialMessages`, default 50) before its
|
|
22
|
+
`snapshot`, without another model request; `history({ limit, before? })` asks that open
|
|
23
|
+
subscription for an older `page`. One subscription per agent: a second `subscribe` on the same
|
|
24
|
+
agent replaces the first, which receives a final `{ type: 'replaced' }` event. Do not
|
|
25
|
+
render a send receipt as an assistant message. Check final statuses and preserve input IDs
|
|
26
|
+
across delivery retries. A new ID is a new attempt and can produce another app action.
|
|
27
|
+
|
|
28
|
+
## Multiple conversations
|
|
29
|
+
|
|
30
|
+
Declare named agents in `config.agents`, for example
|
|
31
|
+
`{ helper: { instructions: 'Help with this app.' } }`, then `await croche.agent('helper')`.
|
|
32
|
+
Use `croche.agent('helper', { instance: 'save-2' })` for a named conversation or
|
|
33
|
+
`{ fresh: true }` for a new one. Keep instances tied to the current app user.
|
|
34
|
+
`agent.setTools(names)` filters available tools; `agent.setTools(null)` removes the filter.
|
|
35
|
+
`agent.setMode(name)` selects a configured mode; `agent.setMode(null)` leaves it.
|
|
36
|
+
|
|
37
|
+
## App-visible memories
|
|
38
|
+
|
|
39
|
+
The app can read or remove AI-written memories, not set keyed facts:
|
|
40
|
+
|
|
41
|
+
- `await agent.memory.list()` is the current list; use memory IDs, not invented keys.
|
|
42
|
+
- `await agent.memory.export()` exports memory data for a user-requested export.
|
|
43
|
+
- `await agent.memory.delete(id)` removes an item and its earlier versions.
|
|
44
|
+
- `await agent.memory.clear()` removes all memory items.
|
|
45
|
+
- `await agent.memory.enabled(false)` disables memory; `true` enables it again.
|
|
46
|
+
- `agent.memory.onChanged(callback)` signals that the UI should re-read `list()`; it is a hint,
|
|
47
|
+
not a complete event log. Awaiting the read works for both TS and RN.
|
|
48
|
+
|
|
49
|
+
Deleting memories does not erase conversation history. Use `agent.clearHistory()` only for
|
|
50
|
+
an explicitly requested conversation reset. Never promise that clearing one surface deletes
|
|
51
|
+
all user data. Exported conversations and memories are private user data; do not paste them
|
|
52
|
+
into a bug report. For `memory_store_too_old`, use `croche-troubleshoot` before touching storage.
|
|
53
|
+
|
|
54
|
+
## Optional app state and images
|
|
55
|
+
|
|
56
|
+
Most turns contain only a user message. `context` is optional app state, kept apart from
|
|
57
|
+
that message. It costs tokens each time it is included and is useful when the request needs
|
|
58
|
+
app state: a command or button acting on app data, or after that state changed. An image
|
|
59
|
+
can share the input when needed. Without context, an input carries only the message;
|
|
60
|
+
earlier states stay as sent until older turns are folded. Tools check current app data,
|
|
61
|
+
not an old snapshot. This optional photo path combines state and inputs in **one** request.
|
|
62
|
+
The input shape is either top-level `text`/`images` or an `inputs` stack, not both:
|
|
63
|
+
|
|
64
|
+
```ts
|
|
65
|
+
const result = await agent.request({
|
|
66
|
+
id: crypto.randomUUID(),
|
|
67
|
+
context: { todos: currentTodos },
|
|
68
|
+
inputs: [{ kind: 'user', text: 'Add these items.',
|
|
69
|
+
images: [{ data: photoBase64, mime: 'image/jpeg',
|
|
70
|
+
alt: 'Photo of a handwritten shopping list', resolution: 'high' }] }],
|
|
71
|
+
});
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Use base64 with its MIME type (PNG, JPEG, WebP or GIF); at most four images per message,
|
|
75
|
+
3 MB each and 6 MB total. With `request`, set resolution on each image, not in request
|
|
76
|
+
options. Choose an image-capable model; otherwise the request fails with
|
|
77
|
+
`images_unsupported`. A useful `alt` describes the image when its bytes are no longer in
|
|
78
|
+
the active conversation. See the [Models page](https://docs.croche.ai/models.md).
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Node: one real reply
|
|
2
|
+
|
|
3
|
+
Use for a Node script or the first local check before adding UI. Node.js 22+ on macOS/Linux;
|
|
4
|
+
Windows verification pending. SDK 0.5.1 is published on npm; a real first turn on the user’s
|
|
5
|
+
platform still needs verification. With installation permission, install the published SDK:
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm install @h1r-ai/croche
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
The user completes only signup, one account key and user-run `croche login`. You obtain the
|
|
12
|
+
public project key from CLI project creation and use the `debug-keys create` command to write the SDK debug key
|
|
13
|
+
into `.env` without exposing it. TODO verify that CLI workflow against the released version.
|
|
14
|
+
Insert the **public** project key into the placeholder below; do not open or print `.env`.
|
|
15
|
+
Do not use the account `CROCHE_ACCOUNT_KEY` as an SDK option. Ignore `croche-state/` as private
|
|
16
|
+
app data and verify `.env` is ignored; preserve existing ignore rules.
|
|
17
|
+
|
|
18
|
+
Save as `first-turn.mjs`:
|
|
19
|
+
|
|
20
|
+
```js
|
|
21
|
+
import { randomUUID } from 'node:crypto';
|
|
22
|
+
import { Croche } from '@h1r-ai/croche';
|
|
23
|
+
import { FileStorage } from '@h1r-ai/croche/node';
|
|
24
|
+
|
|
25
|
+
if (!process.env.CROCHE_DEBUG_KEY) throw new Error('Load the private CLI-created env file.');
|
|
26
|
+
const croche = await Croche.open({
|
|
27
|
+
projectKey: '<public project key returned by CLI>',
|
|
28
|
+
debugKey: process.env.CROCHE_DEBUG_KEY,
|
|
29
|
+
user: 'local-demo-user', // replace with your authenticated app user's stable ID
|
|
30
|
+
storage: new FileStorage('./croche-state'),
|
|
31
|
+
config: { model: 'deepseek/deepseek-v4.1-flash', instructions: 'You are a friendly guide. Reply in one or two sentences.' },
|
|
32
|
+
});
|
|
33
|
+
try {
|
|
34
|
+
const agent = await croche.agent();
|
|
35
|
+
const result = await agent.request({ id: randomUUID(), text: 'Hello! What can you do?' });
|
|
36
|
+
const reply = result.messages.at(-1);
|
|
37
|
+
if (result.status !== 'answered' || reply?.status !== 'completed' || !reply.text?.trim()) {
|
|
38
|
+
console.error('First turn did not complete:', result.status, reply?.error?.code ?? 'no_reply');
|
|
39
|
+
process.exitCode = 1;
|
|
40
|
+
} else {
|
|
41
|
+
console.log(reply.text);
|
|
42
|
+
}
|
|
43
|
+
} finally {
|
|
44
|
+
await croche.close();
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
**Node does not load `.env` automatically.** Plain `node first-turn.mjs` leaves `debugKey`
|
|
49
|
+
unset unless the process already has that variable. A successful CLI login does not populate it.
|
|
50
|
+
Check syntax first, then use the real env-file loader for one authorized live turn:
|
|
51
|
+
|
|
52
|
+
```sh
|
|
53
|
+
node --check first-turn.mjs
|
|
54
|
+
node --env-file=.env first-turn.mjs
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
`--env-file` exists in Node 20.6+; Croche still requires Node 22+. The project's existing dotenv
|
|
58
|
+
setup is an alternative only if it loads the chosen file before `Croche.open`; do not install
|
|
59
|
+
another loader without permission. For another entry point, use `node --env-file=.env app.mjs`.
|
|
60
|
+
Use the selected file path if it differs. The missing-key guard fails locally before opening;
|
|
61
|
+
check presence, never the value. Node loads the file directly without printing it. Do not source
|
|
62
|
+
it or paste it into chat. A completed, nonempty reply is the check; neither a successful open
|
|
63
|
+
nor a queued receipt proves the model answered. Report error codes without dumping options,
|
|
64
|
+
environment variables, or whole error objects that may contain private data.
|
|
65
|
+
|
|
66
|
+
For a persistence check, reopen with the same options and subscribe instead of sending another
|
|
67
|
+
message. The subscription replays the latest stored messages (`initialMessages`, default 50)
|
|
68
|
+
before its `snapshot` event; confirm the earlier reply's `message.end` is among them, then close
|
|
69
|
+
the subscription and the project. `history()` is not this check: it returns nothing, needs an
|
|
70
|
+
open subscription, and only delivers an older `page` event to it. In an app, substitute authenticated user IDs, give each
|
|
71
|
+
user isolated durable storage, and reuse the open project rather than opening per message.
|
|
72
|
+
|
|
73
|
+
If a Studio draft already exists, it may replace this sample's config after a sync and next
|
|
74
|
+
open. Read `croche-config` before trying to debug an apparent instruction mismatch.
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# App actions
|
|
2
|
+
|
|
3
|
+
Use when implementing a tool, not for a text-only first turn. Put serializable declarations
|
|
4
|
+
in `config.tools` and executable handlers in `handlers`, indexed by the tool's name.
|
|
5
|
+
|
|
6
|
+
```ts
|
|
7
|
+
import type { ToolDeclaration, ToolHandler } from '@h1r-ai/croche';
|
|
8
|
+
|
|
9
|
+
const inventory: ToolDeclaration = {
|
|
10
|
+
name: 'inventory',
|
|
11
|
+
summary: 'The player inventory.',
|
|
12
|
+
commands: [{
|
|
13
|
+
key: 'inventory_list', name: 'list', reads: true,
|
|
14
|
+
summary: 'List the items this player owns when asked about their inventory.',
|
|
15
|
+
}],
|
|
16
|
+
};
|
|
17
|
+
// app.inventoryFor is your app function, not a Croche API.
|
|
18
|
+
const inventoryHandler: ToolHandler = async ({ key }, context) => {
|
|
19
|
+
if (key !== 'inventory_list') return { status: 'rejected', reason: 'Unknown action.' };
|
|
20
|
+
return { items: await app.inventoryFor(context.user) };
|
|
21
|
+
};
|
|
22
|
+
// In Croche.open: config: { instructions, tools: [inventory] },
|
|
23
|
+
// handlers: { inventory: inventoryHandler }
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
- Use a globally unique command `key` (for example `inventory_list`). Group related commands;
|
|
27
|
+
flags support `type`, `enum`, `required`, `minimum`, `maximum`, and `list`.
|
|
28
|
+
- Mark every read-only command `reads: true`. Its summary should explain when to use it.
|
|
29
|
+
- For mutations, say **when the user must request the action** in the command summary or
|
|
30
|
+
`toolGuide`. Enforce authorization, allowed values and current app state in the handler;
|
|
31
|
+
the description is not an access-control boundary.
|
|
32
|
+
- For a purchase, deletion or other action needing consent, use the app's confirmation UI.
|
|
33
|
+
Return `{ status: 'waiting_for_approval' }` while waiting; only execute after real approval.
|
|
34
|
+
Croche does not supply a `confirm` declaration field. Do not invent one.
|
|
35
|
+
- Return structured expected rejections (reason and next step). A thrown handler error ends
|
|
36
|
+
the turn; do not report a successful change when nothing changed.
|
|
37
|
+
- Keep authoritative balances/inventory in the app. Pass bounded current app state as input
|
|
38
|
+
`context`, and deduplicate business operations in app code; a new model request is not a
|
|
39
|
+
guarantee that an earlier effect did not happen.
|
|
40
|
+
- Studio drafts must include **every tool the app uses**. Omitting a declaration removes the
|
|
41
|
+
agent's access at the next open; a declaration without a registered handler is not delivered.
|
|
42
|
+
|
|
43
|
+
Verify one safe read/action and one denial against app state, not just the assistant's words.
|