evolcore 0.0.42-test.0 → 0.0.43-test.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 (187) hide show
  1. package/CHANGELOG.md +31 -2
  2. package/bin/ec-safe-output.js +4 -1
  3. package/dist/ability/application-service.js +882 -0
  4. package/dist/ability/authorization.js +70 -0
  5. package/dist/ability/command-contract.js +105 -0
  6. package/dist/ability/daemon.js +137 -0
  7. package/dist/ability/development.js +450 -0
  8. package/dist/ability/environment.js +75 -0
  9. package/dist/ability/interop-v1.js +547 -0
  10. package/dist/ability/management.js +79 -0
  11. package/dist/ability/package.js +264 -0
  12. package/dist/ability/provider.js +73 -0
  13. package/dist/ability/publication.js +107 -0
  14. package/dist/ability/resources.js +106 -0
  15. package/dist/ability/runtime.js +212 -0
  16. package/dist/ability/secrets.js +47 -0
  17. package/dist/ability/store.js +112 -0
  18. package/dist/ability/toolchain.js +69 -0
  19. package/dist/ability/types.js +14 -0
  20. package/dist/ability/versions.js +32 -0
  21. package/dist/agents/baseagent.js +2 -2
  22. package/dist/agents/claude-runner.js +4 -0
  23. package/dist/agents/codex-runner.js +81 -17
  24. package/dist/agents/ecagent-plugin-lazy.js +41 -0
  25. package/dist/agents/ecagent-runner.js +18 -11
  26. package/dist/aun/ability-device-routing.js +12 -1
  27. package/dist/aun/aid/agentmd.js +2 -2
  28. package/dist/aun/aid/identity.js +45 -0
  29. package/dist/aun/aid/index.js +1 -0
  30. package/dist/aun/aid/managed-operation.js +73 -2
  31. package/dist/channels/aun.js +64 -18
  32. package/dist/channels/builtin-plugins.js +14 -0
  33. package/dist/channels/dingtalk.js +78 -26
  34. package/dist/channels/feishu.js +89 -14
  35. package/dist/channels/qqbot.js +84 -19
  36. package/dist/channels/wechat.js +77 -19
  37. package/dist/channels/wecom.js +67 -22
  38. package/dist/cli/ability-command.js +92 -0
  39. package/dist/cli/aun-commands.js +124 -85
  40. package/dist/cli/daemon-commands.js +37 -85
  41. package/dist/cli/index.js +14 -0
  42. package/dist/cli/init.js +11 -13
  43. package/dist/cli/managed-command-guard.js +6 -0
  44. package/dist/cli/model.js +101 -104
  45. package/dist/cli/provider-command.js +6 -4
  46. package/dist/cli/restart-monitor.js +52 -11
  47. package/dist/cli/upgrade-command.js +102 -0
  48. package/dist/cli/version.js +1 -1
  49. package/dist/config/access-policy.js +4 -2
  50. package/dist/config/builtin-roles.js +1 -0
  51. package/dist/config/config-field-policy.js +4 -0
  52. package/dist/config/config-manager.js +7 -0
  53. package/dist/config/provider-ipc-service.js +10 -0
  54. package/dist/config/providers-config.js +12 -3
  55. package/dist/config/providers-management.js +45 -9
  56. package/dist/config/schema-migration.js +40 -22
  57. package/dist/contracts/ecweb-service-protocol.js +2 -1
  58. package/dist/core/auth/agent-delegation.js +21 -5
  59. package/dist/core/auth/auth-gateway.js +31 -9
  60. package/dist/core/auth/authorization-audit.js +52 -4
  61. package/dist/core/auth/delegation-authorization.js +140 -4
  62. package/dist/core/auth/operation-authorizer.js +114 -13
  63. package/dist/core/auth/operation-catalog.js +118 -4
  64. package/dist/core/baseagent-loader.js +14 -1
  65. package/dist/core/channel-loader.js +47 -9
  66. package/dist/core/channel-runtime.js +1 -1
  67. package/dist/core/command/agent-storage-menu.js +1 -1
  68. package/dist/core/command/cli-intent-parser.js +26 -13
  69. package/dist/core/command/command-handler.js +232 -76
  70. package/dist/core/command/connect-menu.js +10 -4
  71. package/dist/core/command/daemon-diagnostics.js +3 -3
  72. package/dist/core/command/data-root-resolver.js +2 -3
  73. package/dist/core/command/menu-catalog.js +10 -3
  74. package/dist/core/command/menu-handler.js +321 -46
  75. package/dist/core/command/menu-protocol.js +53 -7
  76. package/dist/core/command/pa-workspace-calendar.js +1 -2
  77. package/dist/core/command/pa-workspace-items.js +486 -0
  78. package/dist/core/command/pa-workspace-store.js +10 -1
  79. package/dist/core/command/slash-gate.js +2 -2
  80. package/dist/core/command/slash-handler.js +67 -25
  81. package/dist/core/contact-bind-registry.js +27 -0
  82. package/dist/core/daemon-control.js +3 -3
  83. package/dist/core/daemon-lifecycle.js +2 -1
  84. package/dist/core/event-bus.js +9 -2
  85. package/dist/core/handoff/ipc-registration.js +1 -0
  86. package/dist/core/host-snapshot.js +1 -2
  87. package/dist/core/initialization/service.js +32 -11
  88. package/dist/core/ipc-registration.js +18 -5
  89. package/dist/core/memory/consolidation-context.js +2 -2
  90. package/dist/core/message/aun-request-registry.js +99 -18
  91. package/dist/core/message/im-renderer.js +16 -11
  92. package/dist/core/message/message-admission.js +25 -20
  93. package/dist/core/message/message-bridge.js +21 -47
  94. package/dist/core/message/message-queue.js +3 -0
  95. package/dist/core/message/response-engine.js +7 -5
  96. package/dist/core/model/catalog-service.js +1 -1
  97. package/dist/core/permission/ec-command-parser.js +41 -9
  98. package/dist/core/permission/permission-result.js +1 -0
  99. package/dist/core/permission/protected-paths.js +25 -14
  100. package/dist/core/permission/tool-policy.js +108 -107
  101. package/dist/core/plugin-lifecycle.js +133 -0
  102. package/dist/core/runner-reload-transaction.js +4 -1
  103. package/dist/core/system-session/memory.js +16 -3
  104. package/dist/core/task/task-activity-store.js +50 -0
  105. package/dist/core/task/task-image-resources.js +140 -0
  106. package/dist/core/thread/ipc-operation.js +1 -1
  107. package/dist/core/thread/thread-service.js +0 -1
  108. package/dist/directory/canonical-digest.js +5 -3
  109. package/dist/directory/owner-directory-admission.js +22 -2
  110. package/dist/directory/owner-directory-cache.js +394 -60
  111. package/dist/directory/owner-directory-markdown.js +29 -2
  112. package/dist/directory/owner-directory-scope.js +35 -16
  113. package/dist/ecweb/basic-settings-service.js +4 -1
  114. package/dist/ecweb/pairing.js +41 -0
  115. package/dist/ecweb/providers-service.js +8 -1
  116. package/dist/{utils/ecweb-utils.js → ecweb/runtime/launch.js} +3 -27
  117. package/dist/ecweb/runtime/lifecycle.js +184 -0
  118. package/dist/{utils/ecweb-supervisor.js → ecweb/runtime/supervisor.js} +32 -27
  119. package/dist/index.js +34 -25
  120. package/dist/ipc.js +124 -7
  121. package/dist/response-system/engines/v1/proactive-flow.js +1 -1
  122. package/dist/trigger/authorization.js +2 -2
  123. package/dist/utils/atomic-write.js +24 -0
  124. package/dist/utils/avatar-upload.js +3 -1
  125. package/dist/utils/cross-platform.js +31 -2
  126. package/dist/utils/host-info.js +36 -0
  127. package/dist/utils/instance-registry.js +38 -11
  128. package/dist/utils/logger.js +9 -0
  129. package/dist/utils/{process-tree-stats.js → process-tree.js} +29 -0
  130. package/dist/utils/tool-summary.js +9 -1
  131. package/dist/utils/upgrade-jobs.js +96 -15
  132. package/dist/utils/windows-autostart.js +1 -1
  133. package/ecagent/README.md +19 -0
  134. package/ecagent/dist/harness/agent-harness.js +9 -0
  135. package/ecagent/dist/harness/env/nodejs.js +71 -11
  136. package/ecagent/dist/harness/env/windows-shell.d.ts +7 -0
  137. package/ecagent/dist/harness/env/windows-shell.js +132 -0
  138. package/kits/docs/aun/ABILITY_CALLING.md +38 -9
  139. package/kits/docs/evolcore/INDEX.md +5 -1
  140. package/kits/docs/evolcore/ability.md +181 -0
  141. package/kits/docs/evolcore/aid.md +20 -0
  142. package/kits/docs/evolcore/config.md +10 -6
  143. package/kits/docs/evolcore/menu-protocol.md +40 -1
  144. package/kits/docs/evolcore/provider.md +2 -2
  145. package/kits/docs/evolcore/tool-authorization.md +270 -0
  146. package/kits/runtime/ability-job.ps1 +41 -0
  147. package/kits/runtime/ability-runner.mjs +67 -0
  148. package/kits/runtime/ability-secret.ps1 +59 -0
  149. package/kits/runtime/ability-templates/go/main.go +59 -0
  150. package/kits/runtime/ability-templates/java/Json.java +67 -0
  151. package/kits/runtime/ability-templates/java/Runner.java +42 -0
  152. package/kits/runtime/ability-templates/python/runner.py +48 -0
  153. package/kits/runtime/ability-templates/rust/json.rs +87 -0
  154. package/kits/runtime/ability-templates/rust/runner.rs +35 -0
  155. package/kits/schemas/_meta.json +12 -1
  156. package/kits/schemas/ability-plugin.schema.1.json +107 -0
  157. package/kits/schemas/ability-project.schema.1.json +31 -0
  158. package/kits/schemas/agent-config.schema.16.json +20 -0
  159. package/kits/schemas/agent-config.schema.17.json +20 -0
  160. package/kits/schemas/agent-config.schema.18.json +917 -0
  161. package/kits/skills/.switches.json +4 -0
  162. package/kits/skills/aid-ability/SKILL.md +5 -4
  163. package/kits/skills/ec-ability/SKILL.md +67 -0
  164. package/kits/skills/ec-ability/references/contract-checklist.md +37 -0
  165. package/kits/skills/ec-ability/references/development.md +104 -0
  166. package/kits/skills/ec-ability/references/management.md +117 -0
  167. package/kits/skills/ec-ability/references/recovery.md +27 -0
  168. package/kits/skills/ec-ability/references/runtime-protocol.md +109 -0
  169. package/kits/skills/ec-ability/references/workflows.md +15 -0
  170. package/kits/skills/ec-service-proxy/SKILL.md +12 -0
  171. package/kits/skills/personal-assistant/SKILL.md +240 -6
  172. package/kits/skills/personal-assistant/references/02-bootstrap.md +78 -4
  173. package/kits/skills/personal-assistant/scripts/clean.mjs +397 -0
  174. package/kits/skills/personal-assistant/scripts/init.mjs +113 -25
  175. package/kits/skills/personal-assistant/scripts/lock.mjs +189 -0
  176. package/kits/skills/personal-assistant/scripts/migrate.mjs +35 -10
  177. package/kits/skills/personal-assistant/scripts/verify.mjs +2 -1
  178. package/kits/skills/personal-assistant/templates/persona-section.md +54 -0
  179. package/kits/skills/personal-assistant/triggers/ingest-daily.json +1 -1
  180. package/kits/templates/memory-consolidation/notes.md +1 -1
  181. package/kits/templates/system-fragments/channel.md +2 -1
  182. package/kits/templates/system-fragments/commands.md +1 -0
  183. package/package.json +4 -2
  184. package/dist/core/command/data-root-error.js +0 -10
  185. package/dist/utils/machine-info.js +0 -46
  186. package/dist/utils/process-tree-worker.js +0 -31
  187. package/dist/utils/windows-output.js +0 -36
