@tomato414941/foundation 0.12.0 → 0.13.0

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 (3) hide show
  1. package/package.json +1 -2
  2. package/runtime.mjs +8 -22
  3. package/guide.mjs +0 -225
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tomato414941/foundation",
3
- "version": "0.12.0",
3
+ "version": "0.13.0",
4
4
  "description": "Foundation CLI: make a key, and hand what is kept to a command without it passing through the agent.",
5
5
  "type": "module",
6
6
  "engines": {
@@ -11,7 +11,6 @@
11
11
  },
12
12
  "files": [
13
13
  "runtime.mjs",
14
- "guide.mjs",
15
14
  "env-name.mjs"
16
15
  ],
17
16
  "repository": {
package/runtime.mjs CHANGED
@@ -8,7 +8,6 @@ import { homedir, hostname, tmpdir } from 'node:os';
8
8
  import { dirname, join } from 'node:path';
9
9
  import { createRequire } from 'node:module';
10
10
  import { validEnvName } from './env-name.mjs';
11
- import { guide } from './guide.mjs';
12
11
 
13
12
  // This program does only what the agent running it cannot do for itself.
14
13
  //
@@ -96,8 +95,7 @@ async function outputBytes(path) {
96
95
  } finally { await handle?.close(); }
97
96
  }
98
97
 
