@artenx/dshb 0.1.18 → 0.1.20

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 (112) hide show
  1. package/lib/auth/decorate-webserver.d.ts +2 -1
  2. package/lib/auth/decorate-webserver.js +21 -10
  3. package/lib/auth/decorate-webserver.js.map +1 -1
  4. package/lib/auth/gate.d.ts +3 -1
  5. package/lib/auth/gate.js +18 -1
  6. package/lib/auth/gate.js.map +1 -1
  7. package/lib/auth/index.js +11 -3
  8. package/lib/auth/index.js.map +1 -1
  9. package/lib/auth/webserver.d.ts +3 -1
  10. package/lib/auth/webserver.js +10 -1
  11. package/lib/auth/webserver.js.map +1 -1
  12. package/lib/client.js +2157 -567
  13. package/lib/client.js.map +1 -1
  14. package/lib/core/index.js +72 -4
  15. package/lib/core/index.js.map +1 -1
  16. package/lib/core/node-registry.d.ts +2 -108
  17. package/lib/core/node-registry.js +43 -2
  18. package/lib/core/node-registry.js.map +1 -1
  19. package/lib/core/routes.d.ts +4 -3
  20. package/lib/core/routes.js +67 -23
  21. package/lib/core/routes.js.map +1 -1
  22. package/lib/core/sync/coordinator.d.ts +48 -0
  23. package/lib/core/sync/coordinator.js +247 -0
  24. package/lib/core/sync/coordinator.js.map +1 -0
  25. package/lib/core/sync/host-key.d.ts +2 -0
  26. package/lib/core/sync/host-key.js +71 -0
  27. package/lib/core/sync/host-key.js.map +1 -0
  28. package/lib/core/sync/internal-routes.d.ts +9 -0
  29. package/lib/core/sync/internal-routes.js +236 -0
  30. package/lib/core/sync/internal-routes.js.map +1 -0
  31. package/lib/core/sync/model.d.ts +2 -0
  32. package/lib/core/sync/model.js +106 -0
  33. package/lib/core/sync/model.js.map +1 -0
  34. package/lib/core/sync/node-sync.d.ts +2 -0
  35. package/lib/core/sync/node-sync.js +660 -0
  36. package/lib/core/sync/node-sync.js.map +1 -0
  37. package/lib/core/sync/offline-archive.d.ts +55 -0
  38. package/lib/core/sync/offline-archive.js +673 -0
  39. package/lib/core/sync/offline-archive.js.map +1 -0
  40. package/lib/core/sync/offline-journal.d.ts +22 -0
  41. package/lib/core/sync/offline-journal.js +74 -0
  42. package/lib/core/sync/offline-journal.js.map +1 -0
  43. package/lib/core/sync/offline-routes.d.ts +7 -0
  44. package/lib/core/sync/offline-routes.js +192 -0
  45. package/lib/core/sync/offline-routes.js.map +1 -0
  46. package/lib/core/sync/peer-manager.d.ts +56 -0
  47. package/lib/core/sync/peer-manager.js +258 -0
  48. package/lib/core/sync/peer-manager.js.map +1 -0
  49. package/lib/core/sync/protocol.d.ts +2 -0
  50. package/lib/core/sync/protocol.js +124 -0
  51. package/lib/core/sync/protocol.js.map +1 -0
  52. package/lib/core/sync/remote-helper.d.ts +5 -0
  53. package/lib/core/sync/remote-helper.js +160 -0
  54. package/lib/core/sync/remote-helper.js.map +1 -0
  55. package/lib/core/sync/revision.d.ts +2 -0
  56. package/lib/core/sync/revision.js +77 -0
  57. package/lib/core/sync/revision.js.map +1 -0
  58. package/lib/core/sync/routes.d.ts +9 -0
  59. package/lib/core/sync/routes.js +339 -0
  60. package/lib/core/sync/routes.js.map +1 -0
  61. package/lib/core/sync/scheduler.d.ts +14 -0
  62. package/lib/core/sync/scheduler.js +81 -0
  63. package/lib/core/sync/scheduler.js.map +1 -0
  64. package/lib/core/sync/session-journal.d.ts +2 -0
  65. package/lib/core/sync/session-journal.js +191 -0
  66. package/lib/core/sync/session-journal.js.map +1 -0
  67. package/lib/core/sync/session-routes.d.ts +7 -0
  68. package/lib/core/sync/session-routes.js +67 -0
  69. package/lib/core/sync/session-routes.js.map +1 -0
  70. package/lib/core/sync/session-sync.d.ts +2 -0
  71. package/lib/core/sync/session-sync.js +2 -0
  72. package/lib/core/sync/ssh-transport.d.ts +2 -0
  73. package/lib/core/sync/ssh-transport.js +408 -0
  74. package/lib/core/sync/ssh-transport.js.map +1 -0
  75. package/lib/core/sync/stores.d.ts +3 -0
  76. package/lib/core/sync/stores.js +385 -0
  77. package/lib/core/sync/stores.js.map +1 -0
  78. package/lib/core/test.d.ts +1 -1
  79. package/lib/core/workspace-bindings.d.ts +2 -28
  80. package/lib/core/workspace-bindings.js +14 -14
  81. package/lib/core/workspace-bindings.js.map +1 -1
  82. package/lib/core/workspace-instruction-context.d.ts +3 -2260
  83. package/lib/core/workspace-instruction-context.js +104 -2
  84. package/lib/core/workspace-instruction-context.js.map +1 -0
  85. package/lib/core/workspace-instruction-routes.d.ts +1 -1
  86. package/lib/core/workspace-instructions.d.ts +2 -68
  87. package/lib/core/workspace-instructions.js +13 -0
  88. package/lib/core/workspace-instructions.js.map +1 -1
  89. package/lib/core/workspaces.d.ts +4 -3
  90. package/lib/core/workspaces.js +17 -1
  91. package/lib/core/workspaces.js.map +1 -1
  92. package/lib/host-key-C5afhAUd.d.ts +30 -0
  93. package/lib/index-VF8bcBeX.d.ts +2293 -0
  94. package/lib/{workspace-instruction-context-DytAmaPY.js → lib-gdtU_WKT.js} +159 -102
  95. package/lib/lib-gdtU_WKT.js.map +1 -0
  96. package/lib/model-BP7Gw1yk.d.ts +104 -0
  97. package/lib/node-registry-BTnnM5-k.d.ts +112 -0
  98. package/lib/node-sync-3Z9QLz2n.d.ts +89 -0
  99. package/lib/protocol-CV7LGE44.d.ts +35 -0
  100. package/lib/revision-C9sOlDZ6.d.ts +25 -0
  101. package/lib/router/router-fs.d.ts +12 -3
  102. package/lib/router/router-fs.js.map +1 -1
  103. package/lib/session-journal-pgPqcWn9.d.ts +40 -0
  104. package/lib/session-sync-EdfwUON5.js +2177 -0
  105. package/lib/session-sync-EdfwUON5.js.map +1 -0
  106. package/lib/session-sync-g6qKZzjV.d.ts +1252 -0
  107. package/lib/ssh-transport-BcIiLxsX.d.ts +55 -0
  108. package/lib/stores-CKyEt0yk.d.ts +31 -0
  109. package/lib/workspace-bindings-CsB0TIJB.d.ts +28 -0
  110. package/lib/workspace-instructions-DirYYiku.d.ts +69 -0
  111. package/package.json +20 -1
  112. package/lib/workspace-instruction-context-DytAmaPY.js.map +0 -1
