@alisio/core 0.1.0-alpha.20 → 0.1.0-alpha.22

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 (104) hide show
  1. package/dist/agents/active.d.ts +19 -0
  2. package/dist/agents/active.js +41 -0
  3. package/dist/agents/capabilities.d.ts +26 -0
  4. package/dist/agents/capabilities.js +120 -0
  5. package/dist/agents/create-agent-skill.d.ts +11 -0
  6. package/dist/agents/create-agent-skill.js +60 -0
  7. package/dist/agents/definitions.d.ts +88 -0
  8. package/dist/agents/definitions.js +404 -0
  9. package/dist/agents/draft.d.ts +41 -0
  10. package/dist/agents/draft.js +133 -0
  11. package/dist/agents/service.d.ts +57 -0
  12. package/dist/agents/service.js +86 -0
  13. package/dist/agents/templates.d.ts +8 -0
  14. package/dist/agents/templates.js +102 -0
  15. package/dist/analysis/capabilities.d.ts +48 -0
  16. package/dist/analysis/capabilities.js +90 -0
  17. package/dist/analysis/data/csv.d.ts +46 -0
  18. package/dist/analysis/data/csv.js +240 -0
  19. package/dist/analysis/data/datasets.d.ts +132 -0
  20. package/dist/analysis/data/datasets.js +441 -0
  21. package/dist/analysis/data/describe.d.ts +27 -0
  22. package/dist/analysis/data/describe.js +103 -0
  23. package/dist/analysis/data/engine-client.d.ts +58 -0
  24. package/dist/analysis/data/engine-client.js +304 -0
  25. package/dist/analysis/data/engine-entry.d.ts +1 -0
  26. package/dist/analysis/data/engine-entry.js +59 -0
  27. package/dist/analysis/data/engine-source.d.ts +4 -0
  28. package/dist/analysis/data/engine-source.js +6 -0
  29. package/dist/analysis/data/engine-types.d.ts +86 -0
  30. package/dist/analysis/data/engine-types.js +7 -0
  31. package/dist/analysis/data/infer.d.ts +42 -0
  32. package/dist/analysis/data/infer.js +118 -0
  33. package/dist/analysis/data/ingest-worker.d.ts +17 -0
  34. package/dist/analysis/data/ingest-worker.js +365 -0
  35. package/dist/analysis/data/json.d.ts +19 -0
  36. package/dist/analysis/data/json.js +44 -0
  37. package/dist/analysis/data/query-worker.d.ts +12 -0
  38. package/dist/analysis/data/query-worker.js +75 -0
  39. package/dist/analysis/data/rows.d.ts +39 -0
  40. package/dist/analysis/data/rows.js +120 -0
  41. package/dist/analysis/data/sql-guard.d.ts +20 -0
  42. package/dist/analysis/data/sql-guard.js +129 -0
  43. package/dist/analysis/data/stats.d.ts +18 -0
  44. package/dist/analysis/data/stats.js +77 -0
  45. package/dist/analysis/install-hints.d.ts +33 -0
  46. package/dist/analysis/install-hints.js +144 -0
  47. package/dist/analysis/janitor.d.ts +60 -0
  48. package/dist/analysis/janitor.js +264 -0
  49. package/dist/analysis/jobs.d.ts +94 -0
  50. package/dist/analysis/jobs.js +165 -0
  51. package/dist/analysis/oci.d.ts +129 -0
  52. package/dist/analysis/oci.js +330 -0
  53. package/dist/analysis/python/sources.d.ts +2 -0
  54. package/dist/analysis/python/sources.js +10 -0
  55. package/dist/analysis/requirements.d.ts +32 -0
  56. package/dist/analysis/requirements.js +73 -0
  57. package/dist/analysis/rerun.d.ts +40 -0
  58. package/dist/analysis/rerun.js +136 -0
  59. package/dist/analysis/runtime-manager.d.ts +146 -0
  60. package/dist/analysis/runtime-manager.js +472 -0
  61. package/dist/analysis/status.d.ts +21 -0
  62. package/dist/analysis/status.js +52 -0
  63. package/dist/application.d.ts +48 -0
  64. package/dist/application.js +228 -0
  65. package/dist/artifacts/kinds.d.ts +35 -0
  66. package/dist/artifacts/kinds.js +177 -0
  67. package/dist/artifacts/publisher.d.ts +7 -0
  68. package/dist/artifacts/publisher.js +29 -0
  69. package/dist/artifacts/store.d.ts +119 -0
  70. package/dist/artifacts/store.js +581 -0
  71. package/dist/commands/builtins.js +13 -0
  72. package/dist/commands/catalog.js +13 -1
  73. package/dist/config.d.ts +102 -0
  74. package/dist/config.js +167 -6
  75. package/dist/core/contracts.d.ts +69 -1
  76. package/dist/core/runner.d.ts +34 -4
  77. package/dist/core/runner.js +388 -130
  78. package/dist/index.d.ts +30 -5
  79. package/dist/index.js +29 -4
  80. package/dist/mcp/rich.js +4 -0
  81. package/dist/plugins/host.js +14 -6
  82. package/dist/runtime/blobs.d.ts +22 -0
  83. package/dist/runtime/blobs.js +84 -1
  84. package/dist/runtime/ids.d.ts +8 -0
  85. package/dist/runtime/ids.js +32 -0
  86. package/dist/runtime/paths.d.ts +5 -0
  87. package/dist/runtime/paths.js +6 -0
  88. package/dist/runtime/process.d.ts +12 -0
  89. package/dist/runtime/process.js +64 -4
  90. package/dist/runtime/sqlite.d.ts +2 -0
  91. package/dist/runtime/sqlite.js +18 -0
  92. package/dist/runtime/store.d.ts +5 -0
  93. package/dist/runtime/store.js +75 -0
  94. package/dist/runtime/zip.d.ts +24 -0
  95. package/dist/runtime/zip.js +126 -0
  96. package/dist/sessions/children.js +4 -0
  97. package/dist/tools/analysis.d.ts +37 -0
  98. package/dist/tools/analysis.js +572 -0
  99. package/dist/tools/artifacts.d.ts +14 -0
  100. package/dist/tools/artifacts.js +143 -0
  101. package/dist/tools/data.d.ts +7 -0
  102. package/dist/tools/data.js +160 -0
  103. package/dist/tools/execute.js +6 -2
  104. package/package.json +2 -2
