opencode-ipynb 0.1.2 → 3.0.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 (130) hide show
  1. package/CHANGELOG.md +187 -0
  2. package/README.md +197 -41
  3. package/dist/domain/cell.d.ts +4 -3
  4. package/dist/domain/errors.d.ts +3 -31
  5. package/dist/domain/execution.d.ts +4 -1
  6. package/dist/domain/notebook.d.ts +6 -3
  7. package/dist/domain/output.d.ts +0 -1
  8. package/dist/format/diagnostics.d.ts +0 -1
  9. package/dist/format/markdown.d.ts +1 -2
  10. package/dist/format/{diff.d.ts → notebook.d.ts} +1 -1
  11. package/dist/format/outputs.d.ts +2 -2
  12. package/dist/index.d.ts +3 -1
  13. package/dist/index.js +11294 -28152
  14. package/dist/load-document.d.ts +10 -0
  15. package/dist/lsp.d.ts +58 -0
  16. package/dist/lsp.js +172 -0
  17. package/dist/notebook-diagnostics.d.ts +52 -0
  18. package/dist/notebook-hooks.d.ts +18 -0
  19. package/dist/plugin-options.d.ts +4 -1
  20. package/dist/plugin-v2.d.ts +31 -0
  21. package/dist/plugin.d.ts +2 -3
  22. package/dist/registrations.d.ts +5 -0
  23. package/dist/rpc.d.ts +134 -0
  24. package/dist/rpc.js +84 -0
  25. package/dist/services/KernelManager.d.ts +45 -0
  26. package/dist/services/NotebookCleanService.d.ts +7 -7
  27. package/dist/services/NotebookEditService.d.ts +15 -12
  28. package/dist/services/NotebookExecutionService.d.ts +41 -12
  29. package/dist/services/NotebookExportService.d.ts +3 -7
  30. package/dist/services/NotebookFileService.d.ts +31 -16
  31. package/dist/services/NotebookInspectService.d.ts +15 -19
  32. package/dist/services/NotebookOutputService.d.ts +7 -10
  33. package/dist/services/NotebookReadService.d.ts +4 -10
  34. package/dist/services/PathService.d.ts +10 -8
  35. package/dist/services/PermissionService.d.ts +13 -8
  36. package/dist/services/PythonService.d.ts +14 -43
  37. package/dist/services/index.d.ts +23 -28
  38. package/dist/services/revision.d.ts +9 -0
  39. package/dist/tool.d.ts +45 -0
  40. package/dist/tools/_readPermission.d.ts +2 -0
  41. package/dist/tools/_resolveOptions.d.ts +13 -2
  42. package/dist/tools/cell_delete.d.ts +4 -13
  43. package/dist/tools/cell_insert.d.ts +10 -21
  44. package/dist/tools/cell_move.d.ts +5 -15
  45. package/dist/tools/clean.d.ts +8 -21
  46. package/dist/tools/doctor.d.ts +3 -11
  47. package/dist/tools/edit.d.ts +10 -21
  48. package/dist/tools/export.d.ts +12 -23
  49. package/dist/tools/inspect.d.ts +7 -19
  50. package/dist/tools/kernel.d.ts +13 -21
  51. package/dist/tools/lsp.d.ts +9 -0
  52. package/dist/tools/outputs.d.ts +15 -29
  53. package/dist/tools/read.d.ts +12 -29
  54. package/dist/tools/repro.d.ts +6 -14
  55. package/dist/tools/run.d.ts +17 -34
  56. package/dist/utils/ansi.d.ts +1 -1
  57. package/dist/utils/atomic-replace.d.ts +2 -0
  58. package/dist/utils/attachments.d.ts +2 -3
  59. package/dist/utils/execution-order.d.ts +7 -0
  60. package/dist/utils/fence.d.ts +1 -0
  61. package/dist/utils/i18n.d.ts +1 -2
  62. package/dist/utils/imports.d.ts +0 -1
  63. package/dist/utils/json-patch.d.ts +58 -0
  64. package/dist/utils/json.d.ts +16 -2
  65. package/dist/utils/limits.d.ts +11 -2
  66. package/dist/utils/markdown-safe.d.ts +2 -0
  67. package/dist/utils/metadata.d.ts +2 -0
  68. package/dist/utils/mime.d.ts +1 -1
  69. package/dist/utils/paths.d.ts +2 -2
  70. package/dist/utils/realpath.d.ts +1 -0
  71. package/dist/utils/rename-hook.d.ts +6 -0
  72. package/dist/utils/truncate.d.ts +0 -1
  73. package/dist/utils/warnings.d.ts +15 -0
  74. package/dist/utils/windows.d.ts +3 -0
  75. package/dist/virtual-materialize.d.ts +25 -0
  76. package/package.json +30 -18
  77. package/python/ipynb_runner.py +418 -31
  78. package/python/requirements.txt +5 -4
  79. package/server.js +3 -0
  80. package/dist/domain/cell.d.ts.map +0 -1
  81. package/dist/domain/errors.d.ts.map +0 -1
  82. package/dist/domain/execution.d.ts.map +0 -1
  83. package/dist/domain/notebook.d.ts.map +0 -1
  84. package/dist/domain/output.d.ts.map +0 -1
  85. package/dist/format/diagnostics.d.ts.map +0 -1
  86. package/dist/format/diff.d.ts.map +0 -1
  87. package/dist/format/markdown.d.ts.map +0 -1
  88. package/dist/format/outputs.d.ts.map +0 -1
  89. package/dist/index.d.ts.map +0 -1
  90. package/dist/plugin-options.d.ts.map +0 -1
  91. package/dist/plugin.d.ts.map +0 -1
  92. package/dist/services/DiffService.d.ts +0 -17
  93. package/dist/services/DiffService.d.ts.map +0 -1
  94. package/dist/services/NotebookCleanService.d.ts.map +0 -1
  95. package/dist/services/NotebookEditService.d.ts.map +0 -1
  96. package/dist/services/NotebookExecutionService.d.ts.map +0 -1
  97. package/dist/services/NotebookExportService.d.ts.map +0 -1
  98. package/dist/services/NotebookFileService.d.ts.map +0 -1
  99. package/dist/services/NotebookInspectService.d.ts.map +0 -1
  100. package/dist/services/NotebookOutputService.d.ts.map +0 -1
  101. package/dist/services/NotebookReadService.d.ts.map +0 -1
  102. package/dist/services/PathService.d.ts.map +0 -1
  103. package/dist/services/PermissionService.d.ts.map +0 -1
  104. package/dist/services/PythonService.d.ts.map +0 -1
  105. package/dist/services/index.d.ts.map +0 -1
  106. package/dist/tools/_resolveOptions.d.ts.map +0 -1
  107. package/dist/tools/cell_delete.d.ts.map +0 -1
  108. package/dist/tools/cell_insert.d.ts.map +0 -1
  109. package/dist/tools/cell_move.d.ts.map +0 -1
  110. package/dist/tools/clean.d.ts.map +0 -1
  111. package/dist/tools/doctor.d.ts.map +0 -1
  112. package/dist/tools/edit.d.ts.map +0 -1
  113. package/dist/tools/export.d.ts.map +0 -1
  114. package/dist/tools/inspect.d.ts.map +0 -1
  115. package/dist/tools/kernel.d.ts.map +0 -1
  116. package/dist/tools/outputs.d.ts.map +0 -1
  117. package/dist/tools/read.d.ts.map +0 -1
  118. package/dist/tools/repro.d.ts.map +0 -1
  119. package/dist/tools/run.d.ts.map +0 -1
  120. package/dist/utils/ansi.d.ts.map +0 -1
  121. package/dist/utils/attachments.d.ts.map +0 -1
  122. package/dist/utils/fiber.d.ts +0 -2
  123. package/dist/utils/fiber.d.ts.map +0 -1
  124. package/dist/utils/i18n.d.ts.map +0 -1
  125. package/dist/utils/imports.d.ts.map +0 -1
  126. package/dist/utils/json.d.ts.map +0 -1
  127. package/dist/utils/limits.d.ts.map +0 -1
  128. package/dist/utils/mime.d.ts.map +0 -1
  129. package/dist/utils/paths.d.ts.map +0 -1
  130. package/dist/utils/truncate.d.ts.map +0 -1