@@ -1,4 +1,3 @@
1
- import { sharedSessionInstructionSnapshotStore, sharedWorkspaceInstructionStore } from "./core/workspace-instructions.js";
2
1
  import { createRequire } from "node:module";
3
2
  import { Context, Service } from "@deepseek-ai/cordis";
4
3
  //#region ../../node_modules/@deepseek-ai/dsh-typert-protocol/lib/index.js
@@ -817,6 +816,155 @@ function assertNever(value, context) {
817
816
  const rendered = JSON.stringify(value) ?? String(value);
818
817
  throw new Error(`unreachable variant${context ? ` in ${context}` : ""}: ${rendered}`);
819
818
  }
819
+ /** Whether a realm-owned intrinsic prototype has a native constructor matching this engine's representation. */
820
+ function hasIntrinsicConstructor(prototype, name) {
821
+ const constructor = Object.getOwnPropertyDescriptor(prototype, "constructor")?.value;
822
+ if (typeof constructor !== "function") return false;
823
+ try {
824
+ return constructor.name === name && constructor.prototype === prototype && Function.prototype.toString.call(constructor) === Function.prototype.toString.call(name === "Array" ? Array : Object);
825
+ } catch {
826
+ return false;
827
+ }
828
+ }
829
+ /** Whether a candidate is one realm's intrinsic `Object.prototype`. */
830
+ function isIntrinsicObjectPrototype(value) {
831
+ return Object.getPrototypeOf(value) === null && hasIntrinsicConstructor(value, "Object");
832
+ }
833
+ /** Whether an array uses one realm's intrinsic `Array.prototype`, not a subclass or forged prototype. */
834
+ function hasPlainArrayPrototype(value) {
835
+ const prototype = Object.getPrototypeOf(value);
836
+ if (!Array.isArray(prototype) || !hasIntrinsicConstructor(prototype, "Array")) return false;
837
+ const objectPrototype = Object.getPrototypeOf(prototype);
838
+ return typeof objectPrototype === "object" && objectPrototype !== null && isIntrinsicObjectPrototype(objectPrototype);
839
+ }
840
+ /** Whether an object is a plain or null-prototype record from any JavaScript realm. */
841
+ function hasPlainObjectPrototype(value) {
842
+ const prototype = Object.getPrototypeOf(value);
843
+ return prototype === null || typeof prototype === "object" && isIntrinsicObjectPrototype(prototype);
844
+ }
845
+ /** Return every JSON-visible object key, or reject own data JSON would discard. */
846
+ function enumerableStringKeys(value) {
847
+ const keys = Reflect.ownKeys(value);
848
+ if (keys.some((key) => typeof key !== "string" || !Object.prototype.propertyIsEnumerable.call(value, key))) return void 0;
849
+ return keys;
850
+ }
851
+ /** Validate lossless JSON iteratively, optionally materializing a detached snapshot. */
852
+ function walkJsonValue(value, detach) {
853
+ const ancestors = /* @__PURE__ */ new Set();
854
+ let root;
855
+ const assign = (destination, item) => {
856
+ if (destination === void 0) return;
857
+ if (destination.kind === "root") root = item;
858
+ else if (destination.kind === "array") destination.target[destination.index] = item;
859
+ else Object.defineProperty(destination.target, destination.key, {
860
+ value: item,
861
+ enumerable: true,
862
+ configurable: true,
863
+ writable: true
864
+ });
865
+ };
866
+ const tasks = [{
867
+ kind: "visit",
868
+ value,
869
+ ...detach ? { destination: { kind: "root" } } : {}
870
+ }];
871
+ for (let task = tasks.pop(); task !== void 0; task = tasks.pop()) {
872
+ if (task.kind === "leave") {
873
+ ancestors.delete(task.source);
874
+ continue;
875
+ }
876
+ if (task.kind === "array-item") {
877
+ if (!Object.prototype.hasOwnProperty.call(task.source, task.index)) return void 0;
878
+ tasks.push({
879
+ kind: "visit",
880
+ value: task.source[task.index],
881
+ ...task.target === void 0 ? {} : { destination: {
882
+ kind: "array",
883
+ target: task.target,
884
+ index: task.index
885
+ } }
886
+ });
887
+ continue;
888
+ }
889
+ if (task.kind === "object-property") {
890
+ tasks.push({
891
+ kind: "visit",
892
+ value: task.source[task.key],
893
+ ...task.target === void 0 ? {} : { destination: {
894
+ kind: "object",
895
+ target: task.target,
896
+ key: task.key
897
+ } }
898
+ });
899
+ continue;
900
+ }
901
+ const current = task.value;
902
+ if (current === null) {
903
+ assign(task.destination, null);
904
+ continue;
905
+ }
906
+ if (typeof current === "boolean" || typeof current === "string") {
907
+ assign(task.destination, current);
908
+ continue;
909
+ }
910
+ if (typeof current === "number") {
911
+ if (!Number.isFinite(current) || Object.is(current, -0)) return void 0;
912
+ assign(task.destination, current);
913
+ continue;
914
+ }
915
+ if (typeof current !== "object") return void 0;
916
+ if (ancestors.has(current)) return void 0;
917
+ if (Array.isArray(current)) {
918
+ if (!hasPlainArrayPrototype(current)) return void 0;
919
+ const length = current.length;
920
+ if (Reflect.ownKeys(current).length !== length + 1) return void 0;
921
+ const target = detach ? [] : void 0;
922
+ if (target !== void 0) assign(task.destination, target);
923
+ ancestors.add(current);
924
+ tasks.push({
925
+ kind: "leave",
926
+ source: current
927
+ });
928
+ for (let index = length - 1; index >= 0; index--) tasks.push({
929
+ kind: "array-item",
930
+ source: current,
931
+ index,
932
+ ...target === void 0 ? {} : { target }
933
+ });
934
+ continue;
935
+ }
936
+ if (!hasPlainObjectPrototype(current)) return void 0;
937
+ const keys = enumerableStringKeys(current);
938
+ if (keys === void 0) return void 0;
939
+ const target = detach ? {} : void 0;
940
+ if (target !== void 0) assign(task.destination, target);
941
+ ancestors.add(current);
942
+ tasks.push({
943
+ kind: "leave",
944
+ source: current
945
+ });
946
+ for (let index = keys.length - 1; index >= 0; index--) {
947
+ const key = keys[index];
948
+ /* v8 ignore next -- the loop is bounded by the captured key count. */
949
+ if (key === void 0) return void 0;
950
+ tasks.push({
951
+ kind: "object-property",
952
+ source: current,
953
+ key,
954
+ ...target === void 0 ? {} : { target }
955
+ });
956
+ }
957
+ }
958
+ return detach ? root : true;
959
+ }
960
+ /**
961
+ * Validate and detach lossless JSON in one read per property.
962
+ * @param value - candidate value to validate and detach.
963
+ * @returns the detached snapshot, or `undefined` when the value is not losslessly JSON-serializable.
964
+ */
965
+ function snapshotJsonValue(value) {
966
+ return walkJsonValue(value, true);
967
+ }
820
968
  /**
821
969
  * Deep-freeze an object graph in place while leaving live AbortSignal objects mutable.
822
970
  * @param value - value to freeze.
@@ -895,6 +1043,14 @@ function randomUUID() {
895
1043
  function brandString(value) {
896
1044
  return value;
897
1045
  }
1046
+ /**
1047
+ * Apply a compile-time number brand without changing the value.
1048
+ * @param value - number admitted by the domain that owns the target brand.
1049
+ * @returns the same number with the requested compile-time brand.
1050
+ */
1051
+ function brandNumber(value) {
1052
+ return value;
1053
+ }
898
1054
  //#endregion
