@arcforge/kernel 2.0.124 → 2.0.126

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.124",
3
+ "version": "2.0.126",
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.124",
19
- "@arcforge/engines": "2.0.124",
20
- "@arcforge/err": "2.0.124",
21
- "@arcforge/session": "2.0.124",
22
- "@arcforge/types": "2.0.124",
23
- "@arclabs/cloud": "2.0.124",
24
- "@axon/capsule": "2.0.124"
18
+ "@arcforge/air": "2.0.126",
19
+ "@arcforge/engines": "2.0.126",
20
+ "@arcforge/err": "2.0.126",
21
+ "@arcforge/session": "2.0.126",
22
+ "@arcforge/types": "2.0.126",
23
+ "@arclabs/cloud": "2.0.126",
24
+ "@axon/capsule": "2.0.126"
25
25
  },
26
26
  "devDependencies": {
27
27
  "@types/bun": "latest",
package/src/engine.ts CHANGED
@@ -48,6 +48,35 @@ function describeViolations(problems: readonly OutputDiagnostic[]): string {
48
48
  ].join("\n")
49
49
  }
50
50
 
51
+ /**
52
+ * What the model is told when its reply parsed to nothing at all.
53
+ *
54
+ * Written as an instruction rather than a report, and it names the exact tags,
55
+ * because this is fed straight back as the next attempt's context and the model
56
+ * has to act on it without any other explanation. The most common cause is
57
+ * prose emitted bare — the reply is right there, just outside any block, and
58
+ * the parser has nowhere to put it.
59
+ */
60
+ function describeEmptyResponse(protocol: string | undefined, excerpt: string): string {
61
+ return [
62
+ "Your reply contained no <template> or <script> block, so none of it could be used.",
63
+ "Every reply must wrap its content:",
64
+ " <template>…what you want to say…</template>",
65
+ " <script>…code you want to run…</script>",
66
+ "Text outside a block is discarded.",
67
+ ...(protocol ? [`Protocol: ${protocol}.`] : []),
68
+ excerpt ? `You replied: ${excerpt}` : "",
69
+ "Send the same reply again, wrapped correctly.",
70
+ ].filter(Boolean).join("\n")
71
+ }
72
+
73
+ /** The head of a raw reply, for quoting back to the model without flooding context. */
74
+ function excerptOf(text: string | undefined): string {
75
+ if (!text) return ""
76
+ const flat = text.replace(/\s+/g, " ").trim()
77
+ return flat.length > 200 ? `${flat.slice(0, 200)}…` : flat
78
+ }
79
+
51
80
  /**
52
81
  * Engine — the inference layer of the runtime. Drivers are raw token pipes;
53
82
  * this manager owns AIR parsing, bounded pre-output retries, and the durable
@@ -309,11 +338,19 @@ export function Engine(opts: EngineOpts) {
309
338
  */