@@ -0,0 +1,212 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { StringDecoder } from 'node:string_decoder';
4
+ import { spawn } from 'node:child_process';
5
+ import { getPackageRoot } from '../paths.js';
6
+ import { abilityTemp, packageFile, packageDigest } from './package.js';
7
+ import { AbilityError, abilityAssert } from './types.js';
8
+ import { assertEnvironment, checkRuntimeEnvironment, processRuntimeCommand, resolveExecutable } from './environment.js';
9
+ const PROTOCOL = 'evolcore.ability-runtime/1';
10
+ export function runtimeCommand(pkg) {
11
+ const runtime = pkg.manifest.runtime;
12
+ if (runtime.kind === 'node-subprocess')
13
+ return [process.execPath, path.join(getPackageRoot(), 'kits/runtime/ability-runner.mjs')];
14
+ return processRuntimeCommand(runtime).map(value => value.startsWith('package:') ? packageFile(pkg.root, value.slice('package:'.length)) : value);
15
+ }
16
+ export function runtimeDescriptor(pkg) {
17
+ const runtime = pkg.manifest.runtime;
18
+ const resolved = runtimeCommand(pkg);
19
+ const command = runtime.kind === 'node-subprocess' ? [process.execPath, runtime.entry] : processRuntimeCommand(runtime);
20
+ const found = resolveExecutable(resolved[0]);
21
+ const executable = found ?? resolved[0];
22
+ const executableExists = !!found;
23
+ return { kind: runtime.kind, language: runtime.kind === 'node-subprocess' ? 'node' : runtime.language, command,
24
+ executable, executableExists,
25
+ processTreeIsolation: process.platform === 'win32' ? runtime.kind === 'node-subprocess' ? 'windows-job-object' : 'direct-spawn' : 'process-group' };
26
+ }
27
+ export class AbilityRunner {
28
+ broker;
29
+ exited;
30
+ child;
31
+ pending = new Map();
32
+ sequence = 0;
33
+ work;
34
+ closing = false;
35
+ brokerCalls = 0;
36
+ notified = false;
37
+ healthTimer;
38
+ constructor(broker, exited) {
39
+ this.broker = broker;
40
+ this.exited = exited;
41
+ }
42
+ async start(pkg, instance, migration) {
43
+ abilityAssert(packageDigest(pkg.root) === pkg.digest, 'PACKAGE_CHANGED', 'Stored package changed');
44
+ const command = runtimeCommand(pkg);
45
+ const runtime = pkg.manifest.runtime;
46
+ const legacyNode = runtime.kind === 'node-subprocess';
47
+ const language = runtime.kind === 'node-subprocess' ? 'node' : runtime.language;
48
+ const packagedExecutable = runtime.kind === 'process-rpc' && processRuntimeCommand(runtime)[0].startsWith('package:');
49
+ const versionArgs = packagedExecutable ? undefined : language === 'python' || language === 'node' ? ['--version'] : language === 'java' ? ['-version'] : undefined;
50
+ const environment = await checkRuntimeEnvironment(command[0], versionArgs, pkg.manifest.engines[language]);
51
+ assertEnvironment(environment);
52
+ command[0] = environment.executable;
53
+ this.work = abilityTemp('ability-runner-');
54
+ const env = { TMPDIR: process.env.TMPDIR, TMP: process.env.TMPDIR, TEMP: process.env.TMPDIR,
55
+ SystemRoot: process.env.SystemRoot, WINDIR: process.env.WINDIR, PATH: legacyNode ? (process.env.SystemRoot ? path.join(process.env.SystemRoot, 'System32') : '/usr/bin:/bin') : process.env.PATH ?? (process.env.SystemRoot ? path.join(process.env.SystemRoot, 'System32') : '/usr/bin:/bin'),
56
+ PYTHONUTF8: '1', PYTHONUNBUFFERED: '1' };
57
+ const windows = process.platform === 'win32';
58
+ if (windows && legacyNode) {
59
+ env.EC_ABILITY_NODE = process.execPath;
60
+ env.EC_ABILITY_RUNNER = path.join(getPackageRoot(), 'kits/runtime/ability-runner.mjs');
61
+ }
62
+ const useWindowsJobHost = windows && legacyNode;
63
+ const executable = useWindowsJobHost ? path.join(process.env.SystemRoot ?? 'C:\\Windows', 'System32/WindowsPowerShell/v1.0/powershell.exe') : command[0];
64
+ const args = useWindowsJobHost
65
+ ? ['-NoProfile', '-NonInteractive', '-Command', fs.readFileSync(path.join(getPackageRoot(), 'kits/runtime/ability-job.ps1'), 'utf8')]
66
+ : command.slice(1);
67
+ this.child = spawn(executable, args, { cwd: this.work, env, shell: false, windowsHide: true, detached: !windows, stdio: ['pipe', 'pipe', 'pipe'] });
68
+ let buffer = '';
69
+ let logBytes = 0;
70
+ const decoder = new StringDecoder('utf8');
71
+ this.child.stdin.on('error', () => { void this.close(true); });
72
+ this.child.stderr.on('data', chunk => { logBytes += chunk.length; if (logBytes > pkg.manifest.limits.maxLogBytesPerMinute)
73
+ void this.close(true); });
74
+ const logTimer = setInterval(() => { logBytes = 0; }, 60000);
75
+ logTimer.unref();
76
+ this.child.stdout.on('data', chunk => {
77
+ buffer += decoder.write(chunk);
78
+ if (Buffer.byteLength(buffer) > 2 * 1024 * 1024) {
79
+ void this.close(true);
80
+ return;
81
+ }
82
+ for (;;) {
83
+ const split = buffer.indexOf('\n');
84
+ if (split < 0)
85
+ break;
86
+ const line = buffer.slice(0, split);
87
+ buffer = buffer.slice(split + 1);
88
+ try {
89
+ void this.receive(JSON.parse(line)).catch(() => this.close(true));
90
+ }
91
+ catch {
92
+ void this.close(true);
93
+ }
94
+ }
95
+ });
96
+ const ended = () => { clearInterval(logTimer); clearInterval(this.healthTimer); this.failPending(); if (!this.closing) {
97
+ this.closing = true;
98
+ this.notifyExit();
99
+ } this.cleanWork(); };
100
+ this.child.once('error', (error) => { this.failPending(new AbilityError('RUNTIME_START_FAILED', `Runtime could not start (${error.code ?? 'spawn error'}); check executable, platform and dependencies`, 503)); ended(); });
101
+ this.child.once('exit', ended);
102
+ try {
103
+ const health = await this.call('initialize', {
104
+ ...(pkg.manifest.runtime.kind === 'node-subprocess' ? { entry: packageFile(pkg.root, pkg.manifest.runtime.entry) } : {}),
105
+ config: instance.config, handlers: pkg.manifest.abilities.map(item => item.handler), ...(migration ? { migration } : {})
106
+ }, 30000);
107
+ abilityAssert(health?.ready === true, 'RUNTIME_NOT_READY', 'Runner did not report readiness', 503);
108
+ abilityAssert(Array.isArray(health.handlers) && JSON.stringify([...health.handlers].sort()) === JSON.stringify(pkg.manifest.abilities.map(row => row.handler).sort()), 'RUNTIME_HANDLERS_MISMATCH', 'Runner handler set differs from Manifest', 503);
109
+ this.healthTimer = setInterval(() => {
110
+ if (!this.closing)
111
+ void this.call('health', {}, 5000).then(value => {
112
+ if (!value?.ready)
113
+ return this.close(true);
114
+ }).catch(() => this.close(true));
115
+ }, 30000);
116
+ this.healthTimer.unref();
117
+ return health.migratedData;
118
+ }
119
+ catch (error) {
120
+ await this.close();
121
+ throw error;
122
+ }
123
+ }
124
+ async receive(frame) {
125
+ abilityAssert(frame.protocol === PROTOCOL && typeof frame.id === 'string', 'RUNTIME_PROTOCOL_ERROR', 'Invalid runner response');
126
+ if (frame.method) {
127
+ abilityAssert(frame.method === 'broker.call' && frame.params && typeof frame.params.method === 'string', 'RUNTIME_PROTOCOL_ERROR', 'Invalid Broker request');
128
+ if (this.brokerCalls >= 8) {
129
+ this.write({ id: frame.id, error: { code: 'RESOURCE_BUSY', message: 'Broker busy' } });
130
+ return;
131
+ }
132
+ this.brokerCalls++;
133
+ try {
134
+ const result = await this.broker(frame.params.invocationId, frame.params.method, frame.params.args ?? {});
135
+ this.write({ id: frame.id, result: result ?? null });
136
+ }
137
+ catch {
138
+ this.write({ id: frame.id, error: { code: 'BROKER_DENIED', message: 'Resource operation unavailable' } });
139
+ }
140
+ finally {
141
+ this.brokerCalls--;
142
+ }
143
+ return;
144
+ }
145
+ const waiter = this.pending.get(frame.id);
146
+ if (!waiter)
147
+ return;
148
+ this.pending.delete(frame.id);
149
+ clearTimeout(waiter.timer);
150
+ frame.error ? waiter.reject(new AbilityError('PLUGIN_FAILED', 'Plugin handler failed', 502)) : waiter.resolve(frame.result);
151
+ }
152
+ write(frame) {
153
+ abilityAssert(this.child && !this.closing && !this.child.stdin.destroyed, 'RUNTIME_UNAVAILABLE', 'Runner is unavailable', 503);
154
+ abilityAssert(this.child.stdin.writableLength < 4 * 1024 * 1024, 'RESOURCE_BUSY', 'Runner output queue is full', 503);
155
+ this.child.stdin.write(JSON.stringify({ protocol: PROTOCOL, ...frame }) + '\n');
156
+ }
157
+ call(method, params, timeoutMs) {
158
+ abilityAssert(this.pending.size < 240, 'RESOURCE_BUSY', 'Runner pending limit reached', 503);
159
+ const id = `h:${++this.sequence}`;
160
+ return new Promise((resolve, reject) => {
161
+ const timer = setTimeout(() => { this.pending.delete(id); reject(new AbilityError('EXECUTION_UNKNOWN', 'Runner deadline exceeded; do not repeat the operation', 504)); void this.close(true); }, timeoutMs);
162
+ this.pending.set(id, { resolve, reject, timer });
163
+ try {
164
+ this.write({ id, method, params });
165
+ }
166
+ catch (error) {
167
+ this.pending.delete(id);
168
+ clearTimeout(timer);
169
+ reject(error);
170
+ }
171
+ });
172
+ }
173
+ failPending(error = new AbilityError('EXECUTION_UNKNOWN', 'Runner exited; operation outcome is unknown', 503)) { for (const item of this.pending.values()) {
174
+ clearTimeout(item.timer);
175
+ item.reject(error);
176
+ } this.pending.clear(); }
177
+ cleanWork() { if (this.work) {
178
+ try {
179
+ fs.rmSync(this.work, { recursive: true, force: true });
180
+ }
181
+ catch { }
182
+ this.work = undefined;
183
+ } }
184
+ notifyExit() { if (!this.notified) {
185
+ this.notified = true;
186
+ this.exited();
187
+ } }
188
+ async close(unexpected = false) {
189
+ if (unexpected)
190
+ this.notifyExit();
191
+ if (this.closing)
192
+ return;
193
+ this.closing = true;
194
+ this.failPending();
195
+ clearInterval(this.healthTimer);
196
+ const child = this.child;
197
+ if (child && child.exitCode === null) {
198
+ if (process.platform === 'win32')
199
+ child.kill();
200
+ else {
201
+ try {
202
+ process.kill(-child.pid, 'SIGKILL');
203
+ }
204
+ catch {
205
+ child.kill('SIGKILL');
206
+ }
207
+ }
208
+ await new Promise(resolve => { const timer = setTimeout(resolve, 5000); child.once('exit', () => { clearTimeout(timer); resolve(); }); });
209
+ }
210
+ this.cleanWork();
211
+ }
212
+ }
@@ -0,0 +1,47 @@
1
+ import path from 'node:path';
2
+ import { spawn } from 'node:child_process';
3
+ import { getPackageRoot } from '../paths.js';
4
+ import { AbilityError, abilityAssert } from './types.js';
5
+ /** Values travel only over private pipes; there is no plaintext file fallback. */
6
+ export class AbilitySecrets {
7
+ directory;
8
+ constructor(directory) {
9
+ this.directory = directory;
10
+ }
11
+ backend = process.platform === 'win32' ? 'dpapi-current-user' : 'unavailable';
12
+ status = 'unverified';
13
+ async probe() { try {
14
+ await this.execute({ action: 'probe' });
15
+ this.status = 'ready';
16
+ return true;
17
+ }
18
+ catch {
19
+ this.status = 'unavailable';
20
+ return false;
21
+ } }
22
+ async set(instanceId, slot, handle, value) {
23
+ abilityAssert(typeof value === 'string' && value.length > 0 && Buffer.byteLength(value) <= 16384 && !/[\r\n]/.test(value), 'SECRET_INVALID', 'Secret must be a nonempty single-line value under 16 KiB');
24
+ await this.execute({ action: 'set', handle, value, binding: instanceId + ':' + slot });
25
+ this.status = 'ready';
26
+ }
27
+ async get(instanceId, slot, handle) {
28
+ return Buffer.from(await this.execute({ action: 'get', handle, binding: instanceId + ':' + slot }), 'base64').toString('utf8');
29
+ }
30
+ execute(input) {
31
+ abilityAssert(process.platform === 'win32', 'SECRET_BACKEND_UNAVAILABLE', 'An encrypted secret backend is not configured on this platform', 503);
32
+ return new Promise((resolve, reject) => {
33
+ const child = spawn(path.join(process.env.SystemRoot || 'C:\\Windows', 'System32/WindowsPowerShell/v1.0/powershell.exe'), ['-NoProfile', '-NonInteractive', '-File', path.join(getPackageRoot(), 'kits/runtime/ability-secret.ps1')], { windowsHide: true, stdio: ['pipe', 'pipe', 'pipe'], env: { SystemRoot: process.env.SystemRoot, WINDIR: process.env.WINDIR, TEMP: process.env.TMPDIR, TMP: process.env.TMPDIR } });
34
+ let output = '';
35
+ let stage = '';
36
+ const timer = setTimeout(() => child.kill(), 15000);
37
+ child.stdout.on('data', value => { output += value.toString('utf8'); if (output.length > 32768)
38
+ child.kill(); });
39
+ child.stderr.on('data', chunk => { const match = String(chunk).match(/Ability secret backend unavailable: (initialize|directory|object):([A-Za-z]+Exception)/); if (match)
40
+ stage = match[1] + ':' + match[2]; });
41
+ child.stdin.on('error', () => { });
42
+ child.once('error', () => { clearTimeout(timer); reject(new AbilityError('SECRET_BACKEND_UNAVAILABLE', 'Encrypted secret backend unavailable', 503)); });
43
+ child.once('close', code => { clearTimeout(timer); code === 0 ? resolve(output) : reject(new AbilityError('SECRET_BACKEND_UNAVAILABLE', 'Secret account, encrypted object or DACL could not be verified' + (stage ? ' (' + stage + ')' : ''), 503)); });
44
+ child.stdin.end(JSON.stringify({ ...input, directory: this.directory }));
45
+ });
46
+ }
47
+ }
@@ -0,0 +1,112 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { DatabaseSync } from 'node:sqlite';
4
+ import { randomUUID } from 'node:crypto';
5
+ import { AbilityError, abilityAssert } from './types.js';
6
+ /** Daemon-owned durable state. All callers pass through the application service. */
7
+ export class AbilityStore {
8
+ root;
9
+ transactionDepth = 0;
10
+ db;
11
+ constructor(root) {
12
+ this.root = root;
13
+ fs.mkdirSync(root, { recursive: true });
14
+ this.db = new DatabaseSync(path.join(root, 'ability.db'));
15
+ const version = this.db.prepare('PRAGMA user_version').get().user_version;
16
+ if (version > 1) {
17
+ this.db.close();
18
+ throw new AbilityError('STORE_VERSION_UNSUPPORTED', 'Ability state requires a newer EvolCore', 503);
19
+ }
20
+ this.db.exec(`PRAGMA journal_mode=WAL; PRAGMA synchronous=FULL; PRAGMA foreign_keys=ON;
21
+ CREATE TABLE IF NOT EXISTS records(kind TEXT NOT NULL,id TEXT NOT NULL,aid TEXT NOT NULL,revision INTEGER NOT NULL,body TEXT NOT NULL,PRIMARY KEY(kind,id));
22
+ CREATE INDEX IF NOT EXISTS records_target ON records(kind,aid);
23
+ CREATE TABLE IF NOT EXISTS commands(actor TEXT NOT NULL,aid TEXT NOT NULL,command TEXT NOT NULL,job TEXT NOT NULL,PRIMARY KEY(actor,aid,command));
24
+ CREATE TABLE IF NOT EXISTS instance_names(aid TEXT NOT NULL,name TEXT NOT NULL,id TEXT NOT NULL UNIQUE,PRIMARY KEY(aid,name));
25
+ CREATE TABLE IF NOT EXISTS audit(id TEXT PRIMARY KEY,ts INTEGER NOT NULL,actor TEXT NOT NULL,aid TEXT NOT NULL,action TEXT NOT NULL,subject TEXT NOT NULL);
26
+ PRAGMA user_version=1;`);
27
+ }
28
+ close() { this.db.close(); }
29
+ get(kind, id) {
30
+ const row = this.db.prepare('SELECT body FROM records WHERE kind=? AND id=?').get(kind, id);
31
+ return row ? JSON.parse(row.body) : undefined;
32
+ }
33
+ list(kind, aid) {
34
+ const rows = (aid === undefined ? this.db.prepare('SELECT body FROM records WHERE kind=? ORDER BY id').all(kind)
35
+ : this.db.prepare('SELECT body FROM records WHERE kind=? AND aid=? ORDER BY id').all(kind, aid));
36
+ return rows.map(row => JSON.parse(row.body));
37
+ }
38
+ put(kind, id, aid, value, revision = 1, expected) {
39
+ if (expected !== undefined) {
40
+ const result = this.db.prepare('UPDATE records SET body=?,revision=? WHERE kind=? AND id=? AND revision=?')
41
+ .run(JSON.stringify(value), revision, kind, id, expected);
42
+ if (result.changes !== 1)
43
+ throw new AbilityError('REVISION_CONFLICT', 'Resource changed; refresh before submitting', 409);
44
+ }
45
+ else
46
+ this.db.prepare('INSERT INTO records(kind,id,aid,revision,body) VALUES(?,?,?,?,?) ON CONFLICT(kind,id) DO UPDATE SET aid=excluded.aid,revision=excluded.revision,body=excluded.body')
47
+ .run(kind, id, aid, revision, JSON.stringify(value));
48
+ }
49
+ transaction(fn) {
50
+ if (this.transactionDepth)
51
+ return fn();
52
+ this.db.exec('BEGIN IMMEDIATE');
53
+ this.transactionDepth++;
54
+ try {
55
+ const result = fn();
56
+ this.db.exec('COMMIT');
57
+ return result;
58
+ }
59
+ catch (error) {
60
+ this.db.exec('ROLLBACK');
61
+ throw error;
62
+ }
63
+ finally {
64
+ this.transactionDepth--;
65
+ }
66
+ }
67
+ audit(actor, aid, action, subject) {
68
+ this.db.prepare('INSERT INTO audit VALUES(?,?,?,?,?,?)').run(randomUUID(), Date.now(), actor, aid, action, subject);
69
+ }
70
+ claimName(aid, name, id) {
71
+ try {
72
+ this.db.prepare('INSERT INTO instance_names VALUES(?,?,?)').run(aid, name, id);
73
+ }
74
+ catch {
75
+ throw new AbilityError('INSTANCE_NAME_CONFLICT', 'Instance name already exists for this AID', 409);
76
+ }
77
+ }
78
+ releaseName(id) { this.db.prepare('DELETE FROM instance_names WHERE id=?').run(id); }
79
+ remove(kind, id) { this.db.prepare('DELETE FROM records WHERE kind=? AND id=?').run(kind, id); }
80
+ auditRows(aid) { return this.db.prepare('SELECT * FROM audit WHERE aid=? ORDER BY ts DESC LIMIT 200').all(aid); }
81
+ commandJob(actor, aid, command) {
82
+ return this.db.prepare('SELECT job FROM commands WHERE actor=? AND aid=? AND command=?').get(actor, aid, command)?.job;
83
+ }
84
+ bindCommand(actor, aid, command, job) {
85
+ this.db.prepare('INSERT INTO commands VALUES(?,?,?,?)').run(actor, aid, command, job);
86
+ }
87
+ kvAddress(instance, key) {
88
+ return instance.dataGeneration ? { kind: 'kv-generation', id: `${instance.id}:${instance.dataGeneration}:${key}` } : { kind: 'kv', id: `${instance.id}:${key}` };
89
+ }
90
+ kvValues(instance) {
91
+ const address = this.kvAddress(instance, '');
92
+ const values = Object.create(null);
93
+ const rows = this.db.prepare('SELECT id,body FROM records WHERE kind=? AND aid=? AND substr(id,1,?)=?').all(address.kind, instance.target.aid, address.id.length, address.id);
94
+ for (const row of rows)
95
+ values[row.id.slice(address.id.length)] = JSON.parse(row.body);
96
+ return values;
97
+ }
98
+ replaceKv(instance, values) {
99
+ abilityAssert(values && typeof values === 'object' && !Array.isArray(values), 'DATA_INVALID', 'Migrated KV must be an object');
100
+ for (const [key, value] of Object.entries(values))
101
+ abilityAssert(/^[A-Za-z0-9._-]{1,128}$/.test(key) && Buffer.byteLength(JSON.stringify(value) ?? '') <= 65536, 'DATA_INVALID', 'KV keys or values exceed storage limits');
102
+ this.transaction(() => {
103
+ const address = this.kvAddress(instance, '');
104
+ this.db.prepare('DELETE FROM records WHERE kind=? AND aid=? AND substr(id,1,?)=?').run(address.kind, instance.target.aid, address.id.length, address.id);
105
+ for (const [key, value] of Object.entries(values)) {
106
+ const entry = this.kvAddress(instance, key);
107
+ this.put(entry.kind, entry.id, instance.target.aid, value);
108
+ }
109
+ });
110
+ }
111
+ checkpointKv(source, target) { this.replaceKv(target, this.kvValues(source)); }
112
+ }
@@ -0,0 +1,69 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { endianness } from 'node:os';
4
+ import { spawnSync } from 'node:child_process';
5
+ import { assertEnvironment, checkEnvironment } from './environment.js';
6
+ import { AbilityError, abilityAssert } from './types.js';
7
+ export function toolchainReport(language, engines) {
8
+ switch (language) {
9
+ case 'node': return [checkEnvironment(process.execPath, ['--version'], engines.node)];
10
+ case 'python': return [checkEnvironment(process.platform === 'win32' ? 'python' : 'python3', ['--version'], engines.python)];
11
+ case 'java': {
12
+ const javac = checkEnvironment('javac', ['-version'], engines.java);
13
+ if (javac.available && Number(javac.version.split('.')[0]) < 17) {
14
+ Object.assign(javac, { available: false, code: 'ENGINE_UNSUPPORTED', required: '>=17.0.0', message: 'The built-in Java builder requires JDK 17 or newer.' });
15
+ }
16
+ const jar = javac.executable ? path.join(path.dirname(fs.realpathSync(javac.executable)), process.platform === 'win32' ? 'jar.exe' : 'jar') : 'jar';
17
+ return [javac, checkEnvironment(jar, ['--version'], '>=17.0.0'), checkEnvironment('java', ['-version'], engines.java)];
18
+ }
19
+ case 'go': return [checkEnvironment('go', ['version'], engines.go)];
20
+ case 'rust': return [checkEnvironment('rustc', ['--version'], engines.rust)];
21
+ default: return [];
22
+ }
23
+ }
24
+ function run(command, args, cwd, env) {
25
+ const result = spawnSync(command, args, { cwd, env, shell: false, windowsHide: true,
26
+ timeout: 120000, maxBuffer: 4 * 1024 * 1024, encoding: 'utf8' });
27
+ if (result.error || result.status !== 0) {
28
+ const details = String(result.error?.message ?? result.stderr ?? result.stdout ?? '').trim().slice(-4096);
29
+ throw new AbilityError('BUILD_FAILED', `Compiler failed${details ? ': ' + details : ''}. No host environment was installed or configured.`, 422);
30
+ }
31
+ }
32
+ /** Sources and outputs are provided by development.ts in a session-owned snapshot. */
33
+ export function buildProcessRpcArtifact(build, workspace, output, manifest) {
34
+ const env = { ...process.env, TMPDIR: process.env.TMPDIR, TMP: process.env.TMPDIR, TEMP: process.env.TMPDIR,
35
+ RUSTUP_AUTO_INSTALL: '0', RUSTUP_NO_UPDATE_CHECK: '1' };
36
+ fs.mkdirSync(path.dirname(output), { recursive: true });
37
+ if (build.kind === 'command') {
38
+ abilityAssert(build.command?.length, 'PROJECT_INVALID', 'Custom build requires an argv command');
39
+ const command = build.command.map(arg => arg === '{output}' ? output : arg === '{project}' ? workspace : arg);
40
+ const check = checkEnvironment(command[0]);
41
+ assertEnvironment(check);
42
+ run(check.executable, command.slice(1), workspace, env);
43
+ }
44
+ else {
45
+ const checks = toolchainReport(build.kind, manifest.engines);
46
+ for (const check of checks)
47
+ assertEnvironment(check);
48
+ const compiler = checks[0].executable;
49
+ if (build.kind === 'java') {
50
+ const classes = path.join(workspace, 'classes');
51
+ fs.mkdirSync(classes);
52
+ run(compiler, ['--release', '17', '-encoding', 'UTF-8', '-proc:none', '-d', classes, ...build.sources.filter(file => file.endsWith('.java'))], workspace, env);
53
+ run(checks[1].executable, ['--create', '--file', output, '--main-class', build.mainClass ?? 'Runner', '--date=2000-01-01T00:00:00Z', '-C', classes, '.'], workspace, env);
54
+ }
55
+ else if (build.kind === 'go') {
56
+ Object.assign(env, { GOPROXY: 'off', GOSUMDB: 'off', GOTOOLCHAIN: 'local', GOENV: 'off', GOFLAGS: '', GOOS: process.platform === 'win32' ? 'windows' : process.platform,
57
+ GOARCH: process.arch === 'x64' ? 'amd64' : process.arch === 'ia32' ? '386' : process.arch === 'ppc64' && endianness() === 'LE' ? 'ppc64le' : process.arch,
58
+ CGO_ENABLED: '0', GOCACHE: path.join(workspace, 'go-cache') });
59
+ run(compiler, ['build', '-trimpath', '-buildvcs=false', '-o', output, ...build.sources.filter(file => file.endsWith('.go'))], workspace, env);
60
+ }
61
+ else {
62
+ const entry = build.sources.find(file => file.endsWith('.rs'));
63
+ abilityAssert(entry, 'PROJECT_INVALID', 'Rust build requires a .rs entry source');
64
+ run(compiler, ['--edition=2021', '-O', '--crate-name=ability_runner', '--remap-path-prefix=' + workspace + '=.',
65
+ ...(process.platform === 'win32' ? ['-C', 'target-feature=+crt-static'] : []), entry, '-o', output], workspace, env);
66
+ }
67
+ }
68
+ abilityAssert(fs.existsSync(output) && fs.lstatSync(output).isFile() && !fs.lstatSync(output).isSymbolicLink(), 'BUILD_FAILED', 'Build did not produce a regular runtime artifact');
69
+ }
@@ -0,0 +1,14 @@
1
+ export class AbilityError extends Error {
2
+ code;
3
+ status;
4
+ constructor(code, message, status = 400) {
5
+ super(message);
6
+ this.code = code;
7
+ this.status = status;
8
+ this.name = 'AbilityError';
9
+ }
10
+ }
11
+ export function abilityAssert(condition, code, message, status = 400) {
12
+ if (!condition)
13
+ throw new AbilityError(code, message, status);
14
+ }
@@ -0,0 +1,32 @@
1
+ import { createRequire } from 'node:module';
2
+ import canonicalize from 'canonicalize';
3
+ import { abilityAssert } from './types.js';
4
+ const semver = createRequire(import.meta.url)('semver');
5
+ export const sameJson = (a, b) => canonicalize(a) === canonicalize(b);
6
+ export const dataVersion = (pkg) => pkg.manifest.data?.schemaVersion ?? 1;
7
+ export function versionImpact(instance, previous, candidate) {
8
+ const oldPaths = previous.definitions.map(row => String(row.definition.path));
9
+ const newPaths = candidate.definitions.map(row => String(row.definition.path));
10
+ const changedPaths = newPaths.filter(path => {
11
+ const old = previous.definitions.find(row => row.definition.path === path);
12
+ return old && !sameJson(old, candidate.definitions.find(row => row.definition.path === path));
13
+ });
14
+ return {
15
+ fromVersion: previous.manifest.version, toVersion: candidate.manifest.version,
16
+ downgrade: semver.lt(candidate.manifest.version, previous.manifest.version), samePackage: previous.digest === candidate.digest,
17
+ addedPaths: newPaths.filter(path => !oldPaths.includes(path)), removedPaths: oldPaths.filter(path => !newPaths.includes(path)), changedPaths,
18
+ contracts: changedPaths.map(path => ({ path, before: previous.definitions.find(row => row.definition.path === path), after: candidate.definitions.find(row => row.definition.path === path) })),
19
+ configSchemaChanged: !sameJson(previous.configSchema, candidate.configSchema),
20
+ configuration: { before: previous.configSchema, after: candidate.configSchema },
21
+ permissionsChanged: !sameJson(previous.manifest.permissions, candidate.manifest.permissions),
22
+ permissions: { before: previous.manifest.permissions, after: candidate.manifest.permissions },
23
+ data: { fromVersion: dataVersion(previous), toVersion: dataVersion(candidate), migrationRequired: dataVersion(previous) !== dataVersion(candidate) },
24
+ invalidatedGrantIds: instance.grants.filter(grant => grant.permission === 'remote-call' && !grant.revokedAt).map(grant => grant.id),
25
+ externalDataWarning: instance.grants.some(grant => grant.permission === 'workspace' && !grant.revokedAt
26
+ && (grant.expiresAt ?? 0) > Date.now() && grant.issuedByAid === instance.approvedByAid && grant.value.mode === 'read-write'),
27
+ };
28
+ }
29
+ export function assertPackageVersion(store, candidate) {
30
+ for (const previous of store.list('package'))
31
+ abilityAssert(previous.manifest.id !== candidate.manifest.id || previous.manifest.version !== candidate.manifest.version || previous.digest === candidate.digest, 'VERSION_CONTENT_CONFLICT', 'A plugin version already identifies different content on this host; publish a new version', 409);
32
+ }
@@ -68,7 +68,7 @@ const BASEAGENT_ALIASES = {
68
68
  };
