@arcforge/kernel 2.0.105 → 2.0.107

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.105",
3
+ "version": "2.0.107",
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/cognet": "2.0.105",
19
- "@arcforge/engines": "2.0.105",
20
- "@arcforge/err": "2.0.105",
21
- "@arcforge/session": "2.0.105",
22
- "@arcforge/types": "2.0.105",
23
- "@arclabs/cloud": "2.0.105",
24
- "@axon/capsule": "2.0.105"
18
+ "@arcforge/cognet": "2.0.107",
19
+ "@arcforge/engines": "2.0.107",
20
+ "@arcforge/err": "2.0.107",
21
+ "@arcforge/session": "2.0.107",
22
+ "@arcforge/types": "2.0.107",
23
+ "@arclabs/cloud": "2.0.107",
24
+ "@axon/capsule": "2.0.107"
25
25
  },
26
26
  "devDependencies": {
27
27
  "@types/bun": "latest",
package/src/scope-dts.ts CHANGED
@@ -9,6 +9,12 @@ import type { AxonScope } from "@arcforge/types"
9
9
  * calls in the author's own src/tools, src/scripts, hooks, and routes
10
10
  * typecheck against exactly what the capsule will provide.
11
11
  *
12
+ * These globals are real in host-side code, not only inside the capsule:
13
+ * Inject().runtime() binds each one to the matching axon.tools.* proxy when
14
+ * the runtime comes up (see core/src/platform/inject.ts). That is what makes
15
+ * this file honest — for a while it declared globals a script could not
16
+ * actually call, so `kanban.list()` typechecked and then threw at runtime.
17
+ *
12
18
  * These two must never disagree about WHAT is in scope. They cannot,
13
19
  * because neither decides it — toScope() does, once, and both render its
14
20
  * result. This file only chooses how to spell it for `tsc`:
package/src/scope.ts CHANGED
@@ -47,7 +47,50 @@ export function toScopeModule(tool: AxonTool): AxonScopeModule {
47
47
  * The blueprint's executable scope. Tools with no loadable entry are
48
48
  * excluded — declaring something the capsule cannot call would tell the
49
49
  * model to invoke a function that does not exist there.
50
+ *
51
+ * Flat members are then deduped by CALLABLE NAME, which is a different
52
+ * question from the one merge() answers. merge() resolves collisions between
53
+ * TOOL names (the filename): an agent's `weather.ts` shadowing a module's
54
+ * `weather.ts`. It cannot see two differently-named files whose exports
55
+ * collide — an agent's `weather.ts` and a module's `forecast.ts` both
56
+ * exporting `now()` are two distinct tools by its reckoning, so both survive.
57
+ *
58
+ * Both then install flat, and everything downstream silently picks a winner:
59
+ * the .d.ts and the model's <scope> each declare `function now()` twice, and
60
+ * the capsule builds its globals with Object.assign, so whichever tool loads
61
+ * last wins and the other export is unreachable with nothing reported. The
62
+ * agent always wins here, matching merge()'s precedence, and the loser is
63
+ * dropped from the scope rather than rendered as a duplicate declaration.
50
64
  */
51
65
  export function toScope(blueprint: AxonBlueprint): AxonScope {
52
- return { modules: blueprint.tools.filter(isLoadable).map(toScopeModule) }
66
+ const loadable = blueprint.tools.filter(isLoadable)
67
+ const claimed = new Set<string>()
68
+ const modules: AxonScopeModule[] = []
69
+
70
+ // Agent-origin tools first so they claim contested names, regardless of the
71
+ // order modules happen to appear in the blueprint.
72
+ for (const tool of [...loadable].sort((a, b) => rank(a) - rank(b))) {
73
+ const module = toScopeModule(tool)
74
+ if (!module.flat) {
75
+ modules.push(module)
76
+ continue
77
+ }
78
+
79
+ const members = module.members.filter(member => !claimed.has(member.name))
80
+ for (const member of members) claimed.add(member.name)
81
+ if (members.length > 0) modules.push({ ...module, members })
82
+ }
83
+
84
+ // Restore blueprint order: the filtering above needs agent-first, but the
85
+ // rendered scope should read in the order the blueprint declares.
86
+ return { modules: modules.sort((a, b) => order(loadable, a) - order(loadable, b)) }
87
+ }
88
+
89
+ /** Agent-authored tools outrank module tools when both claim a callable name. */
90
+ function rank(tool: AxonTool): number {
91
+ return tool.origin === "module" ? 1 : 0
92
+ }
93
+
94
+ function order(tools: AxonTool[], module: AxonScopeModule): number {
95
+ return tools.findIndex(tool => tool.name === module.name)
53
96
  }