@haus-tech/haus-workflow 6.1.0 → 6.3.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.
- package/CHANGELOG.md +17 -0
- package/dist/cli.js +15581 -9630
- package/library/global/skills/haus-workflow/references/clone.md +136 -0
- package/library/global/skills/request/SKILL.md +11 -14
- package/library/global/skills/request/scripts/bedom.mjs +19 -71
- package/library/schemas/localdev.v2.schema.json +369 -0
- package/package.json +3 -1
|
@@ -202,6 +202,142 @@ seeds: # optional: data sources NOT owned by a manifest repo (e.g. a shared Word
|
|
|
202
202
|
login: 'Add your SSH key to the host (ssh-add …) / request access — or skip the pull.'
|
|
203
203
|
```
|
|
204
204
|
|
|
205
|
+
**Workspace, format v2: the `instance:` section (per-worktree environments, ADR-0163).**
|
|
206
|
+
A workspace that runs features in parallel worktrees adds `version: 2` and an `instance:`
|
|
207
|
+
section, and sets `worktree.env: true` in `haus.workspace.yaml`. Unlike the rest of this
|
|
208
|
+
file, `instance:` is parsed and validated strictly by the CLI (`haus doctor`; schema
|
|
209
|
+
`library/schemas/localdev.v2.schema.json`); unknown keys are errors. A v1 file simply has
|
|
210
|
+
no instance support.
|
|
211
|
+
|
|
212
|
+
```yaml
|
|
213
|
+
version: 2
|
|
214
|
+
instance:
|
|
215
|
+
ports: # name -> main-checkout port; a worktree gets <leased block> + offset, in this order
|
|
216
|
+
vendure: 3000
|
|
217
|
+
admin-ui: 4200
|
|
218
|
+
datastores: # shared engines; a worktree is isolated INSIDE them, never by its own container
|
|
219
|
+
mariadb: { engine: mariadb, compose: { project: shop-workspace, service: mariadb }, port: 3318 }
|
|
220
|
+
# compose.file: the compose file (workspace-relative) when its name is not a default one,
|
|
221
|
+
# e.g. compose: { project: shop-workspace, service: pg, file: docker-compose.local.yml }
|
|
222
|
+
redis: { engine: redis, compose: { project: shop-workspace, service: redis }, port: 6381 } # needs --databases 64
|
|
223
|
+
search:
|
|
224
|
+
{
|
|
225
|
+
engine: elasticsearch,
|
|
226
|
+
compose: { project: shop-workspace, service: es },
|
|
227
|
+
port: 9201,
|
|
228
|
+
prefix: 'vendure-',
|
|
229
|
+
}
|
|
230
|
+
databases: # one database per worktree: <name>_wt_<slug>, cloned from <name>_tpl (or <name>)
|
|
231
|
+
ecom: { on: mariadb, name: shop_ecom, perWorktree: clone } # or perWorktree: empty
|
|
232
|
+
sites: # one Herd site per worktree on a copy-on-write docroot clone
|
|
233
|
+
wordpress:
|
|
234
|
+
kind: herd
|
|
235
|
+
root: shop.se # workspace-relative docroot
|
|
236
|
+
host: '{{slug}}.shop.se' # served at http://<slug>.shop.se.test
|
|
237
|
+
share: [wp-content/uploads] # symlinked to the main docroot, not copied
|
|
238
|
+
plugins: { ecom-widgets: shop-ecom-widgets } # plugin dir -> member repo in this worktree
|
|
239
|
+
config:
|
|
240
|
+
{
|
|
241
|
+
kind: wp-config-override,
|
|
242
|
+
defines: { DB_NAME: '{{db.wp}}', WP_HOME: '{{site.wordpress.url}}' },
|
|
243
|
+
}
|
|
244
|
+
after: ['wp search-replace http://shop.se.test {{site.wordpress.url}} --skip-columns=guid']
|
|
245
|
+
processes: # what `env start <name>` runs, from that member repo, on its leased port
|
|
246
|
+
vendure: { repo: shop-ecom, start: 'yarn dev', port: vendure, health: '/health' }
|
|
247
|
+
copyLocal: # extra machine-local files copied from the main checkout (mode 600)
|
|
248
|
+
- { repo: shop-ecom, path: auth.json }
|
|
249
|
+
teardown: # shell commands `env down --destroy` / `env gc --write` run before dropping databases
|
|
250
|
+
- 'docker compose -p shop-ecom-e2e-{{slug}} down -v --remove-orphans'
|
|
251
|
+
env: # the same map as v1; values may now use templates
|
|
252
|
+
- value: '{{port.vendure}}'
|
|
253
|
+
sinks: [{ repo: shop-ecom, key: API_PORT }]
|
|
254
|
+
- value: '{{db.ecom}}'
|
|
255
|
+
sinks: [{ repo: shop-ecom, key: DB_NAME }]
|
|
256
|
+
- value: '{{redis.redis.db}}'
|
|
257
|
+
sinks: [{ repo: shop-ecom, key: REDIS_DB }]
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
Templates: `{{slug}}`, `{{port.<name>}}`, `{{db.<name>}}`, `{{redis.<name>.db}}`,
|
|
261
|
+
`{{search.<name>.prefix}}`, `{{site.<name>.url|host|root}}`. In the main checkout they
|
|
262
|
+
resolve to today's values (the main ports and database names, Redis DB 0, the main
|
|
263
|
+
prefix), so one manifest serves both; only a worktree gets new ones. Only keys fed by a
|
|
264
|
+
templated entry are instance-owned; every other key in a repo's `.env` is copied as it is.
|
|
265
|
+
`teardown` (workspace file only) cleans up per-worktree resources the CLI does not track,
|
|
266
|
+
such as a compose project an app's own test harness starts; keep each command idempotent.
|
|
267
|
+
`after` (workspace file only) is its counterpart for `env up`: commands that run once per
|
|
268
|
+
environment in the worktree root, after the `.env` files and `.haus-env.json` exist, such as
|
|
269
|
+
copying the main bucket into a per-worktree one (`mc mirror local/assets
|
|
270
|
+
local/assets-wt-{{slug}}`); a failed one is retried by the next `env up`.
|
|
271
|
+
|
|
272
|
+
**Single-repo projects** (a plain repo with Claude Code worktrees, ADR-0167): the repo's own
|
|
273
|
+
`.haus-workflow/localdev.yml` takes the whole `instance:` section, the flag is
|
|
274
|
+
`"worktree": { "env": true }` in `.haus-workflow/haus.config.json`, and `repo:` in sinks,
|
|
275
|
+
processes and `copyLocal` names a folder inside the repo (`.` for the root, `apps/server`
|
|
276
|
+
for an app).
|
|
277
|
+
|
|
278
|
+
**Other engines and site kinds.** The same section covers the other client stacks:
|
|
279
|
+
|
|
280
|
+
```yaml
|
|
281
|
+
instance:
|
|
282
|
+
datastores:
|
|
283
|
+
# An engine on the host (DBngin, Homebrew), not in Docker: haus never starts it and
|
|
284
|
+
# connects with the host's mysql/mariadb client. Credentials: export MYSQL_USER and
|
|
285
|
+
# MYSQL_PWD, or use ~/.my.cnf. `port` defaults to native.port. Supported for mariadb,
|
|
286
|
+
# mysql, elasticsearch and opensearch.
|
|
287
|
+
mysql: { engine: mysql, native: { host: 127.0.0.1, port: 3306 } }
|
|
288
|
+
# native: { host: 127.0.0.1, port: 3306, client: /Users/Shared/DBngin/mysql/8.0.33/bin/mysql }
|
|
289
|
+
# SQL Server: database isolation (BACKUP / RESTORE WITH MOVE into <name>_wt_<slug>).
|
|
290
|
+
# azure-sql-edge has no sqlcmd; haus then runs mcr.microsoft.com/mssql-tools (amd64) on
|
|
291
|
+
# the engine's network. The SA password stays in the engine container's env.
|
|
292
|
+
mssql: { engine: mssql, compose: { project: vafab-workspace, service: mssql }, port: 49760 }
|
|
293
|
+
sites:
|
|
294
|
+
cms: # Bedrock: the root is a member repo, its .env gets the defines (copy: none is the default)
|
|
295
|
+
kind: herd
|
|
296
|
+
root: bad-varme.se
|
|
297
|
+
host: '{{slug}}.bad-varme.se'
|
|
298
|
+
php: '8.2'
|
|
299
|
+
share: [web/app/uploads]
|
|
300
|
+
config:
|
|
301
|
+
kind: bedrock-env
|
|
302
|
+
defines:
|
|
303
|
+
DB_NAME: '{{db.wp}}'
|
|
304
|
+
WP_HOME: '{{site.cms.url}}'
|
|
305
|
+
WP_SITEURL: '{{site.cms.url}}/wp'
|
|
306
|
+
app: # Laravel on Herd: same, with Laravel's keys
|
|
307
|
+
kind: herd
|
|
308
|
+
root: app.example.se
|
|
309
|
+
host: '{{slug}}.app.example.se'
|
|
310
|
+
secure: true
|
|
311
|
+
config:
|
|
312
|
+
kind: laravel-env
|
|
313
|
+
defines: { APP_URL: '{{site.app.url}}', DB_DATABASE: '{{db.api}}' }
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
`bedrock-env` and `laravel-env` write no PHP file and need no `patch-wp-config`: the
|
|
317
|
+
defines become instance-owned keys of the member's `.env`, next to any `env:` sinks for
|
|
318
|
+
that repo, and the rest of the main checkout's `.env` is copied as it is. Teardown unlinks
|
|
319
|
+
the Herd site and never deletes the member repo.
|
|
320
|
+
|
|
321
|
+
**How this relates to the clone flow.** This procedure sets up the **main checkout**: it
|
|
322
|
+
brings the shared engines up, seeds the main databases and writes each repo's `.env`. It
|
|
323
|
+
never touches `instance:`. A worktree then gets its own environment from that main
|
|
324
|
+
checkout with one command, run inside the worktree:
|
|
325
|
+
|
|
326
|
+
```bash
|
|
327
|
+
haus workspace worktree env snapshot ecom # once, and whenever fresh data is wanted: <name>_tpl from the main DB
|
|
328
|
+
haus workspace worktree env up # lease ports, clone DBs, Redis index, prefix, site, .env files
|
|
329
|
+
haus workspace worktree env start vendure # runs on the worktree's own port
|
|
330
|
+
haus workspace worktree env status # ports, URLs, databases
|
|
331
|
+
haus workspace worktree env down --destroy # or just `worktree remove`, which runs it first
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
`env up` copies each repo's `.env` from the main checkout (secrets included, never printed)
|
|
335
|
+
and replaces only the instance-owned keys, so the main checkout's `.env` must exist first:
|
|
336
|
+
that is exactly what this clone flow produces. Agents never read a `.env`; they use
|
|
337
|
+
`haus workspace worktree env get <key>` or `.haus-env.json`. For a WordPress site with
|
|
338
|
+
`config.kind: wp-config-override`, run `haus workspace worktree env patch-wp-config <site>`
|
|
339
|
+
once in the main checkout (it backs the file up and never prints it).
|
|
340
|
+
|
|
205
341
|
#### Run order
|
|
206
342
|
|
|
207
343
|
1. **Discover** `.haus-workflow/localdev.yml` in the workspace root and each repo.
|
|
@@ -744,15 +744,14 @@ dispatches no agent and runs no check in this leg. `--repo-rot` is the checkout
|
|
|
744
744
|
code the assessor reads (the session's cwd; a worktree is fine) and `--arkiv` is
|
|
745
745
|
`ARKIVROT:` from `rot`. The starter writes the running receipt (`archive.mjs korning-start`,
|
|
746
746
|
`state.korning`) before the process starts and clears it after
|
|
747
|
-
(`korning-slut`), skips an item whose receipt carries a living pid (`pågår`)
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
item in flight at the average of the finished ones. Read its
|
|
747
|
+
(`korning-slut`), and skips an item whose receipt carries a living pid (`pågår`). There is
|
|
748
|
+
no spend cap: every item that passes the gate starts, and the cost shows instead, as the
|
|
749
|
+
USD per item in the table and the total spent on the line under it (ADR-0162). Read its
|
|
751
750
|
final table (`| post | status | poäng | utfall | wall | USD |`), paste it under the BLUF
|
|
752
751
|
in step 8, and route every row by its status: `priced` goes on to step 8, `stopp` and
|
|
753
752
|
`väntar på dom` take the stop and OLIKA routing below, `ofärdig` shows the reason from
|
|
754
|
-
the table and `<post>/korningar/<körning>/stderr.log`, `grind`
|
|
755
|
-
reason and
|
|
753
|
+
the table and `<post>/korningar/<körning>/stderr.log`, `grind` shows the
|
|
754
|
+
reason and stops, and a `pågår` row is left alone.
|
|
756
755
|
`bedom.mjs` passes the board's design mode on to `korning.mjs` as `--design-mode`
|
|
757
756
|
(`design_mode` in `.haus-workflow/request.json`; `interview` and an absent key read as
|
|
758
757
|
`intervju`; the flag overrides one run). In draft mode the process drafts a missing design
|
|
@@ -2015,22 +2014,20 @@ reference files whose rules it mirrors and WARNS when a catalog bump has changed
|
|
|
2015
2014
|
and skipped. `--arkiv` is the archive root; omitted, it is derived from
|
|
2016
2015
|
`--repo-rot`'s git common dir (ADR-0154). Exit 0 when no run became
|
|
2017
2016
|
`ofärdig`, 1 otherwise, 2 on a usage error.
|
|
2018
|
-
- `scripts/bedom.mjs --repo-rot <abs> [--arkiv <abs>] --post <gid|gid/del-N>... [--parallellt 2] [--
|
|
2017
|
+
- `scripts/bedom.mjs --repo-rot <abs> [--arkiv <abs>] --post <gid|gid/del-N>... [--parallellt 2] [--claude <kommando>] [--om] [--sprak <svenska|engelska>]`:
|
|
2019
2018
|
production's starter (see `bedöm`), one `korning.mjs --post` process per item, two at a
|
|
2020
2019
|
time. `--post` is relative to the archive root (`--arkiv`, or derived from `--repo-rot`'s
|
|
2021
2020
|
git common dir as in `svep.mjs`); an absolute `--post` is a usage error. Per item: the
|
|
2022
2021
|
receipt via `archive.mjs korning-start`/`korning-slut` (the latter always, also when the
|
|
2023
2022
|
run fails), the run directory `<post>/korningar/<stämpel>/` with `stderr.log`,
|
|
2024
|
-
`matning.json` and the raw replies under `steg/`,
|
|
2025
|
-
|
|
2026
|
-
USD, plus each item in flight at the average of the finished ones, reaches it no further
|
|
2027
|
-
item starts, `tak nått`, and a running item is never killed), `--startare <its own pid>` on
|
|
2023
|
+
`matning.json` and the raw replies under `steg/`, no spend cap (every item that passes
|
|
2024
|
+
the gate starts, ADR-0162), `--startare <its own pid>` on
|
|
2028
2025
|
every `korning.mjs` it starts, SIGINT and SIGTERM both killing the running items and
|
|
2029
2026
|
clearing their receipts (exit 130),
|
|
2030
2027
|
and the final table `| post | status | poäng | utfall | wall | USD |` in argument order
|
|
2031
|
-
with the line `
|
|
2032
|
-
(`priced`, `stopp`, `väntar på dom`), 1 on `ofärdig`, `pågår
|
|
2033
|
-
on a usage error (ADR-0155).
|
|
2028
|
+
with the line `använt: <m> USD`. Exit 0 when every item ended in a result
|
|
2029
|
+
(`priced`, `stopp`, `väntar på dom`), 1 on `ofärdig`, `pågår` or `grind`, 2
|
|
2030
|
+
on a usage error (ADR-0155, ADR-0162).
|
|
2034
2031
|
`bedom.mjs` takes `--design-mode draft|intervju` and passes it to every `korning.mjs` it
|
|
2035
2032
|
starts; without the flag the value is `request.json`'s `design_mode` (`interview` is read
|
|
2036
2033
|
as `intervju`), and without that key `intervju` (ADR-0156).
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/**
|
|
3
|
-
* Startaren för produktionens prisning (ADR-0155 beslut 1, 3
|
|
3
|
+
* Startaren för produktionens prisning (ADR-0155 beslut 1, 3 och 5; beslut 4
|
|
4
|
+
* ersatt av ADR-0162):
|
|
4
5
|
* `bedöm`:s steg 3 till 7 körs som EN `korning.mjs`-process per post i
|
|
5
6
|
* produktionsläget (`--post`), startad härifrån, så huvudkonversationen
|
|
6
7
|
* dispatchar ingen agent för prisbenet. Huvudkonversationen behåller grinden,
|
|
@@ -9,7 +10,7 @@
|
|
|
9
10
|
*
|
|
10
11
|
* Användning:
|
|
11
12
|
* node bedom.mjs --repo-rot <abs> [--arkiv <abs>] --post <gid|gid/del-N> [--post ...]...
|
|
12
|
-
* [--parallellt 2] [--
|
|
13
|
+
* [--parallellt 2] [--claude <kommando>] [--om]
|
|
13
14
|
* [--sprak <svenska|engelska>] [--design-mode <draft|intervju>]
|
|
14
15
|
*
|
|
15
16
|
* `--post` är relativ arkivroten: `--arkiv` när den ges (ARKIVROT: från
|
|
@@ -20,7 +21,7 @@
|
|
|
20
21
|
* Per post, i ordning: förkontroll (state.json läsbar, ingen experimentkatalog,
|
|
21
22
|
* ingen splitrot med `del-N/` under sig, `approval` satt, inget stående
|
|
22
23
|
* `stopp`, inte redan `priced`/`guard_run` utan `--om`; annars raden `grind`
|
|
23
|
-
* och inget startas),
|
|
24
|
+
* och inget startas), körningskatalogen
|
|
24
25
|
* `<post>/korningar/<YYYYMMDDTHHMMSS>/`, kvittot `archive.mjs korning-start`
|
|
25
26
|
* (en levande pid ger raden `pågår` och den tomma katalogen tas bort),
|
|
26
27
|
* `korning.mjs` med `stderr.log` och `matning.json` i körningskatalogen och
|
|
@@ -28,22 +29,17 @@
|
|
|
28
29
|
* `korning.json`:s `total_cost_usd`, `archive.mjs sparr` och statusen. Kvittot
|
|
29
30
|
* rensas alltid med `archive.mjs korning-slut` i en finally.
|
|
30
31
|
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
* posterna med sin USD plus varje post i flykt till de klaras snittkostnad
|
|
35
|
-
* (0 så länge ingen är klar). När summan nått taket startas inga fler poster
|
|
36
|
-
* (raden `tak nått`), och ingen pågående körning dödas. Två poster som startar
|
|
37
|
-
* samtidigt innan någon är klar passerar båda kontrollen: det är accepterat,
|
|
38
|
-
* taket stoppar nästa start och aldrig en körning som pågår.
|
|
32
|
+
* Inget tak (ADR-0162 ersätter ADR-0155 beslut 4): varje post som klarar
|
|
33
|
+
* förkontrollen startas, oavsett vad batchen kostat. Kostnaden syns i stället:
|
|
34
|
+
* USD per post i tabellen och summan på sista raden.
|
|
39
35
|
*
|
|
40
36
|
* stdout under körningen: `START <post>`, `KLAR <post> <status>`,
|
|
41
|
-
* `GRIND <post>: <orsak>`, `PÅGÅR <post> (pid N)
|
|
37
|
+
* `GRIND <post>: <orsak>`, `PÅGÅR <post> (pid N)`; till sist
|
|
42
38
|
* tabellen `| post | status | poäng | utfall | wall | USD |` och raden
|
|
43
|
-
* `
|
|
39
|
+
* `använt: <m.mm> USD`.
|
|
44
40
|
*
|
|
45
41
|
* Exit 0 = varje rad är `priced`, `stopp` eller `väntar på dom`; 1 = minst en
|
|
46
|
-
* rad är `ofärdig`, `pågår
|
|
42
|
+
* rad är `ofärdig`, `pågår` eller `grind`; 2 = användningsfel.
|
|
47
43
|
* SIGINT och SIGTERM skickar SIGTERM till varje pågående körning, skriver
|
|
48
44
|
* matning.json med signalen, rensar varje kvitto med korning-slut och avslutar
|
|
49
45
|
* med 130. Ett oväntat kast i huvudloopen skrivs på stderr och ger exit 2.
|
|
@@ -58,30 +54,20 @@ const HAR = path.dirname(fileURLToPath(import.meta.url))
|
|
|
58
54
|
const ARCHIVE = path.join(HAR, 'archive.mjs')
|
|
59
55
|
const KORNING = path.join(HAR, 'korning.mjs')
|
|
60
56
|
|
|
61
|
-
export const STANDARD_TAK_USD = 100
|
|
62
57
|
const STANDARD_PARALLELLT = 2
|
|
63
58
|
const SIGNAL_EXIT = 130
|
|
64
59
|
/** Signalerna som avbryter batchen; samma hanterare för båda. */
|
|
65
60
|
export const AVBROTTSSIGNALER = ['SIGINT', 'SIGTERM']
|
|
66
61
|
const SPRAKEN = ['svenska', 'engelska']
|
|
67
62
|
const DESIGNLAGEN = ['draft', 'intervju']
|
|
68
|
-
const VARDEFLAGGOR = [
|
|
69
|
-
'repo-rot',
|
|
70
|
-
'arkiv',
|
|
71
|
-
'post',
|
|
72
|
-
'parallellt',
|
|
73
|
-
'max-usd',
|
|
74
|
-
'claude',
|
|
75
|
-
'sprak',
|
|
76
|
-
'design-mode',
|
|
77
|
-
]
|
|
63
|
+
const VARDEFLAGGOR = ['repo-rot', 'arkiv', 'post', 'parallellt', 'claude', 'sprak', 'design-mode']
|
|
78
64
|
const BOOLFLAGGOR = ['om']
|
|
79
65
|
/** Statusar som är ett resultat: exit 0 när varje rad bär en av dem. */
|
|
80
66
|
const RESULTAT = ['priced', 'stopp', 'väntar på dom']
|
|
81
67
|
|
|
82
68
|
export const ANVANDNING = [
|
|
83
69
|
'användning: bedom.mjs --repo-rot <abs> [--arkiv <abs>] --post <gid|gid/del-N> [--post ...]...',
|
|
84
|
-
` [--parallellt ${STANDARD_PARALLELLT}] [--
|
|
70
|
+
` [--parallellt ${STANDARD_PARALLELLT}] [--claude <kommando>] [--om]`,
|
|
85
71
|
` [--sprak <${SPRAKEN.join('|')}>] [--design-mode <${DESIGNLAGEN.join('|')}>]`,
|
|
86
72
|
].join('\n')
|
|
87
73
|
|
|
@@ -127,12 +113,6 @@ export function tolkaArgv(argv) {
|
|
|
127
113
|
const parText = enkla.parallellt ?? String(STANDARD_PARALLELLT)
|
|
128
114
|
if (!/^\d+$/.test(parText) || Number(parText) < 1)
|
|
129
115
|
return { fel: `--parallellt måste vara ett heltal >= 1 (fick "${parText}")` }
|
|
130
|
-
let maxUsd = null
|
|
131
|
-
if (enkla['max-usd'] !== undefined) {
|
|
132
|
-
maxUsd = Number(enkla['max-usd'])
|
|
133
|
-
if (enkla['max-usd'].trim() === '' || !Number.isFinite(maxUsd) || maxUsd < 0)
|
|
134
|
-
return { fel: `--max-usd måste vara ett tal >= 0 (fick "${enkla['max-usd']}")` }
|
|
135
|
-
}
|
|
136
116
|
if (enkla.sprak !== undefined && !SPRAKEN.includes(enkla.sprak))
|
|
137
117
|
return { fel: `--sprak måste vara ${SPRAKEN.join(' eller ')} (fick "${enkla.sprak}")` }
|
|
138
118
|
if (enkla['design-mode'] !== undefined && !DESIGNLAGEN.includes(enkla['design-mode']))
|
|
@@ -144,7 +124,6 @@ export function tolkaArgv(argv) {
|
|
|
144
124
|
arkiv: enkla.arkiv ?? null,
|
|
145
125
|
poster: normerade,
|
|
146
126
|
parallellt: Number(parText),
|
|
147
|
-
maxUsd,
|
|
148
127
|
claude: enkla.claude ?? 'claude',
|
|
149
128
|
om,
|
|
150
129
|
sprak: enkla.sprak ?? null,
|
|
@@ -164,16 +143,6 @@ export function losPost(post, arkiv) {
|
|
|
164
143
|
return { dir }
|
|
165
144
|
}
|
|
166
145
|
|
|
167
|
-
/** Taket för körningen: flaggan vinner, sedan `max_usd_per_batch` i
|
|
168
|
-
* `<arkiv>/../request.json` (`.haus-workflow/request.json`), sedan 100. En
|
|
169
|
-
* saknad eller trasig fil är defaulten, aldrig ett fel. */
|
|
170
|
-
export function lasTak({ arkiv, maxUsd = null }) {
|
|
171
|
-
if (maxUsd !== null && maxUsd !== undefined) return maxUsd
|
|
172
|
-
const v = lasRequestJson(arkiv)?.max_usd_per_batch
|
|
173
|
-
if (typeof v === 'number' && Number.isFinite(v) && v >= 0) return v
|
|
174
|
-
return STANDARD_TAK_USD
|
|
175
|
-
}
|
|
176
|
-
|
|
177
146
|
/** `<arkiv>/../request.json` som objekt, eller null när den saknas eller är
|
|
178
147
|
* trasig (defaulten gäller då, aldrig ett fel). */
|
|
179
148
|
function lasRequestJson(arkiv) {
|
|
@@ -294,9 +263,6 @@ export function avgorStatus({ exitCode, signal = null, state, sparrExit }) {
|
|
|
294
263
|
return { status: 'ofärdig', orsak: `status ${state?.status ?? 'okänd'} utan stopp eller spärr` }
|
|
295
264
|
}
|
|
296
265
|
|
|
297
|
-
/** Har summan (de klara posterna plus de i flykt till snittet) nått taket? */
|
|
298
|
-
export const kapNatt = (summaUsd, tak) => summaUsd >= tak
|
|
299
|
-
|
|
300
266
|
/** Standardlöparen för archive.mjs: synkron, cwd i posten. */
|
|
301
267
|
export const arkivStandard = (args, cwd) =>
|
|
302
268
|
spawnSync(process.execPath, [ARCHIVE, ...args], { cwd, encoding: 'utf8' })
|
|
@@ -421,7 +387,7 @@ const lasUsd = (runDir) => {
|
|
|
421
387
|
/** En post, hela ordningen ur ADR-0155. Kastar aldrig medvetet; ett kast
|
|
422
388
|
* blir en `ofärdig`-rad i korBatch. */
|
|
423
389
|
async function korPost(post, ctx) {
|
|
424
|
-
const { ut, arkivKor, korKorning, kvitton,
|
|
390
|
+
const { ut, arkivKor, korKorning, kvitton, konto } = ctx
|
|
425
391
|
const rad = (status, extra = {}) => ({ post, status, ...extra })
|
|
426
392
|
const los = losPost(post, ctx.arkiv)
|
|
427
393
|
if (los.fel) {
|
|
@@ -439,10 +405,6 @@ async function korPost(post, ctx) {
|
|
|
439
405
|
ut(`GRIND ${post}: ${grind}`)
|
|
440
406
|
return rad('grind', { orsak: grind, ...lasPoang(dir) })
|
|
441
407
|
}
|
|
442
|
-
if (kapNatt(summa(), tak)) {
|
|
443
|
-
ut(`TAK ${post}`)
|
|
444
|
-
return rad('tak nått')
|
|
445
|
-
}
|
|
446
408
|
const runDir = korningsKatalog(dir, ctx.now ? ctx.now() : new Date())
|
|
447
409
|
const start = startaKorning(dir, ctx.pid ?? process.pid, runDir, { arkivKor })
|
|
448
410
|
if (start.pagar) {
|
|
@@ -457,7 +419,6 @@ async function korPost(post, ctx) {
|
|
|
457
419
|
}
|
|
458
420
|
if (start.varning) console.error(`${post}: ${start.varning}`)
|
|
459
421
|
kvitton.add(dir)
|
|
460
|
-
konto.iFlykt++
|
|
461
422
|
let belopp = null
|
|
462
423
|
try {
|
|
463
424
|
ut(`START ${post}`)
|
|
@@ -488,10 +449,7 @@ async function korPost(post, ctx) {
|
|
|
488
449
|
usd: belopp,
|
|
489
450
|
})
|
|
490
451
|
} finally {
|
|
491
|
-
//
|
|
492
|
-
// (en post utan korning.json räknas som 0).
|
|
493
|
-
konto.iFlykt--
|
|
494
|
-
konto.klara++
|
|
452
|
+
// Postens USD in i summan (en post utan korning.json räknas som 0).
|
|
495
453
|
if (Number.isFinite(belopp)) konto.anvant += belopp
|
|
496
454
|
const slut = avslutaKorning(dir, { arkivKor })
|
|
497
455
|
if (!slut.ok) console.error(`VARNING ${post}: ${slut.fel}`)
|
|
@@ -499,20 +457,14 @@ async function korPost(post, ctx) {
|
|
|
499
457
|
}
|
|
500
458
|
}
|
|
501
459
|
|
|
502
|
-
/**
|
|
503
|
-
*
|
|
504
|
-
|
|
505
|
-
anvant + (klara > 0 ? iFlykt * (anvant / klara) : 0)
|
|
506
|
-
|
|
507
|
-
/** Kör posterna med högst `parallellt` i flykt. Taket prövas vid varje
|
|
508
|
-
* poststart mot `taksumma` (en post utan korning.json räknas som 0).
|
|
509
|
-
* Returnerar raderna i argv-ordning och de klara posternas summa. */
|
|
460
|
+
/** Kör posterna med högst `parallellt` i flykt. Returnerar raderna i
|
|
461
|
+
* argv-ordning och de klara posternas summa (en post utan korning.json
|
|
462
|
+
* räknas som 0). */
|
|
510
463
|
export async function korBatch({
|
|
511
464
|
poster,
|
|
512
465
|
arkiv,
|
|
513
466
|
repoRot,
|
|
514
467
|
parallellt,
|
|
515
|
-
tak,
|
|
516
468
|
om,
|
|
517
469
|
claude,
|
|
518
470
|
sprak,
|
|
@@ -525,7 +477,7 @@ export async function korBatch({
|
|
|
525
477
|
pid = process.pid,
|
|
526
478
|
now,
|
|
527
479
|
}) {
|
|
528
|
-
const konto = { anvant: 0
|
|
480
|
+
const konto = { anvant: 0 }
|
|
529
481
|
const ctx = {
|
|
530
482
|
arkiv,
|
|
531
483
|
repoRot,
|
|
@@ -533,7 +485,6 @@ export async function korBatch({
|
|
|
533
485
|
claude,
|
|
534
486
|
sprak,
|
|
535
487
|
designMode,
|
|
536
|
-
tak,
|
|
537
488
|
ut,
|
|
538
489
|
arkivKor,
|
|
539
490
|
korKorning,
|
|
@@ -542,7 +493,6 @@ export async function korBatch({
|
|
|
542
493
|
pid,
|
|
543
494
|
now,
|
|
544
495
|
konto,
|
|
545
|
-
summa: () => taksumma(konto),
|
|
546
496
|
}
|
|
547
497
|
const resultat = await schemalagg(poster, parallellt, (post) => korPost(post, ctx))
|
|
548
498
|
const rader = resultat.map((r, i) =>
|
|
@@ -604,7 +554,6 @@ async function main(argv) {
|
|
|
604
554
|
console.error(ANVANDNING)
|
|
605
555
|
return 2
|
|
606
556
|
}
|
|
607
|
-
const tak = lasTak({ arkiv, maxUsd: val.maxUsd })
|
|
608
557
|
const designMode = lasDesignlage({ arkiv, designMode: val.designMode })
|
|
609
558
|
const ut = (rad) => process.stdout.write(rad + '\n')
|
|
610
559
|
const pagaende = new Map()
|
|
@@ -617,7 +566,6 @@ async function main(argv) {
|
|
|
617
566
|
arkiv,
|
|
618
567
|
repoRot: val.repoRot,
|
|
619
568
|
parallellt: val.parallellt,
|
|
620
|
-
tak,
|
|
621
569
|
om: val.om,
|
|
622
570
|
claude: val.claude,
|
|
623
571
|
sprak: val.sprak,
|
|
@@ -628,7 +576,7 @@ async function main(argv) {
|
|
|
628
576
|
})
|
|
629
577
|
ut('')
|
|
630
578
|
ut(renderaTabell(rader))
|
|
631
|
-
ut(`
|
|
579
|
+
ut(`använt: ${anvant.toFixed(2)} USD`)
|
|
632
580
|
return rader.every((r) => RESULTAT.includes(r.status)) ? 0 : 1
|
|
633
581
|
}
|
|
634
582
|
|