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.
- package/CHANGELOG.md +31 -2
- package/bin/ec-safe-output.js +4 -1
- package/dist/ability/application-service.js +882 -0
- package/dist/ability/authorization.js +70 -0
- package/dist/ability/command-contract.js +105 -0
- package/dist/ability/daemon.js +137 -0
- package/dist/ability/development.js +450 -0
- package/dist/ability/environment.js +75 -0
- package/dist/ability/interop-v1.js +547 -0
- package/dist/ability/management.js +79 -0
- package/dist/ability/package.js +264 -0
- package/dist/ability/provider.js +73 -0
- package/dist/ability/publication.js +107 -0
- package/dist/ability/resources.js +106 -0
- package/dist/ability/runtime.js +212 -0
- package/dist/ability/secrets.js +47 -0
- package/dist/ability/store.js +112 -0
- package/dist/ability/toolchain.js +69 -0
- package/dist/ability/types.js +14 -0
- package/dist/ability/versions.js +32 -0
- package/dist/agents/baseagent.js +2 -2
- package/dist/agents/claude-runner.js +4 -0
- package/dist/agents/codex-runner.js +81 -17
- package/dist/agents/ecagent-plugin-lazy.js +41 -0
- package/dist/agents/ecagent-runner.js +18 -11
- package/dist/aun/ability-device-routing.js +12 -1
- package/dist/aun/aid/agentmd.js +2 -2
- package/dist/aun/aid/identity.js +45 -0
- package/dist/aun/aid/index.js +1 -0
- package/dist/aun/aid/managed-operation.js +73 -2
- package/dist/channels/aun.js +64 -18
- package/dist/channels/builtin-plugins.js +14 -0
- package/dist/channels/dingtalk.js +78 -26
- package/dist/channels/feishu.js +89 -14
- package/dist/channels/qqbot.js +84 -19
- package/dist/channels/wechat.js +77 -19
- package/dist/channels/wecom.js +67 -22
- package/dist/cli/ability-command.js +92 -0
- package/dist/cli/aun-commands.js +124 -85
- package/dist/cli/daemon-commands.js +37 -85
- package/dist/cli/index.js +14 -0
- package/dist/cli/init.js +11 -13
- package/dist/cli/managed-command-guard.js +6 -0
- package/dist/cli/model.js +101 -104
- package/dist/cli/provider-command.js +6 -4
- package/dist/cli/restart-monitor.js +52 -11
- package/dist/cli/upgrade-command.js +102 -0
- package/dist/cli/version.js +1 -1
- package/dist/config/access-policy.js +4 -2
- package/dist/config/builtin-roles.js +1 -0
- package/dist/config/config-field-policy.js +4 -0
- package/dist/config/config-manager.js +7 -0
- package/dist/config/provider-ipc-service.js +10 -0
- package/dist/config/providers-config.js +12 -3
- package/dist/config/providers-management.js +45 -9
- package/dist/config/schema-migration.js +40 -22
- package/dist/contracts/ecweb-service-protocol.js +2 -1
- package/dist/core/auth/agent-delegation.js +21 -5
- package/dist/core/auth/auth-gateway.js +31 -9
- package/dist/core/auth/authorization-audit.js +52 -4
- package/dist/core/auth/delegation-authorization.js +140 -4
- package/dist/core/auth/operation-authorizer.js +114 -13
- package/dist/core/auth/operation-catalog.js +118 -4
- package/dist/core/baseagent-loader.js +14 -1
- package/dist/core/channel-loader.js +47 -9
- package/dist/core/channel-runtime.js +1 -1
- package/dist/core/command/agent-storage-menu.js +1 -1
- package/dist/core/command/cli-intent-parser.js +26 -13
- package/dist/core/command/command-handler.js +232 -76
- package/dist/core/command/connect-menu.js +10 -4
- package/dist/core/command/daemon-diagnostics.js +3 -3
- package/dist/core/command/data-root-resolver.js +2 -3
- package/dist/core/command/menu-catalog.js +10 -3
- package/dist/core/command/menu-handler.js +321 -46
- package/dist/core/command/menu-protocol.js +53 -7
- package/dist/core/command/pa-workspace-calendar.js +1 -2
- package/dist/core/command/pa-workspace-items.js +486 -0
- package/dist/core/command/pa-workspace-store.js +10 -1
- package/dist/core/command/slash-gate.js +2 -2
- package/dist/core/command/slash-handler.js +67 -25
- package/dist/core/contact-bind-registry.js +27 -0
- package/dist/core/daemon-control.js +3 -3
- package/dist/core/daemon-lifecycle.js +2 -1
- package/dist/core/event-bus.js +9 -2
- package/dist/core/handoff/ipc-registration.js +1 -0
- package/dist/core/host-snapshot.js +1 -2
- package/dist/core/initialization/service.js +32 -11
- package/dist/core/ipc-registration.js +18 -5
- package/dist/core/memory/consolidation-context.js +2 -2
- package/dist/core/message/aun-request-registry.js +99 -18
- package/dist/core/message/im-renderer.js +16 -11
- package/dist/core/message/message-admission.js +25 -20
- package/dist/core/message/message-bridge.js +21 -47
- package/dist/core/message/message-queue.js +3 -0
- package/dist/core/message/response-engine.js +7 -5
- package/dist/core/model/catalog-service.js +1 -1
- package/dist/core/permission/ec-command-parser.js +41 -9
- package/dist/core/permission/permission-result.js +1 -0
- package/dist/core/permission/protected-paths.js +25 -14
- package/dist/core/permission/tool-policy.js +108 -107
- package/dist/core/plugin-lifecycle.js +133 -0
- package/dist/core/runner-reload-transaction.js +4 -1
- package/dist/core/system-session/memory.js +16 -3
- package/dist/core/task/task-activity-store.js +50 -0
- package/dist/core/task/task-image-resources.js +140 -0
- package/dist/core/thread/ipc-operation.js +1 -1
- package/dist/core/thread/thread-service.js +0 -1
- package/dist/directory/canonical-digest.js +5 -3
- package/dist/directory/owner-directory-admission.js +22 -2
- package/dist/directory/owner-directory-cache.js +394 -60
- package/dist/directory/owner-directory-markdown.js +29 -2
- package/dist/directory/owner-directory-scope.js +35 -16
- package/dist/ecweb/basic-settings-service.js +4 -1
- package/dist/ecweb/pairing.js +41 -0
- package/dist/ecweb/providers-service.js +8 -1
- package/dist/{utils/ecweb-utils.js → ecweb/runtime/launch.js} +3 -27
- package/dist/ecweb/runtime/lifecycle.js +184 -0
- package/dist/{utils/ecweb-supervisor.js → ecweb/runtime/supervisor.js} +32 -27
- package/dist/index.js +34 -25
- package/dist/ipc.js +124 -7
- package/dist/response-system/engines/v1/proactive-flow.js +1 -1
- package/dist/trigger/authorization.js +2 -2
- package/dist/utils/atomic-write.js +24 -0
- package/dist/utils/avatar-upload.js +3 -1
- package/dist/utils/cross-platform.js +31 -2
- package/dist/utils/host-info.js +36 -0
- package/dist/utils/instance-registry.js +38 -11
- package/dist/utils/logger.js +9 -0
- package/dist/utils/{process-tree-stats.js → process-tree.js} +29 -0
- package/dist/utils/tool-summary.js +9 -1
- package/dist/utils/upgrade-jobs.js +96 -15
- package/dist/utils/windows-autostart.js +1 -1
- package/ecagent/README.md +19 -0
- package/ecagent/dist/harness/agent-harness.js +9 -0
- package/ecagent/dist/harness/env/nodejs.js +71 -11
- package/ecagent/dist/harness/env/windows-shell.d.ts +7 -0
- package/ecagent/dist/harness/env/windows-shell.js +132 -0
- package/kits/docs/aun/ABILITY_CALLING.md +38 -9
- package/kits/docs/evolcore/INDEX.md +5 -1
- package/kits/docs/evolcore/ability.md +181 -0
- package/kits/docs/evolcore/aid.md +20 -0
- package/kits/docs/evolcore/config.md +10 -6
- package/kits/docs/evolcore/menu-protocol.md +40 -1
- package/kits/docs/evolcore/provider.md +2 -2
- package/kits/docs/evolcore/tool-authorization.md +270 -0
- package/kits/runtime/ability-job.ps1 +41 -0
- package/kits/runtime/ability-runner.mjs +67 -0
- package/kits/runtime/ability-secret.ps1 +59 -0
- package/kits/runtime/ability-templates/go/main.go +59 -0
- package/kits/runtime/ability-templates/java/Json.java +67 -0
- package/kits/runtime/ability-templates/java/Runner.java +42 -0
- package/kits/runtime/ability-templates/python/runner.py +48 -0
- package/kits/runtime/ability-templates/rust/json.rs +87 -0
- package/kits/runtime/ability-templates/rust/runner.rs +35 -0
- package/kits/schemas/_meta.json +12 -1
- package/kits/schemas/ability-plugin.schema.1.json +107 -0
- package/kits/schemas/ability-project.schema.1.json +31 -0
- package/kits/schemas/agent-config.schema.16.json +20 -0
- package/kits/schemas/agent-config.schema.17.json +20 -0
- package/kits/schemas/agent-config.schema.18.json +917 -0
- package/kits/skills/.switches.json +4 -0
- package/kits/skills/aid-ability/SKILL.md +5 -4
- package/kits/skills/ec-ability/SKILL.md +67 -0
- package/kits/skills/ec-ability/references/contract-checklist.md +37 -0
- package/kits/skills/ec-ability/references/development.md +104 -0
- package/kits/skills/ec-ability/references/management.md +117 -0
- package/kits/skills/ec-ability/references/recovery.md +27 -0
- package/kits/skills/ec-ability/references/runtime-protocol.md +109 -0
- package/kits/skills/ec-ability/references/workflows.md +15 -0
- package/kits/skills/ec-service-proxy/SKILL.md +12 -0
- package/kits/skills/personal-assistant/SKILL.md +240 -6
- package/kits/skills/personal-assistant/references/02-bootstrap.md +78 -4
- package/kits/skills/personal-assistant/scripts/clean.mjs +397 -0
- package/kits/skills/personal-assistant/scripts/init.mjs +113 -25
- package/kits/skills/personal-assistant/scripts/lock.mjs +189 -0
- package/kits/skills/personal-assistant/scripts/migrate.mjs +35 -10
- package/kits/skills/personal-assistant/scripts/verify.mjs +2 -1
- package/kits/skills/personal-assistant/templates/persona-section.md +54 -0
- package/kits/skills/personal-assistant/triggers/ingest-daily.json +1 -1
- package/kits/templates/memory-consolidation/notes.md +1 -1
- package/kits/templates/system-fragments/channel.md +2 -1
- package/kits/templates/system-fragments/commands.md +1 -0
- package/package.json +4 -2
- package/dist/core/command/data-root-error.js +0 -10
- package/dist/utils/machine-info.js +0 -46
- package/dist/utils/process-tree-worker.js +0 -31
- package/dist/utils/windows-output.js +0 -36
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
> 状态:[done]
|
|
2
|
+
> 创建:2026-11-02
|
|
3
|
+
> 类型:工具执行、审批与 EC 授权说明
|
|
4
|
+
> 归档来源:2026-11-02 与 Owner 的两轮图解说明;决策模型等预留能力在正文中单独标明,尚未启用。
|
|
5
|
+
|
|
6
|
+
# 工具执行、审批与授权:流程图与身份对照
|
|
7
|
+
|
|
8
|
+
本文保存两部分说明:
|
|
9
|
+
|
|
10
|
+
1. [工具调用怎样经过预检、审批和 EC 授权](#一工具执行审批与授权总览)。
|
|
11
|
+
2. [trusted fullaccess 与 DaemonOwner 有什么区别](#二trusted-fullaccess-与-daemonowner)。
|
|
12
|
+
|
|
13
|
+
阅读口径:说明已改造的托管 EC 授权主链路;不是所有命令、Handler 或远端协议检查均已迁移完毕的声明。源码修改构建成功后,运行中的 daemon 仍需宿主重启才加载新代码。
|
|
14
|
+
|
|
15
|
+
## 一、工具执行、审批与授权总览
|
|
16
|
+
|
|
17
|
+
> 工具调用要过三道门:**能不能安全发起、谁有权批准、目标资源是否允许访问。**
|
|
18
|
+
|
|
19
|
+
### 1. 先看整体流程
|
|
20
|
+
|
|
21
|
+
```mermaid
|
|
22
|
+
flowchart TD
|
|
23
|
+
A[模型发起工具调用] --> B{工具预检}
|
|
24
|
+
|
|
25
|
+
B -->|命令结构或路径不安全| X[拒绝执行并记录原因]
|
|
26
|
+
B -->|普通工具| C{是否需要审批}
|
|
27
|
+
|
|
28
|
+
C -->|不需要| H[执行工具]
|
|
29
|
+
C -->|需要人工审批| D[PermissionGateway]
|
|
30
|
+
C -->|bypass 且策略允许| H
|
|
31
|
+
D -->|批准或命中有效临时授权| H
|
|
32
|
+
D -->|拒绝、超时或审批不可用| X
|
|
33
|
+
|
|
34
|
+
B -->|ec 命令| E[解析并规范化 EC 命令]
|
|
35
|
+
E --> F[携带 session、delegation 和命令指纹进入 daemon]
|
|
36
|
+
F --> G[验证会话、任务凭据和命令绑定]
|
|
37
|
+
G -->|失败| X
|
|
38
|
+
G -->|通过| I[构造可信授权主体 AuthSubject]
|
|
39
|
+
I --> J[Operation Catalog 查操作元数据]
|
|
40
|
+
|
|
41
|
+
J --> K{执行身份}
|
|
42
|
+
K -->|trusted fullaccess| L[通用 EC 授权分支]
|
|
43
|
+
K -->|Owner + bypass| M[明确授予的 Agent 与 Owner 范围]
|
|
44
|
+
K -->|DaemonOwner| N[明确授予的主机管理操作]
|
|
45
|
+
K -->|其他角色| O[角色、关系和渠道规则]
|
|
46
|
+
|
|
47
|
+
L --> P[命令 Handler 与远端协议检查目标资源]
|
|
48
|
+
M --> P
|
|
49
|
+
N --> P
|
|
50
|
+
O --> P
|
|
51
|
+
P -->|不满足| X
|
|
52
|
+
P -->|满足| H
|
|
53
|
+
H --> Q[记录授权依据、执行状态和结果]
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
**怎么看这张图:**
|
|
57
|
+
|
|
58
|
+
- 普通工具主要经过工具策略与审批网关;不需要为了执行普通工具去查询 EC Operation Catalog。
|
|
59
|
+
- EC 命令通过工具预检,仅表示可以进入命令处理,不代表取得目标资源权限。
|
|
60
|
+
- trusted fullaccess 在统一授权器中优先于普通角色、来源和 DaemonOwner 门槛,但仍保留命令结构、专用协议以及当前实例生命周期保护。
|
|
61
|
+
- 图中拒绝出口和后续执行都有对应诊断/审计机制;部分历史入口的记录方式仍各有实现。
|
|
62
|
+
|
|
63
|
+
### 2. 这些名称分别管什么
|
|
64
|
+
|
|
65
|
+
| 身份或模式 | 主要作用 | 能力边界 |
|
|
66
|
+
|---|---|---|
|
|
67
|
+
| `readonly / auto / request` | 普通任务的执行策略 | 还要结合角色、关系、工具策略与命令权限;其中 `request` 可进入人工审批 |
|
|
68
|
+
| `bypass` | 对策略允许的操作免去交互审批 | 不自动取得 EC 业务权限,不自动成为 DaemonOwner |
|
|
69
|
+
| `Owner + bypass` | Agent Owner 身份与 bypass 任务模式的组合 | 可使用明确标注的 Agent/Owner 能力,目标范围仍须符合规则 |
|
|
70
|
+
| `trusted fullaccess` | daemon 验证过的任务执行身份 | 以 `fullaccess-run` 进入通用授权路径,保留当前实例保护与命令自身校验 |
|
|
71
|
+
| `DaemonOwner` | 主机管理主体身份 | 在受认证的管理入口执行明确授予的 process/control 操作 |
|
|
72
|
+
|
|
73
|
+
Agent Owner 和 DaemonOwner 是两个独立身份维度。一个人可以同时拥有两者,但不能仅凭某个 Agent 的 Owner 角色推导出主机所有权。
|
|
74
|
+
|
|
75
|
+
```text
|
|
76
|
+
Owner + bypass
|
|
77
|
+
= Agent Owner 身份
|
|
78
|
+
+ bypass 任务模式
|
|
79
|
+
+ 明确授予的 Agent/Owner 操作与目标范围
|
|
80
|
+
|
|
81
|
+
trusted fullaccess
|
|
82
|
+
= daemon 签发并验证的 fullaccess 任务执行身份
|
|
83
|
+
+ daemon 级执行范围
|
|
84
|
+
+ 当前实例保护和协议/资源检查
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### 3. 用命令举例
|
|
88
|
+
|
|
89
|
+
下表描述这次改造后的典型授权路径,不代替具体命令的参数、目标和远端权限检查。
|
|
90
|
+
|
|
91
|
+
| 命令/操作 | Owner + bypass 托管任务 | trusted fullaccess 任务 | DaemonOwner 管理请求 |
|
|
92
|
+
|---|---|---|---|
|
|
93
|
+
| `ec aid list` | 可列本地身份及受支持的筛选项 | 可执行 | 宿主或受支持的控制面入口处理 |
|
|
94
|
+
| `ec directory list --self <aid>` | 需要符合当前 Agent/同 Owner 的目标范围 | 可进入授权执行路径 | 不能仅凭 DaemonOwner 身份推导出该 Agent 的 Owner 关系 |
|
|
95
|
+
| `ec provider list` | 不能单凭 Agent Owner+bypass 获得进程权限 | 通用授权允许 | 受认证的 DaemonOwner 控制入口允许 |
|
|
96
|
+
| `ec fs` 访问当前 Agent 个人存储 | Owner 身份满足个人存储角色要求,路径等仍需通过 | 通过通用角色授权,资源校验仍在 | 不从 DaemonOwner 自动推导出 Agent Owner 关系 |
|
|
97
|
+
| `ec msg history` 的非 AUN selector | CLI 送 daemon 判断;普通托管任务仍受 Trigger 等专用目标约束 | 可通过相关授权分支,仍验证 selector 和历史资源 | 取决于实际请求入口,不是一般的 process 操作 |
|
|
98
|
+
| 重启承载当前任务的 EvolCore 实例 | bypass 不解除保护 | fullaccess 也不解除保护 | 可由获准的宿主管理入口执行;托管任务不能借操作人的 Owner 身份绕过保护 |
|
|
99
|
+
|
|
100
|
+
### 4. 普通工具的人工审批怎样工作
|
|
101
|
+
|
|
102
|
+
```text
|
|
103
|
+
检查工具和输入
|
|
104
|
+
│
|
|
105
|
+
├─ 策略直接允许 ───────────────→ 执行
|
|
106
|
+
│
|
|
107
|
+
├─ 策略直接拒绝 ───────────────→ 返回具体拒绝原因
|
|
108
|
+
│
|
|
109
|
+
└─ 需要人工审批
|
|
110
|
+
│
|
|
111
|
+
├─ 命中有效的临时授权 ─→ 执行
|
|
112
|
+
│
|
|
113
|
+
└─ 创建审批请求
|
|
114
|
+
│
|
|
115
|
+
├─ 审批人身份与授权仍有效,批准 ─→ 执行
|
|
116
|
+
└─ 拒绝、超时、撤销或基础设施失败 → 不执行
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
`bypass` 只免去符合策略的交互审批。单独要求管理者审批的操作,仍按该操作的审批范围处理,不能笼统理解成“危险操作全部免审”。
|
|
120
|
+
|
|
121
|
+
临时批准不是给工具发一张永久通行证:
|
|
122
|
+
|
|
123
|
+
```text
|
|
124
|
+
临时授权匹配条件
|
|
125
|
+
sessionId
|
|
126
|
+
+ toolName
|
|
127
|
+
+ 输入指纹或批准的文件系统范围
|
|
128
|
+
+ 授权上下文
|
|
129
|
+
+ 有效期
|
|
130
|
+
+ 审批人当前仍具备相应资格
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
例如,“批准本次上传文件 A”不会自动变成“以后可以上传任意文件”。如果审批人选择了界面明确提供的目录范围授权,则只能在该范围和有效期内复用。
|
|
134
|
+
|
|
135
|
+
### 5. EC 命令由谁负责判断
|
|
136
|
+
|
|
137
|
+
| 环节 | 负责什么 | 输出 |
|
|
138
|
+
|---|---|---|
|
|
139
|
+
| 工具预检/Runner | 命令结构、Shell、路径、当前执行策略与获准调用绑定 | 允许继续、需要审批或拒绝 |
|
|
140
|
+
| EC CLI | 参数解析、命令规范化、身份/路由补全及 IPC 请求 | 结构化命令与托管凭据 |
|
|
141
|
+
| daemon 身份验证 | delegation、session、self AID、任务与命令指纹是否匹配 | 可信 `AuthSubject` |
|
|
142
|
+
| Operation Catalog + 授权器 | operation、scope、来源、角色、Owner/DaemonOwner/fullaccess 等规则 | 有理由和命中规则的授权结果 |
|
|
143
|
+
| Handler/资源/远端协议 | 实际文件、AID、群、存储、身份与协议条件 | 执行结果或具体资源/协议拒绝 |
|
|
144
|
+
|
|
145
|
+
这次移除了 managed AID、消息和群 CLI 中重复的若干角色/关系预检,把判断交给 daemon。仍存在历史入口和专用检查;本文不把架构方向写成所有命令已经零残留的承诺。
|
|
146
|
+
|
|
147
|
+
**Agent 目标字段:**Operation Catalog 声明了 `authorizationTarget` 的操作,调用入口必须显式生成
|
|
148
|
+
`intent.args.targetAgentAid`。该字段来自已解析的命令目标或已绑定的 Agent 上下文,不新增公共 CLI
|
|
149
|
+
参数,也不直接信任客户端自报的同名授权字段。普通授权路径缺少该字段时拒绝;授权器不再从
|
|
150
|
+
`aid`、`self`、`targetId` 兼容推断 Agent 目标。`self` 继续表示调用上下文,`targetId` 可表示群、
|
|
151
|
+
关系或其他资源,二者不替代 Agent 目标。已有 trusted fullaccess 通用授权的先后顺序不变,
|
|
152
|
+
命令结构、Handler 和远端协议检查仍保留。
|
|
153
|
+
|
|
154
|
+
### 6. 审计怎样区分“谁放行的”
|
|
155
|
+
|
|
156
|
+
审计分别记录决策来源、执行身份和未来凭证来源,不能把它们当成同一个枚举:
|
|
157
|
+
|
|
158
|
+
| 维度 | 典型字段/值 | 回答的问题 |
|
|
159
|
+
|---|---|---|
|
|
160
|
+
| 决策来源 | `decisionSource`:如 `policy`、`approval`、`infrastructure`、`command` | 是策略、审批、基础设施还是命令处理产生的结果? |
|
|
161
|
+
| 执行身份 | `processRole`:`none`、`fullaccess-run`、`daemon-owner`、`daemon-service` | 谁以什么进程权限执行? |
|
|
162
|
+
| 审批机制 | `approvalMechanism`:`human`、`decision-model` | 是人工审批还是模型审批?后者尚未启用 |
|
|
163
|
+
| 普通 Owner 放行凭证 | `authorizationCredentialId` | 哪张 Owner 凭证授权此次操作?预留 |
|
|
164
|
+
| 模型审批能力凭证 | `approvalAuthorizationCredentialId` | Owner 凭哪张能力凭证允许该模型审批?预留 |
|
|
165
|
+
| 本次工具审批结果 | `approvalCredentialId`、`approvalProviderId`、`approvalModelId` | 哪次决定、哪个 Provider/模型作出审批?预留 |
|
|
166
|
+
|
|
167
|
+
这样可以把“策略拒绝”“人工明确拒绝”“审批超时/不可用”和“命令实际执行失败”区分开。
|
|
168
|
+
|
|
169
|
+
### 7. 已做预留,但尚未启用的两项能力
|
|
170
|
+
|
|
171
|
+
**Owner 签名放行凭证:**预留主体、Agent、session/task、operation、目标、精确输入指纹、时间和签名。未来必须由 daemon 验证,不能仅凭调用者传入一个对象就取得权限。
|
|
172
|
+
|
|
173
|
+
**决策模型工具审批:**把 Owner 授予模型的审批能力与模型对单次输入的决定分开。
|
|
174
|
+
|
|
175
|
+
```mermaid
|
|
176
|
+
flowchart TD
|
|
177
|
+
A[Owner 签发模型审批能力凭证] --> B[daemon 验证 Owner、签名和 provider/model/tool 范围]
|
|
178
|
+
B --> C[提交本次工具请求与输入指纹]
|
|
179
|
+
C --> D[模型返回 approve-once / deny / abstain]
|
|
180
|
+
D --> E[daemon 核验结果与请求、签名和有效期]
|
|
181
|
+
E --> F[结合现有授权边界执行或拒绝]
|
|
182
|
+
F --> G[审计保留能力凭证和单次结果的不同来源]
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
| 内容 | 回答的问题 | 绑定范围 |
|
|
186
|
+
|---|---|---|
|
|
187
|
+
| Owner 放行凭证 | “允许这项具体操作吗?” | 主体、session/task、operation、目标与输入指纹 |
|
|
188
|
+
| 模型审批能力凭证 | “这个 Provider/模型有没有资格审批这类工具?” | Agent、Owner、Provider、模型、工具范围及有效期 |
|
|
189
|
+
| 模型单次审批结果 | “是否批准这一次具体工具输入?” | Agent、session/task/request、工具、输入指纹、模型和有效期 |
|
|
190
|
+
|
|
191
|
+
能力凭证本身不等于本次输入已获批准;模型的 `approve-once` 也不等于取得新的永久角色。当前只有类型、证据上下文和审计字段预留,verifier 与实际放行策略尚未启用,现有人工审批流程继续工作。
|
|
192
|
+
|
|
193
|
+
## 二、trusted fullaccess 与 DaemonOwner
|
|
194
|
+
|
|
195
|
+
> **trusted fullaccess 说明“这次任务拿到了多大的执行范围”;DaemonOwner 说明“当前是谁在操作这台主机”。**
|
|
196
|
+
|
|
197
|
+
### 1. 两条不同的授权来源
|
|
198
|
+
|
|
199
|
+
```mermaid
|
|
200
|
+
flowchart LR
|
|
201
|
+
A[daemon 验证任务获准 fullaccess] --> B[身份:fullaccess-run]
|
|
202
|
+
B --> C[EC 通用授权分支]
|
|
203
|
+
C --> D[仍检查命令结构、目标资源和当前实例保护]
|
|
204
|
+
|
|
205
|
+
E[认证当前操作人或管理凭据] --> F{具备 DaemonOwner 且入口符合要求?}
|
|
206
|
+
F -->|是| G[身份:daemon-owner]
|
|
207
|
+
F -->|否| H[不具备该请求的 DaemonOwner 管理权限]
|
|
208
|
+
G --> I[执行明确授予的主机管理操作]
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
### 2. 对照着看
|
|
212
|
+
|
|
213
|
+
| 对比项 | trusted fullaccess | DaemonOwner |
|
|
214
|
+
|---|---|---|
|
|
215
|
+
| 代表什么 | daemon 验证的任务执行授权 | 经过认证的主机管理主体/管理身份 |
|
|
216
|
+
| 授权对象 | 当前任务;可由一次性任务或已获准策略产生 | 当前操作人及其受认证的管理请求 |
|
|
217
|
+
| daemon 中的身份 | `fullaccess-run` | `daemon-owner` |
|
|
218
|
+
| 权限方式 | 对已知且结构合法的 operation 走通用授权分支 | 根据 operation、scope 和受支持控制入口明确授权 |
|
|
219
|
+
| 常见场景 | 模型执行获准的主机级任务 | 管理 Provider、网关、主机服务等控制面资源 |
|
|
220
|
+
| 当前实例保护 | 托管任务不能重启、停止或替换承载自身的实例 | 宿主管理请求可以按授权管理实例;不能据此让托管任务绕过自身保护 |
|
|
221
|
+
| 与 Agent Owner 的关系 | 任务身份不自动变成该 Agent 的 Owner | 主机身份也不自动成为各 Agent 关系中的 Owner |
|
|
222
|
+
| 能否冒充批准人 | 不能把任务获准执行当作主机 Owner 本人批准 | 本人审批仍要求可信身份、通道与相应审批资格 |
|
|
223
|
+
|
|
224
|
+
### 3. 同一个命令,为什么两者都能执行
|
|
225
|
+
|
|
226
|
+
以 `ec provider list` 为例:
|
|
227
|
+
|
|
228
|
+
```text
|
|
229
|
+
受信任的 fullaccess 任务
|
|
230
|
+
→ 验证 delegation 和 fullaccess 执行身份
|
|
231
|
+
→ 命中 fullaccess-run 通用授权
|
|
232
|
+
→ 执行 Provider 查询
|
|
233
|
+
|
|
234
|
+
DaemonOwner 管理请求
|
|
235
|
+
→ 认证请求者或管理凭据
|
|
236
|
+
→ 检查控制入口、process scope 和 DaemonOwner 策略
|
|
237
|
+
→ 执行 Provider 查询
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
**命令相同,授权理由不同。**审计也保留不同身份,不能把任务记录成 Owner 本人在执行。
|
|
241
|
+
|
|
242
|
+
### 4. 哪些结论不能从一个名字推导出来
|
|
243
|
+
|
|
244
|
+
| 已知事实 | 不能自动推导的结论 |
|
|
245
|
+
|---|---|
|
|
246
|
+
| “这次任务是 fullaccess” | “这个 Agent 从此成为 DaemonOwner” |
|
|
247
|
+
| “这次任务由 DaemonOwner 授权” | “任务本身就是 Owner,能代替本人作新的持久审批” |
|
|
248
|
+
| “请求者是 DaemonOwner” | “请求者自然拥有所有 Agent 的关系 Owner 权限” |
|
|
249
|
+
| “工具审批通过” | “后续 EC 命令、目标资源和远端协议一定允许” |
|
|
250
|
+
| “当前任务 fullaccess 已获准” | “可以重启承载自己的 EvolCore 实例” |
|
|
251
|
+
|
|
252
|
+
当前实现会把 `fullaccess-run` 与 `isDaemonOwner` 分开。持久 fullaccess Trigger 的审批也保留独立的人类/管理入口授权,不能拿一个正在执行的任务当作新的宿主本人批准。
|
|
253
|
+
|
|
254
|
+
## 三、查实现时从哪里开始
|
|
255
|
+
|
|
256
|
+
以下相对链接指向仓库源码。本文按 2026-11-02 的实现说明整理,后续行为变化应同时更新说明。
|
|
257
|
+
|
|
258
|
+
| 关注点 | 入口 |
|
|
259
|
+
|---|---|
|
|
260
|
+
| 工具预检、EC 命令分类与路径策略 | [`tool-policy.ts`](../../../src/core/permission/tool-policy.ts) |
|
|
261
|
+
| 人工审批、临时授权、输入指纹与有效期 | [`approval-gateway.ts`](../../../src/core/permission/approval-gateway.ts) |
|
|
262
|
+
| 任务 delegation 与可信执行身份 | [`agent-delegation.ts`](../../../src/core/auth/agent-delegation.ts) |
|
|
263
|
+
| AuthSubject、所有权刷新和统一授权上下文 | [`auth-gateway.ts`](../../../src/core/auth/auth-gateway.ts) |
|
|
264
|
+
| Operation Catalog 元数据 | [`operation-catalog.ts`](../../../src/core/auth/operation-catalog.ts) |
|
|
265
|
+
| Fullaccess、Owner/DaemonOwner 与角色规则 | [`operation-authorizer.ts`](../../../src/core/auth/operation-authorizer.ts) |
|
|
266
|
+
| 审批结果结构 | [`permission-result.ts`](../../../src/core/permission/permission-result.ts) |
|
|
267
|
+
| 授权与审批审计 | [`authorization-audit.ts`](../../../src/core/auth/authorization-audit.ts) |
|
|
268
|
+
| 预留的签名凭证、Verifier 与模型审批接口 | [`types.ts`](../../../src/types.ts) |
|
|
269
|
+
|
|
270
|
+
相关使用手册:[配置与权限](config.md)、[Provider](provider.md)、[文件系统](fs.md)、[消息](msg.md)、[Trigger](trigger.md)。旧文档与当前源码不一致时,以源码和当前授权结果为准。
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
$ErrorActionPreference = 'Stop'
|
|
2
|
+
Add-Type -TypeDefinition @'
|
|
3
|
+
using System;
|
|
4
|
+
using System.Text;
|
|
5
|
+
using System.Runtime.InteropServices;
|
|
6
|
+
public static class AbilityJobHost {
|
|
7
|
+
[StructLayout(LayoutKind.Sequential)] struct SI { public int cb; public IntPtr reserved,desktop,title; public int x,y,cx,cy,xchars,ychars,fill,flags; public short show,reserved2; public IntPtr reserved3,input,output,error; }
|
|
8
|
+
[StructLayout(LayoutKind.Sequential)] struct PI { public IntPtr process,thread; public int pid,tid; }
|
|
9
|
+
[StructLayout(LayoutKind.Sequential)] struct IO { public ulong a,b,c,d,e,f; }
|
|
10
|
+
[StructLayout(LayoutKind.Sequential)] struct BASIC { public long processTime,jobTime; public uint flags; public UIntPtr min,max; public uint active; public UIntPtr affinity; public uint priority,scheduling; }
|
|
11
|
+
[StructLayout(LayoutKind.Sequential)] struct LIMIT { public BASIC basic; public IO io; public UIntPtr processMemory,jobMemory,peakProcess,peakJob; }
|
|
12
|
+
[DllImport("kernel32.dll",CharSet=CharSet.Unicode,SetLastError=true)] static extern IntPtr CreateJobObject(IntPtr attr,string name);
|
|
13
|
+
[DllImport("kernel32.dll",SetLastError=true)] static extern bool SetInformationJobObject(IntPtr job,int type,ref LIMIT value,int length);
|
|
14
|
+
[DllImport("kernel32.dll",CharSet=CharSet.Unicode,SetLastError=true)] static extern bool CreateProcess(string app,StringBuilder command,IntPtr pa,IntPtr ta,bool inherit,uint flags,IntPtr env,string cwd,ref SI si,out PI pi);
|
|
15
|
+
[DllImport("kernel32.dll",SetLastError=true)] static extern bool AssignProcessToJobObject(IntPtr job,IntPtr process);
|
|
16
|
+
[DllImport("kernel32.dll")] static extern uint ResumeThread(IntPtr thread);
|
|
17
|
+
[DllImport("kernel32.dll")] static extern uint WaitForSingleObject(IntPtr handle,uint ms);
|
|
18
|
+
[DllImport("kernel32.dll")] static extern bool GetExitCodeProcess(IntPtr process,out uint code);
|
|
19
|
+
[DllImport("kernel32.dll")] static extern bool TerminateProcess(IntPtr process,uint code);
|
|
20
|
+
[DllImport("kernel32.dll")] static extern bool CloseHandle(IntPtr handle);
|
|
21
|
+
[DllImport("kernel32.dll")] static extern IntPtr GetStdHandle(int value);
|
|
22
|
+
[DllImport("kernel32.dll",SetLastError=true)] static extern bool SetHandleInformation(IntPtr handle,uint mask,uint flags);
|
|
23
|
+
public static int Run(string node,string runner) {
|
|
24
|
+
if(node.Contains("\"") || runner.Contains("\"")) throw new Exception("Invalid executable path");
|
|
25
|
+
IntPtr job=CreateJobObject(IntPtr.Zero,null); if(job==IntPtr.Zero) throw new Exception("Job unavailable");
|
|
26
|
+
PI pi=new PI();
|
|
27
|
+
try {
|
|
28
|
+
LIMIT limit=new LIMIT(); limit.basic.flags=0x2000;
|
|
29
|
+
if(!SetInformationJobObject(job,9,ref limit,Marshal.SizeOf(typeof(LIMIT)))) throw new Exception("Job limits unavailable");
|
|
30
|
+
SI si=new SI(); si.cb=Marshal.SizeOf(typeof(SI)); si.flags=0x100;
|
|
31
|
+
si.input=GetStdHandle(-10); si.output=GetStdHandle(-11); si.error=GetStdHandle(-12);
|
|
32
|
+
foreach(IntPtr h in new[]{si.input,si.output,si.error}) if(!SetHandleInformation(h,1,1)) throw new Exception("Inherited pipe unavailable");
|
|
33
|
+
if(!CreateProcess(node,new StringBuilder("\""+node+"\" \""+runner+"\""),IntPtr.Zero,IntPtr.Zero,true,0x08000004,IntPtr.Zero,Environment.CurrentDirectory,ref si,out pi)) throw new Exception("Runner creation failed");
|
|
34
|
+
if(!AssignProcessToJobObject(job,pi.process)) { TerminateProcess(pi.process,70); throw new Exception("Job assignment failed"); }
|
|
35
|
+
if(ResumeThread(pi.thread)==0xffffffff) { TerminateProcess(pi.process,70); throw new Exception("Runner resume failed"); }
|
|
36
|
+
WaitForSingleObject(pi.process,0xffffffff); uint code; GetExitCodeProcess(pi.process,out code); return (int)code;
|
|
37
|
+
} finally { if(pi.thread!=IntPtr.Zero) CloseHandle(pi.thread); if(pi.process!=IntPtr.Zero) CloseHandle(pi.process); CloseHandle(job); }
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
'@
|
|
41
|
+
exit [AbilityJobHost]::Run($env:EC_ABILITY_NODE, $env:EC_ABILITY_RUNNER)
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import readline from 'node:readline';
|
|
2
|
+
import { pathToFileURL } from 'node:url';
|
|
3
|
+
import { Console } from 'node:console';
|
|
4
|
+
|
|
5
|
+
globalThis.console = new Console({ stdout: process.stderr, stderr: process.stderr });
|
|
6
|
+
const protocol = 'evolcore.ability-runtime/1';
|
|
7
|
+
const pending = new Map(); const invocations = new Map();
|
|
8
|
+
let plugin; let config; let sequence = 0; let initialized = false;
|
|
9
|
+
const send = frame => process.stdout.write(JSON.stringify({ protocol, ...frame }) + '\n');
|
|
10
|
+
function broker(invocationId, method, args) {
|
|
11
|
+
if (pending.size >= 240) return Promise.reject(new Error('Broker queue is full'));
|
|
12
|
+
const id = `r:${++sequence}`;
|
|
13
|
+
return new Promise((resolve, reject) => {
|
|
14
|
+
const timer = setTimeout(() => { pending.delete(id); reject(new Error('Broker timed out')); }, 10000);
|
|
15
|
+
pending.set(id, { resolve, reject, timer }); send({ id, method: 'broker.call', params: { invocationId, method, args } });
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
async function handle(frame) {
|
|
19
|
+
if (frame.protocol !== protocol || typeof frame.id !== 'string') throw new Error('Invalid runtime frame');
|
|
20
|
+
if (!frame.method) {
|
|
21
|
+
const waiter = pending.get(frame.id); if (!waiter) return;
|
|
22
|
+
pending.delete(frame.id); clearTimeout(waiter.timer);
|
|
23
|
+
frame.error ? waiter.reject(new Error(frame.error.message)) : waiter.resolve(frame.result); return;
|
|
24
|
+
}
|
|
25
|
+
try {
|
|
26
|
+
let result;
|
|
27
|
+
if (frame.method === 'initialize') {
|
|
28
|
+
if (initialized) throw new Error('Already initialized');
|
|
29
|
+
config = Object.freeze(frame.params.config);
|
|
30
|
+
plugin = (await import(pathToFileURL(frame.params.entry).href)).default;
|
|
31
|
+
if (!plugin || plugin.apiVersion !== '1' || !plugin.handlers || typeof plugin.handlers !== 'object') throw new Error('Invalid plugin export');
|
|
32
|
+
const handlers = Object.keys(plugin.handlers).sort();
|
|
33
|
+
if (JSON.stringify(handlers) !== JSON.stringify([...frame.params.handlers].sort()) || handlers.some(name => !Object.hasOwn(plugin.handlers, name) || typeof plugin.handlers[name] !== 'function')) throw new Error('Handler set differs from manifest');
|
|
34
|
+
let migratedData;
|
|
35
|
+
if (frame.params.migration) {
|
|
36
|
+
if (typeof plugin.migrateData !== 'function') throw new Error('Data migration handler is required');
|
|
37
|
+
migratedData = await plugin.migrateData(structuredClone(frame.params.migration));
|
|
38
|
+
if (!migratedData || typeof migratedData !== 'object' || Array.isArray(migratedData) || Buffer.byteLength(JSON.stringify(migratedData)) > 524288) throw new Error('Invalid migrated data');
|
|
39
|
+
}
|
|
40
|
+
await plugin.initialize?.(); const health = await plugin.health?.() ?? { ready: true };
|
|
41
|
+
if (health.ready !== true) throw new Error('Plugin is not ready'); initialized = true; result = { handlers, ready: true, ...(migratedData?{migratedData}:{}) };
|
|
42
|
+
} else if (frame.method === 'invoke') {
|
|
43
|
+
if (!initialized || !Object.hasOwn(plugin.handlers, frame.params.handler)) throw new Error('Unknown handler');
|
|
44
|
+
const input = frame.params; const controller = new AbortController(); invocations.set(input.invocationId, controller);
|
|
45
|
+
const call = (method, args) => broker(input.invocationId, method, args);
|
|
46
|
+
try {
|
|
47
|
+
result = await plugin.handlers[input.handler](input.params, {
|
|
48
|
+
invocationId: input.invocationId, operationId: input.operationId, idempotencyKey: input.idempotencyKey,
|
|
49
|
+
caller: Object.freeze(input.caller), signal: controller.signal, config,
|
|
50
|
+
host: { status: () => call('host.status', {}) },
|
|
51
|
+
storage: { get: key => call('storage.get', { key }), set: (key, value) => call('storage.set', { key, value }), delete: key => call('storage.delete', { key }) },
|
|
52
|
+
workspace: { read: file => call('workspace.read', { file }), write: (file, text) => call('workspace.write', { file, text }), list: file => call('workspace.list', { file }) },
|
|
53
|
+
http: { request: args => call('http.request', args) },
|
|
54
|
+
log: { info: console.info, warn: console.warn, error: console.error, debug: console.debug },
|
|
55
|
+
});
|
|
56
|
+
} finally { invocations.delete(input.invocationId); }
|
|
57
|
+
} else if (frame.method === 'cancel') { invocations.get(frame.params.invocationId)?.abort(); result = { cancelled: true }; }
|
|
58
|
+
else if (frame.method === 'health') result = initialized ? await plugin.health?.() ?? { ready: true } : { ready: false };
|
|
59
|
+
else if (frame.method === 'shutdown') { initialized = false; for (const item of invocations.values()) item.abort(); await plugin?.shutdown?.(); result = { stopped: true }; }
|
|
60
|
+
else throw new Error('Unknown runtime method');
|
|
61
|
+
send({ id: frame.id, result: result ?? null });
|
|
62
|
+
} catch (error) { send({ id: frame.id, error: { code: 'PLUGIN_FAILED', message: 'Plugin handler failed' } }); }
|
|
63
|
+
}
|
|
64
|
+
readline.createInterface({ input: process.stdin, crlfDelay: Infinity }).on('line', line => {
|
|
65
|
+
if (Buffer.byteLength(line) > 1024 * 1024) process.exit(70);
|
|
66
|
+
try { void handle(JSON.parse(line)).catch(() => process.exit(70)); } catch { process.exit(70); }
|
|
67
|
+
}).on('close', () => process.exit(0));
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
$ErrorActionPreference = 'Stop'
|
|
2
|
+
$stage = 'initialize'
|
|
3
|
+
try {
|
|
4
|
+
[Console]::InputEncoding = New-Object Text.UTF8Encoding($false)
|
|
5
|
+
[Console]::OutputEncoding = New-Object Text.UTF8Encoding($false)
|
|
6
|
+
Add-Type -AssemblyName System.Security
|
|
7
|
+
$inputRecord = [Console]::In.ReadToEnd() | ConvertFrom-Json
|
|
8
|
+
$directory = [IO.Path]::GetFullPath($inputRecord.directory)
|
|
9
|
+
$sid = [Security.Principal.WindowsIdentity]::GetCurrent().User
|
|
10
|
+
$stage = 'directory'
|
|
11
|
+
$systemSid = New-Object Security.Principal.SecurityIdentifier('S-1-5-18')
|
|
12
|
+
if (-not [IO.Directory]::Exists($directory)) {
|
|
13
|
+
$security = New-Object Security.AccessControl.DirectorySecurity
|
|
14
|
+
$security.SetOwner($sid)
|
|
15
|
+
$security.SetAccessRuleProtection($true, $false)
|
|
16
|
+
foreach ($identity in @($sid, $systemSid)) {
|
|
17
|
+
$rule = New-Object Security.AccessControl.FileSystemAccessRule($identity, 'FullControl', 'ContainerInherit,ObjectInherit', 'None', 'Allow')
|
|
18
|
+
$security.AddAccessRule($rule)
|
|
19
|
+
}
|
|
20
|
+
[IO.Directory]::CreateDirectory($directory, $security) | Out-Null
|
|
21
|
+
}
|
|
22
|
+
$item = Get-Item -LiteralPath $directory -Force
|
|
23
|
+
if (($item.Attributes -band [IO.FileAttributes]::ReparsePoint) -ne 0 -or $item.PSDrive.Provider.Name -ne 'FileSystem') { throw 'Invalid secret directory' }
|
|
24
|
+
$acl = Get-Acl -LiteralPath $directory
|
|
25
|
+
if (-not $acl.AreAccessRulesProtected -or $acl.GetOwner([Security.Principal.SecurityIdentifier]).Value -ne $sid.Value) { throw 'Invalid directory owner or DACL' }
|
|
26
|
+
foreach ($rule in $acl.GetAccessRules($true,$true,[Security.Principal.SecurityIdentifier])) {
|
|
27
|
+
if ($rule.AccessControlType -ne 'Allow' -or $rule.IdentityReference.Value -notin @($sid.Value,$systemSid.Value)) { throw 'Unexpected secret ACL principal' }
|
|
28
|
+
}
|
|
29
|
+
if ($inputRecord.action -eq 'probe') { [Console]::Out.Write('ready'); exit 0 }
|
|
30
|
+
if ($inputRecord.handle -notmatch '^[a-f0-9-]{36}$') { throw 'Invalid secret handle' }
|
|
31
|
+
$stage = 'object'
|
|
32
|
+
$file = [IO.Path]::Combine($directory, $inputRecord.handle + '.dpapi')
|
|
33
|
+
$entropy = [Text.Encoding]::UTF8.GetBytes('evolcore.ability-secret/v1:' + $inputRecord.binding)
|
|
34
|
+
if ($inputRecord.action -eq 'set') {
|
|
35
|
+
if ([IO.File]::Exists($file)) { throw 'Immutable secret exists' }
|
|
36
|
+
$bytes = [Text.Encoding]::UTF8.GetBytes($inputRecord.value)
|
|
37
|
+
try { $cipher = [Security.Cryptography.ProtectedData]::Protect($bytes,$entropy,[Security.Cryptography.DataProtectionScope]::CurrentUser) }
|
|
38
|
+
finally { [Array]::Clear($bytes,0,$bytes.Length) }
|
|
39
|
+
$stream = New-Object IO.FileStream($file,[IO.FileMode]::CreateNew,[IO.FileAccess]::Write,[IO.FileShare]::None)
|
|
40
|
+
try { $stream.Write($cipher,0,$cipher.Length); $stream.Flush($true) } finally { $stream.Dispose() }
|
|
41
|
+
$fileSecurity = New-Object Security.AccessControl.FileSecurity
|
|
42
|
+
$fileSecurity.SetOwner($sid)
|
|
43
|
+
$fileSecurity.SetAccessRuleProtection($true,$false)
|
|
44
|
+
foreach ($identity in @($sid,$systemSid)) { $fileSecurity.AddAccessRule((New-Object Security.AccessControl.FileSystemAccessRule($identity,'FullControl','Allow'))) }
|
|
45
|
+
Set-Acl -LiteralPath $file -AclObject $fileSecurity
|
|
46
|
+
}
|
|
47
|
+
$fileItem = Get-Item -LiteralPath $file -Force
|
|
48
|
+
if (($fileItem.Attributes -band [IO.FileAttributes]::ReparsePoint) -ne 0) { throw 'Invalid secret object' }
|
|
49
|
+
$fileAcl = Get-Acl -LiteralPath $file
|
|
50
|
+
if ($fileAcl.GetOwner([Security.Principal.SecurityIdentifier]).Value -ne $sid.Value) { throw 'Invalid secret owner' }
|
|
51
|
+
foreach ($rule in $fileAcl.GetAccessRules($true,$true,[Security.Principal.SecurityIdentifier])) {
|
|
52
|
+
if ($rule.AccessControlType -ne 'Allow' -or $rule.IdentityReference.Value -notin @($sid.Value,$systemSid.Value)) { throw 'Unexpected secret ACL principal' }
|
|
53
|
+
}
|
|
54
|
+
$clear = [Security.Cryptography.ProtectedData]::Unprotect([IO.File]::ReadAllBytes($file),$entropy,[Security.Cryptography.DataProtectionScope]::CurrentUser)
|
|
55
|
+
try {
|
|
56
|
+
if ($inputRecord.action -eq 'get') { [Console]::Out.Write([Convert]::ToBase64String($clear)) }
|
|
57
|
+
else { [Console]::Out.Write('ok') }
|
|
58
|
+
} finally { [Array]::Clear($clear,0,$clear.Length) }
|
|
59
|
+
} catch { [Console]::Error.Write('Ability secret backend unavailable: ' + $stage + ':' + $_.Exception.GetType().Name); exit 1 }
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// Readiness example using only the Go standard library.
|
|
2
|
+
package main
|
|
3
|
+
|
|
4
|
+
import (
|
|
5
|
+
"bufio"
|
|
6
|
+
"encoding/json"
|
|
7
|
+
"fmt"
|
|
8
|
+
"os"
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
type Frame struct {
|
|
12
|
+
Protocol string `json:"protocol"`
|
|
13
|
+
ID string `json:"id"`
|
|
14
|
+
Method string `json:"method"`
|
|
15
|
+
Params struct {
|
|
16
|
+
Handler string `json:"handler"`
|
|
17
|
+
Handlers []string `json:"handlers"`
|
|
18
|
+
Config map[string]interface{} `json:"config"`
|
|
19
|
+
Migration json.RawMessage `json:"migration"`
|
|
20
|
+
Params json.RawMessage `json:"params"`
|
|
21
|
+
} `json:"params"`
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
func main() {
|
|
25
|
+
const protocol = "evolcore.ability-runtime/1"
|
|
26
|
+
ready := false
|
|
27
|
+
decoder := json.NewDecoder(bufio.NewReader(os.Stdin))
|
|
28
|
+
encoder := json.NewEncoder(os.Stdout)
|
|
29
|
+
for {
|
|
30
|
+
var frame Frame
|
|
31
|
+
if err := decoder.Decode(&frame); err != nil { return }
|
|
32
|
+
if frame.Protocol != protocol || frame.ID == "" { os.Exit(70) }
|
|
33
|
+
if frame.Method == "" { continue }
|
|
34
|
+
response := map[string]interface{}{"protocol": protocol, "id": frame.ID}
|
|
35
|
+
var result interface{}
|
|
36
|
+
var failure string
|
|
37
|
+
switch frame.Method {
|
|
38
|
+
case "initialize":
|
|
39
|
+
if ready || len(frame.Params.Handlers) != 1 || frame.Params.Handlers[0] != "getReadiness" || len(frame.Params.Migration) > 0 {
|
|
40
|
+
failure = "Implement the declared handlers/data migration before enabling"
|
|
41
|
+
} else {
|
|
42
|
+
ready = true
|
|
43
|
+
result = map[string]interface{}{"ready": true, "handlers": []string{"getReadiness"}}
|
|
44
|
+
}
|
|
45
|
+
case "health": result = map[string]bool{"ready": ready}
|
|
46
|
+
case "invoke":
|
|
47
|
+
if !ready || frame.Params.Handler != "getReadiness" { failure = "Unknown handler or not ready" } else { result = map[string]bool{"ready": true} }
|
|
48
|
+
case "cancel": result = map[string]bool{"cancelled": false}
|
|
49
|
+
case "shutdown": ready = false; result = map[string]bool{"stopped": true}
|
|
50
|
+
default: failure = "Unsupported method"
|
|
51
|
+
}
|
|
52
|
+
if failure != "" {
|
|
53
|
+
fmt.Fprintln(os.Stderr, failure)
|
|
54
|
+
response["error"] = map[string]string{"code": "PLUGIN_FAILED", "message": "Plugin handler failed"}
|
|
55
|
+
} else { response["result"] = result }
|
|
56
|
+
if err := encoder.Encode(response); err != nil { return }
|
|
57
|
+
if frame.Method == "shutdown" { return }
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import java.math.BigDecimal;
|
|
2
|
+
import java.util.*;
|
|
3
|
+
|
|
4
|
+
/** Small JSON codec for the dependency-free example; applications can use their chosen codec. */
|
|
5
|
+
final class Json {
|
|
6
|
+
private final String text; private int at;
|
|
7
|
+
private Json(String text) { this.text = text; }
|
|
8
|
+
static Object parse(String text) {
|
|
9
|
+
var parser = new Json(text); Object value = parser.value(); parser.space();
|
|
10
|
+
if (parser.at != text.length()) throw new IllegalArgumentException("Trailing JSON data");
|
|
11
|
+
return value;
|
|
12
|
+
}
|
|
13
|
+
private void space() { while (at < text.length() && " \t\r\n".indexOf(text.charAt(at)) >= 0) at++; }
|
|
14
|
+
private char take() { if (at >= text.length()) throw new IllegalArgumentException("Incomplete JSON"); return text.charAt(at++); }
|
|
15
|
+
private boolean eat(char c) { space(); if (at < text.length() && text.charAt(at) == c) { at++; return true; } return false; }
|
|
16
|
+
private void need(char c) { if (!eat(c)) throw new IllegalArgumentException("Expected " + c); }
|
|
17
|
+
private Object value() {
|
|
18
|
+
space(); if (at == text.length()) throw new IllegalArgumentException("Missing value");
|
|
19
|
+
char c = text.charAt(at);
|
|
20
|
+
if (c == '"') return string();
|
|
21
|
+
if (c == '{') {
|
|
22
|
+
at++; var map = new LinkedHashMap<String, Object>(); if (eat('}')) return map;
|
|
23
|
+
do { space(); String key = string(); need(':'); map.put(key, value()); } while (eat(',')); need('}'); return map;
|
|
24
|
+
}
|
|
25
|
+
if (c == '[') {
|
|
26
|
+
at++; var list = new ArrayList<Object>(); if (eat(']')) return list;
|
|
27
|
+
do { list.add(value()); } while (eat(',')); need(']'); return list;
|
|
28
|
+
}
|
|
29
|
+
for (String literal : new String[]{"true", "false", "null"}) if (text.startsWith(literal, at)) {
|
|
30
|
+
at += literal.length(); return literal.equals("null") ? null : literal.equals("true");
|
|
31
|
+
}
|
|
32
|
+
int start = at; while (at < text.length() && "-+0123456789.eE".indexOf(text.charAt(at)) >= 0) at++;
|
|
33
|
+
String number = text.substring(start, at);
|
|
34
|
+
if (!number.matches("-?(0|[1-9][0-9]*)(\\.[0-9]+)?([eE][+-]?[0-9]+)?")) throw new IllegalArgumentException("Invalid number");
|
|
35
|
+
return new BigDecimal(number);
|
|
36
|
+
}
|
|
37
|
+
private String string() {
|
|
38
|
+
if (take() != '"') throw new IllegalArgumentException("Expected string"); var out = new StringBuilder();
|
|
39
|
+
for (;;) {
|
|
40
|
+
char c = take(); if (c == '"') return out.toString();
|
|
41
|
+
if (c < 32) throw new IllegalArgumentException("Invalid string");
|
|
42
|
+
if (c != '\\') { out.append(c); continue; }
|
|
43
|
+
char escape = take();
|
|
44
|
+
switch (escape) {
|
|
45
|
+
case '"': case '\\': case '/': out.append(escape); break;
|
|
46
|
+
case 'b': out.append('\b'); break; case 'f': out.append('\f'); break;
|
|
47
|
+
case 'n': out.append('\n'); break; case 'r': out.append('\r'); break; case 't': out.append('\t'); break;
|
|
48
|
+
case 'u': out.append((char) Integer.parseInt("" + take() + take() + take() + take(), 16)); break;
|
|
49
|
+
default: throw new IllegalArgumentException("Invalid escape");
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
static String stringify(Object value) {
|
|
54
|
+
if (value == null || value instanceof Boolean || value instanceof Number) return String.valueOf(value);
|
|
55
|
+
if (value instanceof String s) {
|
|
56
|
+
var out = new StringBuilder("\"");
|
|
57
|
+
for (char c : s.toCharArray()) { if (c == '"' || c == '\\') out.append('\\').append(c); else if (c < 32) out.append(String.format("\\u%04x", (int)c)); else out.append(c); }
|
|
58
|
+
return out.append('"').toString();
|
|
59
|
+
}
|
|
60
|
+
if (value instanceof Map<?, ?> map) {
|
|
61
|
+
var parts = new ArrayList<String>(); for (var row : map.entrySet()) parts.add(stringify(row.getKey()) + ":" + stringify(row.getValue()));
|
|
62
|
+
return "{" + String.join(",", parts) + "}";
|
|
63
|
+
}
|
|
64
|
+
if (value instanceof List<?> list) { var parts = new ArrayList<String>(); for (var item : list) parts.add(stringify(item)); return "[" + String.join(",", parts) + "]"; }
|
|
65
|
+
throw new IllegalArgumentException("Unsupported JSON value");
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import java.io.*;
|
|
2
|
+
import java.nio.charset.StandardCharsets;
|
|
3
|
+
import java.util.*;
|
|
4
|
+
|
|
5
|
+
/** Readiness example; stdout carries protocol frames only. */
|
|
6
|
+
public class Runner {
|
|
7
|
+
public static void main(String[] args) throws Exception {
|
|
8
|
+
boolean ready = false;
|
|
9
|
+
final String protocol = "evolcore.ability-runtime/1";
|
|
10
|
+
var input = new BufferedReader(new InputStreamReader(System.in, StandardCharsets.UTF_8));
|
|
11
|
+
var output = new PrintWriter(new OutputStreamWriter(System.out, StandardCharsets.UTF_8), true);
|
|
12
|
+
for (String line; (line = input.readLine()) != null;) {
|
|
13
|
+
var frame = (Map<?, ?>) Json.parse(line);
|
|
14
|
+
if (!protocol.equals(frame.get("protocol")) || !(frame.get("id") instanceof String)) System.exit(70);
|
|
15
|
+
if (!(frame.get("method") instanceof String method)) continue;
|
|
16
|
+
var response = new LinkedHashMap<String, Object>();
|
|
17
|
+
response.put("protocol", protocol); response.put("id", frame.get("id"));
|
|
18
|
+
try {
|
|
19
|
+
var params = (Map<?, ?>) frame.get("params");
|
|
20
|
+
Object result;
|
|
21
|
+
switch (method) {
|
|
22
|
+
case "initialize":
|
|
23
|
+
if (ready || !List.of("getReadiness").equals(params.get("handlers")) || params.containsKey("migration")) throw new IllegalStateException("Implement declared handlers/migration first");
|
|
24
|
+
ready = true; result = Map.of("ready", true, "handlers", List.of("getReadiness")); break;
|
|
25
|
+
case "health": result = Map.of("ready", ready); break;
|
|
26
|
+
case "invoke":
|
|
27
|
+
if (!ready || !"getReadiness".equals(params.get("handler"))) throw new IllegalArgumentException("Unknown handler or not ready");
|
|
28
|
+
result = Map.of("ready", true); break;
|
|
29
|
+
case "cancel": result = Map.of("cancelled", false); break;
|
|
30
|
+
case "shutdown": ready = false; result = Map.of("stopped", true); break;
|
|
31
|
+
default: throw new IllegalArgumentException("Unsupported method");
|
|
32
|
+
}
|
|
33
|
+
response.put("result", result);
|
|
34
|
+
} catch (Exception error) {
|
|
35
|
+
System.err.println(error.getMessage());
|
|
36
|
+
response.put("error", Map.of("code", "PLUGIN_FAILED", "message", "Plugin handler failed"));
|
|
37
|
+
}
|
|
38
|
+
output.println(Json.stringify(response));
|
|
39
|
+
if (method.equals("shutdown")) return;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|