99
- // --help is the usual thing: the commands and their options. The guide (what Foundation is and how to ask it
100
- // for things) is its own command, since it is the server's document, not this program's.
98
+ // --help describes the CLI. The server publishes its API contract at /openapi.json.
101
99
  const HELP = `Usage: foundation <command> [options]
102
100
 
103
101
  Commands:
@@ -109,9 +107,11 @@ Commands:
109
107
  Run a command with saved values in its environment.
110
108
  exec --inputs '<json>' -- <command> The same, with files, structured inputs, or a credential for a service by id.
111
109
  exec --output '<json>' -- <command> Also save a file the command writes.
112
- guide Read the server's API guide (bundled reference when offline).
113
110
  version Print the version.
114
111
 
112
+ API specification:
113
+ foundation api GET /openapi.json Read the server's OpenAPI specification; no key required.
114
+
115
115
  Environment:
116
116
  FOUNDATION_URL The server for this run (otherwise the one saved by connect).
117
117
  FOUNDATION_AGENT Your name, such as claude or codex; gives each agent its own key file.
@@ -125,21 +125,6 @@ async function main() {
125
125
  if (action === '--version' || action === '-v' || action === 'version') { console.log(VERSION); return; }
126
126
  const configured = process.env.FOUNDATION_URL || await savedUrl();
127
127
  if (action === '--help' || action === '-h' || action === 'help' || !action) { console.log(HELP); return; }
128
- if (action === 'guide') {
129
- if (configured) {
130
- try {
131
- const response = await fetch(new URL('/start', serverUrl(configured)), { redirect: 'error', signal: AbortSignal.timeout(5_000) });
132
- if (!response.ok || response.headers.get('content-type')?.split(';')[0].trim() !== 'text/plain') throw new Error('Guide unavailable');
133
- const instructions = await response.text();
134
- if (!instructions.trim()) throw new Error('Empty guide');
135
- console.log(instructions.trimEnd());
136
- return;
137
- } catch {}
138
- }
139
- console.error(`${configured ? 'Could not read the server guide.' : 'No Foundation server configured.'} Using the bundled reference from CLI ${VERSION}; it may differ from your server.`);
140
- console.log(guide());
141
- return;
142
- }
143
128
  const separatorAt = args.indexOf('--'), command = separatorAt >= 0 ? args.slice(separatorAt + 1) : [];
144
129
  // Names remain literal. Inputs inject bytes; an optional output saves one generated file.
145
130
  let names = [], output;
@@ -187,7 +172,8 @@ async function main() {
187
172
  }
188
173
  const url = serverUrl(connectTo ?? configured);
189
174
  const keyPath = process.env.FOUNDATION_RUNTIME_KEY_FILE || join(homedir(), '.local', 'state', 'foundation', createHash('sha256').update(url.origin).digest('hex').slice(0, 24) + (agentName ? '-' + agentName.toLowerCase().replace(/[^a-z0-9]+/g, '-') : '') + '.key');
190
- let token = await readKey(keyPath, { missingOk: action === 'connect' });
175
+ const publicSpec = action === 'api' && call.method === 'GET' && call.target === '/openapi.json';
176
+ let token = publicSpec ? null : await readKey(keyPath, { missingOk: action === 'connect' });
191
177
  async function send(target, payload, { accept, method = 'POST', type = 'application/json' } = {}) {
192
178
  const response = await fetch(url.origin + target, { method, headers: { authorization: 'Bearer ' + token, ...(payload === undefined ? {} : { 'content-type': type }) },
193
179
  body: payload === undefined ? undefined : type === 'application/json' ? JSON.stringify(payload) : payload, redirect: 'error', signal: AbortSignal.timeout(30_000) });
@@ -197,11 +183,11 @@ async function main() {
197
183
  }
198
184
  // One request, with the key attached and the answer printed as it came. Nothing here knows the endpoints.
199
185
  if (action === 'api') {
200
- if (!/[?&]as=/.test(call.target)) {
186
+ if (!publicSpec && !/[?&]as=/.test(call.target)) {
201
187
  const me = await send('/v1/principals/me', undefined, { method: 'GET', accept: () => true });
202
188
  if (me.acts_for?.length === 1) call.target += (call.target.includes('?') ? '&' : '?') + 'as=' + encodeURIComponent(me.acts_for[0]);
203
189
  }
204
- const response = await fetch(url.origin + call.target, { method: call.method, headers: { authorization: 'Bearer ' + token, ...(call.body === undefined ? {} : { 'content-type': call.type }) },
190
+ const response = await fetch(url.origin + call.target, { method: call.method, headers: { ...(token ? { authorization: 'Bearer ' + token } : {}), ...(call.body === undefined ? {} : { 'content-type': call.type }) },
205
191
  ...(call.body === undefined ? {} : { body: call.body }), redirect: 'error', signal: AbortSignal.timeout(30_000) });
206
192
  const bytes = Buffer.from(await response.arrayBuffer());
207
193
  process.stdout.write(bytes);
package/guide.mjs DELETED
@@ -1,225 +0,0 @@
1
- // Printed by `foundation guide` (and served to MCP clients): the one page an agent reads before using any of this.
2
- //
3
- // What Foundation offers is an HTTP API, and that is what this describes. Not every agent can run a
4
- // command, so nothing here assumes a shell; where one exists there is a small program that adds the one
5
- // thing HTTP cannot do, and it is described last.
6
- //
7
- // This text is read by the agent, not by the owner, so it is English; everything the owner reads
8
- // (purposes, steps, the dashboard) stays in the owner's language.
9
- // The services this server knows, each with the schemes it can be connected by.
10
- function serviceLines(services) {
11
- if (!services) return [' GET /v1/services lists the services this server knows.'];
12
- return services.map(service => ' ' + service.id + ' ' + service.name + ' ' + Object.entries(service.auth_schemes)
13
- .map(([id, scheme]) => id + (id === 'oauth' ? (scheme.foundation_app ? ' (Foundation\'s app)' : scheme.takes_apps ? ' (owner\'s app)' : '') : id === 'role' && !scheme.available ? ' (unavailable)' : '')).join(', '));
14
- }
15
-
16
- export function guide(services) {
17
- return ['Foundation holds, for each principal, credentials and objects, and runs explicitly requested built-in functions.',
18
- 'A credential lets something act at a service on its holder\'s behalf. It is either for a service Foundation knows,',
19
- 'by one of that service\'s schemes - oauth (the holder said yes at the service), token (the holder made a token there and',
20
- 'handed it over) or role (the holder made a role for Foundation to assume) - or a secret: bytes the holder handed over',
21
- 'for no service in particular. An object is bytes placed here. Reading never reaches a service. Injecting a credential',
22
- 'derives what it yields now: a secret its bytes, the others what their scheme obtains. A name is the holder\'s word for',
23
- 'a thing; it decides no service, function or variable.', '',
24
- 'Everything below is HTTP with your approved key: Authorization: Bearer fdn_...',
25
- 'Nothing here needs a shell. With one, use foundation api to attach the key and foundation exec to inject values',
26
- 'into a command. api prints responses: use function save options when output should not enter your context.',
27
- 'Never ask the owner to paste passwords, keys or tokens into chat. Use a request instead.', '',
28
- 'WHO YOU ARE',
29
- ' Everything that comes to Foundation is a principal: a person, an AI, an app. You are one, and your access key is',
30
- ' what proves it. Foundation issues it, once, and shows it once: keep it private and never print it. If you can',
31
- ' write a private file, keep it there; otherwise keep it wherever your secrets go.',
32
- ' POST /v1/principals {"name": "<what to call you>"} with no key at all. Makes you, and answers with token.',
33
- ' What you may reach follows from lines between principals: whoever you act for (actor), whoever made you (owner).',
34
- ' POST /v1/requests {"kind": "actor", "input": {"name": "<what to call you>"}} with your key as the bearer.',
35
- ' Asks whoever opens it to let you act for them. Returns verification_uri and confirmation_code. Give the person',
36
- ' both; they open the URL and type the code. Until they do you act for nobody. Retry GET /v1/principals/me every',
37
- ' few seconds and look at acts_for. Do not hammer it.',
38
- ' GET /v1/principals/me who you are: principal, acts_for (whom you act for), owners, keys, your open requests.',
39
- ' Every call below reaches your own resources unless you name whose: ?as=<id of one you act for>. The foundation',
40
- ' CLI and the MCP tool add ?as= for you when you act for exactly one; over raw HTTP, add it yourself.',
41
- ' PATCH /v1/principals/me {"name"} DELETE /v1/principals/me a new name; leaving (your key stops working).',
42
- ' GET /v1/requests/<id> one of your requests and what happened at its page (events). DELETE cancels it.',
43
- ' GET /v1/relations every line you are on. GET /v1/audit-log what was done in your name or to you.',
44
- ' Every resource has an id, shown in every listing. What a principal may do comes from lines drawn to it:',
45
- ' POST /v1/relations {"subject":"<principal id>","relation":"<role or action>","object_type":"resource"|"principal","object_id":"<id>"}',
46
- ' A role is viewer or editor onto a resource, or actor onto a principal (acting for it). An action is one the rules',
47
- ' name, such as credential.disconnect, onto one resource or onto a principal (all it holds). One draws a line where',
48
- ' one may give lines (share on a resource, relate on a principal) and may do all the line reaches. DELETE takes it',
49
- ' back; anyone may step off a line drawn to them. Owning a principal is never drawn: it comes from making or approving.',
50
- ' GET /v1/resources?shown=me what others have shown you. GET /v1/resources/<id> one resource, whoever holds it.',
51
- ' GET /v1/resources/<id>/content reads it; PUT writes it, as editor. Lines point at the id, so renaming changes nothing.',
52
- '',
53
- 'CREDENTIALS',
54
- ' GET /v1/resources?kind=credential every credential: id, name, status, and for one made for a service, its',
55
- ' service, auth_scheme, facts and the variables it yields. &service=<id> narrows to one service; &secret=true to',
56
- ' secrets, &secret=false to those for services; &prefix= by name.',
57
- ' PUT /v1/resources?kind=credential&name=<name> body: raw bytes, up to 1MB. A secret: the same exact name replaces',
58
- ' that value; the answer carries its id.',
59
- ' What you keep for the holder you may read back (an editor line is drawn for you). What the holder kept, or a',
60
- ' service authorized, you may inject into a command but not read, unless the holder draws you a line.',
61
- ' Do not print injected values into your context.',
62
- ' GET /v1/resources?kind=credential&name=<name> one secret by name: its id and metadata. 404 if no such name.',
63
- ' GET /v1/resources/<id>/content a secret\'s bytes, as written; 403 forbidden without a line to it. PUT writes them.',
64
- ' A credential for a service has no content to read (405): what it yields is derived when injected.',
65
- ' PATCH /v1/resources/<id> {"name"} a new name. DELETE /v1/resources/<id> removes it (one for a service: see below).',
66
- ' URL-encode the name. A name is any text, which is why it travels as a query and not as a path. Names are 1-200',
67
- ' characters without control characters; case, spaces, slashes and punctuation remain literal.', '',
68
- 'HANDING IT TO A COMMAND',
69
- ' POST /v1/injections {"names": [{"name": "build token", "as": "GH_TOKEN"}, {"name": "<id of a credential for a service>"}]}',
70
- ' Each item is {name, as, filename?}. name is a secret\'s name or any credential\'s id. For a secret, as is required:',
71
- ' it names the environment variable. A credential for a service yields its scheme\'s variables (see variables); as',
72
- ' may rename the one variable of a scheme that has exactly one. Injecting one may ask the service for a fresh',
73
- ' token; expires_at says how long what came back is good.',
74
- ' filename makes the bytes a temporary file instead; as holds its local path. Use this for binary or multiline data.',
75
- ' Up to 16 inputs. Variables and filenames must be distinct; reserved system variables are refused.',
76
- ' Returns injection: {environment, files}. Calling this into an agent context exposes values. Use exec when the',
77
- ' intent is to run a local command.', '',
78
- 'SERVICES',
79
- ' GET /v1/services every service this server knows: its api, docs, console (where an app or a token for it is',
80
- ' made) and auth_schemes. For each scheme: variables (what a credential yields), hint (how to use it), and',
81
- ' - oauth: scopes (base and documentation_url), foundation_app (Foundation has its own app for it), takes_apps (the',
82
- ' owner may bring their own app) and app_fields (what registering one asks for);',
83
- ' - token: fields (what the owner types; secret ones are sealed);',
84
- ' - role: available.',
85
- ...serviceLines(services),
86
- ' A service the list does not know can be described by the owner, or by you acting for them, as a resource:',
87
- ' PUT /v1/resources?kind=service&name=<name> body: its definition, the same JSON shape as a listed service',
88
- ' {"version":1, "name", "api"?, "docs"?, "console"?, "auth_schemes": {"oauth"?: {...}, "token"?: {...}}}',
89
- ' oauth: authorize, token (https URLs; {field} is filled from the app), injection {"VARIABLE":"{access_token}"...},',
90
- ' and as the service needs them: scopes {base, docs}, scope_separator, pkce, client_auth (basic / body),',
91
- ' token_format (form / json), ok_field, identity {url, id, label}, revoke {url, style: rfc7009 / bearer / delete},',
92
- ' app_fields, authorize_params, keep. Placeholders: access_token, account, expires_at, kept fields, app fields.',
93
- ' token: fields [{name, label, secret?, pattern?}], injection {"VARIABLE":"{field}"}, identity {url, headers, id, label}.',
94
- ' A refusal (invalid_definition) says where. It is then connected like any other, by its resource id.', '',
95
- 'FILLING IN CREDENTIALS',
96
- '',
97
- '1. Put a secret there yourself. Anything you obtained or wrote: PUT /v1/resources?kind=credential&name=<name>, above.',
98
- '',
99
- '2. ASKING THE OWNER FOR A SECRET, for what only they can fetch and no listed service describes.',
100
- ' POST /v1/requests {"kind":"store", "input":{"fields":[{...}]}, "purpose":"...", "steps":["..."], "valid_minutes":30}',
101
- ' fields[].name suggested name; result.names returns the names the owner chose, result.replaced those replaced',
102
- ' fields[].label what they are being asked for, in their language. It titles the screen and names the field.',
103
- ' fields[].site the page where they make it, offered as a link',
104
- ' fields[].readable true asks to read it back afterwards (a viewer line); the default is that you cannot',
105
- ' fields[].multiline true for something like a PEM',
106
- ' fields[].replace true to put the value in place of the one already kept under that exact name (rotation).',
107
- ' Refused at creation: name_taken when the name exists and replace is not declared, name_missing',
108
- ' when it is declared and nothing is there. The owner may still give it another name, in which',
109
- ' case nothing is replaced; result.replaced lists the names that were.',
110
- ' purpose one concrete sentence the owner can judge, in their language',
111
- ' steps what they do, one string per step (up to 20, 500 characters each, no line breaks). Foundation',
112
- ' holds no instructions for anyone else\'s site: look up what to click now, and write it yourself.',
113
- ' Give the owner the verification_uri (there is no code). When they finish, it is simply kept.',
114
- ' Ask for what the owner already holds. Never take it through the conversation and put it there yourself.',
115
- '',
116
- '3. CONNECTING A SERVICE, for a credential Foundation keeps (and, for OAuth, renews) itself.',
117
- ' POST /v1/requests {"kind":"connect", "input":{"service":"<id>", "auth_scheme":"oauth"|"token"|"role",',
118
- ' "scopes":["<the service\'s scope>", ...]}, "purpose":"...", "steps":["..."], "valid_minutes":30}',
119
- ' Give the owner the verification_uri. auth_scheme defaults to the service\'s first.',
120
- ' Choose the scheme that fits the owner: OAuth through Foundation\'s app is the easiest when foundation_app is true.',
121
- ' Otherwise a token the owner makes at the service (console) is often simplest for one person\'s own use; write the',
122
- ' steps for making it. OAuth through the owner\'s own app suits an organization or scopes Foundation\'s app lacks.',
123
- ' scopes (OAuth) are the service\'s own names for what the credential may do (scopes.documentation_url). Ask for',
124
- ' what the work needs; the owner sees each one before agreeing. Foundation adds only the few it needs to know who',
125
- ' authorized (scopes.base). facts.missing_scopes lists any the service did not grant.',
126
- ' OAuth goes through an app: Foundation\'s own, or one the owner holds (or was lent).',
127
- ' GET /v1/resources?kind=app the apps the owner may connect through, Foundation\'s included (foundation: true).',
128
- ' Add "app":"<app id>" inside input to connect through one; without it, Foundation\'s is used, or on reconnecting,',
129
- ' the app the credential was made through. A request nobody could complete is refused (app_required): ask for an',
130
- ' app first when the service has no Foundation app.',
131
- ' POST /v1/requests {"kind":"app", "input":{"service":"<id>"}, "purpose":"...", "steps":["..."]} asks the owner',
132
- ' to register one: they make it at the service (console; redirect URL <this server>/oauth/callback) and type its',
133
- ' values on the page. result.app_id names it. You never see or handle its secret.',
134
- ' To reconnect, add "credential_id":"<existing id>" inside input. This updates that credential and keeps its id,',
135
- ' its scopes (add more with scopes) and the app it was made through. Without it, a new credential is made, even',
136
- ' for the same account. List and use an existing credential when no new authorization is needed.',
137
- ' A role (aws) has the owner make a role for Foundation in their own console and paste its name; nothing of theirs',
138
- ' is kept but that name, and each injection obtains an hour of credentials.',
139
- ' Poll GET /v1/requests/<id> every few seconds until done; result.credential_id identifies the credential.',
140
- ' DELETE /v1/resources/<id> {"revoke": true|false} disconnects one (the owner, in a browser); revoke also asks the',
141
- ' service to withdraw what it granted. What was already handed out stays where it went.', '',
142
- 'ENVIRONMENTS (a machine with a shell, for when you have none)',
143
- ' A lent machine: a shell, files and the network, thrown away when done. By itself it reaches nothing of Foundation.',
144
- ' Give it an identity - a principal you may act as (yourself, one you own, or one you act for) - and it holds that',
145
- ' principal\'s key for its life: inside, the foundation CLI works as that principal (foundation exec, foundation api).',
146
- ' POST /v1/environments {"identity":"<principal id>"|null, "size":"small|medium|large",',
147
- ' "lifetime":{"end":"idle|exit","idle_seconds":600,"max_seconds":3600}} opens one; it is a resource (kind environment).',
148
- ' POST /v1/environments/<id>/commands {"command":["npm","test"],"stdin":null,"timeout_seconds":300}',
149
- ' runs one command: exit_code, stdout, stderr. 202 with status running if it takes longer; then',
150
- ' GET /v1/environments/<id>/commands/<command id>. One command at a time; files persist between commands.',
151
- ' PATCH /v1/environments/<id> {"identity":… or null} gives or takes away its identity. DELETE closes it.',
152
- ' POST /v1/runs {…as opening, plus "command"} opens, runs one command, stops: the answer carries the result.',
153
- ' What a command prints is cleaned of values handed in with injections. Keep what matters as an object.',
154
- ' Computing is spent: GET /v1/principals/<id>/compute shows this month\'s use and limit; its owner may lower the',
155
- ' limit with PUT {"monthly_seconds": n}. A medium machine spends twice its time, a large one four times.', '',
156
- 'FUNCTIONS',
157
- ' GET /v1/functions catalog of built-in operations and their invocation endpoints.', '',
158
- 'WHEN IT DOES NOT WORK',
159
- ' GET /v1/requests/<id> one of your requests, and what happened at its page (events).',
160
- ' GET /v1/requests?status=pending your requests. Several may be open at once (up to 10).',
161
- ' events is the raw record, in order: page_opened / page_viewed / connect_started / connect_failed (with a code and',
162
- ' Foundation\'s own message) / connect_review (awaiting confirmation of changes) / connected / stored / denied / cancelled. What was typed is never recorded.',
163
- ' DELETE /v1/requests/<id> cancels it. status is pending / done / denied / cancelled.',
164
- ' Completion and result are fixed until the request expires, even if the resulting resource changes or is removed.',
165
- ' Current credential state is at GET /v1/resources?kind=credential. Revoked keys receive 401; their pending requests are cancelled.',
166
- ' Request feedback expires with the request. A done result is a credential_id or the names saved at completion.',
167
- ' Why a connection failed: invalid_fields (wrong shape) / token_refused (the service would not take the token) /',
168
- ' reconnect_required (the service rejected it) / credential_changed (the target changed). A key approval shows its own events at',
169
- ' GET /v1/requests/<id>: confirmation_required (a wrong code) / confirmation_locked (5 tries).', '',
170
- 'A PLACE FOR FILES (object storage the owner did not have to sign up for)',
171
- ' PUT /v1/resources?kind=object&name=<key> body is the bytes; the Content-Type you send is what a reader gets back. Up to 25MB.',
172
- ' GET /v1/resources?kind=object&prefix=<p> lists what is there, with ids. &name=<key> finds one.',
173
- ' GET /v1/resources/<id>/content the bytes. PUT writes them. DELETE /v1/resources/<id> removes it. PATCH renames it.',
174
- ' POST /v1/resources/<id>/link {"minutes":n} a time-limited URL anyone can read, for a thing that only takes a URL.',
175
- ' Keys look like a path (a/b/c.txt) but name one whole object: no renaming, no directories, no partial reads or writes.',
176
- ' This is not a filesystem. If the owner needs one, they need a machine to mount it on.',
177
- ' Where the bytes live is the owner\'s business: a space lent to them now, a bucket of their own later. Nothing you call changes.', '',
178
- 'HTTPS REQUEST FUNCTION',
179
- ' POST /v1/functions/http.request {"url": "https://api.example.com/v1/items", "method": "POST",',
180
- ' "headers": {"authorization": "Bearer {{foundation:token}}"}, "bindings": {"token": "build token"}, "body": "..."}',
181
- ' Each placeholder identifies an input slot. bindings maps slots to credentials: a secret\'s exact name (including',
182
- ' braces or spaces), or a credential\'s id (<id>#<VARIABLE> when it yields several). Without bindings, a slot',
183
- ' is itself a name. Inputs only in headers/body, never in the URL. Up to 8 inputs. A bound credential for a service is',
184
- ' derived first, so its service may be asked for a fresh token.',
185
- ' body_encoding "base64" sends bytes without substitution.',
186
- ' Returns {response: {status, headers, body, body_encoding}}. Common echoes of input secrets are redacted;',
187
- ' do not treat redaction as protection against arbitrary transformations by an untrusted destination.',
188
- ' Optional save: "<name>" keeps the response body as a secret and returns only status/headers and saved metadata.',
189
- ' Redirects are returned, not followed.',
190
- ' HTTPS on 443, public hostnames only, never this server or private networks. 1MB each way, 20 seconds, 30/minute.',
191
- ' No workflow, schedule or implicit execution: the caller chooses each invocation and each saved output.', '',
192
- 'THE SHELL (only if you can run commands)',
193
- ' Install: npm install -g @tomato414941/foundation (Node.js 24 or later)',
194
- ' foundation connect [<url>] [--name <name>]',
195
- ' Makes the key as a private file and asks for approval. The key is never printed, so it never reaches you.',
196
- ' Given a URL, it also remembers that server for every later command; run it again when the server moves.',
197
- ' foundation api <GET|POST|PUT|DELETE|PATCH> </path> [--json <body>] [--from <file>] [--type <media-type>]',
198
- ' Any request above, with the key attached and the answer printed as it came. Prefer this over curl: reading the key',
199
- ' file to build a header yourself would put the key in your context, which is the thing this avoids.',
200
- ' foundation exec <ENV>=<name> [...] -- <command> [args...]',
201
- ` foundation exec --inputs '[{"name":"signing key","as":"KEY_FILE","filename":"AuthKey.p8"}]' -- <command>`,
202
- ' ENV=name treats everything after the first = literally. Use --inputs JSON for files or structured inputs.',
203
- ' Only the child process gets injected values; files exist only while it runs. FOUNDATION_NAMES is a JSON array',
204
- ' of the exact saved names used. Prevent the child command from logging or echoing secrets.',
205
- ' Use this instead of POST /v1/injections whenever the point is to run something.',
206
- ` foundation exec --output '{"name":"login config","as":"AUTH_FILE","filename":"auth.json"}' -- <command>`,
207
- ' Creates one empty private file and sets as to its path. Tell the command to write its authentication result there.',
208
- ' After exit 0, keeps the file bytes as a secret under the exact name, then removes the temporary file.',
209
- ' An existing value at that name is replaced. Output must be a private regular file containing 1 byte to 1MB.',
210
- ' May be combined with inputs, using a different environment variable. A failed command never saves its output.',
211
- ' If upload cannot be confirmed, exits with an error and reports the retained private file for recovery; inputs are',
212
- ' still removed. Retry with api PUT --from, then remove the recovery file. Other temporary files are removed.',
213
- ' Use native service login URLs; never collect passwords in chat. Stored credentials keep their original expiry.',
214
- ' Environment: FOUNDATION_URL (optional; overrides the remembered server), FOUNDATION_AGENT (optional; your name, e.g. claude / codex), FOUNDATION_RUNTIME_KEY_FILE (optional).',
215
- ' One key per machine and OS user by default. FOUNDATION_AGENT gives each agent its own key, but any agent running as the',
216
- ' same OS user can read that file, so it is bookkeeping, not protection. To separate them for real, use separate OS users.', '',
217
- 'RULES',
218
- '- Never print, log or write out what is injected. Hand it to a command, and nowhere else.',
219
- '- Send saved values only to an authorized destination. http.request and exec use the destinations you choose.',
220
- '- Ask for the least you need. Do not request something the work does not use.',
221
- '- Be honest in name, purpose and label. The owner decides based on them.',
222
- '- If a request is denied or expires, ask the owner why rather than guessing.',
223
- '- Use what you receive only for the work it was asked for.',
224
- ].join('\n');
225
- }