@@ -0,0 +1,10 @@
1
+ import type { PluginOptions } from "./plugin-options.js";
2
+ import { type NotebookVirtualDocument } from "./lsp.js";
3
+ export interface LoadDocumentContext {
4
+ readonly directory: string;
5
+ readonly worktree: string;
6
+ readonly allowOutsideWorktree?: boolean;
7
+ readonly options: PluginOptions;
8
+ readonly resolvePython?: boolean;
9
+ }
10
+ export declare const loadNotebookDocument: (context: LoadDocumentContext, filePath: string) => Promise<NotebookVirtualDocument>;
package/dist/lsp.d.ts ADDED
@@ -0,0 +1,58 @@
1
+ export interface NotebookLike {
2
+ readonly metadata: {
3
+ readonly language_info?: unknown;
4
+ readonly kernelspec?: unknown;
5
+ };
6
+ readonly cells: ReadonlyArray<{
7
+ readonly cell_type: string;
8
+ readonly source: string | ReadonlyArray<string>;
9
+ }>;
10
+ }
11
+ export interface NotebookCellDocument {
12
+ readonly cellIndex: number;
13
+ readonly cellType: "code" | "markdown" | "raw";
14
+ readonly languageId: string;
15
+ readonly text: string;
16
+ readonly uri?: string;
17
+ readonly startLine: number;
18
+ readonly endLine: number;
19
+ readonly lineCount: number;
20
+ }
21
+ export interface NotebookVirtualDocument {
22
+ readonly filePath: string;
23
+ readonly notebookUri?: string;
24
+ readonly languageId: string;
25
+ readonly fileExtension?: string;
26
+ readonly kernelName?: string;
27
+ readonly pythonPath?: string;
28
+ readonly text: string;
29
+ readonly cells: ReadonlyArray<NotebookCellDocument>;
30
+ }
31
+ export interface CellPosition {
32
+ readonly cellIndex: number;
33
+ readonly line: number;
34
+ readonly character: number;
35
+ }
36
+ export interface VirtualPosition {
37
+ readonly line: number;
38
+ readonly character: number;
39
+ }
40
+ export interface VirtualDocumentOptions {
41
+ readonly filePath?: string;
42
+ readonly includeMarkdown?: boolean;
43
+ readonly pythonPath?: string;
44
+ readonly notebookUri?: string;
45
+ readonly cellUri?: (cellIndex: number) => string;
46
+ }
47
+ export interface PositionMapper {
48
+ readonly toCellPosition: (line: number, character: number) => CellPosition | undefined;
49
+ readonly toVirtualPosition: (cellIndex: number, line: number, character: number) => VirtualPosition | undefined;
50
+ }
51
+ export declare const buildNotebookVirtualDocument: (notebook: NotebookLike, options?: VirtualDocumentOptions) => NotebookVirtualDocument;
52
+ export declare const cellsAroundIndex: (document: NotebookVirtualDocument, cellIndex: number) => {
53
+ readonly current: NotebookCellDocument;
54
+ readonly previous: NotebookCellDocument | undefined;
55
+ } | undefined;
56
+ export declare const toCellPosition: (document: NotebookVirtualDocument, line: number, character: number) => CellPosition | undefined;
57
+ export declare const toVirtualPosition: (document: NotebookVirtualDocument, cellIndex: number, line: number, character: number) => VirtualPosition | undefined;
58
+ export declare const makePositionMapper: (document: NotebookVirtualDocument) => PositionMapper;
package/dist/lsp.js ADDED
@@ -0,0 +1,172 @@
1
+ // @bun
2
+ // src/lsp.ts
3
+ var languageIdFor = (notebook) => {
4
+ const languageInfo = notebook.metadata.language_info;
5
+ const kernelspec = notebook.metadata.kernelspec;
6
+ const name = typeof languageInfo?.name === "string" && languageInfo.name || typeof kernelspec?.language === "string" && kernelspec.language || "python";
7
+ return normalizeLanguageId(name);
8
+ };
9
+ var normalizeLanguageId = (name) => {
10
+ const value = name.trim().toLowerCase();
11
+ if (value === "python3" || value === "python 3" || value === "ipython") {
12
+ return "python";
13
+ }
14
+ return value;
15
+ };
16
+ var defaultExtensionFor = (languageId) => {
17
+ switch (languageId) {
18
+ case "python":
19
+ return ".py";
20
+ case "r":
21
+ return ".r";
22
+ case "julia":
23
+ return ".jl";
24
+ case "javascript":
25
+ return ".js";
26
+ case "typescript":
27
+ return ".ts";
28
+ default:
29
+ return;
30
+ }
31
+ };
32
+ var kernelNameFor = (notebook) => {
33
+ const kernelspec = notebook.metadata.kernelspec;
34
+ return typeof kernelspec?.name === "string" && kernelspec.name.length > 0 ? kernelspec.name : undefined;
35
+ };
36
+ var fileExtensionFor = (notebook) => {
37
+ const languageInfo = notebook.metadata.language_info;
38
+ if (typeof languageInfo?.file_extension === "string" && languageInfo.file_extension.length > 0) {
39
+ return languageInfo.file_extension;
40
+ }
41
+ return defaultExtensionFor(languageIdFor(notebook));
42
+ };
43
+ var normalizeSource = (source) => source.replace(/\r\n?/g, `
44
+ `);
45
+ var sourceOf = (cell) => normalizeSource(typeof cell.source === "string" ? cell.source : cell.source.join(""));
46
+ var cellType = (cell) => {
47
+ switch (cell.cell_type) {
48
+ case "code":
49
+ case "markdown":
50
+ case "raw":
51
+ return cell.cell_type;
52
+ default:
53
+ return "code";
54
+ }
55
+ };
56
+ var languageIdForCell = (type, notebookLanguage) => {
57
+ if (type === "markdown")
58
+ return "markdown";
59
+ if (type === "raw")
60
+ return "plaintext";
61
+ return notebookLanguage;
62
+ };
63
+ var buildNotebookVirtualDocument = (notebook, options = {}) => {
64
+ const blocks = [];
65
+ const cells = [];
66
+ const languageId = languageIdFor(notebook);
67
+ const kernelName = kernelNameFor(notebook);
68
+ const fileExtension = fileExtensionFor(notebook);
69
+ let nextLine = 0;
70
+ notebook.cells.forEach((cell, cellIndex) => {
71
+ const type = cellType(cell);
72
+ if (type !== "code" && options.includeMarkdown !== true)
73
+ return;
74
+ const source = sourceOf(cell);
75
+ const lineCount = source.split(`
76
+ `).length;
77
+ const startLine = nextLine;
78
+ const uri = options.cellUri?.(cellIndex);
79
+ blocks.push(source);
80
+ cells.push({
81
+ cellIndex,
82
+ cellType: type,
83
+ languageId: languageIdForCell(type, languageId),
84
+ text: source,
85
+ startLine,
86
+ endLine: startLine + lineCount,
87
+ lineCount,
88
+ ...uri === undefined ? {} : { uri }
89
+ });
90
+ nextLine = startLine + lineCount;
91
+ });
92
+ return {
93
+ filePath: options.filePath ?? "",
94
+ ...options.notebookUri === undefined ? {} : { notebookUri: options.notebookUri },
95
+ languageId,
96
+ ...fileExtension === undefined ? {} : { fileExtension },
97
+ ...kernelName === undefined ? {} : { kernelName },
98
+ ...options.pythonPath === undefined ? {} : { pythonPath: options.pythonPath },
99
+ text: blocks.join(`
100
+ `),
101
+ cells
102
+ };
103
+ };
104
+ var cellCoveringLine = (cells, line) => {
105
+ let low = 0;
106
+ let high = cells.length - 1;
107
+ let candidate;
108
+ while (low <= high) {
109
+ const mid = low + high >> 1;
110
+ const cell = cells[mid];
111
+ if (cell.startLine <= line) {
112
+ candidate = cell;
113
+ low = mid + 1;
114
+ } else {
115
+ high = mid - 1;
116
+ }
117
+ }
118
+ return candidate !== undefined && line < candidate.endLine ? candidate : undefined;
119
+ };
120
+ var cellPositionOfIndex = (cells, cellIndex) => {
121
+ let low = 0;
122
+ let high = cells.length - 1;
123
+ while (low <= high) {
124
+ const mid = low + high >> 1;
125
+ const cell = cells[mid];
126
+ if (cell.cellIndex === cellIndex)
127
+ return mid;
128
+ if (cell.cellIndex < cellIndex) {
129
+ low = mid + 1;
130
+ } else {
131
+ high = mid - 1;
132
+ }
133
+ }
134
+ return -1;
135
+ };
136
+ var cellsAroundIndex = (document, cellIndex) => {
137
+ const position = cellPositionOfIndex(document.cells, cellIndex);
138
+ if (position < 0)
139
+ return;
140
+ return {
141
+ current: document.cells[position],
142
+ previous: position > 0 ? document.cells[position - 1] : undefined
143
+ };
144
+ };
145
+ var toCellPosition = (document, line, character) => {
146
+ const cell = cellCoveringLine(document.cells, line);
147
+ if (!cell)
148
+ return;
149
+ return {
150
+ cellIndex: cell.cellIndex,
151
+ line: line - cell.startLine,
152
+ character
153
+ };
154
+ };
155
+ var toVirtualPosition = (document, cellIndex, line, character) => {
156
+ const position = cellPositionOfIndex(document.cells, cellIndex);
157
+ const cell = position >= 0 ? document.cells[position] : undefined;
158
+ if (!cell || line < 0 || line >= cell.lineCount)
159
+ return;
160
+ return { line: cell.startLine + line, character };
161
+ };
162
+ var makePositionMapper = (document) => ({
163
+ toCellPosition: (line, character) => toCellPosition(document, line, character),
164
+ toVirtualPosition: (cellIndex, line, character) => toVirtualPosition(document, cellIndex, line, character)
165
+ });
166
+ export {
167
+ buildNotebookVirtualDocument,
168
+ cellsAroundIndex,
169
+ makePositionMapper,
170
+ toCellPosition,
171
+ toVirtualPosition
172
+ };
@@ -0,0 +1,52 @@
1
+ import { type NotebookVirtualDocument } from "./lsp.js";
2
+ import { type Warning, type WarningSink } from "./utils/warnings.js";
3
+ export interface NotebookDiagnostic {
4
+ readonly cellIndex: number;
5
+ readonly line: number;
6
+ readonly character: number;
7
+ readonly endLine: number;
8
+ readonly endCharacter: number;
9
+ readonly severity: "error";
10
+ readonly message: string;
11
+ readonly rule?: string;
12
+ /** pyright reported this for the whole file and supplied no position. */
13
+ readonly fileLevel?: boolean;
14
+ }
15
+ export interface NotebookDiagnosticsOptions {
16
+ readonly filePath: string;
17
+ readonly document: NotebookVirtualDocument;
18
+ readonly displayPath?: string;
19
+ readonly where?: string;
20
+ readonly tempFilePath?: string;
21
+ readonly ownedTempFile?: boolean;
22
+ readonly requestFallbackPermission?: () => Promise<void>;
23
+ readonly pythonPath?: string;
24
+ readonly pyrightPath?: string;
25
+ readonly timeoutMs?: number;
26
+ readonly signal?: AbortSignal;
27
+ readonly warningSink?: WarningSink;
28
+ }
29
+ export interface NotebookDiagnosticsResult {
30
+ readonly filePath: string;
31
+ readonly diagnostics: ReadonlyArray<NotebookDiagnostic>;
32
+ readonly text: string;
33
+ readonly warnings?: ReadonlyArray<Warning>;
34
+ readonly skipped?: "pyright-not-found" | "timeout" | "aborted" | "invalid-output" | "not-analyzed" | "temp-unwritable" | "pyright-not-executable" | "unsafe-shell-command";
35
+ }
36
+ export declare class ShellCommandError extends Error {
37
+ }
38
+ export declare const hasShellMetacharacters: (value: string) => boolean;
39
+ export declare const shellCommandRefusal: (command: string, args: ReadonlyArray<string>, shell: boolean) => ShellCommandError | undefined;
40
+ export declare const diagnosticsSkipReason: (error: unknown) => NonNullable<NotebookDiagnosticsResult["skipped"]>;
41
+ export declare const sanitizeNotebookText: (document: NotebookVirtualDocument) => string;
42
+ export declare const resolvePyrightCommand: (configured: string | undefined) => {
43
+ readonly command: string;
44
+ readonly shell: boolean;
45
+ };
46
+ export interface PyrightAvailabilityOptions {
47
+ readonly warningSink?: WarningSink | undefined;
48
+ }
49
+ export declare const isPyrightAvailable: (configured: string | undefined, timeoutMs?: number, signal?: AbortSignal, options?: PyrightAvailabilityOptions) => Promise<boolean>;
50
+ export declare const diagnosticTempPath: (filePath: string) => string;
51
+ export declare const diagnosticFallbackTempPath: (filePath: string) => string;
52
+ export declare const diagnoseNotebook: (options: NotebookDiagnosticsOptions) => Promise<NotebookDiagnosticsResult>;
@@ -0,0 +1,18 @@
1
+ export declare const notebookMutatingTools: Set<string>;
2
+ export declare const diagnosableTools: Set<string>;
3
+ export declare function toolName(tool: string): string;
4
+ export declare const changedNotebook: (tool: string, input: unknown, metadata?: Record<string, unknown>) => boolean;
5
+ export declare const changesCode: (name: string, metadata?: Record<string, unknown>) => boolean;
6
+ export type MutableResult = {
7
+ content?: string | ReadonlyArray<{
8
+ type: "text";
9
+ text: string;
10
+ } | {
11
+ type: "file";
12
+ uri: string;
13
+ mime: string;
14
+ name?: string;
15
+ }>;
16
+ metadata?: Record<string, unknown>;
17
+ };
18
+ export declare const appendResultText: (result: MutableResult, text: string) => void;
@@ -7,7 +7,10 @@ export declare const PluginOptionsSchema: z.ZodObject<{
7
7
  allowOutsideWorktree: z.ZodOptional<z.ZodBoolean>;
8
8
  defaultMaxOutputChars: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
9
9
  warmKernel: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
10
+ lspDiagnostics: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
11
+ pyrightPath: z.ZodDefault<z.ZodOptional<z.ZodString>>;
12
+ diagnosticsTimeoutMs: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
10
13
  }, z.core.$strip>;