@@ -0,0 +1,126 @@
1
+ /**
2
+ * Streaming ZIP writer on `node:zlib` (no dependency): DEFLATE entries with a data descriptor,
3
+ * UTF-8 names (general-purpose bit 11) and no ZIP64, so archives and entries must stay below
4
+ * 4 GiB. Used for multi-file artifact downloads and for folders published as one archive.
5
+ */
6
+ import { createReadStream } from "node:fs";
7
+ import { createDeflateRaw } from "node:zlib";
8
+ let table;
9
+ /** CRC-32 (IEEE) of `bytes`, continuing from `crc`. */
10
+ export function crc32(bytes, crc = 0) {
11
+ if (!table) {
12
+ table = new Uint32Array(256);
13
+ for (let n = 0; n < 256; n++) {
14
+ let c = n;
15
+ for (let k = 0; k < 8; k++)
16
+ c = c & 1 ? 0xedb88320 ^ (c >>> 1) : c >>> 1;
17
+ table[n] = c >>> 0;
18
+ }
19
+ }
20
+ let value = ~crc >>> 0;
21
+ for (let i = 0; i < bytes.length; i++)
22
+ value = table[(value ^ bytes[i]) & 0xff] ^ (value >>> 8);
23
+ return ~value >>> 0;
24
+ }
25
+ /** MS-DOS date and time of `date` (local time, 2-second resolution, 1980 minimum). */
26
+ function dosTime(date) {
27
+ const year = Math.max(1980, date.getFullYear());
28
+ return {
29
+ time: (date.getHours() << 11) | (date.getMinutes() << 5) | Math.floor(date.getSeconds() / 2),
30
+ date: ((year - 1980) << 9) | ((date.getMonth() + 1) << 5) | date.getDate(),
31
+ };
32
+ }
33
+ const LIMIT = 0xffff_ffff;
34
+ /**
35
+ * Writes `entries` as a ZIP archive to `out`, streaming file contents. Entry names use `/` and
36
+ * must be relative; the caller validates them. Throws when the archive would need ZIP64.
37
+ */
38
+ export async function writeZip(entries, out, options = {}) {
39
+ if (entries.length > 0xffff)
40
+ throw new Error("ZIP archives hold at most 65535 entries");
41
+ let offset = 0;
42
+ const put = async (chunk) => {
43
+ options.signal?.throwIfAborted();
44
+ offset += chunk.byteLength;
45
+ if (offset > LIMIT)
46
+ throw new Error("ZIP archives larger than 4 GiB are not supported");
47
+ if (!out.write(chunk))
48
+ await new Promise((resolve) => out.once("drain", resolve));
49
+ };
50
+ const { time, date } = dosTime(options.now ?? new Date());
51
+ const central = [];
52
+ for (const entry of entries) {
53
+ const name = Buffer.from(entry.name.replace(/\\/g, "/"), "utf8");
54
+ const start = offset;
55
+ const local = Buffer.alloc(30);
56
+ local.writeUInt32LE(0x04034b50, 0);
57
+ local.writeUInt16LE(20, 4); // version needed
58
+ local.writeUInt16LE(0x0808, 6); // data descriptor + UTF-8 names
59
+ local.writeUInt16LE(8, 8); // deflate
60
+ local.writeUInt16LE(time, 10);
61
+ local.writeUInt16LE(date, 12);
62
+ local.writeUInt16LE(name.length, 26);
63
+ await put(local);
64
+ await put(name);
65
+ let crc = 0, size = 0, compressed = 0;
66
+ const deflate = createDeflateRaw();
67
+ const feed = "data" in entry
68
+ ? (async () => {
69
+ crc = crc32(entry.data);
70
+ size = entry.data.byteLength;
71
+ deflate.end(Buffer.from(entry.data));
72
+ })()
73
+ : new Promise((resolve, reject) => {
74
+ const input = createReadStream(entry.source);
75
+ input.on("data", (chunk) => {
76
+ const bytes = chunk;
77
+ crc = crc32(bytes, crc);
78
+ size += bytes.byteLength;
79
+ });
80
+ input.once("error", (error) => {
81
+ deflate.destroy(error);
82
+ reject(error);
83
+ });
84
+ input.once("end", resolve);
85
+ input.pipe(deflate);
86
+ });
87
+ for await (const chunk of deflate) {
88
+ compressed += chunk.byteLength;
89
+ await put(chunk);
90
+ }
91
+ await feed;
92
+ if (size > LIMIT || compressed > LIMIT)
93
+ throw new Error("ZIP entries larger than 4 GiB are not supported");
94
+ const descriptor = Buffer.alloc(16);
95
+ descriptor.writeUInt32LE(0x08074b50, 0);
96
+ descriptor.writeUInt32LE(crc, 4);
97
+ descriptor.writeUInt32LE(compressed, 8);
98
+ descriptor.writeUInt32LE(size, 12);
99
+ await put(descriptor);
100
+ const header = Buffer.alloc(46);
101
+ header.writeUInt32LE(0x02014b50, 0);
102
+ header.writeUInt16LE(20, 4); // version made by
103
+ header.writeUInt16LE(20, 6); // version needed
104
+ header.writeUInt16LE(0x0808, 8);
105
+ header.writeUInt16LE(8, 10);
106
+ header.writeUInt16LE(time, 12);
107
+ header.writeUInt16LE(date, 14);
108
+ header.writeUInt32LE(crc, 16);
109
+ header.writeUInt32LE(compressed, 20);
110
+ header.writeUInt32LE(size, 24);
111
+ header.writeUInt16LE(name.length, 28);
112
+ header.writeUInt32LE(start, 42);
113
+ central.push(header, name);
114
+ }
115
+ const directoryStart = offset;
116
+ for (const part of central)
117
+ await put(part);
118
+ const end = Buffer.alloc(22);
119
+ end.writeUInt32LE(0x06054b50, 0);
120
+ end.writeUInt16LE(entries.length, 8);
121
+ end.writeUInt16LE(entries.length, 10);
122
+ end.writeUInt32LE(offset - directoryStart, 12);
123
+ end.writeUInt32LE(directoryStart, 16);
124
+ await put(end);
125
+ return { bytes: offset };
126
+ }
@@ -148,6 +148,10 @@ export class ChildSessions {
148
148
  write: caps.write,
149
149
  process: caps.process,
150
150
  external: root.external && !caps.readOnly,
151
+ // --allow-analysis carries to children whose process permission is not narrowed.
152
+ ...(root.analysis && !caps.readOnly && (spec.permission?.process ?? "allow") === "allow"
153
+ ? { analysis: true }
154
+ : {}),
151
155
  },
