mirror of
https://git.openapi.site/https://github.com/desirecore/agent-desirecore.git
synced 2026-12-05 12:09:30 +08:00
feat: 提供工作台应用开发发布技能与示例
This commit is contained in:
1 parent
6cbc736a69
commit
0204c31f54
27 files changed
+874
-5
No files matched your search
@@ -0,0 +1,57 @@
|
||||
---
|
||||
name: app-developer
|
||||
description: 用户要求开发、修改或发布自己的工作台应用,或把固定应用版本分发到 GitHub/Gitea 与 Registry 时使用。外部托管、Git服务和数据库须有真实连接及适用条款,可能另行部署或收费;缺能力时说明原因。
|
||||
version: "1.0.0"
|
||||
requiredClientVersion: "10.0.180"
|
||||
type: procedural
|
||||
risk_level: high
|
||||
status: enabled
|
||||
disable-model-invocation: true
|
||||
provides:
|
||||
tools: [HttpRequest]
|
||||
tags: [application, workbench, development, publishing]
|
||||
metadata:
|
||||
author: desirecore
|
||||
updated_at: "2026-10-13"
|
||||
---
|
||||
|
||||
# 应用开发与发布
|
||||
|
||||
## L0:职责
|
||||
|
||||
Agent 选择技术栈、构建方法与工作方式;平台核验材料、作用域、发布、运行和协作事实。复用文件、执行、Task/Run 与现有安装 writer,不生成固定业务 DAG,不从安装说明自动执行命令。
|
||||
|
||||
## L1:先读能力与当前上下文
|
||||
|
||||
1. 读取或创建本任务唯一文件化 Plan,保存实际来源 Agent/会话、目标设备、工作目录及开发 Task。已有用户需求和授权直接沿用。
|
||||
2. 使用当前授权的 HttpRequest 读取 `GET /api/apps/capabilities`。必须得到 `protocol: app-authoring-v1`,分别看 features 的 supported、authorized、available 和 reason。10.0.180 只是代码基线,已发行的同版本客户端不因此支持新协议。
|
||||
3. 普通自然语言开发不要求新的交接协议。若要登记、安装、更新或卸载,读取 `app-install-manager`;继续沿 ApplicationManagement-v2 解析和唯一 writer,不直接编辑 installed-entries.json。
|
||||
4. 按需读 [作者接口](references/authoring-api.zh-CN.md) 和 [分发指南](references/distribution.zh-CN.md)。两份示例位于 `examples/static-workbench/` 与 `examples/service-workbench/`,只是可修改的教学材料,不能代替真实 Agent 开发和业务验收。
|
||||
|
||||
## L2:开发、预览和个人发布
|
||||
|
||||
- 先确认要解决的工作、数据位置与必要协作。可以使用任何适合的语言/框架,示例不固定技术栈。小任务直接完成;复杂工作保留原 Task、Plan 和用户来源,不另造开发状态机。
|
||||
- 程序材料、业务数据与秘密分开。作者定义 `application.json` 不包含 sourceId、安装实例、宿主路径、builtin 路由或权限凭据。release 的产品 ID/名称/版本/入口只有这份定义。
|
||||
- 固定 `app-release.json`:按显式文件白名单、原始字节摘要、入口映射、数据合同和真实平台证据生成;清单自身不进入 files。可用 `scripts/create-release.mjs` 为示例生成清单,平台仍重新核验实际字节。
|
||||
- 向平台交付 `app-draft.json`,记录真实 fileRef、Plan、Agent/session、稳定 draftId 与目标 installationId。workdir 指向实际完成的 release 材料目录,不猜测 release/ 子目录,也不编造 fileRef。返回此文件的可点击绝对路径,说明可在应用开发工作区读取并继续。
|
||||
- snapshot 预览与正式安装隔离,数据不自动转移。live 预览必须先固定 snapshot 才可发布;刷新/替换用实际 revision。关闭预览撤销当前桥,不取消后台 Task,不将预览临时 URL/token 保存为正式入口。
|
||||
- 个人发布沿 prepare → 用户检查候选 → commit;提交精确 releaseDigest、installationId、expectedRevision 与原提交 ID。旧会话里明确授权的发布可继续,不逐命令重复确认。新目标或超出授权的数据/外部副作用沿现有治理处理。
|
||||
- 发布保存与运行可用分开。静态包通过固定映射承载;带服务应用由原执行 owner 的真实 spawn、代际身份和握手接入。端口响应、PID、历史 observation 不能替代运行绑定;失败如实说明“版本已保存,启动待修复”。
|
||||
- 写入超时、响应丢失或断线,保留原 mutation/submission/clientRequest ID 与正文,查询原结果;unknown 时不创建新 ID 盲重放。修改候选前重读当前版本与数据兼容,迁移中断先观察;代码回退不代表业务数据恢复。
|
||||
|
||||
## L3:网页与 Agent 协作
|
||||
|
||||
应用网页只使用有限 `window.desirecoreApp.call(method,payload)`/`onEvent`,Web 由独立来源的 MessagePort SDK 连接。没有 Conveyor、任意 invoke、平台管理 token、任意文件代理或通用 fetch 工具。缺宿主/授权时禁用相应操作并给出真实原因。
|
||||
|
||||
- `connect.application` 仅为正式实例提供来源/应用/实例前缀;对象 namespace/objectId/revision 由业务 owner 提供并再次校验。预览不借用正式实例,缺对象引用可以只讨论摘要。
|
||||
- 持久数据只用已声明 key 的 readData/saveData;新文件 expectedAbsent,已有文件 expectedETag,unknown 沿原 mutationId 查询。原生后端使用单独获授权数据根,不能把数据库写入固定 release 目录。
|
||||
- 选中对象可 publishSelection。发起工作先 prepareWork,最终接纳由平台自己的控件签发真实 intent。prepare/proposalRef 不等于 Task 已创建;只在 work-accepted 的实际 reserved/committed 回执后显示接纳,queued 不说执行完成。
|
||||
- 请求恢复沿原 clientRequestId;订阅出现 reset_required 时读快照并从合法 cursor 重订阅。取消 Task/Run 只作用于原归属,不用页面关闭或任意 resume 掩盖失败。成果读取/打开仍须核验精确资源引用。
|
||||
|
||||
## L4:分发与交付证据
|
||||
|
||||
个人发布默认私有本机,不隐含上传。用户要求分发后,导出固定版本的完整白名单,审阅确切文件与目标。业务库、.env、凭据、聊天/Task/Plan、日志、机器路径和安装身份不得进入包;环境模板可以包含名称和说明,不能包含真实值。
|
||||
|
||||
先用已授权 GitHub/Gitea 工具上传并核读不可变提交/制品 SHA,再从同一 exportRef 生成 Registry `manifest.json`、`catalog-metadata.v1.json`、`install.md`。目录身份由目标 Provider 注入,个人安装仍是原实例。archiveDigest、releaseDigest、物化 descriptorDigest 分别核验;同版本异内容创建新修订,不覆盖旧固定材料。
|
||||
|
||||
按真实情况分别报告:代码/业务验证、预览、个人发布、启动、来源上传、目录 PR/准入、第二用户安装。候选 4.3 Schema、外仓 PR 或 ZIP 生成都不代表官方市场已开放,也不能代替客户端能力发行或另一设备运行。外部托管/数据库/Git服务的登录、许可、部署及费用由其真实连接和条款决定,缺少时停止相应外部调用。
|
||||
@@ -0,0 +1,9 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2026 DesireCore
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
@@ -0,0 +1,134 @@
|
||||
{
|
||||
"schemaVersion": 1,
|
||||
"canonicalization": "app-release-c14n-v1",
|
||||
"definition": {
|
||||
"id": "service-notes-workbench",
|
||||
"name": "服务笔记工作台",
|
||||
"version": "1.0.0",
|
||||
"productKind": "application",
|
||||
"icon": "PanelsTopLeft",
|
||||
"iconLetter": "台",
|
||||
"entrypoints": [
|
||||
{
|
||||
"id": "main",
|
||||
"name": "笔记",
|
||||
"kind": "embedded-web",
|
||||
"serviceRef": "workbench:main"
|
||||
}
|
||||
],
|
||||
"placementPolicy": {
|
||||
"showInMyApps": true,
|
||||
"allowNavPin": true,
|
||||
"allowAgentBinding": true
|
||||
}
|
||||
},
|
||||
"delivery": {
|
||||
"type": "native-app",
|
||||
"runtimeInstructionsPath": "runtime/运行说明.md"
|
||||
},
|
||||
"files": [
|
||||
{
|
||||
"path": "LICENSE",
|
||||
"role": "license",
|
||||
"sha256": "e863481f423546e8984c07ffa00609d338b7f7533f60e89392301028163aa89e",
|
||||
"size": 1067
|
||||
},
|
||||
{
|
||||
"path": "application.json",
|
||||
"role": "definition",
|
||||
"sha256": "34f3ef80d33f3182f461f93e646d3fdb13865fb07214b505b55a64514c1284e1",
|
||||
"size": 433
|
||||
},
|
||||
{
|
||||
"path": "data-contract.json",
|
||||
"role": "data-contract",
|
||||
"sha256": "e195b2fd60a2798141c4c75ab57e0927d115bfba7888b0881b69dffa9dcb26cc",
|
||||
"size": 266
|
||||
},
|
||||
{
|
||||
"path": "runtime/server.mjs",
|
||||
"role": "runtime",
|
||||
"sha256": "3ccea1e06f3371e98cc8277d2b82d70cdcca7dd43ff8c40ab43a3c14ba0ee456",
|
||||
"size": 2633
|
||||
},
|
||||
{
|
||||
"path": "runtime/运行说明.md",
|
||||
"role": "documentation",
|
||||
"sha256": "6225a3e5afdd835a1de54df1287afd8d3bef69a9ae1b44535aae2e7adf3376b6",
|
||||
"size": 1910
|
||||
},
|
||||
{
|
||||
"path": "ui/app.js",
|
||||
"role": "ui",
|
||||
"sha256": "3bc131e1afd3063e13373c6b64f86f9202a1bda78ce606e9137133c6e60abdae",
|
||||
"size": 5204
|
||||
},
|
||||
{
|
||||
"path": "ui/bridge.js",
|
||||
"role": "ui",
|
||||
"sha256": "0a436b5244acfd924b96274377c8758bf92ea665b0591afaddee064f48d0b599",
|
||||
"size": 2939
|
||||
},
|
||||
{
|
||||
"path": "ui/index.html",
|
||||
"role": "ui",
|
||||
"sha256": "2c028db0db06249768e4222c488554cb8db6e2b75fe5da21630bf59f547044b7",
|
||||
"size": 2282
|
||||
},
|
||||
{
|
||||
"path": "说明.md",
|
||||
"role": "documentation",
|
||||
"sha256": "7b9f6cbb89fbaa51c3ff717f75fd76eaf80afd2ea82a67e40561e9b845cf51a7",
|
||||
"size": 1032
|
||||
}
|
||||
],
|
||||
"source": {
|
||||
"kind": "worktree",
|
||||
"sha256": "5f6448e5f8e45f6720a1d9ee7fc677c2a48cee7e148a1785a293940be427a32f"
|
||||
},
|
||||
"supportedPlatforms": [
|
||||
"darwin",
|
||||
"win32",
|
||||
"linux"
|
||||
],
|
||||
"minimumClientVersion": "10.0.180",
|
||||
"requiredCapabilities": [
|
||||
"app-authoring-v1",
|
||||
"release",
|
||||
"runtime-binding",
|
||||
"bridge",
|
||||
"data"
|
||||
],
|
||||
"dataContract": {
|
||||
"schemaVersion": 1,
|
||||
"formatVersion": "notes-v1",
|
||||
"readableVersions": [
|
||||
"notes-v1"
|
||||
],
|
||||
"writableVersions": [
|
||||
"notes-v1"
|
||||
],
|
||||
"files": [
|
||||
{
|
||||
"key": "notes",
|
||||
"path": "notes.json",
|
||||
"maxBytes": 131072,
|
||||
"contentType": "application/json"
|
||||
}
|
||||
],
|
||||
"uninstallRetention": "retain"
|
||||
},
|
||||
"bridgeCapabilities": [
|
||||
"connect",
|
||||
"capabilities",
|
||||
"readData",
|
||||
"saveData",
|
||||
"lookupDataMutation",
|
||||
"publishSelection",
|
||||
"requestWork",
|
||||
"lookupRequest",
|
||||
"readWork"
|
||||
],
|
||||
"instructionsPath": "说明.md",
|
||||
"releaseDigest": "9db7813e5c44bb64e2fd53bc4f02f556a8e68e01fa0205e0ce301f7d25661bf8"
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"id": "service-notes-workbench",
|
||||
"name": "服务笔记工作台",
|
||||
"version": "1.0.0",
|
||||
"productKind": "application",
|
||||
"icon": "PanelsTopLeft",
|
||||
"iconLetter": "台",
|
||||
"entrypoints": [
|
||||
{
|
||||
"id": "main",
|
||||
"name": "笔记",
|
||||
"kind": "embedded-web",
|
||||
"serviceRef": "workbench:main"
|
||||
}
|
||||
],
|
||||
"placementPolicy": {
|
||||
"showInMyApps": true,
|
||||
"allowNavPin": true,
|
||||
"allowAgentBinding": true
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"schemaVersion": 1, "formatVersion": "notes-v1", "readableVersions": ["notes-v1"], "writableVersions": ["notes-v1"],
|
||||
"files": [{ "key": "notes", "path": "notes.json", "maxBytes": 131072, "contentType": "application/json" }],
|
||||
"uninstallRetention": "retain"
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
{
|
||||
"description": "显式收录网页与只读分析服务;笔记使用平台有限data key,不写固定程序目录。",
|
||||
"delivery": {
|
||||
"type": "native-app",
|
||||
"runtimeInstructionsPath": "runtime/运行说明.md"
|
||||
},
|
||||
"supportedPlatforms": [
|
||||
"darwin",
|
||||
"win32",
|
||||
"linux"
|
||||
],
|
||||
"requiredCapabilities": [
|
||||
"app-authoring-v1",
|
||||
"release",
|
||||
"runtime-binding",
|
||||
"bridge",
|
||||
"data"
|
||||
],
|
||||
"bridgeCapabilities": [
|
||||
"connect",
|
||||
"capabilities",
|
||||
"readData",
|
||||
"saveData",
|
||||
"lookupDataMutation",
|
||||
"publishSelection",
|
||||
"requestWork",
|
||||
"lookupRequest",
|
||||
"readWork"
|
||||
],
|
||||
"dataContractPath": "data-contract.json",
|
||||
"files": [
|
||||
{
|
||||
"path": "application.json",
|
||||
"role": "definition"
|
||||
},
|
||||
{
|
||||
"path": "ui/index.html",
|
||||
"role": "ui"
|
||||
},
|
||||
{
|
||||
"path": "ui/bridge.js",
|
||||
"role": "ui"
|
||||
},
|
||||
{
|
||||
"path": "ui/app.js",
|
||||
"role": "ui"
|
||||
},
|
||||
{
|
||||
"path": "data-contract.json",
|
||||
"role": "data-contract"
|
||||
},
|
||||
{
|
||||
"path": "说明.md",
|
||||
"role": "documentation"
|
||||
},
|
||||
{
|
||||
"path": "LICENSE",
|
||||
"role": "license"
|
||||
},
|
||||
{
|
||||
"path": "runtime/server.mjs",
|
||||
"role": "runtime"
|
||||
},
|
||||
{
|
||||
"path": "runtime/运行说明.md",
|
||||
"role": "documentation"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/** 只读应用服务;业务数据在平台实例data key中,绝不写固定release目录。 */
|
||||
import http from 'node:http'
|
||||
import { readFileSync } from 'node:fs'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
|
||||
const port = Number(process.env.PORT)
|
||||
if (!Number.isInteger(port) || port < 1 || port > 65535) throw new Error('PORT_required')
|
||||
const files = new Map([
|
||||
['/', ['../ui/index.html','text/html; charset=utf-8']],
|
||||
['/app.js',['../ui/app.js','text/javascript; charset=utf-8']],
|
||||
['/bridge.js',['../ui/bridge.js','text/javascript; charset=utf-8']],
|
||||
])
|
||||
const server = http.createServer(async (request,response) => {
|
||||
const url = new URL(request.url ?? '/',`http://127.0.0.1:${port}`)
|
||||
response.setHeader('X-Content-Type-Options','nosniff')
|
||||
response.setHeader('Referrer-Policy','origin')
|
||||
if (request.method !== 'GET') { response.writeHead(405); return response.end() }
|
||||
if (url.pathname === '/.desirecore-app-identity') {
|
||||
response.setHeader('Content-Type','application/json')
|
||||
response.setHeader('Cache-Control','no-store')
|
||||
const identity = {proof:process.env.DESIRECORE_APP_RUNTIME_PROOF,releaseDigest:process.env.DESIRECORE_APP_RELEASE_DIGEST,
|
||||
scopeId:process.env.DESIRECORE_APP_SCOPE_ID,runtimeGeneration:process.env.DESIRECORE_APP_RUNTIME_GENERATION}
|
||||
if (Object.values(identity).some(value => typeof value !== 'string' || !value)) { response.writeHead(503); return response.end(JSON.stringify({error:'managed_runtime_identity_unavailable'})) }
|
||||
return response.end(JSON.stringify(identity))
|
||||
}
|
||||
if (url.pathname === '/api/summary') {
|
||||
const count = Number(url.searchParams.get('count'))
|
||||
if (!Number.isInteger(count) || count < 0 || count > 10000) { response.writeHead(400); return response.end() }
|
||||
response.setHeader('Content-Type','application/json')
|
||||
return response.end(JSON.stringify({count,summary:`当前工作台有 ${count} 条笔记。`,dataAccess:'none'}))
|
||||
}
|
||||
const entry = files.get(url.pathname)
|
||||
if (!entry) { response.writeHead(404); return response.end() }
|
||||
response.setHeader('Content-Type',entry[1])
|
||||
response.setHeader('Content-Security-Policy',"default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; connect-src 'self'; object-src 'none'; base-uri 'none'")
|
||||
try { response.end(readFileSync(fileURLToPath(new URL(entry[0],import.meta.url)))) }
|
||||
catch { response.writeHead(503); response.end('material_unavailable') }
|
||||
})
|
||||
server.listen(port,'127.0.0.1',() => console.log(`Application service listening on loopback port ${port}`))
|
||||
for (const signal of ['SIGINT','SIGTERM']) process.on(signal,() => server.close(() => process.exit(0)))
|
||||
@@ -0,0 +1,11 @@
|
||||
# 运行服务笔记工作台
|
||||
|
||||
需要用户实际选择并可用的 Node.js 运行时。此示例不安装 Node、Docker 或第三方数据库,不向平台注册 MCP。Node 服务只提供固定网页、只读计数分析和当前 TaskHost 运行身份握手;业务笔记使用平台有限 data key,与静态示例采用同一CAS保存约定。
|
||||
|
||||
在获授权的材料目录生成release并prepare后,使用原执行工具实际启动 `PORT=<已选择空闲端口> node runtime/server.mjs`。端口需固定在原接受的执行合同,不能靠网页声明任意endpoint。身份由原TaskHost在受控正式spawn时注入:DESIRECORE_APP_RUNTIME_PROOF、DESIRECORE_APP_RELEASE_DIGEST、DESIRECORE_APP_SCOPE_ID、DESIRECORE_APP_RUNTIME_GENERATION。应用不能自报固定PID或伪造proof,不能将proof用于其他API或日志。
|
||||
|
||||
调用 `/api/apps/runtime/contracts` 时给真实prepareRef、installationId、terminalId、endpoint.port与identityPath `/.desirecore-app-identity`,以及用户选择的 manual/on-open。纳管读取原accepted-command冻结执行合同;由原执行工具明确停掉此前命令,commit后由原owner启动正式新代际,再核读运行身份和应用功能。原先裸启动的服务在没有managed身份时会明确返回503,它只能帮助开发调试,不能证明正式可信直开。
|
||||
|
||||
公开执行环境不接受任意.env。若改造应用需要后端直接读写数据,须使用实际数据owner授予并注入的独立根;缺授权时不写盘,不默认使用cwd或release目录。此教学服务没有后端数据写入,因此不需要APP_DATA_DIR,不持有平台凭据。
|
||||
|
||||
停止、更新、失败恢复沿原TaskHost/Run,不重复开第二个后台进程。scope/release/generation改变后旧连接失效;重启须重新取得owner身份与审批事实。端口被占用不接管,不把HTTP200作为运行归属证明。
|
||||
@@ -0,0 +1,68 @@
|
||||
import { connectBridge } from './bridge.js'
|
||||
const element = id => document.getElementById(id)
|
||||
let bridge, connection, etag, notes = [], selected, pendingSave, pendingWork
|
||||
const status = message => { element('status').textContent = message }
|
||||
function render() {
|
||||
element('notes').replaceChildren()
|
||||
for (const note of notes) {
|
||||
const row = document.createElement('li'), text = document.createElement('div'), button = document.createElement('button')
|
||||
text.textContent = note.text; button.textContent = selected?.id === note.id ? '已选中' : '选择此笔记'
|
||||
button.addEventListener('click', () => { selected = note; render() }); row.append(text,button); element('notes').append(row)
|
||||
}
|
||||
}
|
||||
async function read() {
|
||||
const result = await bridge.call('readData',{key:'notes'})
|
||||
const value = result.exists ? JSON.parse(result.content) : {schemaVersion:1,notes:[]}
|
||||
if (value.schemaVersion !== 1 || !Array.isArray(value.notes)) throw new Error('notes_format_unsupported')
|
||||
notes = value.notes; etag = result.etag; selected = notes.find(note => note.id === selected?.id); render()
|
||||
status('已读取当前实例的数据。')
|
||||
}
|
||||
async function save() {
|
||||
if (!pendingSave) {
|
||||
const text = element('note').value.trim()
|
||||
if (!text) return status('先输入笔记。')
|
||||
pendingSave = {key:'notes',mutationId:crypto.randomUUID(),content:JSON.stringify({schemaVersion:1,notes:[...notes,{id:crypto.randomUUID(),revision:'1',text}]}),
|
||||
...(etag ? {expectedETag:etag} : {expectedAbsent:true})}
|
||||
}
|
||||
try {
|
||||
const receipt = await bridge.call('saveData',pendingSave)
|
||||
if (receipt.status !== 'saved') throw new Error('save_result_unknown')
|
||||
pendingSave = undefined; element('recover').disabled = true; element('note').value = ''; await read(); status('保存回执已核验。')
|
||||
} catch (error) { element('recover').disabled = false; status(`保存尚未确认:${error.message}。保留原ID和正文,先查询原保存;未确认前不要添加另一条笔记。`) }
|
||||
}
|
||||
element('save').addEventListener('click',save)
|
||||
element('refresh').addEventListener('click',() => pendingSave ? status('还有结果不明的原保存,请先查询。') : read().catch(error => status(error.message)))
|
||||
element('recover').addEventListener('click',async () => {
|
||||
if (!pendingSave) return
|
||||
try {
|
||||
const result = await bridge.call('lookupDataMutation',{key:'notes',mutationId:pendingSave.mutationId})
|
||||
if (result.status === 'saved') { pendingSave = undefined; element('recover').disabled = true; element('note').value = ''; await read() }
|
||||
else status(result.status === 'absent' ? '原保存明确未发生。可以用“保存笔记”重试同ID和原正文,冲突时读取并人工合并。' : '原保存仍不明确,请保留当前页面和原ID。')
|
||||
} catch (error) { status(error.message) }
|
||||
})
|
||||
element('request').addEventListener('click',async () => {
|
||||
const agentId = element('agent').value.trim()
|
||||
if (!agentId || !selected) return element('work-status').textContent = '先选择笔记和实际Agent。'
|
||||
if (pendingWork) return element('work-status').textContent = '已有待查询请求,请沿原ID恢复。'
|
||||
pendingWork = {clientRequestId:crypto.randomUUID(),userMessageId:crypto.randomUUID(),agentId,
|
||||
prompt:`请讨论这条笔记并给出可执行建议:${selected.text}`,scopeDescription:'读取notes来源文件核验所选笔记,只讨论该记录,不修改其他记录。',
|
||||
selection:{schemaVersion:1,selectionRevision:crypto.randomUUID(),summary:`笔记ID:${selected.id},记录版本:${selected.revision},内容:${selected.text};正式实例对象引用授予读取notes来源文件。`,objects:connection.application && etag ?
|
||||
[{schemaVersion:1,...connection.application,namespace:'data-files',objectId:'notes',revision:etag}] : []}}
|
||||
element('work').disabled = false
|
||||
try {
|
||||
const proposal = await bridge.call('prepareWork',pendingWork)
|
||||
element('work-status').textContent = `提案已准备,等待平台控件接纳。提案引用:${proposal.proposalRef}`
|
||||
} catch (error) { element('work-status').textContent = `提案/请求结果尚未确认:${error.message};保留原请求ID查询。` }
|
||||
})
|
||||
element('work').addEventListener('click',async () => {
|
||||
if (!pendingWork) return
|
||||
try { element('work-status').textContent = JSON.stringify(await bridge.call('lookupRequest',{clientRequestId:pendingWork.clientRequestId}),null,2) }
|
||||
catch (error) { element('work-status').textContent = error.message }
|
||||
})
|
||||
try {
|
||||
bridge = await connectBridge(); connection = await bridge.call('connect')
|
||||
bridge.onEvent(event => { if (event?.type === 'work-accepted' && event.clientRequestId === pendingWork?.clientRequestId)
|
||||
element('work-status').textContent = `平台接纳回执:${JSON.stringify(event.result)}。通过原请求继续查询,接纳不等于业务完成。` })
|
||||
await read(); element('save').disabled = !connection.capabilities?.includes('saveData'); element('refresh').disabled = false
|
||||
element('request').disabled = !connection.capabilities?.includes('requestWork')
|
||||
} catch (error) { status(`当前持久数据或协作能力不可用:${error.message}。未保存任何业务数据。`) }
|
||||
@@ -0,0 +1,46 @@
|
||||
/** 教学SDK适配:桌面有限preload;Web严格parent来源/nonce握手,没有管理token或任意invoke。 */
|
||||
const methods = new Set(['connect','capabilities','publishSelection','prepareWork','lookupRequest','readWork','readData','saveData','lookupDataMutation'])
|
||||
export async function connectBridge() {
|
||||
if (window.desirecoreApp?.call) return window.desirecoreApp
|
||||
if (window.parent === window) throw new Error('app_bridge_host_unavailable')
|
||||
let origin
|
||||
try { origin = new URL(document.referrer).origin } catch { throw new Error('app_bridge_host_origin_required') }
|
||||
if (origin === 'null' || origin === location.origin) throw new Error('app_bridge_independent_origin_required')
|
||||
return new Promise((resolve, reject) => {
|
||||
let nonce
|
||||
const timer = setTimeout(() => { window.removeEventListener('message', receive); reject(new Error('app_bridge_host_unavailable')) }, 15000)
|
||||
function receive(event) {
|
||||
if (event.source !== window.parent || event.origin !== origin || !event.data || typeof event.data !== 'object') return
|
||||
if (event.data.protocol === 'desirecore-app-hello-v1' && typeof event.data.nonce === 'string' && !nonce) {
|
||||
nonce = event.data.nonce
|
||||
window.parent.postMessage({ protocol:'desirecore-app-ready-v1',nonce },origin)
|
||||
} else if (nonce && event.data.protocol === 'desirecore-app-port-v1' && event.data.nonce === nonce && event.ports.length === 1) {
|
||||
window.removeEventListener('message',receive); clearTimeout(timer); resolve(portClient(event.ports[0]))
|
||||
}
|
||||
}
|
||||
window.addEventListener('message',receive)
|
||||
})
|
||||
}
|
||||
function portClient(port) {
|
||||
const pending = new Map(), listeners = new Set()
|
||||
port.onmessage = event => {
|
||||
const message = event.data
|
||||
if (message?.protocol !== 'desirecore-app-bridge-v1') return
|
||||
const request = pending.get(message.requestId)
|
||||
if (request) { pending.delete(message.requestId); clearTimeout(request.timer); message.error ? request.reject(new Error(message.error)) : request.resolve(message.result) }
|
||||
else if (message.event !== undefined) for (const listener of listeners) listener(message.event)
|
||||
}
|
||||
port.start()
|
||||
return {
|
||||
call(method,payload) {
|
||||
if (!methods.has(method)) return Promise.reject(new Error('app_bridge_method_rejected'))
|
||||
const requestId = crypto.randomUUID()
|
||||
return new Promise((resolve,reject) => {
|
||||
const timer = setTimeout(() => { pending.delete(requestId); reject(new Error('app_bridge_result_unknown')) },30000)
|
||||
pending.set(requestId,{resolve,reject,timer}); port.postMessage({ protocol:'desirecore-app-bridge-v1',requestId,method,payload })
|
||||
})
|
||||
},
|
||||
onEvent(callback) { listeners.add(callback); return () => listeners.delete(callback) },
|
||||
close() { for (const request of pending.values()) { clearTimeout(request.timer); request.reject(new Error('app_bridge_closed')) }; pending.clear(); listeners.clear(); port.close() },
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<!doctype html>
|
||||
<html lang="zh-CN"><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
|
||||
<title>服务笔记工作台</title>
|
||||
<style>
|
||||
:root{font:16px/1.6 system-ui,sans-serif;color:#253447;background:#f1f5f9}body{max-width:920px;margin:40px auto;padding:0 24px}h1{font-size:30px;line-height:1.2}p{color:#526174}section{padding:24px;background:#fff;border:1px solid #dbe3ed;border-radius:16px;margin:20px 0}textarea{box-sizing:border-box;width:100%;min-height:140px;padding:14px;font:inherit;border:1px solid #becbdc;border-radius:8px}button,input{font:inherit;padding:9px 14px;border:1px solid #becbdc;border-radius:8px}button{background:#fff;cursor:pointer;margin:10px 6px 0 0}button.primary{background:#274c77;color:#fff;border-color:#274c77}button:disabled{opacity:.5;cursor:default}ul{padding:0;list-style:none}li{border-top:1px solid #e7edf4;padding:12px 0;white-space:pre-wrap}li button{margin-top:6px}output{display:block;margin-top:12px;color:#526174;white-space:pre-wrap;overflow-wrap:anywhere}label{display:block;margin-top:16px}input{max-width:100%;box-sizing:border-box;width:400px}@media(max-width:580px){body{margin:20px auto;padding:0 12px}section{padding:16px}}
|
||||
</style>
|
||||
<h1>服务笔记工作台</h1><p>先把想法记下来,再把选中的内容交给 Agent。业务数据与应用程序版本分别保存。</p>
|
||||
<section><label for="note">新笔记</label><textarea id="note" placeholder="输入一条笔记"></textarea>
|
||||
<button id="save" class="primary" disabled>保存笔记</button><button id="refresh" disabled>读取最新版本</button><button id="recover" disabled>查询原保存</button>
|
||||
<output id="status" aria-live="polite">正在连接应用宿主…</output><ul id="notes"></ul></section>
|
||||
<section><h2>与 Agent 协作</h2><p>教学示例使用实际 Agent ID;应用可以自行设计选择器。工作须由平台控件接纳。</p>
|
||||
<label for="agent">本次 Agent ID</label><input id="agent" placeholder="由当前授权的 Agent 配置提供">
|
||||
<button id="request" disabled>交给 Agent 讨论选中笔记</button><button id="work" disabled>查询原请求</button><output id="work-status" aria-live="polite">尚未准备请求。</output></section>
|
||||
<script type="module" src="./app.js"></script></html>
|
||||
@@ -0,0 +1,7 @@
|
||||
# 服务笔记工作台教学示例
|
||||
|
||||
这是可修改的固定网页+原生Node只读服务,不是正式市场条目。先读本Skill作者接口和runtime/运行说明.md,在真实目标环境prepare、纳管原执行合同、正式发布并核验。缺TaskHost owner或真实身份时保持不可用,不能重标为静态网页来绕过。
|
||||
|
||||
笔记仍通过应用桥的notes key持久化,用户、实例和预览各有独立scope;Node端不写个人数据或固定程序目录。网页可在本源 `/api/summary?count=<当前笔记条数>` 请求只读统计;这个能力不使用平台token,也不接收任意文件路径或SQL。
|
||||
|
||||
与Agent协作、保存超时恢复及更新/data合同遵循静态示例的相同约定。应用是否能运行与外部Node环境、原执行owner和当前用户授权有关。包不附带用户数据库、.env、平台身份或proof值。分发必须取得真实不可变来源和目录审阅回执;第二用户安装需独立环境,不共享开发者进程或业务数据。
|
||||
@@ -0,0 +1,9 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2026 DesireCore
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
@@ -0,0 +1,128 @@
|
||||
{
|
||||
"schemaVersion": 1,
|
||||
"canonicalization": "app-release-c14n-v1",
|
||||
"definition": {
|
||||
"id": "personal-notes-workbench",
|
||||
"name": "个人笔记工作台",
|
||||
"version": "1.0.0",
|
||||
"productKind": "application",
|
||||
"icon": "Notebook",
|
||||
"iconLetter": "记",
|
||||
"entrypoints": [
|
||||
{
|
||||
"id": "main",
|
||||
"name": "笔记",
|
||||
"kind": "embedded-web",
|
||||
"serviceRef": "workbench:main"
|
||||
}
|
||||
],
|
||||
"placementPolicy": {
|
||||
"showInMyApps": true,
|
||||
"allowNavPin": true,
|
||||
"allowAgentBinding": true
|
||||
}
|
||||
},
|
||||
"delivery": {
|
||||
"type": "web-bundle",
|
||||
"entrypoints": [
|
||||
{
|
||||
"entrypointId": "main",
|
||||
"path": "ui/index.html"
|
||||
}
|
||||
]
|
||||
},
|
||||
"files": [
|
||||
{
|
||||
"path": "LICENSE",
|
||||
"role": "license",
|
||||
"sha256": "e863481f423546e8984c07ffa00609d338b7f7533f60e89392301028163aa89e",
|
||||
"size": 1067
|
||||
},
|
||||
{
|
||||
"path": "application.json",
|
||||
"role": "definition",
|
||||
"sha256": "6f173d257bbb07d85deefe203a18741ec31fed27f244dbce6e37ef42f6662a9a",
|
||||
"size": 371
|
||||
},
|
||||
{
|
||||
"path": "data-contract.json",
|
||||
"role": "data-contract",
|
||||
"sha256": "e195b2fd60a2798141c4c75ab57e0927d115bfba7888b0881b69dffa9dcb26cc",
|
||||
"size": 266
|
||||
},
|
||||
{
|
||||
"path": "ui/app.js",
|
||||
"role": "ui",
|
||||
"sha256": "3bc131e1afd3063e13373c6b64f86f9202a1bda78ce606e9137133c6e60abdae",
|
||||
"size": 5204
|
||||
},
|
||||
{
|
||||
"path": "ui/bridge.js",
|
||||
"role": "ui",
|
||||
"sha256": "0a436b5244acfd924b96274377c8758bf92ea665b0591afaddee064f48d0b599",
|
||||
"size": 2939
|
||||
},
|
||||
{
|
||||
"path": "ui/index.html",
|
||||
"role": "ui",
|
||||
"sha256": "e3c055e13440a8aa472bf2ca73a49c5af26eda0061e17d02a44a3c3de665c3b1",
|
||||
"size": 2282
|
||||
},
|
||||
{
|
||||
"path": "说明.md",
|
||||
"role": "documentation",
|
||||
"sha256": "6a0feb6f009f91430e0e809da6a4f4e81cd12b4e424f250b6adbaff07f9923dd",
|
||||
"size": 1864
|
||||
}
|
||||
],
|
||||
"source": {
|
||||
"kind": "worktree",
|
||||
"sha256": "83af9d981f282ca2ceb4103604b33e6cae07056d81a9718b72f13c5ab0b8527d"
|
||||
},
|
||||
"supportedPlatforms": [
|
||||
"darwin",
|
||||
"win32",
|
||||
"linux",
|
||||
"web"
|
||||
],
|
||||
"minimumClientVersion": "10.0.180",
|
||||
"requiredCapabilities": [
|
||||
"app-authoring-v1",
|
||||
"release",
|
||||
"web-bundle",
|
||||
"bridge",
|
||||
"data"
|
||||
],
|
||||
"dataContract": {
|
||||
"schemaVersion": 1,
|
||||
"formatVersion": "notes-v1",
|
||||
"readableVersions": [
|
||||
"notes-v1"
|
||||
],
|
||||
"writableVersions": [
|
||||
"notes-v1"
|
||||
],
|
||||
"files": [
|
||||
{
|
||||
"key": "notes",
|
||||
"path": "notes.json",
|
||||
"maxBytes": 131072,
|
||||
"contentType": "application/json"
|
||||
}
|
||||
],
|
||||
"uninstallRetention": "retain"
|
||||
},
|
||||
"bridgeCapabilities": [
|
||||
"connect",
|
||||
"capabilities",
|
||||
"readData",
|
||||
"saveData",
|
||||
"lookupDataMutation",
|
||||
"publishSelection",
|
||||
"requestWork",
|
||||
"lookupRequest",
|
||||
"readWork"
|
||||
],
|
||||
"instructionsPath": "说明.md",
|
||||
"releaseDigest": "6ff9f35e8a14a2f35c4a0b1ee84755cfc63ef6e4d16860bb9e420b4514ae04b2"
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"id": "personal-notes-workbench", "name": "个人笔记工作台", "version": "1.0.0", "productKind": "application",
|
||||
"icon": "Notebook", "iconLetter": "记",
|
||||
"entrypoints": [{ "id": "main", "name": "笔记", "kind": "embedded-web", "serviceRef": "workbench:main" }],
|
||||
"placementPolicy": { "showInMyApps": true, "allowNavPin": true, "allowAgentBinding": true }
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"schemaVersion": 1, "formatVersion": "notes-v1", "readableVersions": ["notes-v1"], "writableVersions": ["notes-v1"],
|
||||
"files": [{ "key": "notes", "path": "notes.json", "maxBytes": 131072, "contentType": "application/json" }],
|
||||
"uninstallRetention": "retain"
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"description": "显式收录教学程序材料,业务notes.json只属于实例数据根,不进入发行包。",
|
||||
"delivery": { "type": "web-bundle", "entrypoints": [{ "entrypointId": "main", "path": "ui/index.html" }] },
|
||||
"supportedPlatforms": ["darwin", "win32", "linux", "web"],
|
||||
"requiredCapabilities": ["app-authoring-v1", "release", "web-bundle", "bridge", "data"],
|
||||
"bridgeCapabilities": ["connect", "capabilities", "readData", "saveData", "lookupDataMutation", "publishSelection", "requestWork", "lookupRequest", "readWork"],
|
||||
"dataContractPath": "data-contract.json",
|
||||
"files": [
|
||||
{ "path": "application.json", "role": "definition" }, { "path": "ui/index.html", "role": "ui" },
|
||||
{ "path": "ui/bridge.js", "role": "ui" }, { "path": "ui/app.js", "role": "ui" },
|
||||
{ "path": "data-contract.json", "role": "data-contract" }, { "path": "说明.md", "role": "documentation" }, { "path": "LICENSE", "role": "license" }
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
import { connectBridge } from './bridge.js'
|
||||
const element = id => document.getElementById(id)
|
||||
let bridge, connection, etag, notes = [], selected, pendingSave, pendingWork
|
||||
const status = message => { element('status').textContent = message }
|
||||
function render() {
|
||||
element('notes').replaceChildren()
|
||||
for (const note of notes) {
|
||||
const row = document.createElement('li'), text = document.createElement('div'), button = document.createElement('button')
|
||||
text.textContent = note.text; button.textContent = selected?.id === note.id ? '已选中' : '选择此笔记'
|
||||
button.addEventListener('click', () => { selected = note; render() }); row.append(text,button); element('notes').append(row)
|
||||
}
|
||||
}
|
||||
async function read() {
|
||||
const result = await bridge.call('readData',{key:'notes'})
|
||||
const value = result.exists ? JSON.parse(result.content) : {schemaVersion:1,notes:[]}
|
||||
if (value.schemaVersion !== 1 || !Array.isArray(value.notes)) throw new Error('notes_format_unsupported')
|
||||
notes = value.notes; etag = result.etag; selected = notes.find(note => note.id === selected?.id); render()
|
||||
status('已读取当前实例的数据。')
|
||||
}
|
||||
async function save() {
|
||||
if (!pendingSave) {
|
||||
const text = element('note').value.trim()
|
||||
if (!text) return status('先输入笔记。')
|
||||
pendingSave = {key:'notes',mutationId:crypto.randomUUID(),content:JSON.stringify({schemaVersion:1,notes:[...notes,{id:crypto.randomUUID(),revision:'1',text}]}),
|
||||
...(etag ? {expectedETag:etag} : {expectedAbsent:true})}
|
||||
}
|
||||
try {
|
||||
const receipt = await bridge.call('saveData',pendingSave)
|
||||
if (receipt.status !== 'saved') throw new Error('save_result_unknown')
|
||||
pendingSave = undefined; element('recover').disabled = true; element('note').value = ''; await read(); status('保存回执已核验。')
|
||||
} catch (error) { element('recover').disabled = false; status(`保存尚未确认:${error.message}。保留原ID和正文,先查询原保存;未确认前不要添加另一条笔记。`) }
|
||||
}
|
||||
element('save').addEventListener('click',save)
|
||||
element('refresh').addEventListener('click',() => pendingSave ? status('还有结果不明的原保存,请先查询。') : read().catch(error => status(error.message)))
|
||||
element('recover').addEventListener('click',async () => {
|
||||
if (!pendingSave) return
|
||||
try {
|
||||
const result = await bridge.call('lookupDataMutation',{key:'notes',mutationId:pendingSave.mutationId})
|
||||
if (result.status === 'saved') { pendingSave = undefined; element('recover').disabled = true; element('note').value = ''; await read() }
|
||||
else status(result.status === 'absent' ? '原保存明确未发生。可以用“保存笔记”重试同ID和原正文,冲突时读取并人工合并。' : '原保存仍不明确,请保留当前页面和原ID。')
|
||||
} catch (error) { status(error.message) }
|
||||
})
|
||||
element('request').addEventListener('click',async () => {
|
||||
const agentId = element('agent').value.trim()
|
||||
if (!agentId || !selected) return element('work-status').textContent = '先选择笔记和实际Agent。'
|
||||
if (pendingWork) return element('work-status').textContent = '已有待查询请求,请沿原ID恢复。'
|
||||
pendingWork = {clientRequestId:crypto.randomUUID(),userMessageId:crypto.randomUUID(),agentId,
|
||||
prompt:`请讨论这条笔记并给出可执行建议:${selected.text}`,scopeDescription:'读取notes来源文件核验所选笔记,只讨论该记录,不修改其他记录。',
|
||||
selection:{schemaVersion:1,selectionRevision:crypto.randomUUID(),summary:`笔记ID:${selected.id},记录版本:${selected.revision},内容:${selected.text};正式实例对象引用授予读取notes来源文件。`,objects:connection.application && etag ?
|
||||
[{schemaVersion:1,...connection.application,namespace:'data-files',objectId:'notes',revision:etag}] : []}}
|
||||
element('work').disabled = false
|
||||
try {
|
||||
const proposal = await bridge.call('prepareWork',pendingWork)
|
||||
element('work-status').textContent = `提案已准备,等待平台控件接纳。提案引用:${proposal.proposalRef}`
|
||||
} catch (error) { element('work-status').textContent = `提案/请求结果尚未确认:${error.message};保留原请求ID查询。` }
|
||||
})
|
||||
element('work').addEventListener('click',async () => {
|
||||
if (!pendingWork) return
|
||||
try { element('work-status').textContent = JSON.stringify(await bridge.call('lookupRequest',{clientRequestId:pendingWork.clientRequestId}),null,2) }
|
||||
catch (error) { element('work-status').textContent = error.message }
|
||||
})
|
||||
try {
|
||||
bridge = await connectBridge(); connection = await bridge.call('connect')
|
||||
bridge.onEvent(event => { if (event?.type === 'work-accepted' && event.clientRequestId === pendingWork?.clientRequestId)
|
||||
element('work-status').textContent = `平台接纳回执:${JSON.stringify(event.result)}。通过原请求继续查询,接纳不等于业务完成。` })
|
||||
await read(); element('save').disabled = !connection.capabilities?.includes('saveData'); element('refresh').disabled = false
|
||||
element('request').disabled = !connection.capabilities?.includes('requestWork')
|
||||
} catch (error) { status(`当前持久数据或协作能力不可用:${error.message}。未保存任何业务数据。`) }
|
||||
@@ -0,0 +1,46 @@
|
||||
/** 教学SDK适配:桌面有限preload;Web严格parent来源/nonce握手,没有管理token或任意invoke。 */
|
||||
const methods = new Set(['connect','capabilities','publishSelection','prepareWork','lookupRequest','readWork','readData','saveData','lookupDataMutation'])
|
||||
export async function connectBridge() {
|
||||
if (window.desirecoreApp?.call) return window.desirecoreApp
|
||||
if (window.parent === window) throw new Error('app_bridge_host_unavailable')
|
||||
let origin
|
||||
try { origin = new URL(document.referrer).origin } catch { throw new Error('app_bridge_host_origin_required') }
|
||||
if (origin === 'null' || origin === location.origin) throw new Error('app_bridge_independent_origin_required')
|
||||
return new Promise((resolve, reject) => {
|
||||
let nonce
|
||||
const timer = setTimeout(() => { window.removeEventListener('message', receive); reject(new Error('app_bridge_host_unavailable')) }, 15000)
|
||||
function receive(event) {
|
||||
if (event.source !== window.parent || event.origin !== origin || !event.data || typeof event.data !== 'object') return
|
||||
if (event.data.protocol === 'desirecore-app-hello-v1' && typeof event.data.nonce === 'string' && !nonce) {
|
||||
nonce = event.data.nonce
|
||||
window.parent.postMessage({ protocol:'desirecore-app-ready-v1',nonce },origin)
|
||||
} else if (nonce && event.data.protocol === 'desirecore-app-port-v1' && event.data.nonce === nonce && event.ports.length === 1) {
|
||||
window.removeEventListener('message',receive); clearTimeout(timer); resolve(portClient(event.ports[0]))
|
||||
}
|
||||
}
|
||||
window.addEventListener('message',receive)
|
||||
})
|
||||
}
|
||||
function portClient(port) {
|
||||
const pending = new Map(), listeners = new Set()
|
||||
port.onmessage = event => {
|
||||
const message = event.data
|
||||
if (message?.protocol !== 'desirecore-app-bridge-v1') return
|
||||
const request = pending.get(message.requestId)
|
||||
if (request) { pending.delete(message.requestId); clearTimeout(request.timer); message.error ? request.reject(new Error(message.error)) : request.resolve(message.result) }
|
||||
else if (message.event !== undefined) for (const listener of listeners) listener(message.event)
|
||||
}
|
||||
port.start()
|
||||
return {
|
||||
call(method,payload) {
|
||||
if (!methods.has(method)) return Promise.reject(new Error('app_bridge_method_rejected'))
|
||||
const requestId = crypto.randomUUID()
|
||||
return new Promise((resolve,reject) => {
|
||||
const timer = setTimeout(() => { pending.delete(requestId); reject(new Error('app_bridge_result_unknown')) },30000)
|
||||
pending.set(requestId,{resolve,reject,timer}); port.postMessage({ protocol:'desirecore-app-bridge-v1',requestId,method,payload })
|
||||
})
|
||||
},
|
||||
onEvent(callback) { listeners.add(callback); return () => listeners.delete(callback) },
|
||||
close() { for (const request of pending.values()) { clearTimeout(request.timer); request.reject(new Error('app_bridge_closed')) }; pending.clear(); listeners.clear(); port.close() },
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<!doctype html>
|
||||
<html lang="zh-CN"><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
|
||||
<title>个人笔记工作台</title>
|
||||
<style>
|
||||
:root{font:16px/1.6 system-ui,sans-serif;color:#253447;background:#f1f5f9}body{max-width:920px;margin:40px auto;padding:0 24px}h1{font-size:30px;line-height:1.2}p{color:#526174}section{padding:24px;background:#fff;border:1px solid #dbe3ed;border-radius:16px;margin:20px 0}textarea{box-sizing:border-box;width:100%;min-height:140px;padding:14px;font:inherit;border:1px solid #becbdc;border-radius:8px}button,input{font:inherit;padding:9px 14px;border:1px solid #becbdc;border-radius:8px}button{background:#fff;cursor:pointer;margin:10px 6px 0 0}button.primary{background:#274c77;color:#fff;border-color:#274c77}button:disabled{opacity:.5;cursor:default}ul{padding:0;list-style:none}li{border-top:1px solid #e7edf4;padding:12px 0;white-space:pre-wrap}li button{margin-top:6px}output{display:block;margin-top:12px;color:#526174;white-space:pre-wrap;overflow-wrap:anywhere}label{display:block;margin-top:16px}input{max-width:100%;box-sizing:border-box;width:400px}@media(max-width:580px){body{margin:20px auto;padding:0 12px}section{padding:16px}}
|
||||
</style>
|
||||
<h1>个人笔记工作台</h1><p>先把想法记下来,再把选中的内容交给 Agent。业务数据与应用程序版本分别保存。</p>
|
||||
<section><label for="note">新笔记</label><textarea id="note" placeholder="输入一条笔记"></textarea>
|
||||
<button id="save" class="primary" disabled>保存笔记</button><button id="refresh" disabled>读取最新版本</button><button id="recover" disabled>查询原保存</button>
|
||||
<output id="status" aria-live="polite">正在连接应用宿主…</output><ul id="notes"></ul></section>
|
||||
<section><h2>与 Agent 协作</h2><p>教学示例使用实际 Agent ID;应用可以自行设计选择器。工作须由平台控件接纳。</p>
|
||||
<label for="agent">本次 Agent ID</label><input id="agent" placeholder="由当前授权的 Agent 配置提供">
|
||||
<button id="request" disabled>交给 Agent 讨论选中笔记</button><button id="work" disabled>查询原请求</button><output id="work-status" aria-live="polite">尚未准备请求。</output></section>
|
||||
<script type="module" src="./app.js"></script></html>
|
||||
@@ -0,0 +1,11 @@
|
||||
# 个人笔记工作台教学示例
|
||||
|
||||
这是可修改的最小材料,不是正式市场条目或已经完成的真实 Agent 验收。将示例复制到任务实际授权工作目录,用本 Skill 的 create-release.mjs 生成 app-release.json,再交平台 prepare/snapshot 预览与个人发布。
|
||||
|
||||
笔记保存在声明的 notes key,由平台按用户/实例/预览分配专用数据根。预览数据不自动成为正式数据;包中没有 notes.json。裸浏览器打开可看到页面,缺少可信桥时不会假装已持久保存。Web 须有独立 app origin 和真实 parent MessagePort;同源或无来源时桥拒绝。
|
||||
|
||||
保存使用 expectedETag/expectedAbsent;结果不明保留原 mutationId 和正文,先查原回执。示例只在当前页面保留待查询 ID,完整产品应通过获授权的视图状态或自身数据合同保存可恢复的请求引用,不能持久化平台 token。
|
||||
|
||||
“交给 Agent”先准备提案。真正提交在平台控件上确认,再从 work-accepted 或同请求 lookup 得到真实接纳/Task 状态;页面不能自己签 intent。正式实例引用已声明notes来源文件:namespace为data-files、objectId为notes、revision为readData的真实ETag,平台不猜测notes JSON内部业务schema。选中笔记的稳定id、记录版本及可见文字留在summary;授权范围明确包含读取来源文件并仅讨论所选记录。Agent读取真实文件后定位记录,不能把未实现的notes业务对象owner说成已支持。预览只发讨论摘要,不借正式实例身份。
|
||||
|
||||
更新保持原安装/data scope并先核验 notes-v1兼容;程序回退不恢复旧笔记。卸载默认保留业务数据。示例无需第三方服务,调用 Agent 仍取决于真实算力连接、权限和额度。平台能力未开放或未发行时保持不可用并说明原因。
|
||||
@@ -0,0 +1,29 @@
|
||||
# 作者接口与交付材料
|
||||
|
||||
使用当前 HttpRequest 的授权通道。不要读取管理 token;应用网页不能调用这些作者管理接口。
|
||||
|
||||
| 操作 | 当前接口 | 返回事实 |
|
||||
|---|---|---|
|
||||
| 能力 | `GET /api/apps/capabilities` | 实际 features/policy,不由版本推断 |
|
||||
| 读取交付草稿 | `POST /api/apps/authoring/drafts/read`,`{fileRef}` | 从真实授权文件读取并核验 AppDraftRef |
|
||||
| 预览 | `POST /api/apps/authoring/previews` | snapshot/live、实际 revision、隔离 runtime |
|
||||
| 结束预览 | `POST /api/apps/authoring/previews/:draftId/end`,`{expectedRevision}` | 撤销该预览,Task 保留 |
|
||||
| 固定材料 | `POST /api/apps/releases/prepare` | owned candidate、真实 payload/descriptor 摘要 |
|
||||
| 个人发布 | `POST /api/apps/releases/commit` | writer CAS 和 activation 分开 |
|
||||
| 查询原发布 | `GET /api/apps/installations/:installationId/release-submissions/:submissionId` | committed/absent/unknown |
|
||||
| 历史/更新准备 | `GET /api/apps/installations/:installationId/history`、`update-readiness` | 材料可恢复性与数据兼容,不假定旧数据备份存在 |
|
||||
| 白名单导出 | `POST /api/apps/releases/export` | exportRef、archiveDigest、releaseDigest、实际 files/size |
|
||||
| 下载导出 | export 的 `downloadPath` | 原始 ZIP 响应体,摘要不能以文本解析代替 |
|
||||
| 目录草稿 | `POST /api/apps/distribution/prepare` | Registry 三文件内容、mapping、未上传/未提交事实 |
|
||||
|
||||
`prepare` 输入沿 AppReleasePrepareRequest:`mutationId`、已授权 `materialRoot: FileResourceRef`、`manifestPath`、可选 expectedReleaseDigest、`target:{appId,installationId,deviceId,sourceId}`。首次个人 sourceId 为服务约定的 `user-managed`,不能用名字冒充目录身份。`commit` 使用原 prepareRef、已解析的 ApplicationInstallationRequest、expectedRevision、submissionId。登记失败先查询同提交,不重新复制/启动软件。
|
||||
|
||||
`AppDraftRef` 文件有 `schemaVersion:1`、稳定 draftId/appId、实际授权 `workdir`、绝对 planPath、真实 `source:{agentId,sessionId}`,可选 targetInstallationId/baselineReleaseDigest。文件引用从当前请求或授权读取工具取得,不能复制别的宿主/Agent/root。
|
||||
|
||||
release 采用 `schemaVersion:1` / `canonicalization: app-release-c14n-v1`,包括 definition、delivery、files、source、supportedPlatforms、requiredCapabilities。files 的 role 为 definition/ui/runtime/dependency/documentation/license/evidence/data-contract;路径为包内规范 POSIX。definition 文件必须与 manifest.definition 一致。`app-release.json` 本身不放入 files,不能让摘要自引用。
|
||||
|
||||
web-bundle.delivery.entrypoints 固定 `{entrypointId,path,spaFallback?}`;native-app/docker-app 保存 runtimeInstructionsPath,平台不解释成命令 DSL。source 是实际 Git 完整 commit 或工作树内容 sha256;supportedPlatforms 为 darwin/win32/linux/web。最低客户端是 minimumClientVersion,实际能力仍从握手确认。
|
||||
|
||||
数据合同声明 formatVersion、readableVersions、writableVersions、有限 files key/path/maxBytes/contentType 和 uninstallRetention: retain。备份/迁移/恢复说明引用必须在 payload 白名单中;说明不授权自动执行,安装历史不代表真实数据备份。
|
||||
|
||||
动态 Node 示例的 `/.desirecore-app-identity` 返回当前 TaskHost 注入的 proof/releaseDigest/scopeId/runtimeGeneration;proof 仅用于本次运行身份握手,不当应用 API token,不写日志。`POST /api/apps/runtime/contracts` 使用已 prepare 的材料、installationId、真实 terminalId、endpoint.port/identityPath 与 startupPolicy。服务固定原执行合同后,原 Bash 显式停原命令,正式 commit 后由原 owner 启动新代际再核验。具体环境、执行审批和数据根均由实际 owner 决定。
|
||||
@@ -0,0 +1,15 @@
|
||||
# 固定应用版本分发
|
||||
|
||||
1. 确认用户要分发的精确版本、真实目标仓库/Registry、公共或私有范围、实际登录连接和材料许可。生成文件、个人发布或已有预览都不是上传授权;既有会话中的明确分发授权直接沿用。
|
||||
2. 从 prepareRef,或 installationId + expectedRevision 导出。`paths` 必须显式覆盖全部 payload + app-release.json;不包含服务物化 descriptor、owner 标记、个人数据和秘密。核验响应的 files、size 和下载原始字节 archiveDigest。
|
||||
3. GitHub Release 通过实际授权工具上传此 ZIP,核读真实下载地址、固定 commit 和原始字节摘要;Gitea 私有仓库可提交 `releases/<version>.zip`,取得完整 commit 与该路径。可变 tag/latest 只作展示,必须解析到固定引用。没有真实来源回执就报告“制品已生成,尚未上传”。
|
||||
4. `POST /api/apps/distribution/prepare` 输入 `exportRef`、用户已登记的 registryRepoId、`source:{kind:'release'|'git',url,ref,sha256,path?}` 和实际 metadata。git 必须给固定包路径,sha256 必须等于导出 archiveDigest。产品 ID/名称/版本/入口不由 metadata 另填。
|
||||
5. metadata 包含 author/description/tags/category/license/redistribution/availability/requiredClientVersion,以及实际维护者、品牌和复核材料。证据不足保留 listing-only;不要填不存在的审核者、认证、发布时间或平台验收。已复核的许可证路径应来自同一 release 的 license role 文件。
|
||||
6. 返回的是 `entries/<id>/manifest.json`、`catalog-metadata.v1.json`、`install.md` 内容和摘要。mapping 关联目标 sourceId、逻辑 ID、releaseDigest 与 archiveDigest,descriptor 安装时按真实来源物化。将三文件写入实际授权的目录仓库后审阅 diff,通过其原治理提交 PR;不能自动合并或说目录已开放。
|
||||
7. 查询真实目录可获取状态与目标客户端握手,再由第二用户/设备沿原 acquisition/app-install-manager 路径安装并核验。两来源同名不共享实例或数据;目录更新仅给更新候选,不改原安装快照。
|
||||
|
||||
候选 Registry 4.3 Schema 与客户端 reader 必须先分别 review;正式 Registry seed 只指已合入的受审提交。候选 reader 仅在明确受信的非官方测试来源开放,正式条目等待客户端能力发行,不能借 10.0.180 字符串跳过 app-authoring-v1。
|
||||
|
||||
私有源使用 `access: private` 的真实 Registry 连接,只读登记端点、不转公开镜像;认证失败拒绝新获取。字段不是 ACL,GitHub/Gitea 管理员仍负责实际成员权限。平台团队成员移除不自动改变源端 ACL,不能宣称已撤销。已下载字节不能收回,本机数据不自动删除。
|
||||
|
||||
离线可继续使用已核验的本地固定版本,远端依赖如实不可用;离线不能产生新的来源上传成功。目录撤回阻止新获取并保留理由,不自动卸载已安装应用。临时导出不修改当前个人发布,取消分发保留原工作台。
|
||||
@@ -0,0 +1,33 @@
|
||||
/** 教学清单生成器:读取显式inputs,固定原始字节;不是平台自动build/install器。 */
|
||||
import { createHash } from 'node:crypto'
|
||||
import { lstatSync, readFileSync, writeFileSync } from 'node:fs'
|
||||
import { resolve, join } from 'node:path'
|
||||
|
||||
if (!process.argv[2]) throw new Error('example_directory_required')
|
||||
const directory = resolve(process.argv[2])
|
||||
const input = JSON.parse(readFileSync(join(directory, 'release-inputs.json'), 'utf8'))
|
||||
const hash = bytes => createHash('sha256').update(bytes).digest('hex')
|
||||
const canonical = value => Array.isArray(value) ? value.map(canonical) : value && typeof value === 'object'
|
||||
? Object.fromEntries(Object.keys(value).sort().map(key => [key, canonical(value[key])])) : value
|
||||
const files = input.files.map(file => {
|
||||
if (typeof file.path !== 'string' || /[\\\x00-\x1f?#:]/.test(file.path) || file.path.startsWith('/') ||
|
||||
file.path.split('/').some(part => !part || part === '.' || part === '..') || file.path === 'app-release.json') throw new Error('invalid_payload_path')
|
||||
const parts = file.path.split('/')
|
||||
for (let i = 1; i <= parts.length; i++) if (lstatSync(join(directory, ...parts.slice(0, i))).isSymbolicLink()) throw new Error('payload_link_rejected')
|
||||
const bytes = readFileSync(join(directory, file.path))
|
||||
return { path: file.path, role: file.role, sha256: hash(bytes), size: bytes.length }
|
||||
}).sort((a, b) => a.path < b.path ? -1 : a.path > b.path ? 1 : 0)
|
||||
if (new Set(files.map(file => file.path)).size !== files.length) throw new Error('duplicate_payload_path')
|
||||
if (!files.some(file => file.path === 'application.json' && file.role === 'definition') ||
|
||||
!files.some(file => file.path === '说明.md') ||
|
||||
(input.dataContractPath && !files.some(file => file.path === input.dataContractPath && file.role === 'data-contract'))) throw new Error('missing_declared_payload')
|
||||
const definition = JSON.parse(readFileSync(join(directory, 'application.json'), 'utf8'))
|
||||
const manifest = { schemaVersion: 1, canonicalization: 'app-release-c14n-v1', definition, delivery: input.delivery, files,
|
||||
source: { kind: 'worktree', sha256: hash(JSON.stringify(canonical(files))) }, supportedPlatforms: input.supportedPlatforms,
|
||||
minimumClientVersion: '10.0.180', requiredCapabilities: input.requiredCapabilities,
|
||||
...(input.dataContractPath ? { dataContract: JSON.parse(readFileSync(join(directory, input.dataContractPath), 'utf8')) } : {}),
|
||||
...(input.bridgeCapabilities ? { bridgeCapabilities: input.bridgeCapabilities } : {}),
|
||||
instructionsPath: '说明.md' }
|
||||
manifest.releaseDigest = hash(JSON.stringify(canonical(manifest)))
|
||||
writeFileSync(join(directory, 'app-release.json'), JSON.stringify(manifest, null, 2) + '\n')
|
||||
console.log(JSON.stringify({ appId: definition.id, version: definition.version, releaseDigest: manifest.releaseDigest, files: files.length }))
|
||||
Reference in new issue
Block a user