11
14
  export type PluginOptions = z.infer<typeof PluginOptionsSchema>;
15
+ export declare const resolvePythonPath: (options: Pick<PluginOptions, "pythonPath">) => string | undefined;
12
16
  export declare const parsePluginOptions: (raw: unknown, fallback?: Partial<PluginOptions>) => PluginOptions;
13
- //# sourceMappingURL=plugin-options.d.ts.map
@@ -0,0 +1,31 @@
1
+ import { type WarningSink } from "./utils/warnings.js";
2
+ import type { Plugin } from "@opencode/plugin";
3
+ import type { AnyToolDefinition, ToolContext, ToolResult } from "./tool.js";
4
+ type V2ToolEditor = Parameters<Plugin.Context["tool"]["transform"]>[0] extends (editor: infer Editor) => void ? Editor : never;
5
+ export type V2ToolInfo = Parameters<V2ToolEditor["add"]>[0];
6
+ export type V2ToolContext = Parameters<V2ToolInfo["execute"]>[1];
7
+ export interface V2ToolRegistration {
8
+ readonly name: string;
9
+ readonly definition: AnyToolDefinition;
10
+ readonly permission?: string;
11
+ }
12
+ export interface V2FileContent {
13
+ readonly type: "file";
14
+ readonly uri: string;
15
+ readonly mime: string;
16
+ readonly name?: string;
17
+ }
18
+ export type V2Content = {
19
+ readonly type: "text";
20
+ readonly text: string;
21
+ } | V2FileContent;
22
+ export interface V2ToolResult {
23
+ readonly content: string | ReadonlyArray<V2Content>;
24
+ readonly metadata?: Record<string, unknown>;
25
+ }
26
+ export declare const toV2Result: (result: ToolResult) => V2ToolResult;
27
+ export declare const toToolContext: (pluginContext: Plugin.Context, context: V2ToolContext, pluginOptions: unknown, warningSink?: WarningSink) => ToolContext;
28
+ export declare const toV2Tool: (pluginContext: Plugin.Context, registration: V2ToolRegistration, pluginOptions?: unknown, warningSink?: WarningSink) => V2ToolInfo;
29
+ export declare const registerV2Tools: (context: Plugin.Context, registrations: ReadonlyArray<V2ToolRegistration>, pluginOptions?: unknown) => Promise<import("@opencode/plugin/promise/registration").Registration>;
30
+ export type V2Registration = Awaited<ReturnType<typeof registerV2Tools>>;
31
+ export {};
package/dist/plugin.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- import type { Plugin } from "@opencode-ai/plugin";
2
- declare const plugin: Plugin;
1
+ import type { Plugin } from "@opencode/plugin";
2
+ declare const plugin: Plugin.Plugin;
3
3
  export default plugin;
