@kici-dev/compiler 0.6.0 → 0.7.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 (45) hide show
  1. package/dist/cli.js +10 -2
  2. package/dist/commands/compile.js +5 -1
  3. package/dist/commands/doctor.js +8 -2
  4. package/dist/commands/feedback.d.ts +53 -0
  5. package/dist/commands/feedback.js +142 -0
  6. package/dist/commands/index.d.ts +2 -0
  7. package/dist/commands/index.js +2 -1
  8. package/dist/commands/init.d.ts +9 -0
  9. package/dist/commands/init.js +77 -12
  10. package/dist/commands/preview.js +1 -1
  11. package/dist/commands/report/identity.d.ts +11 -0
  12. package/dist/commands/report/identity.js +7 -2
  13. package/dist/commands/run-routed.js +1 -0
  14. package/dist/commands/types.d.ts +6 -1
  15. package/dist/commands/types.js +2 -1
  16. package/dist/execution/executor.js +7 -1
  17. package/dist/llm-context/llms-architecture.txt +72 -86
  18. package/dist/llm-context/llms-cli-remote.txt +2380 -0
  19. package/dist/llm-context/llms-cli.txt +348 -2615
  20. package/dist/llm-context/llms-features-execution.txt +80 -23
  21. package/dist/llm-context/llms-features.txt +137 -6
  22. package/dist/llm-context/llms-full.txt +2582 -2025
  23. package/dist/llm-context/llms-getting-started.txt +152 -5
  24. package/dist/llm-context/llms-patterns.txt +81 -5
  25. package/dist/llm-context/llms-providers.txt +6 -2
  26. package/dist/llm-context/llms-sdk-runtime.txt +22 -18
  27. package/dist/llm-context/llms-sdk.txt +47 -7
  28. package/dist/llm-context/llms.txt +20 -13
  29. package/dist/local-plane/orchestrator-process.d.ts +0 -8
  30. package/dist/local-plane/orchestrator-process.js +3 -14
  31. package/dist/local-plane/plane-manager.js +2 -2
  32. package/dist/lockfile/generator.js +25 -9
  33. package/dist/lockfile/hasher.d.ts +5 -13
  34. package/dist/lockfile/hasher.js +1 -15
  35. package/dist/lockfile/workspace-siblings.d.ts +46 -0
  36. package/dist/lockfile/workspace-siblings.js +197 -0
  37. package/dist/templates/package-json.js +1 -1
  38. package/dist/test-runner/job-executor.js +1 -1
  39. package/dist/test-runner/rule-evaluator.js +1 -1
  40. package/dist/types.d.ts +6 -1
  41. package/package.json +7 -9
  42. package/sbom.spdx.json +123 -123
  43. package/dist/postinstall.d.ts +0 -9
  44. package/dist/postinstall.js +0 -62
  45. package/hack/postinstall.mjs +0 -105
