@arcforge/kernel 2.0.177 → 2.0.179

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": "@arcforge/kernel",
3
- "version": "2.0.177",
3
+ "version": "2.0.179",
4
4
  "description": "The Axon kernel — ring 0. Owns resources and execution, enforces policy, and is the only constructor of the unprivileged capsule.",
5
5
  "type": "module",
6
6
  "private": false,
@@ -15,13 +15,13 @@
15
15
  "deploy": "echo \"This package is published ONLY by apps/tui/scripts/release.ts, which pins workspace:* deps to concrete versions first. Publishing it directly ships an unresolvable dependency.\" && exit 1"
16
16
  },
17
17
  "dependencies": {
18
- "@arcforge/air": "2.0.177",
19
- "@arcforge/engines": "2.0.177",
20
- "@arcforge/err": "2.0.177",
21
- "@arcforge/session": "2.0.177",
22
- "@arcforge/types": "2.0.177",
23
- "@arcforge/cloud": "2.0.177",
24
- "@arcforge/capsule": "2.0.177"
18
+ "@arcforge/air": "2.0.179",
19
+ "@arcforge/engines": "2.0.179",
20
+ "@arcforge/err": "2.0.179",
21
+ "@arcforge/session": "2.0.179",
22
+ "@arcforge/types": "2.0.179",
23
+ "@arcforge/cloud": "2.0.179",
24
+ "@arcforge/capsule": "2.0.179"
25
25
  },
26
26
  "devDependencies": {
27
27
  "@types/bun": "latest",
package/src/engine.ts CHANGED
@@ -900,32 +900,76 @@ export function Engine(opts: EngineOpts) {
900
900
  break
901
901
 
902
902
  case "text:delta":
903
- // A chunk with no VISIBLE content is not something the
904
- // agent said.
905
- //
906
- // Guarded on `.trim()`, not on truthiness: a model that
907
- // opens `<text>` and closes it after a newline emits a
908
- // delta of `"\n"`, which is truthy, and that reached
909
- // the UI as a bullet with nothing beside it. `text:done`
910
- // already dropped the empty tail; this is the same rule
911
- // one step earlier, and whitespace is the case that
912
- // actually happens in a run.
913
- if (pending?.trim()) {
903
+ /**
904
+ * A whitespace-only delta is CARRIED, never dropped.
905
+ *
906
+ * The guard here was `pending?.trim()`, which discarded
907
+ * the pending chunk outright when it held nothing but
908
+ * whitespace — and the next line overwrote `pending`,
909
+ * so those characters were gone. A provider that split
910
+ * a stream as `"…projectRoot:string"`, `"\n"`,
911
+ * `" cron:string"` therefore committed
912
+ * `projectRoot:string cron:string`: the newline
913
+ * deleted, the indentation of everything after it
914
+ * wrong, and a fenced block progressively less
915
+ * readable the longer the reply ran.
916
+ *
917
+ * That is not cosmetic. Markdown is whitespace-
918
+ * significant — a lost newline merges a list item into
919
+ * the prose above it and collapses a code fence's
920
+ * indentation — and the damage compounds, because every
921
+ * later line inherits the drift. It renders as "the
922
+ * model produced malformed output" when the engine's
923
+ * own recorded text is perfectly formed.
924
+ *
925
+ * What the old guard was RIGHT about: an
926
+ * `engine:text` carrying only whitespace paints a
927
+ * bullet with nothing beside it. So the test moves from
928
+ * "is this chunk worth keeping" to "is this chunk worth
929
+ * EMITTING YET" — whitespace accumulates into the next
930
+ * chunk instead of being thrown away, and reaches the
931
+ * UI attached to the text it belongs to.
932
+ */
933
+ if (pending !== null && pending.trim()) {
914
934
  group ??= crypto.randomUUID()
915
935
  spoke = true
916
936
  events.push({ type: "engine:text", content: pending, lang, chunk: { of: group } })
937
+ pending = block.content
938
+ break
917
939
  }
918
- pending = block.content
940
+
941
+ // Nothing emittable yet — keep what we have and let the
942
+ // next delta carry it.
943
+ pending = (pending ?? "") + block.content
919
944
  break
920
945
 
921
946
  case "text:done": {
922
947
  if (block.incomplete) { truncated = "text"; break }
923
948
  const last = pending ?? block.content
924
949
  pending = null
925
- // Same rule as the delta path: a block whose whole
926
- // content is whitespace is a message the agent did not
927
- // write, and forwarding it produces an empty bubble.
928
- if (!last.trim()) break
950
+
951
+ /**
952
+ * An empty block is dropped; an OPEN GROUP is always
953
+ * closed.
954
+ *
955
+ * These are two different questions and the old
956
+ * `if (!last.trim()) break` answered both with one
957
+ * test. A reply whose tail was whitespace — which is
958
+ * most of them, since models end on a newline — lost
959
+ * those characters AND never emitted `final: true`,
960
+ * so the group stayed open in the consumer's fold
961
+ * forever (`openGroups` in the timeline's incremental
962
+ * fold keys on exactly that flag).
963
+ *
964
+ * So: if a group is open, the closing event goes out
965
+ * carrying whatever the tail actually was, whitespace
966
+ * included. Only a block that was NEVER opened and has
967
+ * nothing visible is dropped — that is the empty
968
+ * bubble the original guard existed to prevent, and it
969
+ * is the only case where dropping loses nothing.
970
+ */
971
+ if (!group && !last.trim()) break
972
+
929
973
  spoke = true
930
974
  texts++
931
975
  events.push(group
package/src/mediation.ts CHANGED
@@ -205,11 +205,16 @@ export function Mediation(opts: MediationOpts) {
205
205
  * Escalation still routes through the same decider, so a `"escalate"`
206
206
  * verdict on an argument pattern prompts exactly like any other.
207
207
  */
208
- async function shell(argv: string[], owner: string): Promise<ShellDecision> {
208
+ async function shell(argv: string[], owner: string, command?: string): Promise<ShellDecision> {
209
209
  // Axon's posture: an agent whose blueprint declares no shell policy is
210
210
  // a personal tool with the user's own privileges. The capsule's is the
211
211
  // opposite — see decideShell's `fallback`.
212
- const decision = decideShell(opts.policy().shell, argv, "allow")
212
+ //
213
+ // `command` is the unsplit line, and only a caller that HAS one passes
214
+ // it: a chain is invisible once split (a newline becomes whitespace, a
215
+ // quote disappears), and deciding without it means deciding about the
216
+ // first program while `/bin/sh -c` runs the rest.
217
+ const decision = decideShell(opts.policy().shell, argv, "allow", command)
213
218
  if (decision.verdict === "allow") return decision
214
219
 
215
220
  const fn = `shell.run:${decision.program}`
@@ -229,9 +234,14 @@ export function Mediation(opts: MediationOpts) {
229
234
  return {
230
235
  check,
231
236
  shell,
232
- /** `shell()` for a command that arrived as a string rather than argv. */
237
+ /**
238
+ * `shell()` for a command that arrived as a string rather than argv.
239
+ *
240
+ * The string is forwarded ALONGSIDE its argv, because it is the only
241
+ * form in which a chain is still visible — see decideShell.
242
+ */
233
243
  shellCommand(command: string, owner: string): Promise<ShellDecision> {
234
- return shell(splitCommand(command), owner)
244
+ return shell(splitCommand(command), owner, command)
235
245
  },
236
246
  /**
237
247
  * The span stream every surface reads.