@silverbulletmd/silverbullet 2.10.0 → 2.12.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 (105) hide show
  1. package/README.md +6 -6
  2. package/client/asset_bundle/bundle.ts +0 -1
  3. package/client/config.ts +343 -0
  4. package/client/data/kv_primitives.ts +2 -2
  5. package/client/markdown_parser/constants.ts +5 -1
  6. package/client/plugos/hooks/command.ts +8 -6
  7. package/client/plugos/hooks/event.ts +60 -24
  8. package/client/plugos/hooks/mq.ts +0 -3
  9. package/client/plugos/hooks/slash_command.ts +3 -20
  10. package/client/plugos/hooks/syscall.ts +0 -4
  11. package/client/plugos/manifest_cache.ts +2 -34
  12. package/client/plugos/plug.ts +0 -3
  13. package/client/plugos/plug_compile.ts +3 -13
  14. package/client/plugos/sandboxes/sandbox.ts +2 -2
  15. package/client/plugos/sandboxes/worker_sandbox.ts +19 -9
  16. package/client/plugos/syscalls/capture.ts +104 -0
  17. package/client/plugos/syscalls/editor.ts +197 -56
  18. package/client/plugos/syscalls/event.ts +12 -9
  19. package/client/plugos/syscalls/fetch.ts +0 -4
  20. package/client/plugos/syscalls/icon.ts +46 -0
  21. package/client/plugos/syscalls/index.ts +33 -13
  22. package/client/plugos/syscalls/jsonschema.ts +0 -1
  23. package/client/plugos/syscalls/mq.ts +0 -1
  24. package/client/plugos/syscalls/navigator.ts +138 -0
  25. package/client/plugos/syscalls/search.ts +44 -0
  26. package/client/plugos/syscalls/shell.ts +0 -1
  27. package/client/plugos/syscalls/space.ts +250 -7
  28. package/client/plugos/syscalls/sync.ts +70 -4
  29. package/client/plugos/syscalls/system.ts +39 -0
  30. package/client/plugos/system.ts +9 -7
  31. package/client/plugos/types.ts +6 -6
  32. package/client/plugos/worker_runtime.ts +0 -2
  33. package/client/space_lua/aggregates.ts +6 -22
  34. package/client/space_lua/ast.ts +0 -5
  35. package/client/space_lua/ast_narrow.ts +0 -5
  36. package/client/space_lua/budget.ts +113 -0
  37. package/client/space_lua/budget_ui.ts +49 -0
  38. package/client/space_lua/eval.ts +113 -88
  39. package/client/space_lua/labels.ts +0 -4
  40. package/client/space_lua/numeric.ts +2 -7
  41. package/client/space_lua/parse.ts +0 -17
  42. package/client/space_lua/quarantine.ts +127 -0
  43. package/client/space_lua/query_collection.ts +18 -51
  44. package/client/space_lua/query_env.ts +0 -2
  45. package/client/space_lua/render_lua_markdown.ts +2 -7
  46. package/client/space_lua/render_widget.ts +18 -1
  47. package/client/space_lua/runtime.ts +64 -77
  48. package/client/space_lua/stdlib/format.ts +0 -12
  49. package/client/space_lua/stdlib/js.ts +0 -2
  50. package/client/space_lua/stdlib/load.ts +0 -1
  51. package/client/space_lua/stdlib/math.ts +0 -7
  52. package/client/space_lua/stdlib/net.ts +0 -4
  53. package/client/space_lua/stdlib/os.ts +0 -10
  54. package/client/space_lua/stdlib/pattern.ts +18 -23
  55. package/client/space_lua/stdlib/space_lua.ts +1 -2
  56. package/client/space_lua/stdlib/string_pack.ts +4 -7
  57. package/client/space_lua/stdlib/table.ts +0 -5
  58. package/client/space_lua/stdlib.ts +18 -31
  59. package/client/space_lua/tonumber.ts +0 -9
  60. package/dist/plug-compile.js +3 -4
  61. package/package.json +52 -41
  62. package/plug-api/lib/async.ts +1 -6
  63. package/plug-api/lib/collation.ts +22 -0
  64. package/plug-api/lib/crypto.ts +16 -15
  65. package/plug-api/lib/dates.ts +33 -0
  66. package/plug-api/lib/fuzzy.ts +282 -0
  67. package/plug-api/lib/json.ts +0 -6
  68. package/plug-api/lib/limited_map.ts +0 -2
  69. package/plug-api/lib/link_write.ts +27 -0
  70. package/plug-api/lib/ref.ts +28 -5
  71. package/plug-api/lib/resolve.ts +1 -9
  72. package/plug-api/lib/resolve_path.ts +290 -0
  73. package/plug-api/lib/shortcut.ts +15 -0
  74. package/plug-api/lib/tags.ts +0 -3
  75. package/plug-api/lib/transclusion.ts +28 -1
  76. package/plug-api/lib/tree.ts +0 -5
  77. package/plug-api/lib/yaml.ts +5 -44
  78. package/plug-api/syscall.ts +1 -5
  79. package/plug-api/syscalls/config.ts +2 -2
  80. package/plug-api/syscalls/editor.ts +75 -213
  81. package/plug-api/syscalls/icon.ts +18 -0
  82. package/plug-api/syscalls/index.ts +22 -4
  83. package/plug-api/syscalls/search.ts +11 -0
  84. package/plug-api/syscalls/space.ts +122 -5
  85. package/plug-api/syscalls/sync.ts +31 -2
  86. package/plug-api/syscalls/system.ts +46 -0
  87. package/plug-api/syscalls.ts +2 -0
  88. package/plug-api/system_mock.ts +13 -0
  89. package/plug-api/types/client.ts +20 -4
  90. package/plug-api/types/datastore.ts +11 -2
  91. package/plug-api/types/index.ts +10 -0
  92. package/plug-api/types/manifest.ts +7 -0
  93. package/plug-api/types/profile.ts +13 -0
  94. package/plug-api/types/revisions.ts +67 -0
  95. package/plug-api/ui/description.ts +64 -0
  96. package/plug-api/ui/hover.ts +69 -0
  97. package/plug-api/ui/index.ts +58 -2
  98. package/plug-api/ui/scroll.ts +30 -0
  99. package/plug-api/ui/tree_model.ts +285 -0
  100. package/plug-api/ui/tree_types.ts +67 -0
  101. package/plug-api/ui/use_fit_collapse.ts +67 -0
  102. package/plugs/builtin_plugs.ts +0 -1
  103. package/plugs/index/types.ts +9 -0
  104. package/plug-api/lib/memory_cache.ts +0 -21
  105. /package/plug-api/{ui → lib}/panel_styles.ts +0 -0
