@cldmv/slothlet 2.8.0 → 2.10.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 (59) hide show
  1. package/AGENT-USAGE.md +1 -1
  2. package/README.md +300 -1557
  3. package/dist/lib/engine/slothlet_child.mjs +1 -1
  4. package/dist/lib/engine/slothlet_engine.mjs +1 -1
  5. package/dist/lib/engine/slothlet_esm.mjs +1 -1
  6. package/dist/lib/engine/slothlet_helpers.mjs +1 -1
  7. package/dist/lib/engine/slothlet_worker.mjs +1 -1
  8. package/dist/lib/helpers/als-eventemitter.mjs +5 -6
  9. package/dist/lib/helpers/api_builder/add_api.mjs +292 -0
  10. package/dist/lib/helpers/api_builder/analysis.mjs +532 -0
  11. package/dist/lib/helpers/api_builder/construction.mjs +457 -0
  12. package/dist/lib/helpers/api_builder/decisions.mjs +737 -0
  13. package/dist/lib/helpers/api_builder/metadata.mjs +248 -0
  14. package/dist/lib/helpers/api_builder.mjs +17 -1568
  15. package/dist/lib/helpers/auto-wrap.mjs +1 -1
  16. package/dist/lib/helpers/hooks.mjs +1 -1
  17. package/dist/lib/helpers/instance-manager.mjs +1 -1
  18. package/dist/lib/helpers/metadata-api.mjs +201 -0
  19. package/dist/lib/helpers/multidefault.mjs +12 -3
  20. package/dist/lib/helpers/resolve-from-caller.mjs +1 -1
  21. package/dist/lib/helpers/sanitize.mjs +1 -1
  22. package/dist/lib/helpers/utilities.mjs +121 -0
  23. package/dist/lib/modes/slothlet_eager.mjs +1 -1
  24. package/dist/lib/modes/slothlet_lazy.mjs +10 -1
  25. package/dist/lib/runtime/runtime-asynclocalstorage.mjs +49 -18
  26. package/dist/lib/runtime/runtime-livebindings.mjs +23 -4
  27. package/dist/lib/runtime/runtime.mjs +15 -4
  28. package/dist/slothlet.mjs +164 -748
  29. package/docs/API-RULES-CONDITIONS.md +508 -0
  30. package/{API-RULES.md → docs/API-RULES.md} +127 -72
  31. package/package.json +11 -9
  32. package/types/dist/lib/helpers/als-eventemitter.d.mts.map +1 -1
  33. package/types/dist/lib/helpers/api_builder/add_api.d.mts +76 -0
  34. package/types/dist/lib/helpers/api_builder/add_api.d.mts.map +1 -0
  35. package/types/dist/lib/helpers/api_builder/analysis.d.mts +189 -0
  36. package/types/dist/lib/helpers/api_builder/analysis.d.mts.map +1 -0
  37. package/types/dist/lib/helpers/api_builder/construction.d.mts +107 -0
  38. package/types/dist/lib/helpers/api_builder/construction.d.mts.map +1 -0
  39. package/types/dist/lib/helpers/api_builder/decisions.d.mts +213 -0
  40. package/types/dist/lib/helpers/api_builder/decisions.d.mts.map +1 -0
  41. package/types/dist/lib/helpers/api_builder/metadata.d.mts +99 -0
  42. package/types/dist/lib/helpers/api_builder/metadata.d.mts.map +1 -0
  43. package/types/dist/lib/helpers/api_builder.d.mts +5 -448
  44. package/types/dist/lib/helpers/api_builder.d.mts.map +1 -1
  45. package/types/dist/lib/helpers/metadata-api.d.mts +132 -0
  46. package/types/dist/lib/helpers/metadata-api.d.mts.map +1 -0
  47. package/types/dist/lib/helpers/multidefault.d.mts.map +1 -1
  48. package/types/dist/lib/helpers/utilities.d.mts +120 -0
  49. package/types/dist/lib/helpers/utilities.d.mts.map +1 -0
  50. package/types/dist/lib/runtime/runtime-asynclocalstorage.d.mts +9 -0
  51. package/types/dist/lib/runtime/runtime-asynclocalstorage.d.mts.map +1 -1
  52. package/types/dist/lib/runtime/runtime-livebindings.d.mts +10 -0
  53. package/types/dist/lib/runtime/runtime-livebindings.d.mts.map +1 -1
  54. package/types/dist/lib/runtime/runtime.d.mts +1 -0
  55. package/types/dist/lib/runtime/runtime.d.mts.map +1 -1
  56. package/types/dist/slothlet.d.mts +0 -11
  57. package/types/dist/slothlet.d.mts.map +1 -1
  58. package/types/index.d.mts +0 -1
  59. package/API-RULES-CONDITIONS.md +0 -367