4
- //# sourceMappingURL=plugin.d.ts.map
@@ -0,0 +1,5 @@
1
+ import type { V2ToolRegistration } from "./plugin-v2.js";
2
+ import type { AnyToolDefinition } from "./tool.js";
3
+ export declare const toolDefinitions: Record<string, AnyToolDefinition>;
4
+ export declare const permissionByTool: Record<string, string>;
5
+ export declare const v2ToolRegistrations: ReadonlyArray<V2ToolRegistration>;
package/dist/rpc.d.ts ADDED
@@ -0,0 +1,134 @@
1
+ export declare const NotebookRpc: {
2
+ readonly id: "opencode-ipynb";
3
+ readonly methods: {
4
+ readonly document: {
5
+ readonly input: {
6
+ readonly type: "object";
7
+ readonly properties: {
8
+ readonly filePath: {
9
+ readonly type: "string";
10
+ };
11
+ };
12
+ readonly required: readonly ["filePath"];
13
+ readonly additionalProperties: false;
14
+ };
15
+ readonly output: {
16
+ readonly type: "object";
17
+ readonly properties: {
18
+ readonly filePath: {
19
+ readonly type: "string";
20
+ };
21
+ readonly notebookUri: {
22
+ readonly type: "string";
23
+ };
24
+ readonly languageId: {
25
+ readonly type: "string";
26
+ };
27
+ readonly fileExtension: {
28
+ readonly type: "string";
29
+ };
30
+ readonly kernelName: {
31
+ readonly type: "string";
32
+ };
33
+ readonly pythonPath: {
34
+ readonly type: "string";
35
+ };
36
+ readonly text: {
37
+ readonly type: "string";
38
+ };
39
+ readonly sanitizedText: {
40
+ readonly type: "string";
41
+ };
42
+ readonly cells: {
43
+ readonly type: "array";
44
+ readonly items: {
45
+ readonly type: "object";
46
+ readonly properties: {
47
+ readonly cellIndex: {
48
+ readonly type: "integer";
49
+ readonly minimum: 0;
50
+ };
51
+ readonly cellType: {
52
+ readonly type: "string";
53
+ readonly enum: readonly ["code", "markdown", "raw"];
54
+ };
55
+ readonly languageId: {
56
+ readonly type: "string";
57
+ };
58
+ readonly text: {
59
+ readonly type: "string";
60
+ };
61
+ readonly uri: {
62
+ readonly type: "string";
63
+ };
64
+ readonly startLine: {
65
+ readonly type: "integer";
66
+ readonly minimum: 0;
67
+ };
68
+ readonly endLine: {
69
+ readonly type: "integer";
70
+ readonly minimum: 0;
71
+ };
72
+ readonly lineCount: {
73
+ readonly type: "integer";
74
+ readonly minimum: 0;
75
+ };
76
+ };
77
+ readonly required: readonly ["cellIndex", "cellType", "languageId", "text", "startLine", "endLine", "lineCount"];
78
+ readonly additionalProperties: false;
79
+ };
80
+ };
81
+ };
82
+ readonly required: readonly ["filePath", "languageId", "text", "cells"];
83
+ readonly additionalProperties: false;
84
+ };
85
+ readonly errors: {
86
+ readonly outside_worktree: {
87
+ readonly type: "object";
88
+ readonly properties: {
89
+ readonly message: {
90
+ readonly type: "string";
91
+ };
92
+ };
93
+ readonly required: readonly ["message"];
94
+ readonly additionalProperties: false;
95
+ };
96
+ readonly not_found: {
97
+ readonly type: "object";
98
+ readonly properties: {
99
+ readonly message: {
100
+ readonly type: "string";
101
+ };
102
+ };
103
+ readonly required: readonly ["message"];
104
+ readonly additionalProperties: false;
105
+ };
106
+ readonly invalid_notebook: {
107
+ readonly type: "object";
108
+ readonly properties: {
109
+ readonly message: {
110
+ readonly type: "string";
111
+ };
112
+ };
113
+ readonly required: readonly ["message"];
114
+ readonly additionalProperties: false;
115
+ };
116
+ };
117
+ };
118
+ };
119
+ readonly events: {
120
+ readonly changed: {
121
+ readonly schema: {
122
+ readonly type: "object";
123
+ readonly properties: {
124
+ readonly filePath: {
125
+ readonly type: "string";
126
+ };
127
+ };
128
+ readonly required: readonly ["filePath"];
129
+ readonly additionalProperties: false;
130
+ };
131
+ };
132
+ };
133
+ };
134
+ export type NotebookRpc = typeof NotebookRpc;
package/dist/rpc.js ADDED
@@ -0,0 +1,84 @@
1
+ // @bun
2
+ // src/rpc.ts
3
+ var cellSchema = {
4
+ type: "object",
5
+ properties: {
6
+ cellIndex: { type: "integer", minimum: 0 },
7
+ cellType: { type: "string", enum: ["code", "markdown", "raw"] },
8
+ languageId: { type: "string" },
9
+ text: { type: "string" },
10
+ uri: { type: "string" },
11
+ startLine: { type: "integer", minimum: 0 },
12
+ endLine: { type: "integer", minimum: 0 },
13
+ lineCount: { type: "integer", minimum: 0 }
14
+ },
15
+ required: ["cellIndex", "cellType", "languageId", "text", "startLine", "endLine", "lineCount"],
16
+ additionalProperties: false
17
+ };
18
+ var documentSchema = {
19
+ type: "object",
20
+ properties: {
21
+ filePath: { type: "string" },
22
+ notebookUri: { type: "string" },
23
+ languageId: { type: "string" },
24
+ fileExtension: { type: "string" },
25
+ kernelName: { type: "string" },
26
+ pythonPath: { type: "string" },
27
+ text: { type: "string" },
28
+ sanitizedText: { type: "string" },
29
+ cells: { type: "array", items: cellSchema }
30
+ },
31
+ required: ["filePath", "languageId", "text", "cells"],
32
+ additionalProperties: false
33
+ };
34
+ var NotebookRpc = {
35
+ id: "opencode-ipynb",
36
+ methods: {
37
+ document: {
38
+ input: {
39
+ type: "object",
40
+ properties: {
41
+ filePath: { type: "string" }
42
+ },
43
+ required: ["filePath"],
44
+ additionalProperties: false
45
+ },
46
+ output: documentSchema,
47
+ errors: {
48
+ outside_worktree: {
49
+ type: "object",
50
+ properties: { message: { type: "string" } },
51
+ required: ["message"],
52
+ additionalProperties: false
53
+ },
54
+ not_found: {
55
+ type: "object",
56
+ properties: { message: { type: "string" } },
57
+ required: ["message"],
58
+ additionalProperties: false
59
+ },
60
+ invalid_notebook: {
61
+ type: "object",
62
+ properties: { message: { type: "string" } },
63
+ required: ["message"],
64
+ additionalProperties: false
65
+ }
66
+ }
67
+ }
68
+ },
69
+ events: {
70
+ changed: {
71
+ schema: {
72
+ type: "object",
73
+ properties: {
74
+ filePath: { type: "string" }
75
+ },
76
+ required: ["filePath"],
77
+ additionalProperties: false
78
+ }
79
+ }
80
+ }
81
+ };
82
+ export {
83
+ NotebookRpc
84
+ };
@@ -0,0 +1,45 @@
1
+ import { Effect } from "effect";
2
+ import { type NotebookError } from "../domain/errors.js";
3
+ import { type RunRequest, type RunResponse } from "../domain/execution.js";
4
+ import { type Warning, type WarningSink } from "../utils/warnings.js";
5
+ export interface KernelManagerOptions {
6
+ readonly pythonPath: string;
7
+ readonly helperPath: string;
8
+ readonly workingDirectory: string | undefined;
9
+ readonly defaultTimeoutMs: number;
10
+ readonly warningSink?: WarningSink;
11
+ readonly sinkTarget?: {
12
+ sink?: WarningSink | undefined;
13
+ };
14
+ }
15
+ export interface KernelRuntimeOptions {
16
+ readonly pythonPath: string;
17
+ readonly helperPath: string;
18
+ }
19
+ export interface KernelInfo {
20
+ readonly filePath: string;
21
+ readonly pid: number;
22
+ readonly lastUsedAt: number;
23
+ readonly requestsHandled: number;
24
+ readonly stderrTail: string;
25
+ readonly warnings?: ReadonlyArray<Warning>;
26
+ }
27
+ export interface KernelManagerStats {
28
+ readonly liveKernels: number;
29
+ readonly totalRequests: number;
30
+ }
31
+ export declare const killPidTree: (pid: number | undefined, signal?: NodeJS.Signals, notify?: (error: unknown) => void) => void;
32
+ export declare const makeKernelManager: (opts: KernelManagerOptions) => KernelManagerShape;
33
+ export interface KernelManagerShape {
34
+ readonly execute: (filePath: string, request: RunRequest, runtime?: KernelRuntimeOptions, options?: {
35
+ readonly signal?: AbortSignal;
36
+ readonly warningSink?: WarningSink;
37
+ }) => Effect.Effect<RunResponse, NotebookError>;
38
+ readonly isRunning: (filePath: string) => boolean;
39
+ readonly list: () => ReadonlyArray<KernelInfo>;
40
+ readonly restart: (filePath: string) => Effect.Effect<void, never>;
41
+ readonly shutdown: (filePath: string) => Effect.Effect<void, never>;
42
+ readonly disposeAll: () => Effect.Effect<void, never>;
43
+ readonly stats: () => KernelManagerStats;
44
+ readonly setWarningSink?: (sink: WarningSink | undefined) => void;
45
+ }
@@ -1,9 +1,10 @@
1
- import { Context, Effect } from "effect";
1
+ import { Effect } from "effect";
2
2
  import { NotebookNotFoundError, NotebookParseError, NotebookValidationError, NotebookWriteError, PathOutsideWorktreeError, PermissionDeniedError } from "../domain/errors.js";