@@ -29,7 +29,7 @@ interface LocalConfig {
29
29
 
30
30
  ### SharedConfig
31
31
 
32
- Shared settings stored in the PostgreSQL `config_versions` table. Defined once, shared across all instances:
32
+ Settings stored in the PostgreSQL `config_versions` table, written and read by the `/admin/config` routes and their `kici-admin config` commands:
33
33
 
34
34
  ```typescript
35
35
  interface SharedConfig {
@@ -73,11 +73,13 @@ interface AppConfig {
73
73
 
74
74
  ### How they merge
75
75
 
76
+ `resolveFullConfig()` takes a `LocalConfig` and an optional `SharedConfig` and merges them:
77
+
76
78
  ```
77
79
  defaults (getDefaults())
78
80
  |
79
81
  v
80
- SharedConfig (from DB) ──deepMerge──> merged layer 1+2
82
+ SharedConfig (argument) ──deepMerge──> merged layer 1+2
81
83
  |
82
84
  v
83
85
  LocalConfig (from YAML) ──deepMerge──> merged layer 1+2+3
@@ -94,29 +96,48 @@ appConfigSchema.safeParse() ──validate──> typed AppConfig
94
96
 
95
97
  The `deepMerge` function merges objects recursively, replaces arrays (does not merge item-by-item), and skips `undefined`/`null` source values (they do not override existing values).
96
98
 
99
+ **The `SharedConfig` argument is `null` in the shipped wiring.** `ConfigReloader` is the only non-test caller of `resolveFullConfig()`, and it is constructed with `sharedStore: null`. So the DB layer is skipped and the effective chain is defaults → YAML → env. The `config_versions` table is read by the `/admin/config` write and inspection routes, by `kici-admin rotate-key`, and by the cluster join flow — never by a running orchestrator's own config.
100
+
97
101
  ## Resolution chain
98
102
 
99
- ### Two-phase design
103
+ ### Startup
104
+
105
+ `server.ts` and `standalone.ts` both call `loadConfig()`, which parses `KICI_*` environment variables against the flat schema in `config.ts`. No YAML file and no database row participates:
100
106
 
101
107
  ```
102
- Phase 1 (local-only):
103
- YAML file + KICI_ env vars
104
- |
105
- v
106
- resolveLocalConfig() -> { databaseUrl, instanceId, port, mode }
107
- |
108
- v
109
- Connect to PostgreSQL
110
- |
111
- v
112
- Phase 2 (full merge):
113
- defaults -> DB -> YAML -> env
114
- |
115
- v
116
- resolveFullConfig() -> AppConfig
108
+ Process start
109
+ |
110
+ v
111
+ loadConfig() -> envDef.parse(process.env) -> AppConfig
112
+ |
113
+ v
114
+ Connect to PostgreSQL, run migrations
115
+ |
116
+ v
117
+ Start server (HTTP, WS, scaler, cluster)
117
118
  ```
118
119
 
119
- **Why two phases?** The database URL must come from local config (YAML or env var) because we need it to connect to PostgreSQL. But the shared config is stored in PostgreSQL. This circular dependency is broken by resolving local config first (Phase 1), connecting to the DB, then doing the full merge (Phase 2).
120
+ The database URL therefore has to be an environment variable: the orchestrator needs it to reach PostgreSQL, and the shared config lives in PostgreSQL.
121
+
122
+ ### Reload
123
+
124
+ `resolveLocalConfig()` and `resolveFullConfig()` run on the reload path, not at startup:
125
+
126
+ ```
127
+ SIGHUP / POST /admin/config/reload / kici-admin config reload
128
+ |
129
+ v
130
+ resolveLocalConfig() -> YAML file + KICI_ env overlay
131
+ |
132
+ v
133
+ resolveFullConfig(local, null) -> defaults -> YAML -> env -> AppConfig
134
+ |
135
+ v
136
+ Hold databaseUrl, port, instanceId and storage at their startup values
137
+ |
138
+ v
139
+ Atomic swap into ConfigReloader.currentConfig
140
+ ```
120
141
 
121
142
  ### Env var processing
122
143
 
@@ -128,43 +149,6 @@ Environment variables are processed in two stages:
128
149
 
129
150
  Type coercion is applied based on known field types: numeric fields are parsed as numbers, boolean fields are compared against `"true"`, all others remain strings.
130
151
 
131
- ## Two-phase bootstrap
132
-
133
- ```
134
- ┌─────────────────┐
135
- │ Process Start │
136
- └────────┬────────┘
137
-
138
-
139
- ┌─────────────────┐
140
- │ Load YAML + │ resolveLocalConfig()
141
- │ Env Overrides │ -> databaseUrl, instanceId, port, mode
142
- └────────┬────────┘
143
-
144
-
145
- ┌─────────────────┐
146
- │ Connect to │ PostgreSQL
147
- │ Database │ Run migrations
148
- └────────┬────────┘
149
-
150
-
151
- ┌─────────────────┐
152
- │ Load Shared │ SharedConfigStore.getLatest()
153
- │ Config from DB │ -> decrypt -> SharedConfig
154
- └────────┬────────┘
155
-
156
-
157
- ┌─────────────────┐
158
- │ Full Merge │ resolveFullConfig(local, db, env)
159
- │ + Validate │ -> AppConfig
160
- └────────┬────────┘
161
-
162
-
163
- ┌─────────────────┐
164
- │ Start Server │ HTTP, WS, scaler, cluster
165
- └─────────────────┘
166
- ```
167
-
168
152
  ## DB schema
169
153
 
170
154
  ### config_versions table
@@ -264,7 +248,7 @@ flowchart TD
264
248
  trigger --> execute["executeReload()<br/>boolean mutex"]
265
249
 
266
250
  execute --> resolveLocal["resolveLocalConfig()"]
267
- execute --> getLatest["getLatest (DB)"]
251
+ execute --> getLatest["getLatest (DB)<br/>skipped: sharedStore is null"]
268
252
  execute --> resolveFull["resolveFullConfig()<br/>(merge + validate)"]
269
253
 
270
254
  resolveLocal --> check["Check restart-required fields"]
@@ -283,26 +267,26 @@ flowchart TD
283
267
  - **Mutex:** Boolean flag prevents concurrent reloads. Second reload returns `{ success: false, errors: ["Reload already in progress"] }`.
284
268
  - **Debounce:** Rapid triggers (e.g., multiple SIGHUP signals) are collapsed into a single reload with a 500ms window.
285
269
  - **Validation before swap:** The new config must pass full schema validation. On failure, the old config is preserved and an error is logged.
286
- - **Restart-required detection:** Fields like `databaseUrl`, `port`, `instanceId` are compared. If changed, the old values are preserved in the applied config and a warning is logged.
270
+ - **Restart-required detection:** `databaseUrl`, `port`, `instanceId` and `storage` are compared. If changed, the old values are preserved in the applied config and a warning is logged.
287
271
  - **No crash on failure:** The orchestrator always keeps running with the old config if anything goes wrong during reload.
288
272
 
289
273
  ### Subsystem callbacks
290
274
 
291
275
  The `ConfigReloader` uses a dependency injection pattern with callbacks for subsystem re-initialization:
292
276
 
293
- | Callback | When Called | Purpose |
294
- | --------------------- | ----------------------------- | -------------------------------------------------------------------------------------------- |
295
- | `onProviderChange` | Provider config changed | Reserved callback (providers are now DB-managed via sources table; currently always a no-op) |
296
- | `onScalerReload` | Always on successful reload | Reload scaler YAML config |
297
- | `onPlatformReconnect` | Platform URL or token changed | Reconnect WS to Platform relay |
298
- | `onConfigApplied` | Always on successful reload | Atomic config reference swap, increment local config version |
277
+ | Callback | When Called | Purpose |
278
+ | --------------------- | ----------------------------- | ------------------------------------------------------------------------------------------------------------------------------ |
279
+ | `onProviderChange` | Provider config changed | Reserved callback. Providers are DB-managed via the sources table, so the change detector always reports no change |
280
+ | `onScalerReload` | Always on successful reload | Reload scaler YAML config, from the path the process started with |
281
+ | `onPlatformReconnect` | Platform URL or token changed | Logs that the Platform connection settings changed. The connection is not re-established; `standalone.ts` registers no handler |
282
+ | `onConfigApplied` | Always on successful reload | Atomic config reference swap, increment local config version |
299
283
 
300
284
  ### Prometheus metrics
301
285
 
302
- | Metric | Type | Labels | Description |
303
- | ------------------------------- | ------- | ----------------------------------------------------------------------- | ------------------------------------- |
304
- | `kici_orch_config_reload_total` | Counter | `result` (attempted/success/failed), `source` (sighup/http/cluster/cli) | Config reload attempts and outcomes |
305
- | `kici_orch_config_version` | Gauge | -- | Current shared config version from DB |
286
+ | Metric | Type | Labels | Description |
287
+ | ------------------------------- | ------- | ----------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------- |
288
+ | `kici_orch_config_reload_total` | Counter | `result` (attempted/success/failed), `source` (sighup/http/cluster/cli) | Config reload attempts and outcomes |
289
+ | `kici_orch_config_version` | Gauge | -- | Shared config version from the DB. Set only when the reload path reads a version, so it carries no value today |
306
290
 
307
291
  ## Multi-Provider
308
292
 
@@ -334,40 +318,42 @@ Each source record contains its own `appId` and `privateKey` (stored as scoped s
334
318
 
335
319
  ### Heartbeat config version
336
320
 
337
- In clustered deployments, each orchestrator includes its current config version in Raft heartbeat metadata via the `configVersion` optional field on the `peerHeartbeatSchema`.
321
+ In clustered deployments, each orchestrator includes its config version in Raft heartbeat metadata via the `configVersion` optional field on the `peerHeartbeatSchema`.
322
+
323
+ **That number is a local reload counter, not a shared config version.** `onConfigApplied` increments it on every successful reload and publishes the new value to the peer registry. It counts how many times this instance has reloaded.
338
324
 
339
325
  When the `PeerRegistry` processes a heartbeat:
340
326
 
341
327
  1. Compare `localConfigVersion` with `peer.configVersion`
342
328
  2. If `peer.configVersion > localConfigVersion` AND both are > 0:
343
329
  - Invoke the `onConfigVersionBehind` callback
344
- - This triggers a config reload from the database
330
+ - This triggers a config reload, which re-reads the environment and the local YAML file
345
331
 
346
332
  ### Auto-remediation flow
347
333
 
348
334
  ```
349
- Orchestrator A (version 5) Orchestrator B (version 3)
335
+ Orchestrator A (reloaded 5x) Orchestrator B (reloaded 3x)
350
336
  │ │
351
337
  │──── heartbeat(configVersion=5) ────>│
352
338
  │ │
353
339
  │ compare: 5 > 3
354
- │ trigger reload from DB
340
+ │ trigger reload
355
341
  │ │
356
- │ resolveFullConfig()
357
- │ -> version 5
342
+ │ resolveFullConfig(local, null)
343
+ │ -> counter becomes 4
358
344
  │ │
359
- │<── heartbeat(configVersion=5) ──────│
345
+ │<── heartbeat(configVersion=4) ──────│
360
346
  │ │
361
- │ both at version 5 ✓ │
362
347
  ```
363
348
 
349
+ B converges on A's count only after it has reloaded as many times as A has. Each instance reads its own environment and its own YAML file, so the two agree on content only when those inputs agree.
350
+
364
351
  ### Guard conditions
365
352
 
366
353
  - Version comparison only triggers when **both** local and peer versions are > 0
367
354
  - This prevents false triggers from:
368
- - Legacy orchestrators that do not report `configVersion` (field is optional, defaults to 0)
369
- - Newly started orchestrators before their first config load
370
- - The `localConfigVersion` is a monotonically incrementing local counter (incremented on each successful reload)
355
+ - Orchestrators that do not report `configVersion` (field is optional, defaults to 0)
356
+ - Newly started orchestrators before their first reload
371
357
 
372
358
  ## See also
373
359
 
@@ -398,7 +384,7 @@ GitHub --> Platform Relay --> Orchestrator --> Agent
398
384
 
399
385
  1. **Provider sends webhook** to the Platform relay endpoint.
400
386
  2. **Platform routes the webhook** to the right orchestrator over WebSocket and forwards the body bytes verbatim. Platform never sees customer HMAC secrets — signature verification happens entirely on the orchestrator after reassembly.
401
- 3. **Orchestrator verifies signature** (HMAC-SHA256 against per-source webhook secret, with dual-secret rotation support).
387
+ 3. **Orchestrator admits the delivery**, then **verifies the signature** (HMAC-SHA256 against per-source webhook secret, with dual-secret rotation support). Admission runs first, on the routing key alone: when the ingest admission controller sheds, the orchestrator records an `event_log` breadcrumb with status `shed` and ACKs `shed_retry_later`, which the Platform answers as **429** with `Retry-After`. See [ingest admission shed](https://docs.kici.dev/architecture/webhooks/webhook-delivery/#ingest-admission-shed-step-3).
402
388
  4. **Orchestrator dedup check** against dual-layer `DedupCache` (in-memory set + `dedup_cache` DB table).
403
389
  5. **Orchestrator resolves provider** by looking up the provider bundle from the `ProviderRegistry` using `getByRoutingKey()` (exact match first, falls back to provider type prefix for backward compatibility). Skips processing if the provider is unknown.
404
390
  6. **Orchestrator normalizes** the webhook via the provider's `WebhookNormalizer` (extracts branch, event type, action, sender).
@@ -525,7 +511,7 @@ Build Job Dispatch --> Build Agent (kici:role:builder + matching kici:os:/kici:a
525
511
  | |-- npm ci in .kici/
526
512
  | |-- Pack .kici/ source (portable tar.gz, excludes node_modules)
527
513
  | |-- Pack .kici/node_modules (portable tar.gz)
528
- | |-- Upload source tarball to cache (source/{contentHash}.tar.gz)
514
+ | |-- Upload source tarball to cache (source/v2/{orgId}/{sourceTarDigest}.tar.gz)
529
515
  | |-- Upload deps tarball to cache (deps/{plat}-{arch}/{depsHash}.tar.gz)
530
516
  | |-- Upload deps companion .hash file
531
517
  | |-- Report success (cache.upload.complete × 2)
@@ -600,7 +586,7 @@ Dep cache misses alone do **not** trigger a build job. Deps are platform-specifi
600
586
 
601
587
  ### Cross-source / no-contentHash workflows
602
588
 
603
- - **Lock files without `contentHash`** (schema v1) skip the source cache entirely; agents compile from source. Regenerate lock files with `kici compile` to enable caching. The current lock file schema version is 39.
589
+ - **Lock files without `contentHash`** (schema v1) skip the source cache entirely; agents compile from source. Regenerate lock files with `kici compile` to enable caching. The current lock file schema version is 41.
604
590
  - **Cross-source / global-workflow dispatch** (a workflow registered against source A fired by a webhook on source B) bypasses both caches. The registration's lock file entry still carries `contentHash`, but the cross-source path always clone-and-installs — the eval temp dir doesn't ship `@kici-dev/sdk`. The execution agent still verifies `contentHash` against the cloned source for drift detection.
605
591
 
606
592
  ### Build deduplication
@@ -639,7 +625,7 @@ Both source and dep caches use `S3CacheStorage` as the sole backend. The `CacheS
639
625
 
640
626
  Cache keys reflect that source tarballs and deps have different platform characteristics:
641
627
 
642
- - **Source:** `source/{contentHash}.tar.gz` — platform-agnostic. Raw TypeScript source is identical regardless of CPU architecture, so one entry is shared across all platforms. `contentHash` is the per-workflow hash from the lock file (`SHA-256(COMPILE_SCHEMA_VERSION + ":" + rawSource [+ "\0" + assetDigest])`, where `COMPILE_SCHEMA_VERSION = 5` and line endings are normalized to LF so the hash agrees across platforms).
628
+ - **Source:** `source/v2/{orgId}/{sourceTarDigest}.tar.gz`, with a `source/v2/{orgId}/{contentHash}.hash` pointer — platform-agnostic, and scoped to the owning organization so two repositories with matching `.kici/` trees never share one object. Raw TypeScript source is identical regardless of CPU architecture, so one entry is shared across all platforms. `contentHash` is the per-workflow hash from the lock file (`SHA-256(COMPILE_SCHEMA_VERSION + ":" + rawSource [+ "\0" + assetDigest])`, where `COMPILE_SCHEMA_VERSION = 7` and line endings are normalized to LF so the hash agrees across platforms).
643
629
  - **Deps:** `deps/{platform}-{arch}/{depsHash}.tar.gz`, with a
644
630
  `deps/{platform}-{arch}/{lockfileHash}.hash` pointer holding that hash — the
645
631
  tarball is addressed by its own content, so two builds sharing a lock file
@@ -1370,14 +1356,14 @@ Shared business logic used by all three tiers. Single source of truth for cross-
1370
1356
  - Label utilities (platform label derivation, runsOn normalization, `kici:*` set-only reserved namespace, role labels)
1371
1357
  - Host inventory (the canonical queryable host-roster schema shared by the orchestrator's roster store, the agent-facing inventory API, and the SDK's `ctx.kici.inventory`)
1372
1358
  - Audit policy and retention (per-action access-log sampling, warm-retention windows for cold-store eligibility, federated activity row schema)
1373
- - Scaler backend type enum (`container`, `bare-metal`, `firecracker`, `kubernetes`, `event`) and the reserved `kici.` event-name prefix that keeps a user step from forging a system event
1359
+ - Scaler backend type enum (`container`, `bare-metal`, `firecracker`, `kubernetes`, `event`; the orchestrator config rejects `kubernetes`) and the reserved `kici.` event-name prefix that keeps a user step from forging a system event
1374
1360
  - Job resource vocabulary (the requests/limits shape the SDK accepts, the compiler validates and emits, the orchestrator uses for capacity math and kernel-side enforcement, and the dashboard displays)
1375
1361
  - Registration trigger type enum (registerable trigger discriminator)
1376
1362
  - Sandbox capability set (the Linux capability names a container sandbox may add or drop, shared by the SDK validator, the compiler, and the dispatch resolver)
1377
1363
  - Plan tier vocabulary (the hosted plan tiers and the purchasable subset, shared by the Platform and the browser dashboard)
1378
1364
  - Infrastructure alert vocabulary (the diagnostics alert types and severities the Platform mints and the dashboard and `kici` CLI render)
1379
1365
  - Metric catalog (the generated Prometheus metric inventory, its naming policy, and metric-kind compatibility checks)
1380
- - Bundler config (shared bundler configuration consumed by `e2e/helpers/service-deploy.ts`; the agent runtime uses the `@kici-dev/core/ts-loader-hook` to transform TypeScript on import, with no runtime bundler step)
1366
+ - Bundler config (the shared workflow-bundle configuration factory on the barrel; the agent runtime uses the `@kici-dev/core/ts-loader-hook` to transform TypeScript on import, so no runtime path bundles a workflow)
1381
1367
 
1382
1368
  > Source: `packages/engine/src/`
1383
1369
 
@@ -1397,7 +1383,7 @@ It also runs the **local dev plane** -- an on-demand, fully local execution stac
1397
1383
 
1398
1384
  ### `@kici-dev/core`
1399
1385
 
1400
- Light shared utilities with no server-side dependencies. It provides JSON-structured logging, error helpers, async-local-storage request context, and human-readable formatting (`formatBytes`/`formatDuration`/`formatUptime`). It also provides cryptographic helpers (`sha256`/`sha256File`/`deriveSharedSecret` plus symmetric encrypt/decrypt), retry-backoff computation, and the shared diagnostics-result contract. The rest of its surface ships as subpath entry points: the temp-directory allocator and its garbage collector, package-manager detection, CI-environment detection, and the idempotent-step runner (the check / confirm / apply primitive behind idempotent steps). Finally it supplies zx initialization (`initZx()`) and the TypeScript loader hook that transforms TypeScript on import. It is the dependency-light core that the SDK, compiler, and `kici` CLI consume directly so they stay free of heavier server-only dependencies. `@kici-dev/shared` re-exports it, so existing `@kici-dev/shared` import paths keep working.
1386
+ Light shared utilities with no server-side dependencies. It provides JSON-structured logging, error helpers, async-local-storage request context, and human-readable formatting (`formatBytes`/`formatDuration`/`formatUptime`). It also provides cryptographic helpers (`sha256`/`sha256File`/`deriveSharedSecret` plus symmetric encrypt/decrypt), retry-backoff computation, and the shared diagnostics-result contract. The rest of its surface ships as subpath entry points: the temp-directory allocator and its garbage collector, package-manager detection, CI-environment detection, and the idempotent-step runner (the check / confirm / apply primitive behind idempotent steps). One further subpath holds the `.kici/` source digest: the single content-hash definition the compiler writes into the lock file and the agent recomputes as its drift gate. Finally it supplies zx initialization (`initZx()`) and the TypeScript loader hook that transforms TypeScript on import. It is the dependency-light core that the SDK, compiler, and `kici` CLI consume directly so they stay free of heavier server-only dependencies. `@kici-dev/shared` re-exports it, so existing `@kici-dev/shared` import paths keep working.
1401
1387
 
1402
1388
  > Source: `packages/core/src/`
1403
1389