yichus 0.3.0 → 0.3.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.
@@ -0,0 +1,11 @@
1
+ # Failure scenarios for an action
2
+
3
+ The studio asks for one of these when the person chose "all or nothing" for an action that changes records in several steps, or chose a plan for an action that calls an outside service. You write the case as JSON at the path `yichus_next` names (`.yichus/cases/<question>.json`). Each `yichus_next` runs it with `api_protocol_check` against the program in the folder. You never run a command for it.
4
+
5
+ A case lists the starting rows, the requests (two deliveries of one request on two servers, for example), the clock values and outside results to try, and the rules that must hold in every order the steps can run, with crashes between them. The checker tries every order within those bounds. "Holds" means it holds for every order in the case, not for every input. The page says so.
6
+
7
+ Observation predicates the case names are Bosatsu functions. Put them in `.yichus/cases/*.bosatsu`: the studio passes those files to protocol checks only, so they never count as part of the app.
8
+
9
+ Write the rules from the person's choice ("a withdrawal is taken once, or not at all"), never from what the code does. Then test the case on a deliberately broken copy of the program: the check must fail there with a named counterexample. A case that passes against broken code checks nothing.
10
+
11
+ `withdrawal-case.json` and `withdrawal.bosatsu`, which come with this topic, are a complete case and the program it checks. Two servers deliver the same withdrawal, and the case requires exactly one durable receipt. The specification follows.
@@ -38,9 +38,11 @@ section does not change the report's universal proof result.
38
38
  ## Case format: protocol-case-1.0
39
39
 
40
40
  Every top-level field below is required. Unknown fields and duplicate JSON keys
41
- are rejected recursively. The complete runnable example is
42
- [article-retrieval.protocol.json](../icetakes/probes/article-retrieval.protocol.json).
43
- The replacement-worker and final-attempt cases sit beside it.
41
+ are rejected recursively. A complete runnable example is the withdrawal case,
42
+ `withdrawal-case.json`, with the program it checks, `withdrawal.bosatsu`. Both
43
+ come with the studio's `protocol-case` reference; in this repository they are
44
+ `eval/corpus/webmcp-traps/iteration-003/programs/Q15/twin/case.json` and
45
+ `ledger.bosatsu` beside it.
44
46
 
45
47
  | Field | Contract |
46
48
  | --- | --- |
@@ -109,8 +111,8 @@ An invariant entry names a compiled `IO[Bool]` function:
109
111
 