152
156
  approvals: caps.approvals,
153
157
  label: this.label(id),
@@ -0,0 +1,37 @@
1
+ import type { DatasetService } from "../analysis/data/datasets.ts";
2
+ import type { AnalysisJobs } from "../analysis/jobs.ts";
3
+ import type { OciRuntime } from "../analysis/oci.ts";
4
+ import type { AnalysisRerun } from "../analysis/rerun.ts";
5
+ import { type AnalysisRuntimeManager } from "../analysis/runtime-manager.ts";
6
+ import { type ArtifactStore } from "../artifacts/store.ts";
7
+ import type { ToolRegistry } from "../core/registry.ts";
8
+ export declare const NOT_SANDBOXED = "Managed Python is not a sandbox: the script runs with your user permissions and can read your files and use the network.";
9
+ export interface AnalysisLimits {
10
+ timeoutMs: number;
11
+ maxLogBytes: number;
12
+ }
13
+ export interface AnalysisToolDeps {
14
+ store: ArtifactStore;
15
+ jobs: AnalysisJobs;
16
+ /** Discovery (`interpreter`) and, for the optional extras, `hasExtras` / `installExtras`. */
17
+ runtime: Pick<AnalysisRuntimeManager, "interpreter"> & Partial<Pick<AnalysisRuntimeManager, "hasExtras" | "installExtras">>;
18
+ /** Container mode (`analysis.runtime: "oci"`), read when each call starts. */
19
+ oci?: {
20
+ mode(): "managed" | "oci";
21
+ runtime(): OciRuntime;
22
+ };
23
+ /** Rerun of an earlier execution (`rerunOf`). */
24
+ rerun?: AnalysisRerun;
25
+ /** Datasets of the session: `inputs: [{ datasetId }]` copies the dataset's SQLite file. */
26
+ datasets?: DatasetService;
27
+ rootOf: (sessionId: string) => string;
28
+ limits: AnalysisLimits;
29
+ /** Startup facts for the description (stat only; no process was launched). */
30
+ startup: {
31
+ candidates: boolean;
32
+ extras: string[];
33
+ };
34
+ }
35
+ /** `48 KB`, `1.2 MB`. */
36
+ export declare function formatBytes(bytes: number): string;
37
+ export declare function registerAnalysisTools(registry: ToolRegistry, deps: AnalysisToolDeps): void;