@arcfold/dsh 0.0.0-stage → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (127) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +8 -2
  3. package/THIRD_PARTY_NOTICES.md +11 -0
  4. package/cordis.patch.yml +138 -0
  5. package/package.json +70 -4
  6. package/patches/deepseek-0.2.2-rc.1-transport.json +65 -0
  7. package/patches/deepseek-0.2.2-rc.1-transport.patch +61 -0
  8. package/presets/arcfold.patch.yml +110 -0
  9. package/runtime/README.md +19 -0
  10. package/runtime/bootstrap.json +15 -0
  11. package/runtime/desktop-python.tar.gz +0 -0
  12. package/runtime/host/package.json +11 -0
  13. package/runtime/host/pnpm-workspace.yaml +9 -0
  14. package/runtime/initial-policy.json +94 -0
  15. package/runtime/profile/pnpm-workspace.yaml +7 -0
  16. package/scripts/exact-package-patch.mjs +106 -0
  17. package/scripts/patch-deepseek-transport.mjs +14 -0
  18. package/src/agent.mjs +56 -0
  19. package/src/browse-scope.mjs +14 -0
  20. package/src/budget.mjs +369 -0
  21. package/src/business.mjs +334 -0
  22. package/src/context-material.mjs +119 -0
  23. package/src/deepseek-budget-plugin.mjs +58 -0
  24. package/src/deepseek-provider.mjs +57 -0
  25. package/src/deepseek-receipt.mjs +97 -0
  26. package/src/deepseek-transport.mjs +97 -0
  27. package/src/desktop/adapter.mjs +16 -0
  28. package/src/desktop/bootstrap.mjs +84 -0
  29. package/src/desktop/configuration.mjs +117 -0
  30. package/src/desktop/provider.mjs +46 -0
  31. package/src/desktop/python-runtime.mjs +105 -0
  32. package/src/desktop/setup-service.mjs +81 -0
  33. package/src/desktop/vendor/LICENSE.deepseek +21 -0
  34. package/src/desktop/vendor/NOTICE.md +5 -0
  35. package/src/desktop/vendor/deepseek-0.2.2-rc.1.mjs +2919 -0
  36. package/src/evidence-ownership.mjs +51 -0
  37. package/src/evidence.mjs +35 -0
  38. package/src/goal-context.mjs +52 -0
  39. package/src/goal-execution-tool.mjs +74 -0
  40. package/src/goal-execution.mjs +333 -0
  41. package/src/goal-tool.mjs +56 -0
  42. package/src/goal-work-control.mjs +63 -0
  43. package/src/goal-work.mjs +257 -0
  44. package/src/goals.mjs +578 -0
  45. package/src/importer.mjs +298 -0
  46. package/src/index.mjs +53 -0
  47. package/src/learning-contracts.mjs +220 -0
  48. package/src/learning-defaults.mjs +98 -0
  49. package/src/learning-goals.mjs +165 -0
  50. package/src/learning-plugin.mjs +28 -0
  51. package/src/learning-runner.mjs +275 -0
  52. package/src/learning.mjs +534 -0
  53. package/src/legacy-export.mjs +332 -0
  54. package/src/legacy-import-source.mjs +356 -0
  55. package/src/metered-provider-host.mjs +101 -0
  56. package/src/metered-transport.mjs +435 -0
  57. package/src/method-context.mjs +57 -0
  58. package/src/method-lifecycle.mjs +34 -0
  59. package/src/method-tool.mjs +61 -0
  60. package/src/methods.mjs +425 -0
  61. package/src/model-selection.mjs +41 -0
  62. package/src/native-context-call.mjs +88 -0
  63. package/src/native-continuation.mjs +217 -0
  64. package/src/native-request-authority.mjs +90 -0
  65. package/src/openai-models.mjs +4 -0
  66. package/src/openai-receipt.mjs +98 -0
  67. package/src/openai-transport.mjs +167 -0
  68. package/src/openai-usage.mjs +194 -0
  69. package/src/opportunities.mjs +295 -0
  70. package/src/preparation-artifacts.mjs +213 -0
  71. package/src/preparation-plugin.mjs +290 -0
  72. package/src/runtime-command.mjs +264 -0
  73. package/src/runtime-config.mjs +417 -0
  74. package/src/runtime-guard.mjs +284 -0
  75. package/src/runtime-host.mjs +212 -0
  76. package/src/runtime-init.mjs +278 -0
  77. package/src/runtime-installation.mjs +518 -0
  78. package/src/runtime-lifecycle.mjs +227 -0
  79. package/src/runtime-model-settings.mjs +111 -0
  80. package/src/runtime-readiness.mjs +285 -0
  81. package/src/runtime-workspace.mjs +18 -0
  82. package/src/session-bridge.mjs +365 -0
  83. package/src/store.mjs +394 -0
  84. package/src/tree/LICENSE +21 -0
  85. package/src/tree/attribution.mjs +120 -0
  86. package/src/tree/clusters.mjs +61 -0
  87. package/src/tree/consolidation.mjs +103 -0
  88. package/src/tree/context.mjs +211 -0
  89. package/src/tree/contracts.mjs +142 -0
  90. package/src/tree/experience.mjs +140 -0
  91. package/src/tree/experiment-budget.mjs +84 -0
  92. package/src/tree/hooks.mjs +254 -0
  93. package/src/tree/host-context.mjs +107 -0
  94. package/src/tree/host-process.mjs +288 -0
  95. package/src/tree/host.mjs +37 -0
  96. package/src/tree/improvement.mjs +106 -0
  97. package/src/tree/items.mjs +294 -0
  98. package/src/tree/jobs.mjs +184 -0
  99. package/src/tree/learning.mjs +202 -0
  100. package/src/tree/metrics.mjs +203 -0
  101. package/src/tree/model-owner.mjs +254 -0
  102. package/src/tree/observations.mjs +73 -0
  103. package/src/tree/prompts.mjs +500 -0
  104. package/src/tree/reports.mjs +67 -0
  105. package/src/tree/repository.mjs +236 -0
  106. package/src/tree/runtime.mjs +745 -0
  107. package/src/tree/script-writer.mjs +149 -0
  108. package/src/tree/scripts.mjs +208 -0
  109. package/src/tree/signals.mjs +118 -0
  110. package/src/tree/snapshots.mjs +379 -0
  111. package/src/tree/token-counter.mjs +75 -0
  112. package/src/tree/token-counter.py +37 -0
  113. package/src/tree/tokenizer-resources/LICENSE +21 -0
  114. package/src/tree/tokenizer-resources/README.md +31 -0
  115. package/src/tree/tokenizer-resources/deepseek_recipe-0.2.0-cp310-abi3-macosx_11_0_arm64.whl +0 -0
  116. package/src/tree/tokenizer-resources/manifest.json +61 -0
  117. package/src/tree/tokenizer-resources/native.pyi +1042 -0
  118. package/src/tree/tokenizer-resources/tokenizer-NOTICE.md +26 -0
  119. package/src/tree/tokenizer-resources/tokenizer-v4-NOTICE.md +27 -0
  120. package/src/tree/tokenizer-resources/tokenizer-v4.json +267359 -0
  121. package/src/tree/tokenizer-resources/tokenizer.json +267359 -0
  122. package/src/tree/tools.mjs +99 -0
  123. package/src/tree/tree.mjs +202 -0
  124. package/src/tree/ui.mjs +285 -0
  125. package/src/tree/verification.mjs +143 -0
  126. package/src/understandings.mjs +309 -0
  127. package/src/web-budget-recovery.mjs +181 -0