69
69
  const SUPPORTED_BASEAGENTS = new Set(['claude', 'codex', 'gemini', 'ecagent']);
70
70
  export const DEFAULT_CLAUDE_MODEL = 'sonnet';
71
- export const DEFAULT_CODEX_MODEL = 'gpt-5.2-codex';
71
+ export const DEFAULT_CODEX_MODEL = 'gpt-6.1-terra';
72
72
  export const DEFAULT_GEMINI_MODEL = 'gemini-2.5-flash';
73
73
  export function normalizeBaseagent(input) {
74
74
  const key = String(input || '').trim().toLowerCase().replace(/_/g, '-');
@@ -645,7 +645,7 @@ export function resolveGoogleConfig(config, override) {
645
645
  }
646
646
  // ── EvolCore bundled ecagent ──────────────────────────────────────────
647
647
  export const DEFAULT_ECAGENT_BASE_URL = 'https://mg-new.evolai.cn/openclaw-proxy/v1';
648
- export const DEFAULT_ECAGENT_MODEL = 'claude-sonnet-4-6';
648
+ export const DEFAULT_ECAGENT_MODEL = 'deepseek-v4.1-flash';
649
649
  export const DEFAULT_ECAGENT_TIMEOUT_MS = 120_000;
650
650
  export const DEFAULT_ECAGENT_MAX_RETRIES = 2;
651
651
  export const DEFAULT_ECAGENT_MAX_RETRY_DELAY_MS = 4_000;
@@ -2278,8 +2278,10 @@ export class AgentRunner {
2278
2278
  role: ctx?.role,
2279
2279
  selfAid: ctx?.selfAid,
2280
2280
  requestId: typeof requestId === 'string' ? requestId : undefined,
2281
+ callId: typeof requestId === 'string' || typeof requestId === 'number' ? String(requestId) : undefined,
2281
2282
  taskId: ctx?.taskId,
2282
2283
  matchedPath: matchedPath ?? (preflight?.behavior === 'deny' ? preflight.matchedPath : undefined),
2284
+ matchedRule: preflight?.behavior === 'deny' ? preflight.matchedRule : undefined,
2283
2285
  });
2284
2286
  try {
2285
2287
  await ctx?.recordExecutionAnomaly?.({
@@ -2307,6 +2309,8 @@ export class AgentRunner {
2307
2309
  const trustedSafeOutputCommands = new Set();
2308
2310
  // PreToolUse Hook - 黑名单检查 + input 修正(不可绕过,所有模式都走)
2309
2311
  const preToolUseHook = async (input, _toolUseId, hookOptions) => {
2312
+ if (!input.tool_use_id && !input.toolUseID && _toolUseId)
2313
+ input = { ...input, tool_use_id: _toolUseId };
2310
2314
  try {
2311
2315
  await assertOwnershipAuthorization(this.permissionContexts.get(sessionId));
2312
2316
  }