typeclaw 0.48.1 → 0.48.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "typeclaw",
3
- "version": "0.48.1",
3
+ "version": "0.48.2",
4
4
  "homepage": "https://github.com/typeclaw/typeclaw#readme",
5
5
  "bugs": {
6
6
  "url": "https://github.com/typeclaw/typeclaw/issues"
@@ -67,6 +67,12 @@ When the user asks you to build, run, fix, or verify something, the deliverable
67
67
 
68
68
  If a tool, install, or network call fails and blocks the real path, say so directly and try an alternative (different approach, different package, ask the user). Never substitute plausible-looking fabricated output (made-up data, invented file contents, synthesised tool results) for a result you could not actually produce — reporting a blocker honestly is always better than inventing a result.
69
69
 
70
+ A change is not done because it compiled. A green build, lint, or type check proves the artifact is well-formed — not that it took effect on the thing you were asked to fix. Restart-required surfaces (config fields, plugin registration, daemons) never reach an already-running process, so the live system keeps its old behavior until something actually restarts it. Before reporting a fix, verify the reported symptom is gone in the running system. When you cannot — the restart is the operator's to run, the process is out of reach, the check needs credentials you don't have — say so and name what is still unverified. "I fixed it" and "I wrote a fix I could not verify" are different claims; never report the second as the first.
71
+
72
+ Never say you performed an action you did not perform, and never promise one you cannot perform from where you run. When an action is out of reach, name who or what has to run it instead of narrating it as done or imminent.
73
+
74
+ Separate what a tool returned from why you think it happened. Report the observed output and label any account of the cause as the inference it is until evidence confirms it. A fluent, unverified cause is a fabrication even when every word of it is well-formed, and it is worse than "I don't know yet" because it closes the investigation early for both of you.
75
+
70
76
  ## Parallel tool calls
71
77
 
72
78
  When you need several pieces of information that don't depend on each other, request them in a single response instead of one tool call per turn. Independent reads, searches, and read-only commands should be batched into the same turn — the runtime runs independent calls concurrently, and batching avoids re-sending the whole conversation on every extra round-trip. Only serialize when a later call genuinely depends on an earlier call's result (e.g. read a file before patching it).
@@ -313,6 +319,8 @@ Never echo secrets from \`secrets.json\` or \`.env\`, or any credential you see
313
319
 
314
320
  Never suppress errors to make things "work", and never fabricate results. If something fails, report the failure clearly so the next run or the operator can act on it.
315
321
 
322
+ A green build or lint proves the artifact is well-formed, not that the change took effect — restart-required surfaces (config, plugins) never reach an already-running process. Verify the symptom is gone in the live system before reporting a fix; when you cannot verify it, say what is still unverified instead of reporting it as done. Never claim an action you did not perform, and label a suspected cause as inference rather than stating it as fact.
323
+
316
324
  Do not narrate routine, low-risk tool calls — just call the tool. Do not over-explain what you did unless asked.
317
325
 
318
326
  ${PACKAGE_JSON_INSTALL_RULE}
@@ -3,6 +3,7 @@ import path from 'node:path'
3
3
 
4
4
  import { parseConfigJson } from '@/config'
5
5
  import { validateCronEdit } from '@/cron'
6
+ import { RECOVER_MISSING, realIntendedPath } from '@/path-safety/real-intended-path'
6
7
 
7
8
  import type { GuardBlock } from '../policy'
8
9
 
@@ -161,25 +162,11 @@ function blockReason(tool: string, targetPath: string, reason: string): GuardBlo
161
162
  }
162
163
  }
163
164
 
165
+ // RECOVER_MISSING only: this policy decides whether a write is ALLOWED, so an
166
+ // ancestor that cannot be resolved must never widen the permitted surface.
164
167
  async function resolveRealIntendedPath(absolutePath: string): Promise<string> {
165
- const pending: string[] = []
166
- let current = absolutePath
167
-
168
- while (true) {
169
- try {
170
- const realCurrent = await realpath(current)
171
- return path.join(realCurrent, ...pending.reverse())
172
- } catch (err) {
173
- if (!isNotFoundError(err)) throw err
174
- }
175
-
176
- const parent = path.dirname(current)
177
- if (parent === current) throw new Error(`could not resolve existing parent for ${absolutePath}`)
178
- pending.push(path.basename(current))
179
- current = parent
180
- }
181
- }
182
-
183
- function isNotFoundError(err: unknown): boolean {
184
- return err instanceof Error && 'code' in err && err.code === 'ENOENT'
168
+ return await realIntendedPath(absolutePath, realpath, {
169
+ recoverable: RECOVER_MISSING,
170
+ onExhausted: 'throw',
171
+ })
185
172
  }
@@ -2,6 +2,7 @@ import { realpath } from 'node:fs/promises'
2
2
  import path from 'node:path'
3
3
 
4
4
  import type { SessionOrigin } from '@/agent/session-origin'
5
+ import { RECOVER_MISSING, realIntendedPath } from '@/path-safety/real-intended-path'
5
6
 
6
7
  import { ACKNOWLEDGE_GUARDS, type GuardBlock, isGuardAcknowledged } from '../policy'
7
8
  import { isMemoryTopicsWriteAllowed } from './memory-topics-write'
@@ -132,25 +133,11 @@ function isInside(parent: string, child: string): boolean {
132
133
  return relative === '' || (!relative.startsWith('..') && !path.isAbsolute(relative))
133
134
  }
134
135
 
136
+ // RECOVER_MISSING only: this policy decides whether a write is ALLOWED, so an
137
+ // ancestor that cannot be resolved must never widen the permitted surface.
135
138
  async function resolveRealIntendedPath(absolutePath: string): Promise<string> {
136
- const pending: string[] = []
137
- let current = absolutePath
138
-
139
- while (true) {
140
- try {
141
- const realCurrent = await realpath(current)
142
- return path.join(realCurrent, ...pending.reverse())
143
- } catch (err) {
144
- if (!isNotFoundError(err)) throw err
145
- }
146
-
147
- const parent = path.dirname(current)
148
- if (parent === current) throw new Error(`could not resolve existing parent for ${absolutePath}`)
149
- pending.push(path.basename(current))
150
- current = parent
151
- }
152
- }
153
-
154
- function isNotFoundError(err: unknown): boolean {
155
- return err instanceof Error && 'code' in err && err.code === 'ENOENT'
139
+ return await realIntendedPath(absolutePath, realpath, {
140
+ recoverable: RECOVER_MISSING,
141
+ onExhausted: 'throw',
142
+ })
156
143
  }
@@ -1,6 +1,8 @@
1
1
  import { readFile, realpath } from 'node:fs/promises'
2
2
  import path from 'node:path'
3
3
 
4
+ import { RECOVER_MISSING, realIntendedPath } from '@/path-safety/real-intended-path'
5
+
4
6
  import type { GuardBlock } from '../policy'
5
7
 
6
8
  export const GUARD_SKILL_AUTHORING = 'skillAuthoring'
@@ -161,25 +163,11 @@ function isInside(parent: string, child: string): boolean {
161
163
  return relative === '' || (!relative.startsWith('..') && !path.isAbsolute(relative))
162
164
  }
163
165
 
166
+ // RECOVER_MISSING only: this policy decides whether a write is ALLOWED, so an
167
+ // ancestor that cannot be resolved must never widen the permitted surface.
164
168
  async function resolveRealIntendedPath(absolutePath: string): Promise<string> {
165
- const pending: string[] = []
166
- let current = absolutePath
167
-
168
- while (true) {
169
- try {
170
- const realCurrent = await realpath(current)
171
- return path.join(realCurrent, ...pending.reverse())
172
- } catch (err) {
173
- if (!isNotFoundError(err)) throw err
174
- }
175
-
176
- const parent = path.dirname(current)
177
- if (parent === current) throw new Error(`could not resolve existing parent for ${absolutePath}`)
178
- pending.push(path.basename(current))
179
- current = parent
180
- }
181
- }
182
-
183
- function isNotFoundError(err: unknown): boolean {
184
- return err instanceof Error && 'code' in err && err.code === 'ENOENT'
169
+ return await realIntendedPath(absolutePath, realpath, {
170
+ recoverable: RECOVER_MISSING,
171
+ onExhausted: 'throw',
172
+ })
185
173
  }
@@ -111,6 +111,8 @@ The subagent uses these signals to:
111
111
 
112
112
  There is no `## Historical observations` bucket. Demoted topics live as their own shards; injection-time filtering (the index/direct split) handles the prompt-budget pressure.
113
113
 
114
+ **The agent's own response style never becomes a belief (rule 10).** Streams capture the agent's own turns, so fragments sometimes describe how it replied rather than what is true — how it apologized, how it took a correction, how terse its status updates were. Consolidating those teaches the next session to reproduce a shape instead of doing the work; a shard describing a convincing apology is the worst case, because it makes accountability a template the agent can perform without having verified anything. The user-side fact is kept ("the user wants status updates under 20 words"), the agent-side self-description dropped. Voice and register belong in `SOUL.md`, which the subagent never writes.
115
+
114
116
  ## Muscle memory (three forms)
115
117
 
116
118
  While reading streams, the dreaming subagent watches for **repeated multi-step procedures** the user has guided the main agent through, and codifies them. There are three forms, picked smallest-that-fits (top to bottom, stop at the first match):
@@ -997,6 +997,8 @@ references:
997
997
 
998
998
  The reference files under \`memory/references/\` are verbatim artifacts. You MUST NOT read, rewrite, or distill their content. You may only cite them by slug. On eviction (Phase 4), citations are pruned — but that is a separate pass, not your concern here.
999
999
 
1000
+ **10. Never turn the main agent's own response style into a belief.** Streams often contain fragments describing how the main agent phrased, structured, or paced its own reply — how it apologized, how it took a correction, how long its status updates ran. A durable fact about the USER is memory; a description of how the agent's own reply *sounded* is not. Consolidating one teaches the next session to reproduce a shape instead of doing the work, and a shard describing a convincing apology is the worst case: it turns accountability into a template the agent can perform without having verified anything, which is exactly the behavior that produces false "I fixed it" claims. Keep the user-side fact ("the user wants status updates under 20 words", "the user corrected the summary language to Korean") and drop the agent-side self-description ("the agent replied with an apology, a root cause, and a fix in under 70 words"). When a fragment carries both, keep only the user-side half. Voice and register live in \`SOUL.md\`, which the user owns and you never write.
1001
+
1000
1002
  # What a topic shard looks like
1001
1003
 
1002
1004
  \`\`\`
@@ -16,6 +16,7 @@ import path from 'node:path'
16
16
  import { fileURLToPath } from 'node:url'
17
17
 
18
18
  import { TOOLS_WITHOUT_LOCAL_FILE_OPERANDS } from '@/agent/tools-without-local-file-operands'
19
+ import { RECOVER_MISSING_OR_UNSEARCHABLE, realIntendedPathSync } from '@/path-safety/real-intended-path'
19
20
  import type { ToolFileOperands } from '@/plugin'
20
21
  import {
21
22
  CANONICAL_AGENT_SECRET_DIRS,
@@ -959,30 +960,16 @@ function hasSameFileIdentity(candidate: string, deniedFile: string): boolean {
959
960
  }
960
961
  }
961
962
 
962
- // Resolves symlinks on the longest existing prefix of an absolute path, then
963
- // re-appends the non-existent tail. A bare realpathSync throws on a path that
964
- // does not exist yet (a write target, or a read of a not-yet-created file), so
965
- // we walk up to the nearest existing ancestor, realpath THAT (collapsing any
966
- // symlinked component including a planted symlink), and rejoin the remainder.
967
- // This catches `public/leak/x` where `public/leak` is a symlink into a hidden
968
- // dir even though `public/leak/x` itself does not exist. Sync (realpathSync)
969
- // keeps the guard synchronous; the cost is one syscall per existing component,
970
- // negligible at the tool-call boundary. Sync mirror of resolveRealIntendedPath
971
- // in the guard plugin's non-workspace-write policy.
963
+ // Sync keeps the guard synchronous; the cost is one syscall per existing
964
+ // component, negligible at the tool-call boundary. EACCES is recoverable here
965
+ // (but NOT in the guard plugin's write policies): this is denylist matching, so
966
+ // a path under an unsearchable ancestor must still be matched rather than
967
+ // aborting the whole guard. See @/path-safety/real-intended-path.
972
968
  function realpathRealIntendedPath(absolutePath: string, realpath: (candidate: string) => string): string {
973
- const pending: string[] = []
974
- let current = absolutePath
975
- while (true) {
976
- try {
977
- return path.join(realpath(current), ...pending.reverse())
978
- } catch (err) {
979
- if (!isNotFoundError(err)) throw err
980
- }
981
- const parent = path.dirname(current)
982
- if (parent === current) return absolutePath
983
- pending.push(path.basename(current))
984
- current = parent
985
- }
969
+ return realIntendedPathSync(absolutePath, realpath, {
970
+ recoverable: RECOVER_MISSING_OR_UNSEARCHABLE,
971
+ onExhausted: 'return-input',
972
+ })
986
973
  }
987
974
 
988
975
  function isNotFoundError(err: unknown): boolean {
@@ -781,10 +781,14 @@ export const KNOWN_PROVIDERS = {
781
781
  // the console, the OpenAI-SDK example, and the agent docs all use bare `/v1`.
782
782
  //
783
783
  // Model lineup spans two families on the same Console API + key:
784
- // * Closed chat models from the official agent API reference
785
- // (console.upstage.ai/api/docs/for-agents) as of 2026-03-23:
786
- // solar-pro3 (102B MoE / 12B active, 128K, flagship), solar-pro2
787
- // (31B, 65K), solar-mini (10.7B, 32K, cheap/fast).
784
+ // * Closed chat models. solar-pro4 (512K context / 128K output, released
785
+ // 2026-08-06, current flagship) is per the live model page
786
+ // console.upstage.ai/docs/models/solar-pro4; the rest are from the agent
787
+ // API reference (console.upstage.ai/api/docs/for-agents) as of
788
+ // 2026-03-23: solar-pro3 (102B MoE / 12B active, 128K), solar-pro2
789
+ // (31B, 65K), solar-mini (10.7B, 32K, cheap/fast). Note that the
790
+ // for-agents dump is stale (self-dated 2026-03-07) and omits pro4 — its
791
+ // absence there is not evidence the model is unavailable.
788
792
  // * The open-weight Solar Open family: solar-open2 (Solar Open 2), a 102B
789
793
  // MoE / 12B active model with a 128K context. It launched on the Console
790
794
  // API for the Solar Agent Partner program (Stage 1, from 2026-07-17) —
@@ -799,6 +803,7 @@ export const KNOWN_PROVIDERS = {
799
803
  // versioned release.
800
804
  //
801
805
  // Costs are USD per 1M tokens from upstage.ai/pricing/api (VAT-exclusive).
806
+ // solar-pro4 is $0.30 in / $1.20 out with a $0.06 "Input(Cached)" rate.
802
807
  // solar-pro3/pro2 publish an "Input(Cached)" cache-read rate ($0.015); no
803
808
  // cache-write surcharge is published, so cacheWrite is 0. solar-mini
804
809
  // publishes a single flat $0.15 rate with no cache line, so cacheRead and
@@ -819,18 +824,37 @@ export const KNOWN_PROVIDERS = {
819
824
  // definitions are both undocumented, so supportsUsageInStreaming and
820
825
  // supportsStrictMode are false (both conservative — pi-ai defaults them to
821
826
  // true, and Upstage only documents `strict` inside response_format.json_schema,
822
- // never on tool defs). `reasoning_effort` IS documented for solar-pro3/pro2
823
- // (and the solar-open2 chat template), so supportsReasoningEffort stays true
824
- // there; solar-mini ignores it, so it is false and reasoning is off.
827
+ // never on tool defs). `reasoning_effort` IS documented for solar-pro4,
828
+ // solar-open2, solar-pro3 and solar-pro2, so supportsReasoningEffort stays
829
+ // true there; solar-mini rejects it, so it is false and reasoning is off.
825
830
  //
826
- // Upstage documents reasoning_effort values minimal/low/medium/high only. pi
827
- // adds an `xhigh` level that typeclaw's attention escalation can select
828
- // (src/agent/attention-escalation.ts), and pi-ai passes the pi level straight
829
- // through as reasoning_effort when no map is set — which would send the
830
- // unsupported `xhigh`. `thinkingLevelMap` clamps xhigh -> high (and maps off ->
831
- // null so nothing is sent) on the reasoning models so every emitted
832
- // reasoning_effort is a value Upstage accepts. solar-mini needs no map (it
833
- // never sends reasoning_effort).
831
+ // Reasoning splits the lineup into two groups with OPPOSITE defaults, per
832
+ // Upstage's reasoning table (console.upstage.ai/docs/capabilities/generate/
833
+ // reasoning). pi adds an `xhigh` level that typeclaw's attention escalation
834
+ // can select (src/agent/attention-escalation.ts), and pi-ai passes the pi
835
+ // level straight through as reasoning_effort when no map is set, so each
836
+ // group needs a different `thinkingLevelMap`:
837
+ //
838
+ // * solar-pro4 and solar-open2 — omitted reasoning_effort means reasoning
839
+ // is ON; `none`/`minimal` turn it OFF; low/medium/high/xhigh/max turn it
840
+ // on. So `off` maps to the string 'none', NOT null: pi-ai emits a string
841
+ // off value verbatim and omits the field only when it is null, and
842
+ // omitting it here would silently leave reasoning enabled (and billed) on
843
+ // every non-reasoning turn. `xhigh` is documented, so it passes through
844
+ // unclamped. Upstage's `max` sits above xhigh, but pi has no level above
845
+ // xhigh to reach it, so `max` is intentionally unreachable.
846
+ // * solar-pro3 and solar-pro2 — omitted means reasoning is OFF, `minimal`
847
+ // and `low` ALSO turn it off, and only `medium`/`high` turn it on. So
848
+ // `off` maps to null (nothing sent) and xhigh clamps to high.
849
+ //
850
+ // Note the trap in both rows: Upstage's `minimal` is an OFF value, but pi's
851
+ // `minimal` is an enabled level meaning "reason a little". Forwarding it
852
+ // verbatim would silently disable reasoning on a request that asked for it.
853
+ // Each group therefore floors pi's enabled levels at its own lowest
854
+ // reasoning-ON value — `low` for pro4/open2, `medium` for pro3/pro2 (which is
855
+ // why pi's `low` also maps to `medium` there). Every level pi can select thus
856
+ // emits a value Upstage treats as reasoning-on. solar-mini needs no map: it
857
+ // does not accept reasoning_effort at all (any value returns HTTP 400).
834
858
  upstage: {
835
859
  id: 'upstage',
836
860
  name: 'Upstage (Solar)',
@@ -839,6 +863,35 @@ export const KNOWN_PROVIDERS = {
839
863
  apiKeyEnv: 'UPSTAGE_API_KEY',
840
864
  oauthProviderId: null,
841
865
  models: {
866
+ 'solar-pro4': {
867
+ id: 'solar-pro4',
868
+ name: 'Solar Pro 4',
869
+ api: 'openai-completions',
870
+ provider: 'upstage',
871
+ baseUrl: 'https://api.upstage.ai/v1',
872
+ reasoning: true,
873
+ // pro4 and open2 reason by DEFAULT — see the reasoning-group note above.
874
+ thinkingLevelMap: {
875
+ off: 'none',
876
+ minimal: 'low',
877
+ low: 'low',
878
+ medium: 'medium',
879
+ high: 'high',
880
+ xhigh: 'xhigh',
881
+ },
882
+ input: ['text'],
883
+ cost: { input: 0.3, output: 1.2, cacheRead: 0.06, cacheWrite: 0 },
884
+ contextWindow: 524288,
885
+ maxTokens: 131072,
886
+ compat: {
887
+ supportsStore: false,
888
+ supportsDeveloperRole: false,
889
+ supportsReasoningEffort: true,
890
+ supportsUsageInStreaming: false,
891
+ supportsStrictMode: false,
892
+ maxTokensField: 'max_tokens',
893
+ },
894
+ },
842
895
  'solar-open2': {
843
896
  id: 'solar-open2',
844
897
  name: 'Solar Open 2',
@@ -846,7 +899,14 @@ export const KNOWN_PROVIDERS = {
846
899
  provider: 'upstage',
847
900
  baseUrl: 'https://api.upstage.ai/v1',
848
901
  reasoning: true,
849
- thinkingLevelMap: { off: null, minimal: 'minimal', low: 'low', medium: 'medium', high: 'high', xhigh: 'high' },
902
+ thinkingLevelMap: {
903
+ off: 'none',
904
+ minimal: 'low',
905
+ low: 'low',
906
+ medium: 'medium',
907
+ high: 'high',
908
+ xhigh: 'xhigh',
909
+ },
850
910
  input: ['text'],
851
911
  cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
852
912
  contextWindow: 128000,
@@ -867,7 +927,14 @@ export const KNOWN_PROVIDERS = {
867
927
  provider: 'upstage',
868
928
  baseUrl: 'https://api.upstage.ai/v1',
869
929
  reasoning: true,
870
- thinkingLevelMap: { off: null, minimal: 'minimal', low: 'low', medium: 'medium', high: 'high', xhigh: 'high' },
930
+ thinkingLevelMap: {
931
+ off: null,
932
+ minimal: 'medium',
933
+ low: 'medium',
934
+ medium: 'medium',
935
+ high: 'high',
936
+ xhigh: 'high',
937
+ },
871
938
  input: ['text'],
872
939
  cost: { input: 0.15, output: 0.6, cacheRead: 0.015, cacheWrite: 0 },
873
940
  contextWindow: 128000,
@@ -888,7 +955,14 @@ export const KNOWN_PROVIDERS = {
888
955
  provider: 'upstage',
889
956
  baseUrl: 'https://api.upstage.ai/v1',
890
957
  reasoning: true,
891
- thinkingLevelMap: { off: null, minimal: 'minimal', low: 'low', medium: 'medium', high: 'high', xhigh: 'high' },
958
+ thinkingLevelMap: {
959
+ off: null,
960
+ minimal: 'medium',
961
+ low: 'medium',
962
+ medium: 'medium',
963
+ high: 'high',
964
+ xhigh: 'high',
965
+ },
892
966
  input: ['text'],
893
967
  cost: { input: 0.15, output: 0.6, cacheRead: 0.015, cacheWrite: 0 },
894
968
  contextWindow: 65000,
@@ -724,6 +724,47 @@ export async function planStart({
724
724
  // misattribute to bot detection. 2g matches the Playwright/Puppeteer
725
725
  // canonical recommendation and is a memory cap, not an allocation (only
726
726
  // used pages count against the host).
727
+ // `--init` puts Docker's bundled `docker-init` (tini) at PID 1 and demotes
728
+ // the entrypoint shim to PID 2. It is load-bearing, not hygiene: without it
729
+ // the container leaks a kernel user namespace on every aborted or timed-out
730
+ // model bash call, until every `bwrap` in the container — and in every other
731
+ // typeclaw container on the same host — dies with
732
+ // `unshare user ns: No space left on device`.
733
+ //
734
+ // The chain: each model bash call runs the sandbox under `bash -c`, and the
735
+ // sandbox mints a fresh user namespace per call on BOTH strategies — under
736
+ // the default `proc-bind`/`tmpfs` it is `bwrap --unshare-all`, while
737
+ // `sandbox.realProc` splits the pid namespace out into `unshare --pid --fork
738
+ // --mount --mount-proc` and has bwrap take the user namespace via an
739
+ // explicit `--unshare-user` (see buildArgv in src/sandbox/build.ts). On
740
+ // timeout or abort the upstream bash tool SIGKILLs the process GROUP, then
741
+ // reaps its own direct `bash` child by waiting on the handle it holds. The
742
+ // sandbox descendant it holds no handle for is re-parented to PID 1 instead.
743
+ // Since the shim `exec`s into bun, PID 1 was the Bun runtime — and a JS
744
+ // runtime never `wait()`s on orphans it did not spawn, so that descendant
745
+ // stays a zombie for the life of the container. A zombie drops its
746
+ // `nsproxy` at `do_exit()` (so
747
+ // mount/net namespaces are freed early) but keeps its `struct cred` until
748
+ // it is reaped, and `cred->user_ns` pins the user namespace; its surviving
749
+ // `struct pid` pins the pid namespace, which pins that same user namespace
750
+ // again. The `UCOUNT_USER_NAMESPACES` charge is only returned by
751
+ // `free_user_ns()`, so it is never returned at all.
752
+ //
753
+ // That charge is accounted against the ANCESTOR (host) user namespace, so
754
+ // the exhausted resource is the host kernel's `user.max_user_namespaces`,
755
+ // shared across every container on the box. Raising the host sysctl only
756
+ // buys time; reaping is the fix. tini reaps re-parented orphans, which
757
+ // releases the creds and returns the ucount.
758
+ //
759
+ // Chosen over baking `tini` into the image because the per-agent Dockerfile
760
+ // pins a PUBLISHED `typeclaw-base:X.Y.Z` (see refreshDockerfile): a new
761
+ // baseline apt package would not exist in already-released base tags. This
762
+ // flag needs no image change and takes effect on the next container create.
763
+ // `--init` is create-time state, so a container launched before this flag
764
+ // existed keeps leaking: `start()` deliberately no-ops on a live container.
765
+ // Operators must `typeclaw restart` (removes and recreates), not
766
+ // `docker restart` (reuses the old HostConfig).
767
+ //
727
768
  // `seccomp=unconfined` lets `bwrap(1)` (installed in baseline; see
728
769
  // BASELINE_APT_PACKAGES in src/init/dockerfile.ts) create user/pid/mount
729
770
  // namespaces from inside the container. Docker's default seccomp profile
@@ -742,6 +783,7 @@ export async function planStart({
742
783
  const runArgs = [
743
784
  'run',
744
785
  '-d',
786
+ '--init',
745
787
  '--name',
746
788
  containerName,
747
789
  '--shm-size=2g',
@@ -0,0 +1,111 @@
1
+ import path from 'node:path'
2
+
3
+ // Canonicalizes the longest RESOLVABLE prefix of an absolute path, then re-appends
4
+ // the remainder lexically. A bare realpath throws on a path that does not exist yet
5
+ // (a write target, or a read of a not-yet-created file), so we walk up to the nearest
6
+ // resolvable ancestor, realpath THAT — collapsing every symlinked component, including
7
+ // a planted one — and rejoin the tail. This is what catches `public/leak/x` where
8
+ // `public/leak` is a symlink into a hidden dir even though `public/leak/x` itself does
9
+ // not exist.
10
+ //
11
+ // Which errnos may be walked past is the security-sensitive part, so it is the
12
+ // CALLER's decision, not a default. See the two exported sets below.
13
+
14
+ // The historical, strictest set: only a missing component is walked past.
15
+ // Correct for allowlist/authorization policies, where an unresolvable component must
16
+ // never widen what is permitted.
17
+ export const RECOVER_MISSING: ReadonlySet<string> = new Set(['ENOENT'])
18
+
19
+ // Adds EACCES for denylist matching. A realpath of a path under a directory the
20
+ // runtime cannot search fails with EACCES, not ENOENT — e.g. resolving
21
+ // `/root/.config/...` while running as a non-root uid when `/root` is mode 700.
22
+ // Treating that as fatal blocks reads of paths that are neither secret nor denied.
23
+ // Walking past it is sound for a DENYLIST because the tail is still matched against
24
+ // the denied surface after rejoining: a masked directory still matches lexically and
25
+ // still blocks. It is NOT sound for an allowlist — see RECOVER_MISSING.
26
+ export const RECOVER_MISSING_OR_UNSEARCHABLE: ReadonlySet<string> = new Set(['ENOENT', 'EACCES'])
27
+
28
+ export type RealIntendedPathOptions = {
29
+ // Defaults to RECOVER_MISSING: callers must opt in to the broader set.
30
+ readonly recoverable?: ReadonlySet<string>
31
+ // What to do when even the filesystem root is unresolvable. Callers that treat an
32
+ // unresolvable path as a hard failure use 'throw'; callers that fall back to the
33
+ // lexical input use 'return-input'.
34
+ readonly onExhausted?: 'throw' | 'return-input'
35
+ }
36
+
37
+ export function realIntendedPathSync(
38
+ absolutePath: string,
39
+ realpath: (candidate: string) => string,
40
+ options: RealIntendedPathOptions = {},
41
+ ): string {
42
+ const walk = createAncestorWalk(absolutePath, options)
43
+ while (true) {
44
+ let resolved: string
45
+ try {
46
+ resolved = realpath(walk.target())
47
+ } catch (error) {
48
+ const exhausted = walk.retreat(error)
49
+ if (exhausted !== undefined) return exhausted
50
+ continue
51
+ }
52
+ return walk.rejoin(resolved)
53
+ }
54
+ }
55
+
56
+ export async function realIntendedPath(
57
+ absolutePath: string,
58
+ realpath: (candidate: string) => Promise<string>,
59
+ options: RealIntendedPathOptions = {},
60
+ ): Promise<string> {
61
+ const walk = createAncestorWalk(absolutePath, options)
62
+ while (true) {
63
+ let resolved: string
64
+ try {
65
+ resolved = await realpath(walk.target())
66
+ } catch (error) {
67
+ const exhausted = walk.retreat(error)
68
+ if (exhausted !== undefined) return exhausted
69
+ continue
70
+ }
71
+ return walk.rejoin(resolved)
72
+ }
73
+ }
74
+
75
+ type AncestorWalk = {
76
+ target(): string
77
+ rejoin(resolvedTarget: string): string
78
+ // Returns the final result when the walk cannot retreat further, or undefined to
79
+ // keep walking. Rethrows anything the caller did not declare recoverable.
80
+ retreat(error: unknown): string | undefined
81
+ }
82
+
83
+ function createAncestorWalk(absolutePath: string, options: RealIntendedPathOptions): AncestorWalk {
84
+ const recoverable = options.recoverable ?? RECOVER_MISSING
85
+ const onExhausted = options.onExhausted ?? 'return-input'
86
+ const pending: string[] = []
87
+ let current = absolutePath
88
+
89
+ return {
90
+ target: () => current,
91
+ // Copy before reversing: the caller may hold this array across iterations.
92
+ rejoin: (resolvedTarget) => path.join(resolvedTarget, ...[...pending].reverse()),
93
+ retreat(error) {
94
+ if (!isRecoverableErrno(error, recoverable)) throw error
95
+ const parent = path.dirname(current)
96
+ if (parent === current) {
97
+ if (onExhausted === 'throw') throw new Error(`could not resolve existing parent for ${absolutePath}`)
98
+ return absolutePath
99
+ }
100
+ pending.push(path.basename(current))
101
+ current = parent
102
+ return undefined
103
+ },
104
+ }
105
+ }
106
+
107
+ function isRecoverableErrno(error: unknown, recoverable: ReadonlySet<string>): boolean {
108
+ if (!(error instanceof Error) || !('code' in error)) return false
109
+ const code = (error as { code: unknown }).code
110
+ return typeof code === 'string' && recoverable.has(code)
111
+ }
@@ -57,6 +57,7 @@
57
57
  "minimax/MiniMax-M2",
58
58
  "deepseek/deepseek-v4-flash",
59
59
  "deepseek/deepseek-v4-pro",
60
+ "upstage/solar-pro4",
60
61
  "upstage/solar-open2",
61
62
  "upstage/solar-pro3",
62
63
  "upstage/solar-pro2",
@@ -114,6 +115,7 @@
114
115
  "minimax/MiniMax-M2",
115
116
  "deepseek/deepseek-v4-flash",
116
117
  "deepseek/deepseek-v4-pro",
118
+ "upstage/solar-pro4",
117
119
  "upstage/solar-open2",
118
120
  "upstage/solar-pro3",
119
121
  "upstage/solar-pro2",
@@ -172,6 +174,7 @@
172
174
  "minimax/MiniMax-M2",
173
175
  "deepseek/deepseek-v4-flash",
174
176
  "deepseek/deepseek-v4-pro",
177
+ "upstage/solar-pro4",
175
178
  "upstage/solar-open2",
176
179
  "upstage/solar-pro3",
177
180
  "upstage/solar-pro2",
@@ -228,6 +231,7 @@
228
231
  "minimax/MiniMax-M2",
229
232
  "deepseek/deepseek-v4-flash",
230
233
  "deepseek/deepseek-v4-pro",
234
+ "upstage/solar-pro4",
231
235
  "upstage/solar-open2",
232
236
  "upstage/solar-pro3",
233
237
  "upstage/solar-pro2",
@@ -285,6 +289,7 @@
285
289
  "minimax/MiniMax-M2",
286
290
  "deepseek/deepseek-v4-flash",
287
291
  "deepseek/deepseek-v4-pro",
292
+ "upstage/solar-pro4",
288
293
  "upstage/solar-open2",
289
294
  "upstage/solar-pro3",
290
295
  "upstage/solar-pro2",