@@ -0,0 +1,248 @@
1
+ /*
2
+ Copyright 2026 CLDMV/Shinrai
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */
16
+
17
+
18
+
19
+
20
+
21
+
22
+ export function createImmutableMetadata(initial = {}) {
23
+
24
+
25
+
26
+ function makeImmutable(obj, visited = new WeakSet()) {
27
+ if (obj === null || typeof obj !== "object") return obj;
28
+ if (visited.has(obj)) return obj;
29
+ visited.add(obj);
30
+
31
+
32
+ if (Array.isArray(obj)) {
33
+
34
+ for (let i = 0; i < obj.length; i++) {
35
+ obj[i] = makeImmutable(obj[i], visited);
36
+ }
37
+
38
+
39
+
40
+ return new Proxy(obj, {
41
+ set() {
42
+
43
+
44
+ return false;
45
+ },
46
+ deleteProperty() {
47
+
48
+ return false;
49
+ }
50
+ });
51
+ }
52
+
53
+
54
+ for (const [key, value] of Object.entries(obj)) {
55
+ const immutableValue = makeImmutable(value, visited);
56
+ Object.defineProperty(obj, key, {
57
+ value: immutableValue,
58
+ writable: false,
59
+ enumerable: true,
60
+ configurable: true
61
+ });
62
+ }
63
+
64
+
65
+ return new Proxy(obj, {
66
+ set(target, prop, value) {
67
+ const descriptor = Object.getOwnPropertyDescriptor(target, prop);
68
+
69
+
70
+ if (descriptor && !descriptor.writable) {
71
+ return false;
72
+ }
73
+
74
+
75
+ if (!descriptor) {
76
+ const immutableValue = makeImmutable(value);
77
+ Object.defineProperty(target, prop, {
78
+ value: immutableValue,
79
+ writable: false,
80
+ enumerable: true,
81
+ configurable: true
82
+ });
83
+ return true;
84
+ }
85
+
86
+ return Reflect.set(target, prop, value);
87
+ },
88
+ deleteProperty() {
89
+
90
+ return false;
91
+ }
92
+ });
93
+ }
94
+
95
+
96
+ const base = {};
97
+
98
+
99
+
100
+ for (const [key, value] of Object.entries(initial)) {
101
+ const immutableValue = makeImmutable(value);
102
+ Object.defineProperty(base, key, {
103
+ value: immutableValue,
104
+ writable: false,
105
+ enumerable: true,
106
+ configurable: true
107
+ });
108
+ }
109
+
110
+
111
+ return new Proxy(base, {
112
+ set(target, prop, value) {
113
+
114
+ const descriptor = Object.getOwnPropertyDescriptor(target, prop);
115
+
116
+
117
+ if (descriptor && !descriptor.writable) {
118
+ if (process.env.SLOTHLET_DEBUG) {
119
+ console.warn(`[slothlet] Cannot modify existing metadata property: "${String(prop)}"`);
120
+ }
121
+
122
+
123
+ return false;
124
+ }
125
+
126
+
127
+ if (!descriptor) {
128
+ Object.defineProperty(target, prop, {
129
+ value,
130
+ writable: false,
131
+ enumerable: true,
132
+ configurable: true
133
+ });
134
+ return true;
135
+ }
136
+
137
+
138
+
139
+ return Reflect.set(target, prop, value);
140
+ },
141
+
142
+ deleteProperty(target, prop) {
143
+
144
+ if (process.env.SLOTHLET_DEBUG) {
145
+ console.warn(`[slothlet] Cannot delete metadata property: "${String(prop)}"`);
146
+ }
147
+ return true;
148
+ }
149
+ });
150
+ }
151
+
152
+
153
+ export function cleanMetadata(obj, visited = new WeakSet()) {
154
+
155
+ if (!obj || (typeof obj !== "object" && typeof obj !== "function")) return;
156
+ if (visited.has(obj)) return;
157
+ visited.add(obj);
158
+
159
+
160
+ if (typeof obj === "function") {
161
+ try {
162
+ if (obj.__metadata) {
163
+ delete obj.__metadata;
164
+ }
165
+ if (obj.__sourceFolder) {
166
+ delete obj.__sourceFolder;
167
+ }
168
+ } catch (_) {
169
+
170
+ }
171
+ }
172
+
173
+
174
+ try {
175
+ const keys = Object.keys(obj);
176
+ for (const key of keys) {
177
+ if (
178
+ key.startsWith("_") ||
179
+ ["hooks", "shutdown", "addApi", "describe", "run", "__proto__", "constructor", "prototype"].includes(key)
180
+ ) {
181
+ continue;
182
+ }
183
+ cleanMetadata(obj[key], visited);
184
+ }
185
+ } catch {
186
+
187
+ }
188
+ }
189
+
190
+
191
+ export function tagLoadedFunctions(obj, metadata, baseDir, visited = new WeakSet()) {
192
+
193
+ if (!obj || (typeof obj !== "object" && typeof obj !== "function")) return;
194
+ if (visited.has(obj)) return;
195
+ visited.add(obj);
196
+
197
+
198
+ if (typeof obj === "function") {
199
+ try {
200
+
201
+ const immutableMeta = createImmutableMetadata(metadata);
202
+
203
+ Object.defineProperty(obj, "__metadata", {
204
+ value: immutableMeta,
205
+ writable: false,
206
+ enumerable: false,
207
+ configurable: true
208
+ });
209
+
210
+
211
+ if (metadata.sourceFolder) {
212
+ Object.defineProperty(obj, "__sourceFolder", {
213
+ value: metadata.sourceFolder,
214
+ writable: false,
215
+ enumerable: false,
216
+ configurable: true
217
+ });
218
+ }
219
+
220
+
221
+
222
+
223
+ } catch (error) {
224
+
225
+ if (metadata.debug) {
226
+ console.warn(`[slothlet] Could not tag function with metadata:`, error.message);
227
+ }
228
+ }
229
+ }
230
+
231
+
232
+ try {
233
+ const keys = Object.keys(obj);
234
+ for (const key of keys) {
235
+
236
+ if (
237
+ key.startsWith("_") ||
238
+ ["hooks", "shutdown", "addApi", "describe", "run", "__proto__", "constructor", "prototype"].includes(key)
239
+ ) {
240
+ continue;
241
+ }
242
+
243
+ tagLoadedFunctions(obj[key], metadata, baseDir, visited);
244
+ }
245
+ } catch {
246
+
247
+ }
248
+ }