899
1055
  //#region ../../node_modules/@deepseek-ai/cosmokit/lib/index.js
900
1056
  /** Return true when a value is `null` or `undefined`. */
@@ -2988,105 +3144,6 @@ function detachDirectoryEntry(entry) {
2988
3144
  };
2989
3145
  }
2990
3146
  //#endregion
2991
- //#region src/core/workspace-instruction-context.ts
2992
- const SYSTEM_REMINDER_OPEN = "<system-reminder>";
2993
- const SYSTEM_REMINDER_CLOSE = "</system-reminder>";
2994
- const INSTRUCTION_INTRO = "The following project instructions are managed by the user for this DSH workspace. Follow them as persistent workspace guidance. They take precedence over repository-provided workspace guidance. System, developer, and direct user instructions take precedence over these project instructions.";
2995
- function escapeInstructionFrameBody(body) {
2996
- return body.replaceAll(SYSTEM_REMINDER_CLOSE, "<\\/system-reminder>");
2997
- }
2998
- function renderInstructionMessageText(workspaceTitle, text) {
2999
- const escaped = escapeInstructionFrameBody(text);
3000
- return `${SYSTEM_REMINDER_OPEN}\n${INSTRUCTION_INTRO}\n\nInstructions for workspace: ${workspaceTitle}\n\n${escaped}\n${SYSTEM_REMINDER_CLOSE}`;
3001
- }
3002
- function createInstructionMessage(workspaceId, workspaceTitle, snapshot) {
3003
- return createUserMessage({
3004
- content: [{
3005
- type: "text",
3006
- text: renderInstructionMessageText(workspaceTitle, snapshot.text)
3007
- }],
3008
- source: {
3009
- kind: "dshb-workspace-instructions",
3010
- form: "instructions",
3011
- workspaceId,
3012
- revision: snapshot.workspaceRevision,
3013
- digest: snapshot.digest,
3014
- snapshot: true
3015
- }
3016
- });
3017
- }
3018
- function hasDirectUserMessage(messages) {
3019
- return messages.some((m) => m.role === "user" && m.source.kind === "user");
3020
- }
3021
- function hasOwnInstructionMessage(agent) {
3022
- const nodes = agent.session.surface?.nodes;
3023
- if (!nodes) return false;
3024
- for (const seq of nodes) {
3025
- const event = agent.session.eventAt?.(seq);
3026
- if (event?.type === "user/message" && event.data.source.kind === "dshb-workspace-instructions") return true;
3027
- }
3028
- return false;
3029
- }
3030
- async function resolveSnapshotForSession(agent, messages, workspaceStore = sharedWorkspaceInstructionStore(), snapshotStore = sharedSessionInstructionSnapshotStore(), registry) {
3031
- const sessionId = agent.session.id;
3032
- const existing = snapshotStore.get(sessionId);
3033
- if (existing) return existing;
3034
- if (!(hasDirectUserMessage(messages) && !hasOwnInstructionMessage(agent))) return void 0;
3035
- let workspaceId;
3036
- const cwd = agent.session.header.cwd;
3037
- if (registry && cwd) try {
3038
- const ws = await registry.resolveByPath(cwd);
3039
- if (ws) {
3040
- workspaceId = ws.id;
3041
- ws.title;
3042
- }
3043
- } catch {}
3044
- const record = workspaceId ? workspaceStore.get(workspaceId) : void 0;
3045
- if (!record || record.text.length === 0) return snapshotStore.createIfAbsent(sessionId, {
3046
- kind: "empty",
3047
- workspaceId
3048
- });
3049
- return snapshotStore.createIfAbsent(sessionId, {
3050
- kind: "workspace",
3051
- record,
3052
- workspaceId
3053
- });
3054
- }
3055
- function registerWorkspaceInstructionInjector(ctx) {
3056
- if (typeof ctx.on !== "function") return;
3057
- const workspaceStore = sharedWorkspaceInstructionStore();
3058
- const snapshotStore = sharedSessionInstructionSnapshotStore();
3059
- ctx.on("agent/pre-step", async ({ agent, messages, signal }, next) => {
3060
- const decision = await next();
3061
- if (decision.kind === "reject") return decision;
3062
- signal.throwIfAborted();
3063
- const agentLike = agent;
3064
- const messagesLike = messages;
3065
- const registry = ctx.get("workspaceRegistry");
3066
- let snapshot = snapshotStore.get(agentLike.session.id);
3067
- if (!snapshot) snapshot = await resolveSnapshotForSession(agentLike, messagesLike, workspaceStore, snapshotStore, registry);
3068
- signal.throwIfAborted();
3069
- if (!snapshot || snapshot.text.length === 0) return decision;
3070
- if (hasOwnInstructionMessage(agentLike)) return decision;
3071
- const workspaceId = snapshot.workspaceId;
3072
- if (!workspaceId) return decision;
3073
- const message = createInstructionMessage(workspaceId, (registry?.get(workspaceId))?.title ?? "Unknown", snapshot);
3074
- const lastClaimedIndex = decision.messages.findLastIndex((m) => messages.includes(m));
3075
- const entered = decision.messages.toSpliced(lastClaimedIndex + 1, 0, message);
3076
- return {
3077
- ...decision,
3078
- messages: entered
3079
- };
3080
- });
3081
- try {
3082
- ctx.on?.("session/deleted", (sessionId) => {
3083
- snapshotStore.remove(sessionId);
3084
- });
3085
- } catch {}
3086
- }
3087
- const name = "dshb-workspace-instruction-injector";
3088
- const inject = ["workspaceRegistry"];
3089
- //#endregion
3090
- export { registerWorkspaceInstructionInjector as a, name as i, escapeInstructionFrameBody as n, renderInstructionMessageText as o, inject as r, resolveSnapshotForSession as s, createInstructionMessage as t };
3147
+ export { snapshotJsonValue as a, deepFreeze as i, brandNumber as n, brandString as r, createUserMessage as t };
3091
3148
 
3092
- //# sourceMappingURL=workspace-instruction-context-DytAmaPY.js.map
3149
+ //# sourceMappingURL=lib-gdtU_WKT.js.map