310
339
  async function* stream(call: AxonEngineCall, context: EngineContext): AsyncGenerator<AxonEngineEvent> {
311
340
  const output = call.output
312
- // Attempts AFTER the first, so `retries: 0` means one shot. Only a
313
- // declared output contract can fail this way; without one there is
314
- // nothing for a response to violate.
315
- const budget = output ? (call.retries ?? DEFAULT_OUTPUT_RETRIES) : 0
341
+ // Attempts AFTER the first, so `retries: 0` means one shot.
342
+ //
343
+ // Every call gets a budget, not only one declaring an output shape. A
344
+ // declared contract is one way a response can be unusable; producing NO
345
+ // BLOCK AT ALL is another, and it does not depend on the caller having
346
+ // asked for a shape — the protocol itself requires the reply to be
347
+ // wrapped. Gating retries on `output` meant a model that forgot
348
+ // `<template>` got exactly one attempt, its prose was discarded by the
349
+ // parser, and the run completed clean with an empty screen.
350
+ const budget = call.retries ?? DEFAULT_OUTPUT_RETRIES
316
351
  let lastFault: string | undefined
352
+ /** Which failure the LAST attempt hit — decides the terminal error code. */
353
+ let lastFailure: "empty" | "shape" | undefined
317
354
 
318
355
  yield { type: "engine:start" }
319
356
 
@@ -393,6 +430,25 @@ export function Engine(opts: EngineOpts) {
393
430
  step = await raw.next()
394
431
  }
395
432
 
433
+ // A reply that parsed to no block is unusable, whatever it said.
434
+ //
435
+ // Checked separately from `violations` because it is a different
436
+ // kind of failure: violations mean "the block was wrong", this
437
+ // means "there was no block". The model almost always DID answer —
438
+ // as prose, outside any tag — so the parser discarded a complete
439
+ // reply and the user saw a blank screen. Retrying with the excerpt
440
+ // quoted back steers it in one attempt.
441
+ //
442
+ // `yielded` is deliberately not part of this test. A reply that
443
+ // spoke or acted but forgot `<done/>` still produced something the
444
+ // cognet can use, and the loop's own stop condition owns that.
445
+ if (violations.length === 0 && !spoke && !acted) {
446
+ lastFault = describeEmptyResponse(call.protocol, excerptOf(step.value?.text))
447
+ lastFailure = "empty"
448
+ await opts.fault({ code: "OUTPUT_EMPTY", message: lastFault })
449
+ continue
450
+ }
451
+
396
452
  if (violations.length === 0) {
397
453
  for (const event of events) yield event
398
454
  yield { type: "engine:done", response: step.value, spoke, acted, yielded }
@@ -404,6 +460,7 @@ export function Engine(opts: EngineOpts) {
404
460
  // one. The diagnostic is committed so the next attempt's context
405
461
  // carries it, and the model rewrites against its own error.
406
462
  lastFault = describeViolations(violations)
463
+ lastFailure = "shape"
407
464
  await opts.fault({ code: "OUTPUT_TYPE_ERROR", message: lastFault })
408
465
  }
409
466
 
@@ -411,12 +468,25 @@ export function Engine(opts: EngineOpts) {
411
468
  // asked for a shape gets that shape or an error explaining why it
412
469
  // could not be produced, never an unchecked value it would treat as
413
470
  // validated.
471
+ //
472
+ // The two exhaustion modes get distinct codes because they mean
473
+ // different things to whoever reads the session. OUTPUT_UNSATISFIED is
474
+ // "your declared shape is more than this model can produce" — a
475
+ // contract problem. OUTPUT_EMPTY is "this model does not follow the
476
+ // block protocol" — usually a model choice problem, and the fix is to
477
+ // change models rather than to loosen a type.
414
478
  yield {
415
479
  type: "engine:failure",
416
- error: err("OUTPUT_UNSATISFIED", {
417
- detail: `the model could not produce the required output shape after ${budget + 1} attempts. `
418
- + `Last errors: ${lastFault ?? "(none recorded)"}`,
419
- }),
480
+ error: lastFailure === "empty"
481
+ ? err("OUTPUT_EMPTY", {
482
+ detail: `the model produced no <template> or <script> block in ${budget + 1} attempts — `
483
+ + `its replies could not be used. Last attempt: ${lastFault}`,
484
+ context: { attempts: budget + 1, provider: current?.name, model: call.model },
485
+ })
486
+ : err("OUTPUT_UNSATISFIED", {
487
+ detail: `the model could not produce the required output shape after ${budget + 1} attempts. `
488
+ + `Last errors: ${lastFault ?? "(none recorded)"}`,
489
+ }),
420
490
  }
421
491
  }
422
492
 
package/src/scope.ts CHANGED
@@ -81,9 +81,23 @@ export function toScope(blueprint: AxonBlueprint): AxonScope {
81
81
  if (members.length > 0) modules.push({ ...module, members })
82
82
  }
83
83
 
84
+ // A module that loaded without part of its surface. Read from the
85
+ // blueprint rather than inferred from missing tools: "has no tools" and
86
+ // "its tools would not compile" are different facts, and only the second
87
+ // is worth telling the model about.
88
+ //
89
+ // `modules` is optional on a partial blueprint — a programmatic one built
90
+ // from tools alone has none — so this must not assume the array exists.
91
+ const unavailable = (blueprint.modules ?? [])
92
+ .filter(module => module.degraded)
93
+ .map(module => ({ name: module.packageName ?? module.name, reason: module.degraded! }))
94
+
84
95
  // Restore blueprint order: the filtering above needs agent-first, but the
85
96
  // rendered scope should read in the order the blueprint declares.
86
- return { modules: modules.sort((a, b) => order(loadable, a) - order(loadable, b)) }
97
+ return {
98
+ modules: modules.sort((a, b) => order(loadable, a) - order(loadable, b)),
99
+ ...(unavailable.length > 0 ? { unavailable } : {}),
100
+ }
87
101
  }
88
102
 
89
103
  /** Agent-authored tools outrank module tools when both claim a callable name. */