@@ -1,19 +1,16 @@
1
- // Define the patch structure
2
- export interface YamlPatch {
1
+ export type YamlPatch = {
3
2
  op: "set-key" | "delete-key";
4
- path: string; // Still assuming simple, top-level key names
3
+ path: string; // Top-level key names only
5
4
  value?: any; // Required for set-key, not used for delete-key
6
- }
5
+ };
7
6
 
8
- // Helper function specifically for serializing scalar types
9
7
  function serializeToYamlScalar(
10
8
  value: string | number | boolean | null,
11
9
  ): string {
12
10
  if (typeof value === "string") {
13
- // Always quote empty strings and strings with special characters
14
11
  if (
15
12
  value === "" || // Empty string
16
- value.match(/[:{#}[],&*!|>'"%@`]/) || // Special YAML characters (added % and ")
13
+ value.match(/[:{#}[],&*!|>'"%@`]/) || // Special YAML characters
17
14
  /^\d+(\.\d+)?([eE][+-]?\d+)?$/.test(value) || // Looks like a number
18
15
  value.includes(":") || // Contains colons
19
16
  ["true", "false", "null", "yes", "no", "on", "off"].includes(
@@ -22,7 +19,6 @@ function serializeToYamlScalar(
22
19
  ) {
23
20
  return JSON.stringify(value);
24
21
  }
25
- // Simple strings without special chars/meaning don't need quotes
26
22
  return value;
27
23
  } else if (
28
24
  typeof value === "number" ||
@@ -31,12 +27,9 @@ function serializeToYamlScalar(
31
27
  ) {
32
28
  return String(value);
33
29
  }
34
- // Default for unsupported scalar types (e.g., undefined)
35
30
  return "null";
36
31
  }
37
32
 
38
- // Updated helper function to serialize various JS types to YAML string representations
39
- // Added baseIndentation parameter for handling nested lists correctly (though we only use it for top-level lists here)
40
33
  function serializeToYamlValue(
41
34
  value: any,
42
35
  baseIndentation: string = "",
@@ -45,9 +38,7 @@ function serializeToYamlValue(
45
38
  if (value.length === 0) {
46
39
  return "[]"; // Use flow style for empty arrays for simplicity
47
40
  }
48
- // Determine indentation for list items (base + 2 spaces)
49
41
  const itemIndentation = `${baseIndentation} `;
50
- // Format each item recursively, preceded by '- ' marker
51
42
  return (
52
43
  "\n" +
53
44
  value
@@ -57,11 +48,8 @@ function serializeToYamlValue(
57
48
  )
58
49
  .join("\n")
59
50
  );
60
- // Note: serializeToYamlValue is used recursively here to handle nested arrays/objects if needed in future
61
- // However, the current `applyMinimalSetKeyPatches` only handles top-level keys.
62
51
  } else if (typeof value === "object" && value !== null) {
63
- // Basic object serialization (not requested, but good to consider)
64
- // This is highly simplified and doesn't handle nesting well without more context
52
+ // Nested object serialization is limited.
65
53
  const itemIndentation = `${baseIndentation} `;
66
54
  const entries = Object.entries(value);
67
55
  if (entries.length === 0) return "{}"; // Flow style empty objects
@@ -78,7 +66,6 @@ function serializeToYamlValue(
78
66
  .join("\n")
79
67
  );
80
68
  } else {
81
- // Handle scalars using the dedicated function
82
69
  return serializeToYamlScalar(value);
83
70
  }
84
71
  }
@@ -88,14 +75,12 @@ export function applyPatches(yamlString: string, patches: YamlPatch[]): string {
88
75
 
89
76
  for (const patch of patches) {
90
77
  if (patch.op === "delete-key") {
91
- // Handle delete operation
92
78
  const key = patch.path;
93
79
  const lines = currentYaml.split("\n");
94
80
  let keyLineIndex = -1;
95
81
  let startDeleteIndex = -1;
96
82
  let endDeleteIndex = -1;
97
83
 
98
- // Find the key line
99
84
  for (let i = 0; i < lines.length; i++) {
100
85
  const line = lines[i];
101
86
  const trimmedLine = line.trim();
@@ -121,16 +106,12 @@ export function applyPatches(yamlString: string, patches: YamlPatch[]): string {
121
106
  }
122
107
  }
123
108
 
124
- // Determine the indentation of the key
125
109
  const keyIndent = lines[i].match(/^(\s*)/)?.[1] || "";
126
110
 
127
- // Look forwards to find all content belonging to this key
128
- // This includes list items and nested objects
129
111
  for (let j = i + 1; j < lines.length; j++) {
130
112
  const nextLine = lines[j];
131
113
  const trimmedNextLine = nextLine.trim();
132
114
 
133
- // Empty line - continue looking
134
115
  if (trimmedNextLine === "") {
135
116
  continue;
136
117
  }
@@ -147,13 +128,10 @@ export function applyPatches(yamlString: string, patches: YamlPatch[]): string {
147
128
  }
148
129
  }
149
130
 
150
- // Check indentation of next non-empty, non-comment line
151
131
  const nextIndent = nextLine.match(/^(\s*)/)?.[1] || "";
152
132
  if (nextIndent.length > keyIndent.length) {
153
- // This line is indented more than the key, so it belongs to the key
154
133
  endDeleteIndex = j;
155
134
  } else {
156
- // This line is at same or less indentation, so it's a new key
157
135
  break;
158
136
  }
159
137
  }
@@ -163,12 +141,9 @@ export function applyPatches(yamlString: string, patches: YamlPatch[]): string {
163
141
  }
164
142
 
165
143
  if (keyLineIndex !== -1) {
166
- // Delete the lines from startDeleteIndex to endDeleteIndex (inclusive)
167
144
  const beforeDelete = lines.slice(0, startDeleteIndex);
168
145
  const afterDelete = lines.slice(endDeleteIndex + 1);
169
146
 
170
- // Clean up excessive empty lines at the boundary
171
- // Remove trailing empty lines from beforeDelete
172
147
  while (
173
148
  beforeDelete.length > 0 &&
174
149
  beforeDelete[beforeDelete.length - 1].trim() === ""
@@ -194,7 +169,6 @@ export function applyPatches(yamlString: string, patches: YamlPatch[]): string {
194
169
  currentYaml += "\n";
195
170
  }
196
171
  }
197
- // If key not found, do nothing
198
172
  continue;
199
173
  }
200
174
 
@@ -202,25 +176,21 @@ export function applyPatches(yamlString: string, patches: YamlPatch[]): string {
202
176
 
203
177
  const key = patch.path;
204
178
 
205
- // Split the YAML into lines for easier processing
206
179
  const lines = currentYaml.split("\n");
207
180
  let keyLineIndex = -1;
208
181
  let commentBlock = "";
209
182
  let trailingComments = "";
210
183
  let inlineComment = "";
211
184
 
212
- // Find the key line and collect comments
213
185
  for (let i = 0; i < lines.length; i++) {
214
186
  const line = lines[i];
215
187
  const trimmedLine = line.trim();
216
188
  if (trimmedLine.startsWith(`${key}:`)) {
217
189
  keyLineIndex = i;
218
- // Extract inline comment if present
219
190
  const commentMatch = line.match(/#.*$/);
220
191
  if (commentMatch) {
221
192
  inlineComment = commentMatch[0];
222
193
  }
223
- // Look backwards for comments
224
194
  for (let j = i - 1; j >= 0; j--) {
225
195
  const prevLine = lines[j].trim();
226
196
  if (prevLine.startsWith("#")) {
@@ -229,7 +199,6 @@ export function applyPatches(yamlString: string, patches: YamlPatch[]): string {
229
199
  break;
230
200
  }
231
201
  }
232
- // Look forwards for comments
233
202
  for (let j = i + 1; j < lines.length; j++) {
234
203
  const nextLine = lines[j].trim();
235
204
  if (nextLine.startsWith("#")) {
@@ -242,16 +211,12 @@ export function applyPatches(yamlString: string, patches: YamlPatch[]): string {
242
211
  }
243
212
  }
244
213
 
245
- // Serialize the new value
246
214
  const serializedNewValue = serializeToYamlValue(patch.value);
247
215
 
248
- // Create the replacement line
249
216
  let replacementLine: string;
250
217
  if (serializedNewValue.startsWith("\n")) {
251
- // For lists/objects, the key line ends with just ':'
252
218
  replacementLine = `${key}:${inlineComment}${serializedNewValue}`;
253
219
  } else {
254
- // For scalars, format as key: value
255
220
  replacementLine = `${key}: ${serializedNewValue}${
256
221
  inlineComment ? ` ${inlineComment}` : ""
257
222
  }`;
@@ -267,7 +232,6 @@ export function applyPatches(yamlString: string, patches: YamlPatch[]): string {
267
232
  keyLineIndex + 1 + trailingComments.split("\n").filter(Boolean).length,
268
233
  );
269
234
 
270
- // Build the new content
271
235
  const newContent = [
272
236
  ...beforeKey,
273
237
  ...commentBlock.split("\n").filter(Boolean),
@@ -276,10 +240,8 @@ export function applyPatches(yamlString: string, patches: YamlPatch[]): string {
276
240
  ...afterKey,
277
241
  ];
278
242
 
279
- // Join lines and ensure proper newlines
280
243
  currentYaml = `${newContent.join("\n").replace(/\n*$/, "\n")}\n`;
281
244
  } else {
282
- // Key not found: Add the new key-value pair to the end
283
245
  const newLineBlock = replacementLine;
284
246
  if (currentYaml.trim() === "") {
285
247
  currentYaml = `${newLineBlock}\n`;
@@ -289,6 +251,5 @@ export function applyPatches(yamlString: string, patches: YamlPatch[]): string {
289
251
  }
290
252
  }
291
253
 
292
- // Ensure the result ends with a newline
293
254
  return currentYaml.replace(/\n*$/, "\n");
294
255
  }
@@ -1,8 +1,4 @@
1
- // declare global {
2
- // function syscall(name: string, ...args: any[]): Promise<any>;
3
- // }
4
-
5
- // This is the case when running tests only, so giving it a dummy syscall function
1
+ // Tests may load this module without a syscall host.
6
2
  if (typeof (globalThis as any).syscall === "undefined") {
7
3
  (globalThis as any).syscall = () => {
8
4
  throw new Error("Not implemented here");
@@ -15,14 +15,14 @@ export function get<T>(path: string | string[], defaultValue: T): Promise<T> {
15
15
  * @param path The path to set the value at
16
16
  * @param value The value to set
17
17
  */
18
- export function set<T>(path: string, value: T): Promise<void>;
18
+ export function set<T>(path: string | string[], value: T): Promise<void>;
19
19
  /**
20
20
  * Sets multiple config values at once.
21
21
  * @param values An object containing key-value pairs to set
22
22
  */
23
23
  export function set(values: Record<string, any>): Promise<void>;
24
24
  export function set<T>(
25
- pathOrValues: string | Record<string, any>,
25
+ pathOrValues: string | string[] | Record<string, any>,
26
26
  value?: T,
27
27
  ): Promise<void> {
28
28
  return syscall("config.set", pathOrValues, value);