@@ -0,0 +1,81 @@
1
+ import { existsSync, lstatSync, mkdirSync, readFileSync, rmdirSync } from 'node:fs';
2
+ import { join } from 'node:path';
3
+ import { randomUUID } from 'node:crypto';
4
+ import { initializeDesktop } from './configuration.mjs';
5
+
6
+ const roles = ['main', 'attribution', 'learning', 'consolidation', 'verification', 'improvement', 'script_writer'];
7
+ const fail = message => { throw new Error(message); };
8
+ const entryAt = path => lstatSync(path, { throwIfNoEntry: false });
9
+
10
+ /** Setup owns only a new Desktop namespace. The caller supplies host-discovered
11
+ * paths and a reviewed policy; credentials remain in the native host. */
12
+ export function createDesktopSetup({ home, installationFile, python, preparePython = () => python, policy, activate }) {
13
+ const dataRoot = join(home, 'arcfold-desktop'), workspace = join(home, 'arcfold-workspace');
14
+ const runtimeRoot = join(home, 'arcfold-desktop-processes'), configPath = join(dataRoot, 'desktop-configuration.json');
15
+ const completed = join(dataRoot, 'desktop-initialization-completed.json');
16
+ function stateOnDisk() {
17
+ if (existsSync(completed)) return 'configured';
18
+ return entryAt(dataRoot) || entryAt(workspace) ? 'interrupted' : 'needs_setup';
19
+ }
20
+ let state = stateOnDisk();
21
+ let busy = false, activationError = null;
22
+ const route = policy.routes?.['deepseek-official'];
23
+ const models = Object.fromEntries(roles.map(role => {
24
+ const main = role === 'main', model = main ? 'deepseek-v4-pro' : 'deepseek-flash';
25
+ const modelPolicy = route?.modelPolicies?.[model];
26
+ if (!modelPolicy?.priceVersion) fail('缺少模型和费用信息,暂时无法设置。');
27
+ const high = ['main', 'learning', 'consolidation'].includes(role);
28
+ return [role, { provider: 'deepseek-official', model, modelVersion: modelPolicy.priceVersion.split('/')[0],
29
+ reasoningEffort: high ? 'high' : 'off', maxTokens: main ? 128000 : role === 'attribution' ? 2048 : 8192 }];
30
+ }));
31
+ const status = () => ({ state, busy, workspace, dataRoot, mainModel: models.main.model,
32
+ followConversationModel: true, priceReviewedAt: policy.reviewedAt, activationError });
33
+ async function activateOptions(options, runtimePython = options.python) {
34
+ const result = await initializeDesktop(options, { confirmed: true }, runtimePython);
35
+ await activate(result, options.python); state = 'ready'; activationError = null; return status();
36
+ }
37
+ async function resume() {
38
+ if (state !== 'configured') return status();
39
+ try {
40
+ const saved = JSON.parse(readFileSync(configPath, 'utf8'));
41
+ if (saved.schema !== 'arcfold-desktop-configuration-v1' || saved.options?.local?.dataRoot !== dataRoot)
42
+ fail('保存的 Desktop 配置与数据位置不一致。');
43
+ return await activateOptions(saved.options, preparePython());
44
+ } catch (error) { activationError = error.message; state = 'activation_failed'; return status(); }
45
+ }
46
+ async function start({ confirmed }) {
47
+ if (confirmed !== true || state !== 'needs_setup' || busy) fail('请先确认模型费用,并检查当前设置状态。');
48
+ busy = true;
49
+ let createdWorkspace;
50
+ try {
51
+ if (entryAt(workspace)) fail('独立工作区已经存在;请先检查已有内容,不能自动认领。');
52
+ const counterPython = preparePython();
53
+ mkdirSync(workspace, { mode: 0o700 });
54
+ createdWorkspace = lstatSync(workspace);
55
+ const main = models.main, selection = { provider: main.provider, model: main.model, reasoningEffort: main.reasoningEffort, maxTokens: main.maxTokens };
56
+ const authority = { authorizationRef: 'arcfold-desktop:' + randomUUID(), authorizedAt: new Date().toISOString(),
57
+ authorizationEvidence: 'Desktop owner explicitly confirmed model usage without a local spending cap.' };
58
+ const evidence = join(dataRoot, 'requests');
59
+ const local = { schema: 'arcfold-local-v2', installationFile, dataRoot, workspace, listen: { host: '127.0.0.1', port: 0 },
60
+ main: selection, learn: { ...selection }, transport: { artifactDirectory: evidence, routes: { 'deepseek-official': {
61
+ kind: 'deepseek', mode: 'web-only', scope: 'web-unlimited', apiKeyRef: 'DEEPSEEK_API_KEY',
62
+ ledgerPath: join(evidence, 'deepseek-web.sqlite'), webAuthorization: authority,
63
+ endpoint: route.endpoint, network: { mode: 'direct' }, modelPolicies: route.modelPolicies, timeoutMs: 60000,
64
+ } } } };
65
+ return await activateOptions({ local, runtimeRoot, python: counterPython, userId: 'desktop-' + randomUUID(), models });
66
+ } catch (error) {
67
+ if (createdWorkspace && !entryAt(dataRoot)) {
68
+ const current = entryAt(workspace);
69
+ if (current?.isDirectory() && current.dev === createdWorkspace.dev && current.ino === createdWorkspace.ino) {
70
+ // An empty-only removal leaves any work added meanwhile intact.
71
+ try { rmdirSync(workspace); } catch { /* The remaining workspace requires inspection. */ }
72
+ }
73
+ }
74
+ const diskState = stateOnDisk();
75
+ state = diskState === 'configured' ? 'activation_failed' : diskState;
76
+ activationError = error.message;
77
+ throw error;
78
+ } finally { busy = false; }
79
+ }
80
+ return Object.freeze({ status, start, resume });
81
+ }
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 DeepSeek
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,5 @@
1
+ # Private DeepSeek adapter
2
+
3
+ `deepseek-0.2.2-rc.1.mjs` is the published `@deepseek-ai/dsh-llm-deepseek` 0.2.2-rc.1 `lib/index.js`, with Arcfold's existing exact transport patch applied. The upstream repository commit and the original and patched SHA-256 values are recorded in `patches/deepseek-0.2.2-rc.1-transport.json`. The upstream license is included as `LICENSE.deepseek`.
4
+
5
+ It is a private copy used only by the Desktop integration. The source still resolves the host's shared services, but its transport is controlled by Arcfold's per-request authority and metering. It does not modify the installed Desktop application or other plugins' copies of the provider.