dal-code 1.0.53 → 1.0.55
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 +15 -0
- package/NOTICE +11 -0
- package/dist/bundle/chunks/{anthropic-messages-Y6ZFHUZY.js → anthropic-messages-LJWWEQIU.js} +1 -1
- package/dist/bundle/chunks/{azure-openai-responses-M6NPMDKK.js → azure-openai-responses-GK4VH6GM.js} +1 -1
- package/dist/bundle/chunks/bedrock-converse-stream.js +1 -1
- package/dist/bundle/chunks/{chunk-FBHNYUW7.js → chunk-2XX4WZT6.js} +1 -1
- package/dist/bundle/chunks/{chunk-EHKSTDLR.js → chunk-3ANBT7AT.js} +1 -1
- package/dist/bundle/chunks/{chunk-EGEFD4CT.js → chunk-44EXLOHK.js} +1 -1
- package/dist/bundle/chunks/{chunk-3KP6IUMV.js → chunk-5TGFM4KW.js} +2 -2
- package/dist/bundle/chunks/{chunk-YALY2HLR.js → chunk-6U37J6E7.js} +343 -345
- package/dist/bundle/chunks/{chunk-EH7SFF47.js → chunk-AL3DFAIM.js} +2 -2
- package/dist/bundle/chunks/{chunk-GHZXS4EI.js → chunk-D3HKK2ZD.js} +1 -1
- package/dist/bundle/chunks/{chunk-22WV5HKU.js → chunk-DBT5OS5V.js} +1 -1
- package/dist/bundle/chunks/{chunk-QYQJQJ5B.js → chunk-DWMC4U2M.js} +1 -1
- package/dist/bundle/chunks/{chunk-K7VBBYTT.js → chunk-F5SIUTR7.js} +1 -1
- package/dist/bundle/chunks/{chunk-HBTEG3CS.js → chunk-GX37DI5S.js} +1 -1
- package/dist/bundle/chunks/{chunk-XQY5ZHQA.js → chunk-KSF7BFGS.js} +1 -1
- package/dist/bundle/chunks/{chunk-N2RRGQFI.js → chunk-NMU45EFT.js} +1 -1
- package/dist/bundle/chunks/{chunk-6VVU2U7I.js → chunk-PRBATF6B.js} +1 -1
- package/dist/bundle/chunks/{chunk-2IIG5FH4.js → chunk-SCSGNIU5.js} +1 -1
- package/dist/bundle/chunks/{chunk-BY4XL3JS.js → chunk-SMPERFJU.js} +1 -1
- package/dist/bundle/chunks/{chunk-YZQKKXBH.js → chunk-SNBVCTMQ.js} +2 -2
- package/dist/bundle/chunks/{chunk-YIBYUMGO.js → chunk-YDOF6JVP.js} +2 -2
- package/dist/bundle/chunks/{chunk-6GCEEEP2.js → chunk-ZYP3V3TD.js} +1 -1
- package/dist/bundle/chunks/{cli-UYQ4R2DI.js → cli-VKNCK5P5.js} +1 -1
- package/dist/bundle/chunks/{cli-DZWQCYIH.js → cli-Z44UHMMU.js} +1 -1
- package/dist/bundle/chunks/{cloudflare-workers-ai-system-one-HI7IU5IW.js → cloudflare-workers-ai-system-one-G4E4L26A.js} +1 -1
- package/dist/bundle/chunks/{easter-egg-3d-5TFBCTIS.js → easter-egg-3d-W2F3ROZ6.js} +1 -1
- package/dist/bundle/chunks/{execute-B5PKAASV.js → execute-3FWM3EMV.js} +1 -1
- package/dist/bundle/chunks/{google-generative-ai-DA5V3QPV.js → google-generative-ai-HVFDKPI3.js} +1 -1
- package/dist/bundle/chunks/{google-vertex-BT23CSDX.js → google-vertex-6E4HATAC.js} +1 -1
- package/dist/bundle/chunks/{llama-cpp-classify-T62K6I4H.js → llama-cpp-classify-3HAEJDKO.js} +1 -1
- package/dist/bundle/chunks/{mcp-KRPDZMNU.js → mcp-SGBPG7LV.js} +1 -1
- package/dist/bundle/chunks/{mistral-conversations-NAYQLEXL.js → mistral-conversations-6UC2WYUC.js} +1 -1
- package/dist/bundle/chunks/{office-UYJNMMJ5.js → office-2F4B572E.js} +1 -1
- package/dist/bundle/chunks/{openai-codex-responses-NN7VPVPU.js → openai-codex-responses-WPSZR4EE.js} +1 -1
- package/dist/bundle/chunks/{openai-completions-OWUZLSV4.js → openai-completions-2RGIFVKJ.js} +1 -1
- package/dist/bundle/chunks/{openai-decisions-RU4UQIAZ.js → openai-decisions-BLZVYNRQ.js} +1 -1
- package/dist/bundle/chunks/{openai-responses-NPZBVAJQ.js → openai-responses-N65DO7MB.js} +1 -1
- package/dist/bundle/chunks/{openrouter-images-YX7ATNAW.js → openrouter-images-LQ4VP5P7.js} +1 -1
- package/dist/bundle/chunks/{pi-messages-IDL3P2ML.js → pi-messages-VYTRLMVB.js} +1 -1
- package/dist/bundle/chunks/{review-34VIXKJ7.js → review-MKITXKSI.js} +1 -1
- package/dist/bundle/chunks/{router-WVWEQNZR.js → router-RL7OYANY.js} +1 -1
- package/dist/bundle/chunks/{runtime-WJYFTWKS.js → runtime-KB5ZUQB6.js} +1 -1
- package/dist/bundle/chunks/{sdk-BGOXS6X2.js → sdk-C5BAFGNR.js} +1 -1
- package/dist/bundle/chunks/sync-AQUDRXHM.js +7 -0
- package/dist/bundle/chunks/{typesafe-system-one-64X2E56P.js → typesafe-system-one-6ZFGVJMV.js} +1 -1
- package/dist/bundle/chunks/{usage-VBIOUGRZ.js → usage-CK3QZLTW.js} +1 -1
- package/dist/bundle/chunks/{virtual-modules-JXLCYYRR.js → virtual-modules-GRXCAWTO.js} +1 -1
- package/dist/bundle/cli-runtime.js +1 -1
- package/dist/bundle/index.js +1 -1
- package/dist/bundle/rpc-entry.js +1 -1
- package/dist/core/extensions/index.d.ts +1 -1
- package/dist/core/extensions/types.d.ts +9 -5
- package/dist/core/settings-manager.d.ts +1 -1
- package/dist/core/settings-manager.js +1 -1
- package/dist/core/tools/bash.js +14 -14
- package/dist/core/tools/edit.js +2 -3
- package/dist/core/tools/renderers/bash.js +8 -8
- package/dist/core/tools/renderers/edit.js +2 -2
- package/dist/modes/interactive/components/assistant-message.d.ts +3 -0
- package/dist/modes/interactive/components/assistant-message.js +2 -2
- package/dist/modes/interactive/components/compaction-summary-message.js +1 -3
- package/dist/modes/interactive/components/diff.d.ts +22 -0
- package/dist/modes/interactive/components/diff.js +4 -3
- package/dist/modes/interactive/components/keybinding-hints.js +1 -1
- package/dist/modes/interactive/components/panel-line.js +1 -0
- package/dist/modes/interactive/components/status-indicator.d.ts +23 -1
- package/dist/modes/interactive/components/status-indicator.js +1 -1
- package/dist/modes/interactive/components/tool-execution.d.ts +2 -2
- package/dist/modes/interactive/components/tool-execution.js +5 -5
- package/dist/modes/interactive/interactive-mode.d.ts +3 -0
- package/dist/modes/interactive/interactive-mode.js +18 -18
- package/dist/modes/interactive/theme/dark.json +4 -0
- package/dist/modes/interactive/theme/light.json +4 -0
- package/dist/modes/interactive/theme/system-theme.js +1 -1
- package/dist/modes/interactive/theme/theme-tokens.d.ts +10 -0
- package/dist/modes/interactive/theme/theme-tokens.js +1 -1
- package/dist/modes/rpc/rpc-types.d.ts +2 -6
- package/dist/node_modules/@dalcode/dal-advisor/package.json +3 -3
- package/dist/node_modules/@dalcode/dal-awake/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-bridge/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-capabilities/package.json +4 -4
- package/dist/node_modules/@dalcode/dal-codeindex/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-compat/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-dap/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-gateway/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-goal/package.json +3 -3
- package/dist/node_modules/@dalcode/dal-guard/package.json +4 -4
- package/dist/node_modules/@dalcode/dal-halo/package.json +1 -1
- package/dist/node_modules/@dalcode/dal-interactive/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-lang/package.json +3 -3
- package/dist/node_modules/@dalcode/dal-learn/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-learn/src/engine.js +2 -2
- package/dist/node_modules/@dalcode/dal-learn/src/index.js +14 -14
- package/dist/node_modules/@dalcode/dal-learn/src/lessons.js +4 -4
- package/dist/node_modules/@dalcode/dal-learn/src/safety.js +2 -2
- package/dist/node_modules/@dalcode/dal-lsp/package.json +4 -4
- package/dist/node_modules/@dalcode/dal-mcp/package.json +6 -6
- package/dist/node_modules/@dalcode/dal-office/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-pi-kit/dist/i18n.js +2 -2
- package/dist/node_modules/@dalcode/dal-pi-kit/package.json +1 -1
- package/dist/node_modules/@dalcode/dal-pi-kit/src/i18n.js +2 -2
- package/dist/node_modules/@dalcode/dal-plugins/package.json +4 -4
- package/dist/node_modules/@dalcode/dal-recall/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-remote/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-review/package.json +3 -3
- package/dist/node_modules/@dalcode/dal-rewind/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-router/package.json +6 -6
- package/dist/node_modules/@dalcode/dal-rtk/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-skills/package.json +3 -3
- package/dist/node_modules/@dalcode/dal-statusline/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-structured/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-subagent/package.json +5 -5
- package/dist/node_modules/@dalcode/dal-sync/package.json +4 -4
- package/dist/node_modules/@dalcode/dal-telemetry/package.json +4 -4
- package/dist/node_modules/@dalcode/dal-terminal/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-tool-catalog/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-usage/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-web/package.json +3 -3
- package/dist/node_modules/@dalcode/dal-workflow/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-workflow/src/todo.js +4 -4
- package/dist/node_modules/@dalcode/deepailab/package.json +3 -3
- package/dist/node_modules/@earendil-works/pi-agent-core/package.json +3 -3
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/.manifest.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/openrouter.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/utils/version.d.ts +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/utils/version.js +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/package.json +3 -3
- package/dist/node_modules/@earendil-works/pi-codemode/package.json +1 -1
- package/dist/node_modules/@earendil-works/pi-coding-agent/package.json +1 -1
- package/dist/node_modules/@earendil-works/pi-mcp/package.json +1 -1
- package/dist/node_modules/@earendil-works/pi-schema/package.json +1 -1
- package/dist/node_modules/@earendil-works/pi-telemetry/package.json +1 -1
- package/dist/node_modules/@earendil-works/pi-tui/package.json +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/gondolin/package-lock.json +2 -2
- package/examples/extensions/gondolin/package.json +1 -1
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/dist/bundle/chunks/sync-D7K3QQKF.js +0 -7
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const PI_AI_VERSION = "1.0.
|
|
1
|
+
export declare const PI_AI_VERSION = "1.0.55";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const I="1.0.
|
|
1
|
+
const I="1.0.55";export{I as PI_AI_VERSION};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@earendil-works/pi-ai",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.55",
|
|
4
4
|
"description": "Unified LLM API with automatic model discovery and provider configuration",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -62,8 +62,8 @@
|
|
|
62
62
|
"dependencies": {
|
|
63
63
|
"@anthropic-ai/sdk": "0.129.0",
|
|
64
64
|
"@aws-sdk/client-bedrock-runtime": "3.1127.0",
|
|
65
|
-
"@earendil-works/pi-schema": "1.0.
|
|
66
|
-
"@earendil-works/pi-telemetry": "1.0.
|
|
65
|
+
"@earendil-works/pi-schema": "1.0.55",
|
|
66
|
+
"@earendil-works/pi-telemetry": "1.0.55",
|
|
67
67
|
"@google/genai": "2.21.0",
|
|
68
68
|
"@smithy/node-http-handler": "4.12.1",
|
|
69
69
|
"http-proxy-agent": "9.1.0",
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-extension-gondolin",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.55",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "pi-extension-gondolin",
|
|
9
|
-
"version": "1.0.
|
|
9
|
+
"version": "1.0.55",
|
|
10
10
|
"dependencies": {
|
|
11
11
|
"@earendil-works/gondolin": "0.14.0"
|
|
12
12
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-extension-with-deps",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.55",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "pi-extension-with-deps",
|
|
9
|
-
"version": "1.0.
|
|
9
|
+
"version": "1.0.55",
|
|
10
10
|
"dependencies": {
|
|
11
11
|
"ms": "^2.1.3"
|
|
12
12
|
},
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dal-code",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.55",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "dal-code",
|
|
9
|
-
"version": "1.0.
|
|
9
|
+
"version": "1.0.55",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@agentclientprotocol/sdk": "1.3.0",
|
package/package.json
CHANGED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
var me=Object.defineProperty;var i=(e,t)=>me(e,"name",{value:t,configurable:!0});import{createRequire as be}from"node:module";const zt=be(import.meta.url);import"./chunk-N2RRGQFI.js";import"./chunk-YALY2HLR.js";import"./chunk-YIBYUMGO.js";import"./chunk-3KP6IUMV.js";import"./chunk-3YGHTGYM.js";import"./chunk-GHZXS4EI.js";import"./chunk-SE42OS3U.js";import"./chunk-K7VBBYTT.js";import"./chunk-EH7SFF47.js";import"./chunk-6QGV3IWD.js";import"./chunk-R47JBGS3.js";import"./chunk-XJFQKN3N.js";import{DATA_FORMAT_KEY as he,declaredDataFormat as F,reportNewerDataFormat as J,t as k,withFileLockSync as R,writeFileAtomicSync as w}from"./chunk-YZQKKXBH.js";import"./chunk-IEBK4HQA.js";import"./chunk-5AGIVGSV.js";import"./chunk-723ZGEZ2.js";import"./chunk-ZG74NES2.js";import"./chunk-TMTOQ7H7.js";import"./chunk-7DDKXS2Q.js";import"./chunk-FFMDRXC4.js";import"./chunk-FBHNYUW7.js";import"./chunk-4LDEEFCY.js";import"./chunk-EGEFD4CT.js";import"./chunk-JXWJOIH4.js";import{existsSync as ye,readFileSync as ge}from"node:fs";import{join as Ee}from"node:path";import{createHash as Ae,randomBytes as ve}from"node:crypto";import{existsSync as G,mkdirSync as C,readdirSync as Se,readFileSync as q,rmSync as ke,statSync as we}from"node:fs";import{join as A}from"node:path";import{join as _e}from"node:path";import{homedir as xe}from"node:os";var Ie=[[/-----BEGIN [A-Z ]*PRIVATE KEY-----[\s\S]*?(?:-----END [A-Z ]*PRIVATE KEY-----|$)/g,"<private-key>"],[/\b(?:sk|pk|rk)-[A-Za-z0-9_-]{8,}/g,"<secret>"],[/\bBearer\s+[A-Za-z0-9._~+/=-]{8,}/gi,"Bearer <secret>"],[/\beyJ[A-Za-z0-9._-]{16,}/g,"<secret>"],[/\b(?:ghp|gho|ghu|ghs|ghr|github_pat)_[A-Za-z0-9_]{8,}/g,"<secret>"],[/\bglpat-[A-Za-z0-9_-]{8,}/g,"<secret>"],[/\bAKIA[0-9A-Z]{12,}/g,"<secret>"],[/\bxox[abposr]-[A-Za-z0-9-]{8,}/g,"<secret>"],[/\bnpm_[A-Za-z0-9]{20,}/g,"<secret>"],[/\b([A-Za-z0-9_.-]*(?:token|secret|password|passwd|api[_-]?key|access[_-]?key|private[_-]?key|auth|cookie|session)[A-Za-z0-9_.-]*)(["']?\s*[:=]\s*["']?)([^\s"',;]{4,})/gi,"$1$2<secret>"],[/(\b[a-z][a-z0-9+.-]*:\/\/)[^\s/@:]+:[^\s/@]+@/gi,"$1<secret>@"],[/[A-Za-z0-9+/_-]{40,}={0,2}/g,"<opaque>"]];function j(e){let t=e;for(let[r,n]of Ie)t=t.replace(r,n);let s=xe();return s&&s.length>1&&(t=t.split(s).join("~")),t=t.replace(/(?:\/Users\/|\/home\/|[A-Za-z]:\\Users\\)[^\s/\\]+/g,"~"),t}i(j,"redact");var Fe=[{reason:"weakens_safety",pattern:/\b(?:skip|bypass|disable|ignore|override|turn off|circumvent)\b[^\n]{0,40}\b(?:approvals?|permissions?|sandbox(?:es)?|safety|guards?|confirmations?|hooks?|polic(?:y|ies)|protections?)\b/i},{reason:"weakens_safety",pattern:/(?:跳过|绕过|关闭|禁用|忽略|无视)[^。\n]{0,12}(?:审批|权限|确认|沙箱|安全|保护|钩子|拦截)/u},{reason:"weakens_safety",pattern:/(?:不要|不必|无需)(?![^。\n]{0,6}未经)[^。\n]{0,6}(?:审批|确认|沙箱)/u},{reason:"weakens_safety",pattern:/\b(?:skip|disable)\b[^\n]{0,20}\btests?\b|--no-verify\b/i},{reason:"weakens_safety",pattern:/--dangerously|\byolo\b|bypassPermissions|\bsudo\b|chmod\s+777|rm\s+-rf\s+[/~]/i},{reason:"exfiltrates",pattern:/\b(?:curl|wget|scp|rsync|nc|upload|send|post|exfiltrate|share)\b[^\n]{0,60}\b(?:tokens?|keys?|secrets?|passwords?|credentials?|cookies?|env|\.ssh|sessions?)\b/i},{reason:"exfiltrates",pattern:/(?:上传|发送|发到|外发|分享|传到)[^。\n]{0,20}(?:密钥|令牌|密码|凭据|凭证|cookie|环境变量|私钥)/iu},{reason:"installs",pattern:/\b(?:npm|pnpm|bun)\s+(?:i|install|add)\b[^\n]*?(?:\s-g\b|--global\b)|\byarn\s+global\s+add\b/i},{reason:"installs",pattern:/\b(?:brew|apt(?:-get)?|yum|dnf|pacman|apk|choco|winget|scoop|snap|cargo|gem|pipx)\s+(?:install|add)\b|\bgo\s+install\b|\buv\s+tool\s+install\b/i},{reason:"installs",pattern:/\b(?:npm\s+(?:i|install)|pnpm\s+(?:add|i|install)|yarn\s+add|bun\s+add)\s+(?!(?:in|at|from|first|before|after|then|and|again|once|for|inside|to|with|when|so|instead|works|fails|succeeds)\b)[@a-z][\w@./-]*/i},{reason:"installs",pattern:/\|\s*(?:sudo\s+)?(?:ba|z)?sh\b|\binstall(?:er)?\s+script\b/i},{reason:"installs",pattern:/\b(?:npx|npm\s+exec)\b[^\n`]*?\s(?:-y|--yes)\b|\bnpx\s+(?:-\S+\s+)*@?[a-z][\w./-]*@[\w.^~*-]+|\b(?:pnpm|yarn)\s+dlx\b|\bbunx\b|\buvx\b|\bpipx\s+run\b/i},{reason:"installs",pattern:/全局安装|从[^。\n]{1,30}下载|下载(?:并|后)?(?:运行|执行|安装)/u},{reason:"concrete_value",pattern:/\bhttps?:\/\/|\bwww\./i},{reason:"concrete_value",pattern:/<(?:secret|opaque|private-key)>/},{reason:"concrete_value",pattern:/[A-Za-z0-9+/=_-]{40,}/},{reason:"concrete_value",pattern:/\b\d{1,3}(?:\.\d{1,3}){3}\b/},{reason:"concrete_value",pattern:/[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}/},{reason:"concrete_value",pattern:/(?:\/Users\/|\/home\/|[A-Za-z]:\\Users\\)[^\s/\\]+/}];function Re(e){let t=[e.content,e.rootCause??"",e.note??""].join(`
|
|
2
|
-
`);for(let{reason:r,pattern:n}of Fe)if(n.test(t))return r;let s=e.content.trim().length;if(s<6||s>320)return"length"}i(Re,"rejectLesson");var Ce=[{category:"deletion",pattern:/\b(?:rm|rmdir|del|unlink|truncate|shred)\b|\bdelet(?:e|es|ed|ing)\b|\bremov(?:e|es|ed|ing)\b|\bdrop\s+(?:table|database|schema)\b|\bgit\s+(?:clean|reset\s+--hard|push\s+[^\n]*--force|branch\s+-D)\b|\bwip(?:e|ing)\b|\bpurge\b|删除|删掉|清空|清除|覆盖(?!率)|重置/iu},{category:"permissions",pattern:/\b(?:chmod|chown|sudo|setfacl|icacls)\b|\bpermissions?\b|\bapprov(?:al|e)s?\b|\bsandbox\b|\bguard\b|\bescalat\w*|权限|审批|放行|沙箱|提权/iu},{category:"credentials",pattern:/\b(?:tokens?|secrets?|passwords?|passwd|credentials?|api[\s_-]?keys?|private\s+keys?|ssh\s+keys?|auth(?:\.json)?|login|cookies?|\.env)\b|凭据|凭证|密钥|密码|令牌|登录|私钥/iu},{category:"network",pattern:/\b(?:curl|wget|http|https|proxy|download|upload|network|internet|dns|ssh|scp|rsync|webhook|api\s+endpoint)\b|联网|网络|下载|上传|代理|外网/iu},{category:"publishing",pattern:/\b(?:publish|release|deploy|push|git\s+tag|merge\s+to\s+main)\b|发布|发版|上线|部署|推送|合并到主/iu}],$=String.raw`(?:package\.json|package-lock\.json|lock\s?files?|pnpm-lock|yarn\.lock|requirements[\w.-]*\.txt|pyproject\.toml|Cargo\.toml|go\.mod|\.github\/workflows[\w./-]*|CI\s+config(?:uration)?)`,H=/\b(?:npm|pnpm|yarn|bun)[ \t]+(?:i|install|add)[ \t]+(?:-{1,2}[\w-]+[ \t]+)*[@a-z][\w@./-]*|\bpip3?[ \t]+install[ \t]+(?!-r\b)[a-z]|--save-dev\b|\binstall(?:ing)?\s+(?:the\s+|a\s+|an\s+|it\s+)?(?:missing\s+)?(?:tool|package|module|librar\w*|runner|linter|dependenc\w*)|as\s+a\s+dev-?dependency|(?:安装|装上|装一下|补装)\s*(?:缺少的|缺失的)?\s*(?:工具|依赖|包|插件|运行器)|装依赖/iu,je=new RegExp(String.raw`\b(?:fix|edit|change|modify|update|rewrite|patch|add\b[^.;\n]{0,40}?\bto)\b[^.;\n]{0,40}?${$}|\b(?:fix|edit|change|modify|update|rewrite|patch)\b[^.;\n]{0,12}?\b(?:the\s+)?(?:npm\s+|test\s+|lint\s+|build\s+)?scripts?\b|(?:改|修改|改写|修复)[^。;;\n]{0,6}?(?:测试|npm|lint|构建)?\s*脚本|${$}[^.;\n]{0,20}?\b(?:should|must)\s+be\s+(?:changed|edited|updated|fixed)|(?:改|修改|编辑|调整|修复|补上|加到|写进)[^。;;\n]{0,12}?${$}`,"iu"),Y=/\b(?:before|instead\s+of|rather\s+than|don'?t|do\s+not|never|avoid|without)\b[^.;\n]{0,24}$|(?:不要|别|不许|先别|而不是|避免|不用)[^。;;\n]{0,8}$/iu;function $e(e){if(H.test(e)){let s=e.search(H);if(!Y.test(e.slice(Math.max(0,s-30),s)))return!0}let t=je.exec(e);return!!(t&&!Y.test(e.slice(Math.max(0,t.index-30),t.index)))}i($e,"prescribesDependencyChange");function Te(e){let t=Ce.filter(({pattern:s})=>s.test(e)).map(({category:s})=>s);return $e(e)?[...t,"dependencies"]:t}i(Te,"riskOf");var Ne=[["typecheck",/\btsc\b(?!.*--build)|\bmypy\b|\bpyright\b|\b(?:npm|pnpm|yarn|bun)\s+(?:run\s+)?(?:typecheck|type-check|check-types)\b/],["test",/\b(?:vitest|jest|mocha|ava|pytest|tox|rspec|phpunit)\b|\b(?:npm|pnpm|yarn|bun)\s+(?:run\s+)?test\b|\bnode\s+--test\b|\b(?:go|cargo|dotnet|mix|deno)\s+test\b|\bmake\s+test\b|\bgradlew?\s+test\b|\bmvn\s+test\b/],["lint",/\b(?:eslint|biome|ruff|flake8|pylint|golangci-lint|clippy|prettier\s+--check)\b|\b(?:npm|pnpm|yarn|bun)\s+(?:run\s+)?(?:lint|check)\b/],["build",/\b(?:npm|pnpm|yarn|bun)\s+(?:run\s+)?build\b|\b(?:cargo|go|dotnet|swift)\s+build\b|\bmake\b(?!\s+test)|\bgradlew?\s+(?:build|assemble)\b|\bmvn\s+(?:package|install)\b|\btsc\s+--build\b|\bvite\s+build\b|\bwebpack\b/],["install",/^(?:npm\s+(?:ci|install|i)|pnpm\s+(?:install|i)|yarn(?:\s+install)?|bun\s+install|pip3?\s+install\s+(?:-r|-e|\.)|poetry\s+install|uv\s+sync|bundle\s+install|composer\s+install|go\s+mod\s+download)(?:\s|$)/]],De=/^(?:tail|head|grep|egrep|fgrep|cat|less|more|tee|wc|sort|uniq|cut|column|sed|awk|nl)\b/,Oe=/^(?:head|grep|egrep|fgrep|cut|sed|awk)\b/,Le=/^(?:echo|printf|cat|ls|pwd|true|false|:|#|sed|awk|grep|rg|head|tail|wc|find|git\s+(?:diff|status|log|show|stash|add)|set|export|printenv|which|whereis|type|command\s+-v|test\s|\[|stat|file|(?:node|npm|pnpm|yarn|bun|npx)\s+(?:-v|--version)|(?:npm|pnpm|yarn)\s+(?:ls|list|view|info|bin|root|config|why))(?:\b|(?=\s|$))/;function Be(e){let t=e.replace(/<<-?\s*(['"]?)(\w+)\1([^\n]*)\n[\s\S]*?\n[ \t]*\2[ \t]*(?=\n|$)/g,"<<$2$3").replace(/\s*\d*>&\d+/g,""),s=[],r=[],n="",a,o=i(()=>{r.push(n.trim()),n=""},"endStage"),d=i(()=>{o();let c=r.filter(Boolean);c.length&&s.push(c),r=[]},"endStatement");for(let c=0;c<t.length;c++){let l=t[c];if(a){if(l==="\\"&&a==='"'){n+=l+(t[c+1]??""),c++;continue}l===a&&(a=void 0),n+=l;continue}l==="'"||l==='"'?(a=l,n+=l):l==="\\"?(n+=l+(t[c+1]??""),c++):l===";"||l===`
|
|
3
|
-
`?d():(l==="&"||l==="|")&&t[c+1]===l?(d(),c++):l==="&"?d():l==="|"?o():n+=l}return d(),s}i(Be,"splitStatements");function Me(e){let t=[],s=!1;for(let r of Be(e)){let n=[...r],a=!1;for(;n.length>1&&De.test(n.at(-1));)Oe.test(n.at(-1))&&(a=!0),n.pop();let o=n.join(" | ").replace(/\s+/g," ");/^cd\s/.test(o)?t.push(o):!Le.test(o)&&T(o)&&(t.push(o),a&&(s=!0))}for(;t.length&&/^cd\s/.test(t.at(-1));)t.pop();return{statements:t,selected:s}}i(Me,"checkParts");function T(e){for(let[t,s]of Ne)if(s.test(e))return t}i(T,"intentOf");var V=120,W=/^(?:at\s|\S+\s\(\S+:\d+:\d+\)$|(?:file:\/\/)?\S+\.(?:[cm]?[jt]sx?|py|go|rs|rb|java|kt|php)(?::\d+){1,2}$|.*\bnode:internal\/|Node\.js v\d)/,X=/^(?:>?\s*\d+\s*\|.*|[\s|]*\^+[\s^~]*|(?:if|else|for|while|switch|const|let|var|return|function|class|import|export|async|await|def|try|catch)\b.*|\}.*)$|\bthrow new\b|=>|[;{]$/,Q=/^(?:(?:duration_ms|type|location|failureType|code|stack|operator|expected|actual|generatedMessage|name):|\.{3}$|-{3}$|TAP version|Subtest:|1\.\.\d+$|(?:tests|suites|pass|fail|cancelled|skipped|todo|duration_ms)\s+\d|Command exited with code)/,ze=/^(?:E\s+)?(?:Uncaught\s+)?(?:[A-Z][\w.]*(?:Error|Exception)|Error|error(?: TS\d+|\[E\d+\])?)(?:\s*\[[\w-]+\])?:\s*\S|\berror TS\d+:\s*\S/,Ze=/^(?:expected\b.*\b(?:received|to (?:be|equal)|but got)\b|(?:Expected|Received)(?: value)?:\s*\S|.+\s!==?\s.+)/i,Pe=/^(?:FAIL(?:ED)?\b|not ok \d+|[✖×✗]\s|--- FAIL:?)/,Ke=/not found|no such|cannot|can't|unable|error|fail|missing|denied|unknown|invalid|找不到|不存在|失败|错误/i;function Ue(e){let t=e.trim().replace(/^#\s?/,"").trim();return t!==""&&(W.test(t)||X.test(t)||Q.test(t))}i(Ue,"isUntellingReason");function Je(e){let t=e.findIndex(n=>Ze.test(n));if(t<0)return;let s=e[t],r=/^Expected(?: value)?:/i.test(s)?e.slice(t+1,t+4).find(n=>/^Received(?: value)?:/i.test(n)):void 0;return r?`${s}, ${r}`:s}i(Je,"comparison");function Ge(e){let t=j(e).replace(/\s+/g," ").trim();return t.length>V?`${t.slice(0,V-1)}\u2026`:t}i(Ge,"clipReason");function qe(e){let t=[];for(let s=0;s<e.length;s++){let r=/^error:\s*(.*)$/.exec(e[s]);if(!r)continue;let n=r[1].replace(/^'(.*)'$/,"$1").replace(/^"(.*)"$/,"$1");if(/^\|-?$/.test(n)){let o=[];for(let d=s+1;d<e.length&&o.length<2&&!/^[a-z_]+:\s/i.test(e[d]);d++)o.push(e[d]);n=o.join(" ")}if(!n||n==="test failed")continue;let a="";for(let o=s+1;o<Math.min(e.length,s+12)&&!/^(?:\.{3}|not ok|ok)\b/.test(e[o]);o++){let d=/^name:\s*'?([\w.]+)'?$/.exec(e[o]);if(d){a=d[1];break}}t.push(a&&!n.startsWith(a)?`${a}: ${n}`:n)}return t}i(qe,"tapErrors");function He(e){let t=e.split(/\r?\n/).map(n=>n.trim().replace(/^#\s?/,"").trim()).filter(Boolean),s=t.filter(n=>!W.test(n)&&!X.test(n)&&!Q.test(n)),r=qe(t)[0]??s.find(n=>ze.test(n))??Je(s)??s.find(n=>Pe.test(n))??s.find(n=>Ke.test(n))??"";return Ge(r)}i(He,"failureReason");function ee(e){let t="",s=[];for(let r of Me(e).statements){let n=/^cd\s+("[^"]+"|'[^']+'|\S+)$/.exec(r);if(n){let o=n[1].replace(/^["']|["']$/g,"");t=t&&!o.startsWith("/")?`${t}/${o}`:o;continue}let a=r.replace(/\s+/g," ").trim();s.some(o=>o.dir===t&&o.check===a)||s.push({dir:t,check:a,...T(a)?{intent:T(a)}:{}})}return s}i(ee,"segmentsOf");function Ye(e,t){return e===t||` ${e} `.includes(` ${t} `)||` ${t} `.includes(` ${e} `)}i(Ye,"overlaps");function Ve(e,t){let s=ee(e),r=ee(t),n=i((h,f)=>h.dir===f.dir&&h.check===f.check,"same"),a=s.filter(h=>!r.some(f=>n(h,f)));if(a.length===0)return;let o=new Set(a.map(h=>h.intent)),d=r.filter(h=>!s.some(f=>n(h,f))||o.has(h.intent)),c=a.filter(h=>d.some(f=>f.intent===h.intent));if(c.length===0||d.length===0||[...c,...d].some(h=>/^(?:\/|~|\$)/.test(h.dir))||c.some(h=>d.some(f=>f.dir===h.dir&&Ye(h.check,f.check))))return;let l=i(h=>{let f=h[0].dir;if(h.some(p=>p.dir!==f))return;let u=h.map(p=>p.check).join(" && ");return f?`cd ${f} && ${u}`:u},"joined"),b=l(c),g=l(d);if(!(!b||!g||b===g))return{bad:b,good:g}}i(Ve,"fixCommands");var We=/command not found|: not found|is not (?:set|defined)|Missing script|Cannot find (?:module|package)|ERR_MODULE_NOT_FOUND|ENOENT|No such file|unknown (?:option|command|script|flag)|not recognized as|No test files|No tests found|permission denied|EACCES|找不到|未设置|不存在|未找到/i,Xe=/AssertionError|^\s*(?:Expected|Received)(?: value)?:|\bexpected\b.*\b(?:received|to (?:be|equal)|but got)\b|\s!==?\s|^not ok \d+|^#\s*fail\s+[1-9]|^\s*\d+ (?:failing|failed)\b|Tests?:\s+\d+ failed|\berror TS\d+:|\d+ problems? \(\d+ errors?/im;function Qe(e){return Xe.test(e)&&!We.test(e)}i(Qe,"codeFailed");import{mkdirSync as et,readFileSync as tt}from"node:fs";import{dirname as st}from"node:path";var N=1;function te(e){let t;try{t=tt(e,"utf8")}catch{return}try{let s=JSON.parse(t);return s&&typeof s=="object"&&!Array.isArray(s)?s:void 0}catch{return}}i(te,"readRaw");function nt(e,t){let s=te(e),r=s!==void 0&&F(s)>N;return r&&J(e),{value:t(s),readOnly:r}}i(nt,"readDoc");function rt(e,t,s){return et(st(e),{recursive:!0,mode:448}),R(e,()=>{let r=te(e);if(r!==void 0&&F(r)>N){J(e);return}let n=s(t(r));if(n===void 0)return;let a={...r??{},...n,[he]:N};return w(e,`${JSON.stringify(a,null," ")}
|
|
4
|
-
`,{mode:384}),n})}i(rt,"updateDoc");function m(e,t){return typeof e=="string"?e.trim().slice(0,t):""}i(m,"str");function v(e){return typeof e=="number"&&Number.isFinite(e)&&e>=0?Math.floor(e):0}i(v,"num");function D(e,t,s){return Array.isArray(e)?e.filter(r=>typeof r=="string"&&r.length>0).map(r=>r.slice(0,s)).slice(-t):[]}i(D,"strList");function O(e){return Array.isArray(e)?e.filter(t=>!!t&&typeof t=="object"&&!Array.isArray(t)):[]}i(O,"records");var Is=10080*60*1e3,it=["harmful","ineffective","unused","user","malformed"],at=6,ot=12,ut=20,dt=["candidate","active","awaiting_user","retired","undone","expired"],ct=["failure_then_fix","user_correction","repeated_detour","guard_denial","success_workflow","imported"],lt=["helpful","harmful","neutral"],pt=["deletion","permissions","credentials","network","publishing","dependencies"];function se(e){return _e(e,"lessons.json")}i(se,"lessonsPath");function ft(e){let t=m(e.id,16),s=m(e.content,400);if(!/^[lu]-\d{4,6}$/.test(t)||!s)return;let r=dt.includes(e.status)?e.status:"candidate",n=e.fix,a=e.proof,o=e.origin;return{...e,id:t,scope:e.scope==="user"?"user":"project",section:m(e.section,40)||"general",content:s,rootCause:m(e.rootCause,400),...m(e.signature,300)?{signature:m(e.signature,300)}:{},...n&&typeof n.good=="string"?{fix:{intent:m(n.intent,20),bad:m(n.bad,200),good:m(n.good,200)}}:{},status:r,risk:D(e.risk,5,20).filter(d=>pt.includes(d)),sessions:D(e.sessions,ot,80),evidence:O(e.evidence).map(d=>({sessionId:m(d.sessionId,80),at:m(d.at,32),signal:ct.includes(d.signal)?d.signal:"user_correction",note:m(d.note,300)})).slice(-at),...a&&typeof a.at=="string"?{proof:{kind:a.kind==="outcome"?"outcome":"test",at:m(a.at,32),sessionId:m(a.sessionId,80),note:m(a.note,300)}}:{},helpful:v(e.helpful),harmful:v(e.harmful),...v(e.neutral)>0?{neutral:v(e.neutral)}:{},...v(e.injections)>0?{injections:v(e.injections)}:{},...m(e.lastInjectedAt,32)?{lastInjectedAt:m(e.lastInjectedAt,32)}:{},feedback:O(e.feedback).filter(d=>lt.includes(d.tag)).map(d=>({sessionId:m(d.sessionId,80),tag:d.tag,at:m(d.at,32),why:m(d.why,200)})).slice(-ut),created:m(e.created,32),updated:m(e.updated,32),...m(e.activatedAt,32)?{activatedAt:m(e.activatedAt,32)}:{},...["sessions","proof","user","import"].includes(e.activatedBy)?{activatedBy:e.activatedBy}:{},...m(e.lastHelpfulAt,32)?{lastHelpfulAt:m(e.lastHelpfulAt,32)}:{},...m(e.retiredAt,32)?{retiredAt:m(e.retiredAt,32)}:{},...it.includes(e.retiredReason)?{retiredReason:e.retiredReason}:{},...o&&o.kind==="desktop"?{origin:{kind:"desktop",projectId:m(o.projectId,32),ruleId:m(o.ruleId,16)}}:{}}}i(ft,"parseLesson");var _=i(e=>e.replace(/\s+/g," ").trim(),"fold");function mt(e){if(!e.fix||!e.signature?.startsWith("fix:")||e.activatedBy==="user"||e.activatedBy==="import")return!1;let t=Ve(e.fix.bad,e.fix.good);return!t||_(t.bad)!==_(e.fix.bad)||_(t.good)!==_(e.fix.good)||Ue(e.rootCause)||e.rootCause.trim()&&!He(e.rootCause)||Qe(e.rootCause)?!0:Re({content:e.content})!==void 0}i(mt,"isMalformed");var bt=["candidate","active","awaiting_user"];function ht(e){return!bt.includes(e.status)||!mt(e)?e:{...e,status:"retired",retiredAt:e.updated||e.created,retiredReason:"malformed"}}i(ht,"retireMalformed");function yt(e){if(e.activatedBy==="user"||e.activatedBy==="import")return e;let t=Te(e.fix?`${e.fix.good}
|
|
5
|
-
${e.rootCause??""}`:e.content).filter(r=>!e.risk.includes(r));if(t.length===0)return e;let s=[...e.risk,...t];return e.status==="active"?{...e,risk:s,status:"awaiting_user"}:{...e,risk:s}}i(yt,"recheckRisk");function ne(e){let t=O(e?.lessons).map(ft).filter(a=>a!==void 0).map(ht).map(yt),s=t.reduce((a,o)=>Math.max(a,Number(o.id.slice(2))),0),r={},n=e?.imported;if(n&&typeof n=="object"&&!Array.isArray(n))for(let[a,o]of Object.entries(n))r[a]=D(o,1e3,16);return{nextId:Math.max(v(e?.nextId),s+1,1),lessons:t,imported:r}}i(ne,"parseLessonsDoc");function re(e){return nt(se(e),ne).value}i(re,"readLessons");function ie(e,t){return rt(se(e),ne,t)}i(ie,"updateLessons");var Fs=new Set("the and for with this that these those from into when then than before after instead only each every use used using run runs running ran make makes made keep edit edits editing file files project projects here there what which while where your you our are was were has have had not but all any its one two fails fail failed failing passes pass passed should must can will just also more most first last same src lib test tests js mjs cjs ts tsx jsx json md py go rs txt yaml yml".split(" ")),Rs=new Set("\u672C\u9879 \u9879\u76EE \u76EE\u91CC \u6539\u7528 \u4F1A\u5931 \u5931\u8D25 \u4F7F\u7528 \u65F6\u5019 \u4E4B\u524D \u4E4B\u540E \u6587\u4EF6 \u8FD0\u884C \u4E00\u4E0B \u8FD9\u4E2A \u90A3\u4E2A \u53EF\u4EE5 \u9700\u8981 \u4E0D\u8981 \u5982\u679C \u7136\u540E \u73B0\u5728 \u5DF2\u7ECF \u6211\u4EEC \u4F60\u7684 \u4E00\u4E2A \u4EC0\u4E48 \u600E\u4E48 \u4E3A\u4EC0\u4E48 \u5E2E\u6211 \u770B\u770B \u95EE\u9898 \u4EE3\u7801".split(" ")),gt=256*1024,ae=/^[a-z0-9]+(?:-[a-z0-9]+)*$/,oe=1,S=class extends Error{static{i(this,"SyncHttpError")}status;constructor(e){super(`dal sync request failed (${e})`),this.status=e}},L=i(e=>A(e,"skills"),"skillsDir"),ue=i(e=>A(e,"learned","user"),"userLessonsDir"),B=i(e=>A(e,"sync","state.json"),"statePath");function M(e){return Array.isArray(e)?`[${e.map(M).join(",")}]`:e&&typeof e=="object"?`{${Object.entries(e).filter(([,t])=>t!==void 0).sort(([t],[s])=>t<s?-1:t>s?1:0).map(([t,s])=>`${JSON.stringify(t)}:${M(s)}`).join(",")}}`:JSON.stringify(e)}i(M,"stable");function x(e){return Ae("sha256").update(M(e)).digest("hex")}i(x,"contentHash");function z(e){return typeof e=="string"?j(e):Array.isArray(e)?e.map(z):e&&typeof e=="object"?Object.fromEntries(Object.entries(e).map(([t,s])=>[t,z(s)])):e}i(z,"redactDeep");var de=["section","content","rootCause","signature","fix","status","risk","helpful","harmful","neutral","injections","lastInjectedAt","created","updated","activatedAt","activatedBy","lastHelpfulAt","retiredAt","retiredReason"],Et=["helpful","harmful","neutral","injections"],At=["lastInjectedAt","lastHelpfulAt"];function vt(e,t){let s={...t};for(let r of Et){let n=e[r]??0,a=typeof t[r]=="number"?t[r]:0;n>a&&(s[r]=n)}for(let r of At){let n=e[r],a=typeof t[r]=="string"?t[r]:void 0;n&&(!a||Date.parse(n)>Date.parse(a))&&(s[r]=n)}return s}i(vt,"mergeLesson");function St(e){let t={};for(let s of de)e[s]!==void 0&&(t[s]=e[s]);return z(t)}i(St,"lessonContent");function kt(e){let t=L(e);if(!G(t))return[];let s=[];for(let r of Se(t)){if(!ae.test(r)||r.length>64)continue;let n=A(t,r,"SKILL.md"),a,o;try{let c=we(n);if(!c.isFile())continue;a=q(n,"utf8"),o=c.mtimeMs}catch{continue}let d={name:r,body:j(a)};s.push({id:`skill.${r}`,kind:"skill",content:d,hash:x(d),updatedAt:o})}return s}i(kt,"readSkills");function wt(e){let t=ue(e);return G(A(t,"lessons.json"))?(re(t).lessons.some(s=>s.scope==="user"&&!s.syncId)&&ie(t,s=>({...s,lessons:s.lessons.map(r=>r.scope==="user"&&!r.syncId?{...r,syncId:_t()}:r)})),re(t).lessons.filter(s=>s.scope==="user"&&typeof s.syncId=="string").map(s=>{let r=St(s);return{id:`lesson.${s.syncId}`,kind:"lesson",content:r,hash:x(r),updatedAt:Date.parse(s.updated)||0}})):[]}i(wt,"readLessonItems");function _t(){return ve(8).toString("hex")}i(_t,"newSyncId");function ce(e){return[...kt(e),...wt(e)]}i(ce,"readLocalItems");function xt(e,t,s,r=()=>!1){if(t.startsWith("skill.")){let c=t.slice(6);if(!ae.test(c)||typeof s.body!="string")return;C(A(L(e),c),{recursive:!0}),w(A(L(e),c,"SKILL.md"),s.body);return}if(!t.startsWith("lesson."))return;let n=t.slice(7),a={};for(let c of de)s[c]!==void 0&&(a[c]=s[c]);let o=a.content;if(typeof o!="string"||!o)return;let d=ue(e);C(d,{recursive:!0,mode:448}),ie(d,c=>{let l=c.lessons,b=l.find(f=>f.syncId===n)??l.find(f=>f.scope==="user"&&(!f.syncId||r(f.syncId))&&f.content===a.content);if(b)return{...c,lessons:l.map(f=>f===b?{...f,...vt(f,a),syncId:n}:f)};let g=new Date().toISOString(),h={id:`u-${String(c.nextId).padStart(4,"0")}`,scope:"user",section:"general",rootCause:"",status:"candidate",risk:[],sessions:[],evidence:[],helpful:0,harmful:0,feedback:[],created:g,updated:g,...a,content:o,syncId:n};return{...c,nextId:c.nextId+1,lessons:[...l,h]}})}i(xt,"applyRemoteItem");function Z(e){try{let t=JSON.parse(q(B(e),"utf8"));if(t.formatVersion!==oe||typeof t.account!="string")return;let s=t.items&&typeof t.items=="object"?t.items:{};return{account:t.account,items:s,lastRun:typeof t.lastRun=="string"?t.lastRun:void 0,lastError:typeof t.lastError=="string"?t.lastError:void 0,lastErrorStatus:typeof t.lastErrorStatus=="number"?t.lastErrorStatus:void 0}}catch{return}}i(Z,"readState");function le(e,t){let s=B(e);C(A(e,"sync"),{recursive:!0,mode:448}),R(s,()=>w(s,`${JSON.stringify({formatVersion:oe,...t},null," ")}
|
|
6
|
-
`,{mode:384}))}i(le,"writeState");function It(e){ke(B(e),{force:!0})}i(It,"clearState");async function Ft(e,t,s){let r=Z(e),n={account:t,items:r?.account===t?{...r.items}:{}},a={uploaded:0,downloaded:0,deletedRemote:0,conflicts:0,refused:[]},o=i(()=>le(e,{...n,lastRun:new Date().toISOString()}),"save"),d=new Map((await s.manifest()).map(u=>[u.id,u])),c=new Map(ce(e).map(u=>[u.id,u])),l=i(u=>{let p=`lesson.${u}`;return!n.items[p]&&!d.has(p)},"neverSynced"),b=new Set,g=i((u,p)=>{xt(e,u,p.content,l),n.items[u]={version:p.version,hash:x(p.content)},b.add(u),a.downloaded++},"apply"),h=i(async u=>{let p=await s.get(u);return p?(g(u,p),!0):!1},"download"),f=i(async(u,p)=>{let y=n.items[u.id];if(y?.refused===u.hash)return;if(Buffer.byteLength(JSON.stringify(u.content))>gt){n.items[u.id]={version:y?.version??0,hash:y?.hash??"",refused:u.hash},a.refused.push(u.id);return}let E=await s.put(u.id,u.kind,p,u.content);E.status==="written"?(n.items[u.id]={version:E.version,hash:u.hash},a.uploaded++):E.status==="conflict"?a.conflicts++:(n.items[u.id]={version:y?.version??0,hash:y?.hash??"",refused:u.hash},a.refused.push(u.id))},"upload");for(let u of d.values()){let p=n.items[u.id]?.remoteDeleted?void 0:n.items[u.id],y=c.get(u.id);if(!y){if(p&&p.version===u.version){await s.remove(u.id)&&a.deletedRemote++,delete n.items[u.id];continue}await h(u.id);continue}if(p&&p.version===u.version)continue;if(p&&y.hash===p.hash){await h(u.id);continue}let E=await s.get(u.id);if(!E)continue;let U=x(E.content);if(U===y.hash){n.items[u.id]={version:E.version,hash:U};continue}a.conflicts++,Date.parse(u.updatedAt)>y.updatedAt?g(u.id,E):await f(y,E.version)}c=new Map(ce(e).map(u=>[u.id,u]));for(let u of b){let p=c.get(u);p&&n.items[u]&&(n.items[u].hash=p.hash)}for(let u of c.values()){let p=n.items[u.id],y=d.get(u.id);if(y){p&&p.version===y.version&&u.hash!==p.hash&&await f(u,y.version);continue}if(p&&u.hash===p.hash){!p.remoteDeleted&&p.version>0&&(n.items[u.id]={...p,remoteDeleted:!0});continue}await f(u,0)}for(let u of Object.keys(n.items))!c.has(u)&&!d.has(u)&&delete n.items[u];return o(),a}i(Ft,"runSync");function Rt(e){let t=`${e.apiBase.replace(/\/+$/,"")}/portal/dal-sync`,s=e.fetch??fetch;async function r(o,d,c){let l=await e.token();if(!l)throw new S(401);let b=await s(`${t}${d}`,{method:o,headers:{Authorization:`Bearer ${l}`,Accept:"application/json",...c===void 0?{}:{"Content-Type":"application/json"}},body:c===void 0?void 0:JSON.stringify(c),signal:AbortSignal.timeout(e.timeoutMs??2e4)}),g=await b.json().catch(()=>null);return{status:b.status,data:g}}i(r,"call");let n=i(o=>o&&typeof o=="object"&&!Array.isArray(o)?o:{},"record"),a=i(o=>`/items/${encodeURIComponent(o)}`,"item");return{async manifest(){let{status:o,data:d}=await r("GET","/manifest");if(o!==200)throw new S(o);let c=n(d).items;return(Array.isArray(c)?c:[]).flatMap(l=>{let b=n(l);return typeof b.id!="string"||b.kind!=="skill"&&b.kind!=="lesson"?[]:[{id:b.id,kind:b.kind,version:Number(b.version)||0,updatedAt:typeof b.updatedAt=="string"?b.updatedAt:new Date(0).toISOString()}]})},async get(o){let{status:d,data:c}=await r("GET",a(o));if(d===404)return;if(d!==200)throw new S(d);let l=n(c);return{version:Number(l.version)||0,content:n(l.content)}},async put(o,d,c,l){let{status:b,data:g}=await r("PUT",a(o),{kind:d,baseVersion:c,content:l,device:e.device.slice(0,64)});if(b===200)return{status:"written",version:Number(n(g).version)||0};if(b===409)return{status:"conflict"};if(b===413||b===422||b===400)return{status:"refused",reason:String(n(g).error??b)};throw new S(b)},async remove(o){let{status:d}=await r("DELETE",a(o));if(d===200)return!0;if(d===404)return!1;throw new S(d)},async removeAll(){let{status:o,data:d}=await r("DELETE","");if(o!==200)throw new S(o);return Number(n(d).removed)||0}}}i(Rt,"createHttpRemote");var I="dalSync",Ct="https://deepailab.ai/dal-sync",pe=i(e=>Ee(e,"settings.json"),"settingsPath");function P(e){try{let t=JSON.parse(ge(e,"utf8"));return t&&typeof t=="object"&&!Array.isArray(t)?t:void 0}catch{return}}i(P,"readJson");function fe(e){return process.env.DAL_SYNC==="0"?!1:P(pe(e))?.[I]?.enabled===!0}i(fe,"syncEnabled");function jt(e,t){let s=pe(e);R(s,()=>{if(ye(s)&&P(s)===void 0)throw new Error(`${s} is not valid JSON; not overwriting it`);let r=P(s)??{};if(F(r)>1)throw new Error(`${s} was written by a newer DAL; not overwriting it`);let n=r[I]??{};r[I]={...n,enabled:t},w(s,`${JSON.stringify(r,null,2)}
|
|
7
|
-
`)})}i(jt,"saveSyncEnabled");function $t(e,t){return e.replace(/\{(\w+)\}/g,(s,r)=>r in t?String(t[r]):s)}i($t,"fill");function K(e){return e instanceof S?e.status:0}i(K,"syncErrorStatus");function Tt(e){let t=K(e);return t===401?k("\u672A\u767B\u5F55 DeepAILab\uFF0C\u6216\u767B\u5F55\u5DF2\u8FC7\u671F\uFF1B\u767B\u5F55\u540E\u4F1A\u81EA\u52A8\u7EE7\u7EED\u540C\u6B65\u3002"):t===404?k("\u540C\u6B65\u670D\u52A1\u5C1A\u672A\u5F00\u653E\uFF0C\u5F00\u653E\u540E\u4F1A\u81EA\u52A8\u5F00\u59CB\u3002"):t===503?k("\u540C\u6B65\u670D\u52A1\u6682\u65F6\u4E0D\u53EF\u7528\uFF0C\u7A0D\u540E\u81EA\u52A8\u91CD\u8BD5\u3002"):t?$t(k("\u540C\u6B65\u8BF7\u6C42\u5931\u8D25\uFF08{status}\uFF09\uFF0C\u7A0D\u540E\u81EA\u52A8\u91CD\u8BD5\u3002"),{status:t}):k("\u7F51\u7EDC\u4E0D\u53EF\u7528\uFF0C\u7A0D\u540E\u81EA\u52A8\u91CD\u8BD5\u3002")}i(Tt,"syncErrorText");function Nt(e){let t=Z(e),s=t?Object.values(t.items).filter(r=>!r.remoteDeleted&&r.version>0).length:0;return{enabled:fe(e),synced:s,...t?.lastRun?{lastRun:t.lastRun}:{},...t?.lastError?{lastError:t.lastError}:{},...t?.lastError&&t.lastErrorStatus!==void 0?{lastErrorStatus:t.lastErrorStatus}:{}}}i(Nt,"syncStatus");function Dt(e){return Rt(e)}i(Dt,"syncRemote");async function Ot(e,t,s){try{return await Ft(e,t,s)}catch(r){let n=Z(e),a=n?.account===t;throw le(e,{account:t,items:a?n.items:{},lastRun:a?n.lastRun:void 0,lastError:Tt(r),lastErrorStatus:K(r)}),r}}i(Ot,"syncOnce");async function Lt(e,t){let s=await t.removeAll();return It(e),s}i(Lt,"removeCloudCopies");export{I as SETTINGS_KEY,Ct as SYNC_CONSOLE_URL,Lt as removeCloudCopies,jt as saveSyncEnabled,fe as syncEnabled,K as syncErrorStatus,Ot as syncOnce,Dt as syncRemote,Nt as syncStatus};
|