110
112
  ```json
111
113
  {
112
- "name": "current-lease-and-input",
113
- "binding": "Icetakes/RetrievalInvariants::completion_has_current_lease",
114
+ "name": "balance-never-negative",
115
+ "binding": "Ledger/Invariants::balance_never_negative",
114
116
  "arguments": { "before": "before", "after": "after", "now": "time" },
115
117
  "when": "always"
116
118
  }
@@ -124,16 +126,14 @@ named argument. Selector types must equal parameter types. Predicates may read
124
126
  these databases; writes and other IO are rejected. Return predicates automatically
125
127
  require a return witness, preventing success from a wholly unobserved return path.
126
128
 
127
- Use `explore --agenda` and `organize` on the predicate's complete source set,
128
- then read their findings alongside the protocol case. The explorer does not
129
- see entry points selected by a separate case JSON, and generic samples of
130
- unrelated records may never satisfy an identity comparison. An unexecuted
131
- reference or constant-result observation is therefore a prompt to investigate,
132
- not evidence that a predicate is dead or correct. Require witnesses for the
133
- states the invariant describes, and test a deliberately broken implementation
134
- that must produce a named counterexample. The
135
- [Icetakes completion cases](../icetakes/probes/2026-09-25-completion-coherence.md)
136
- demonstrate this workflow with typed source relationships and durable receipts.
129
+ Exploring the predicate's complete source set (`api_explore`, or the CLI's
130
+ `explore --agenda` and `organize`) helps, but the explorer does not see entry
131
+ points selected by a separate case JSON, and generic samples of unrelated
132
+ records may never satisfy an identity comparison. An unexecuted reference or
133
+ constant-result observation is therefore a prompt to investigate, not evidence
134
+ that a predicate is dead or correct. Require witnesses for the states the
135
+ invariant describes, and test a deliberately broken implementation that must
136
+ produce a named counterexample.
137
137
 
138
138
  ## Trace assertions
139
139
 
@@ -191,6 +191,4 @@ history, not an exploration of every possible five-attempt history.
191
191
  The conformance suites replay actual generated JavaScript with a controlled
192
192
  adapter and compare JVM transaction and model-call behavior with model transitions. They test
193
193
  that boundary under the declared adapter contract; they do not certify a deployed
194
- PostgreSQL adapter, JWT implementation, external fetch service, or model provider. The retained
195
- [earlier retrieval report](../icetakes/probes/article-retrieval-report.json) remains
196
- a separate artifact and is not replaced by a runtime-test success label.
194
+ PostgreSQL adapter, JWT implementation, external fetch service, or model provider.
@@ -0,0 +1,42 @@
1
+ # A Render Blueprint for the engine and its database. Commit it at the root
2
+ # of the folder Render deploys, with engine.mjs, server.mjs, store.mjs, a
3
+ # package.json that depends on @yichus/postgres-store and pg, and the
4
+ # package-lock.json npm writes (npm ci installs from it).
5
+ databases:
6
+ - name: app-db
7
+ plan: basic-256mb
8
+ services:
9
+ - type: web
10
+ name: app-api
11
+ runtime: node
12
+ plan: starter
13
+ # One server: keep it at 1 and leave autoscaling off. Raise it only when
14
+ # the person chose several copies and the studio's checks hold for that.
15
+ numInstances: 1
16
+ buildCommand: npm ci --omit=dev
17
+ startCommand: node server.mjs
18
+ # Render sends traffic to a new deploy only once this answers.
19
+ healthCheckPath: /health
20
+ envVars:
21
+ - key: NODE_VERSION
22
+ value: "22"
23
+ - key: DATABASE_URL
24
+ fromDatabase:
25
+ name: app-db
26
+ property: connectionString
27
+ - key: YICHUS_STORE
28
+ value: adapter:./store.mjs
29
+ - key: YICHUS_POSTGRES_NAMESPACE
30
+ value: app-1
31
+ # How the engine checks who is calling (see "An identity mode" in
32
+ # deploy-platforms.md). For sign-in with a provider's sessions:
33
+ - key: YICHUS_AUTH
34
+ value: jwt
35
+ - key: YICHUS_JWKS_URL
36
+ sync: false
37
+ # The page's origin, when a browser calls the API directly.
38
+ - key: YICHUS_CORS_ORIGIN
39
+ sync: false
40
+ # Only with worker routes; set it here and on the page host.
41
+ - key: INGEST_WORKER_SECRET
42
+ sync: false
@@ -0,0 +1,33 @@
1
+ // The start command. Applies the store's schema (it is safe to run on every
2
+ // start), then starts the engine api_deploy generated as engine.mjs, which
3
+ // reads YICHUS_STORE, YICHUS_AUTH and PORT from the environment and refuses
4
+ // to listen when sign-in is not configured.
5
+ import pg from 'pg';
6
+ import { migrateYichusPostgres } from '@yichus/postgres-store';
7
+
8
+ import { attachYichusWorkerVerifier, startYichusApiEngine, yichusSecretWorkerVerifier } from './engine.mjs';
9
+
10
+ const connectionString = process.env.DATABASE_URL;
11
+ if (!connectionString) {
12
+ console.error('refusing to start: DATABASE_URL is not set');
13
+ process.exit(1);
14
+ }
15
+ const pool = new pg.Pool({ connectionString });
16
+ try {
17
+ await migrateYichusPostgres(pool);
18
+ } finally {
19
+ await pool.end();
20
+ }
21
+
22
+ // Only for an app with worker routes: the page host's route handlers call
23
+ // them with this secret after checking a webhook's signature or a form's
24
+ // bot check. The roles are the grants the program's worker_route calls
25
+ // name ("ingest" here). Leave it out when the program declares no worker_route.
26
+ if (process.env.INGEST_WORKER_SECRET) {
27
+ attachYichusWorkerVerifier(yichusSecretWorkerVerifier([
28
+ { name: 'ingest', secret: process.env.INGEST_WORKER_SECRET, roles: ['ingest'] },
29
+ ]));
30
+ }
31
+
32
+ const server = await startYichusApiEngine();
33
+ process.on('SIGTERM', () => server.close(() => process.exit(0)));
@@ -0,0 +1,16 @@
1
+ // The engine's store: PostgreSQL through @yichus/postgres-store, which runs
2
+ // every transaction at SERIALIZABLE isolation and retries a bounded number
3
+ // of times. The engine loads this module from YICHUS_STORE=adapter:./store.mjs
4
+ // and calls the factory with no arguments, so the connection comes from the
5
+ // environment.
6
+ import { createYichusPostgresAdapter } from '@yichus/postgres-store';
7
+
8
+ // The namespace has no default: rows of one namespace are never served
9
+ // under another, so a missing value stops the engine.
10
+ export function createYichusStoreAdapter() {
11
+ const connectionString = process.env.DATABASE_URL;
12
+ if (!connectionString) throw new Error('DATABASE_URL is not set');
13
+ const namespace = process.env.YICHUS_POSTGRES_NAMESPACE;
14
+ if (!namespace) throw new Error('YICHUS_POSTGRES_NAMESPACE is not set');
15
+ return createYichusPostgresAdapter({ connectionString, namespace, maxAttempts: 5 });
16
+ }
@@ -4,11 +4,30 @@ The person does not read documentation. The yich.us studio page only tells them
4
4
 
5
5
  `yichus_page` shows you what the page shows them right now, and what they have on screen and last clicked.
6
6
 
7
+ ## Is this worth it?
8
+
9
+ When the person asks whether the studio is worth it, compared with you building the app the usual way, answer for their app, honestly, and give a clear recommendation.
10
+
11
+ You build the app either way. The difference is what they can know about it. You could often avoid these bugs yourself with careful code and tests, but tests cover the cases you thought of, and they cannot read the code or the tests. With the studio they choose the rules, a check that does not depend on you says whether each one holds, on every path through the program, and it says so again after every change you make later. Use what the checks found so far: a bug they caught in your own first draft is the clearest answer to the question.
12
+
13
+ What else they get: the product decisions behind those bugs come to them, so nothing is settled by your default, and a page shows their app in their words.
14
+
15
+ What it costs them, with what limits each cost:
16
+
17
+ - The code is in a less common typed language. You write and maintain it, and they read no code either way, so it matters mostly if a developer will join later and have to learn it. They are not stuck with it: the rules are written down in one place, so an agent can port the app to a mainstream stack later, as cheaply as you can port one in today.
18
+ - It runs on Yichus's engine: MIT-licensed npm packages on a host they pick, with their data in their own PostgreSQL. A built app runs nothing on Yichus's servers.
19
+ - It is slower to start than a quick build: a few questions first, and fixes until the rules hold.
20
+ - The checks cover the rules as written. Read each rule back to them in plain words, because a wrong rule passes. Payments, email, file uploads and scheduled jobs are not asked about yet. They can be built beside the checked part, unchecked; a download they click, such as a monthly export, is an ordinary action and is checked.
21
+
22
+ Recommend it when the app keeps records several people touch and a leak, a double booking or a half-saved change would hurt: bookings, sign-ups, approvals, anything with customers, patients or money. When some parts are not covered, recommend it for the part with the records and the people. For a live app, the port is a side copy: the old app keeps running untouched while the checks run on the new one. With you doing the port it is a much smaller job than it sounds: in one rehearsal a fresh agent ported a copy of a live Next.js and Supabase app in about 45 minutes, keeping its pages and its sign-in, with every property proven (locally, on test data). For a large app you can start with the part they worry about most. If the app keeps no records at all, such as a calculator, the studio's checks have nothing to hold; Yichus's calculator path (Why on every number, checked rules about the numbers) fits better, through the separate @yichus/mcp connection and the QuickStart at https://yich.us/start/quickstart.html. Its exported page carries its own scripts, so the person can host it anywhere. It is usually not worth it for a throwaway prototype, or for code they want to keep in its current language.
23
+
24
+ A scaffold is a starting point: shape its records and who may see them to the person's roles (a coordinator who sees everyone's sign-ups, a manager who approves) before you show them results.
25
+
7
26
  ## When you give them the link
8
27
 
9
28
  Tell them three things, briefly:
10
29
 
11
- - The page runs on their computer only. Nobody else can open it, and it keeps the same address when you restart the studio.
30
+ - The page runs on the computer the studio runs on. Nobody else can open it, and it keeps the same address when you restart the studio. If that is not their computer (you run in a cloud container, say), they cannot open it: tell them, and describe what it shows from `yichus_page` instead.
12
31
  - It updates by itself after every check, so they can leave it open in a tab.
13
32
  - They can ask you about anything on it.
14
33
 
@@ -19,7 +38,7 @@ Do not explain the sections until something appears in them.
19
38
  - What you asked for: their description, exactly as recorded.
20
39
  - What is happening now: the step you are on, in one sentence.
21
40
  - Questions for you: shown while a question is open. Saving an answer there and answering you in the chat do the same thing.
22
- - What your program must do: each choice they made, with its status.
41
+ - What your program must do: each rule they gave and each choice they made, with its status.
23
42
  - What happens when: each thing the app does, followed to every way it can end.
24
43
  - How your app is built: the parts of the app, stacked on the parts they are built from.
25
44
  - The shape of your program: a picture of the whole program as it is now.
@@ -29,14 +48,14 @@ Do not explain the sections until something appears in them.
29
48
  The studio moves you through these steps in order, after every change. Tell the person which one you are on when it changes, in one sentence. The page's "What is happening now" says the same.
30
49
 
31
50
  1. Describe: their description is recorded word for word.
32
- 2. Where it runs: Render, Vercel, Netlify, Amazon Web Services, Google Cloud, Microsoft Azure, or not sure yet. You build the pieces that place can run, so nothing has to be rebuilt later.
33
- 3. Write the first version.
34
- 4. Make it run: fix the mistakes that stop it from running.
51
+ 2. Write the first version.
52
+ 3. Make it run: fix the mistakes that stop it from running.
53
+ 4. Their rules: each rule they gave about what the app must always or never do becomes a law the studio runs on every check.
35
54
  5. Name the parts in their words, so the questions and the pictures use their words instead of the code's.
36
- 6. Ask them the questions the studio found.
37
- 7. What happens when: for each thing the app does, write down in their words every way it can go and what they should get at the end. The studio checks each one.
38
- 8. Match their answers: write the answers into the program as rules the checks hold it to.
39
- 9. Fix whatever does not hold yet.
55
+ 6. Ask them the questions the studio found. For an app with a server, one of them is where it runs: Render, Vercel, Netlify, Amazon Web Services, Google Cloud, Microsoft Azure, or not sure yet. The app is the same wherever it runs, so this only decides how you put it online. Vercel and Netlify hold only the pages, so there they also pick where the server goes: a second service with its own bill. A calculation with no actions people call and no records has no server, and the studio does not ask.
56
+ 7. Match their answers: write the answers into the program as rules the checks hold it to.
57
+ 8. Fix whatever does not hold yet. A broken rule comes first, before describing what happens.
58
+ 9. What happens when: for each thing the app does, write down in their words every way it can go and what they should get at the end. The studio checks each one.
40
59
  10. Test failures: for answers about crashes and outside services, you write a failure scenario and the studio runs it.
41
60
  11. Done: everything they chose holds.
42
61
 
@@ -49,7 +68,9 @@ Questions come from what the program does, never from what things are called. A
49
68
  | Asked when | The question | The choices |
50
69
  | --- | --- | --- |
51
70
  | The app answers requests | One server, or several copies sharing one database? | Several copies (safer, the default); one server (shown as an assumption on every result) |
52
- | The app saves a kind of record | Who may see one of these records, and who may change it? | Only its creator; the creator and people they share with; everyone reads, certain roles change; anyone |
71
+ | Some actions are for signed-in people | How do people sign in? | Not yet; Clerk; Supabase; another provider; only programs, with keys |
72
+ | The app saves records | Are there records somewhere today that this app must start with? | No, it starts empty; copy them in; keep the database they are in |
73
+ | The app saves a kind of record | Who may see one of these records, and who may change it? | Only its creator; only the people a rule lets in (a team, say); no person, only the app's own server; everyone reads, certain roles change; anyone |
53
74
  | An action reads a record and then changes it | Two people change the same record at the same moment. What should happen? | Both changes are kept; the second is refused and they try again |
54
75
  | An action saves in more than one step | If the server stops halfway, may part of the change stay saved? | All or nothing; partial is fine |
55
76
  | An action calls an outside service or an AI model | If that service is down or slow, what should the person see? | An error with nothing saved; save the request and finish it later; no preference |
@@ -63,13 +84,15 @@ Each choice they made shows on the page under "What your program must do", with
63
84
  | On the page | Meaning |
64
85
  | --- | --- |
65
86
  | waiting for your answer | A question they have not answered yet. Ask it. |
66
- | proven | Checked against every path through the program. No input, user or timing can break it. |
87
+ | proven | Checked against every path through the program: no input, user or timing breaks the rule as written. Whether the rule is the right one is theirs to judge. |
67
88
  | holds in every scenario checked | The failure scenario ran and stopped or failed the app at every step it covers. Strong, but limited to that scenario. |
68
89
  | holds, under an assumption | Proven only while the assumption is true, usually that exactly one server runs. A second copy can break it. |
69
90
  | decided | A choice that sets up the other checks, such as several copies of the server. |
70
91
  | broken | The check found a way it fails. You have the evidence; say in their terms what goes wrong, then fix it. |
71
92
  | the code says otherwise | The rule in the program does not match their answer yet. You update it. |
72
93
  | scenario being written | You are writing the failure scenario this answer needs. |
94
+ | check being written | A rule they gave has no law that checks it yet. You write one. |
95
+ | checked, but your app does not use it yet | Its law passes, but no action of the app reaches what the law checks, so the check says nothing about what the actions do. You make the action decide with that function. |
73
96
  | not decided yet | The check ran but could not decide. You find out why. |
74
97
  | no check needed | They chose an option that adds no check, such as "partial is fine". |
75
98
  | answered, waiting for your agent to check | They answered on the page; the result appears after your next check. |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yichus",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "Local Bosatsu compilation, Yichus analysis, and generated apps using the WebMCP engine",
5
5
  "license": "MIT",
6
6
  "homepage": "https://yich.us",
@@ -20,7 +20,7 @@
20
20
  "dependencies": {
21
21
  "zod": "^4.3.6",
22
22
  "@modelcontextprotocol/sdk": "^1.26.0",
23
- "@yichus/api-mcp": "0.1.2"
23
+ "@yichus/api-mcp": "0.1.3"
24
24
  },
25
25
  "devDependencies": {
26
26
  "@types/node": "^22.0.0",