3
- import { type NotebookFileServiceShape } from "./NotebookFileService.js";
4
- import { type PathServiceShape } from "./PathService.js";
3
+ import type { NotebookFileServiceShape } from "./NotebookFileService.js";
4
+ import type { PathServiceShape } from "./PathService.js";
5
5
  import { type PermissionServiceShape } from "./PermissionService.js";
6
6
  import type { NotebookRaw } from "../domain/notebook.js";
7
+ import type { PatchFailureReason, WriteMode } from "../utils/json.js";
7
8
  export interface CleanOptions {
8
9
  readonly clearOutputs: boolean;
9
10
  readonly clearExecutionCount: boolean;
@@ -20,15 +21,14 @@ export interface CleanResult {
20
21
  readonly removedExecutionCounts: number;
21
22
  readonly removedWidgets: number;
22
23
  readonly removedImages: number;
24
+ readonly normalizedSources: number;
23
25
  readonly notebook: NotebookRaw;
26
+ readonly writeMode: WriteMode | undefined;
27
+ readonly writeModeReason?: PatchFailureReason | undefined;
24
28
  }
25
29
  export interface NotebookCleanServiceShape {
26
30
  readonly clean: (filePath: string, options?: Partial<CleanOptions>) => Effect.Effect<CleanResult, NotebookNotFoundError | NotebookParseError | NotebookValidationError | NotebookWriteError | PathOutsideWorktreeError | PermissionDeniedError>;
27
31
  }
28
32
  export type CleanError = NotebookNotFoundError | NotebookParseError | NotebookValidationError | NotebookWriteError | PathOutsideWorktreeError | PermissionDeniedError;
29
- declare const NotebookCleanService_base: Context.TagClass<NotebookCleanService, "@ipynb/NotebookCleanService", NotebookCleanServiceShape>;
30
- export declare class NotebookCleanService extends NotebookCleanService_base {
31
- }
32
33
  declare const makeCleanImpl: (pathSvc: PathServiceShape, fileSvc: NotebookFileServiceShape, permSvc: PermissionServiceShape) => NotebookCleanServiceShape;
33
34
  export { makeCleanImpl };
34
- //# sourceMappingURL=NotebookCleanService.d.ts.map