opencode-ipynb 0.1.1 → 2.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 (126) hide show
  1. package/CHANGELOG.md +37 -0
  2. package/README.md +191 -41
  3. package/dist/domain/cell.d.ts +2 -1
  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 +1 -1
  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 -4
  10. package/dist/format/{diff.d.ts → notebook.d.ts} +2 -1
  11. package/dist/format/outputs.d.ts +3 -4
  12. package/dist/index.d.ts +3 -1
  13. package/dist/index.js +7312 -26442
  14. package/dist/load-document.d.ts +16 -0
  15. package/dist/lsp.d.ts +97 -0
  16. package/dist/lsp.js +129 -0
  17. package/dist/notebook-diagnostics.d.ts +55 -0
  18. package/dist/notebook-hooks.d.ts +23 -0
  19. package/dist/plugin-options.d.ts +4 -1
  20. package/dist/plugin-v2.d.ts +35 -0
  21. package/dist/plugin.d.ts +2 -3
  22. package/dist/registrations.d.ts +5 -0
  23. package/dist/rpc.d.ts +141 -0
  24. package/dist/rpc.js +84 -0
  25. package/dist/services/KernelManager.d.ts +36 -0
  26. package/dist/services/NotebookCleanService.d.ts +3 -7
  27. package/dist/services/NotebookEditService.d.ts +6 -12
  28. package/dist/services/NotebookExecutionService.d.ts +15 -11
  29. package/dist/services/NotebookExportService.d.ts +3 -7
  30. package/dist/services/NotebookFileService.d.ts +19 -13
  31. package/dist/services/NotebookInspectService.d.ts +15 -14
  32. package/dist/services/NotebookOutputService.d.ts +4 -10
  33. package/dist/services/NotebookReadService.d.ts +4 -10
  34. package/dist/services/PathService.d.ts +5 -7
  35. package/dist/services/PermissionService.d.ts +6 -8
  36. package/dist/services/PythonService.d.ts +23 -42
  37. package/dist/services/index.d.ts +22 -29
  38. package/dist/services/revision.d.ts +15 -0
  39. package/dist/tool.d.ts +66 -0
  40. package/dist/tools/_readPermission.d.ts +8 -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 +2 -1
  57. package/dist/utils/atomic-replace.d.ts +6 -0
  58. package/dist/utils/attachments.d.ts +2 -10
  59. package/dist/utils/execution-order.d.ts +8 -0
  60. package/dist/utils/fence.d.ts +2 -0
  61. package/dist/utils/i18n.d.ts +1 -2
  62. package/dist/utils/imports.d.ts +6 -1
  63. package/dist/utils/json.d.ts +0 -1
  64. package/dist/utils/limits.d.ts +12 -2
  65. package/dist/utils/markdown-safe.d.ts +7 -0
  66. package/dist/utils/metadata.d.ts +3 -0
  67. package/dist/utils/mime.d.ts +1 -1
  68. package/dist/utils/paths.d.ts +0 -2
  69. package/dist/utils/truncate.d.ts +0 -1
  70. package/dist/utils/windows.d.ts +4 -0
  71. package/dist/virtual-materialize.d.ts +36 -0
  72. package/package.json +30 -18
  73. package/python/ipynb_runner.py +247 -17
  74. package/python/requirements.txt +5 -4
  75. package/server.js +3 -0
  76. package/dist/domain/cell.d.ts.map +0 -1
  77. package/dist/domain/errors.d.ts.map +0 -1
  78. package/dist/domain/execution.d.ts.map +0 -1
  79. package/dist/domain/notebook.d.ts.map +0 -1
  80. package/dist/domain/output.d.ts.map +0 -1
  81. package/dist/format/diagnostics.d.ts.map +0 -1
  82. package/dist/format/diff.d.ts.map +0 -1
  83. package/dist/format/markdown.d.ts.map +0 -1
  84. package/dist/format/outputs.d.ts.map +0 -1
  85. package/dist/index.d.ts.map +0 -1
  86. package/dist/plugin-options.d.ts.map +0 -1
  87. package/dist/plugin.d.ts.map +0 -1
  88. package/dist/services/DiffService.d.ts +0 -17
  89. package/dist/services/DiffService.d.ts.map +0 -1
  90. package/dist/services/NotebookCleanService.d.ts.map +0 -1
  91. package/dist/services/NotebookEditService.d.ts.map +0 -1
  92. package/dist/services/NotebookExecutionService.d.ts.map +0 -1
  93. package/dist/services/NotebookExportService.d.ts.map +0 -1
  94. package/dist/services/NotebookFileService.d.ts.map +0 -1
  95. package/dist/services/NotebookInspectService.d.ts.map +0 -1
  96. package/dist/services/NotebookOutputService.d.ts.map +0 -1
  97. package/dist/services/NotebookReadService.d.ts.map +0 -1
  98. package/dist/services/PathService.d.ts.map +0 -1
  99. package/dist/services/PermissionService.d.ts.map +0 -1
  100. package/dist/services/PythonService.d.ts.map +0 -1
  101. package/dist/services/index.d.ts.map +0 -1
  102. package/dist/tools/_resolveOptions.d.ts.map +0 -1
  103. package/dist/tools/cell_delete.d.ts.map +0 -1
  104. package/dist/tools/cell_insert.d.ts.map +0 -1
  105. package/dist/tools/cell_move.d.ts.map +0 -1
  106. package/dist/tools/clean.d.ts.map +0 -1
  107. package/dist/tools/doctor.d.ts.map +0 -1
  108. package/dist/tools/edit.d.ts.map +0 -1
  109. package/dist/tools/export.d.ts.map +0 -1
  110. package/dist/tools/inspect.d.ts.map +0 -1
  111. package/dist/tools/kernel.d.ts.map +0 -1
  112. package/dist/tools/outputs.d.ts.map +0 -1
  113. package/dist/tools/read.d.ts.map +0 -1
  114. package/dist/tools/repro.d.ts.map +0 -1
  115. package/dist/tools/run.d.ts.map +0 -1
  116. package/dist/utils/ansi.d.ts.map +0 -1
  117. package/dist/utils/attachments.d.ts.map +0 -1
  118. package/dist/utils/fiber.d.ts +0 -2
  119. package/dist/utils/fiber.d.ts.map +0 -1
  120. package/dist/utils/i18n.d.ts.map +0 -1
  121. package/dist/utils/imports.d.ts.map +0 -1
  122. package/dist/utils/json.d.ts.map +0 -1
  123. package/dist/utils/limits.d.ts.map +0 -1
  124. package/dist/utils/mime.d.ts.map +0 -1
  125. package/dist/utils/paths.d.ts.map +0 -1
  126. package/dist/utils/truncate.d.ts.map +0 -1
@@ -0,0 +1,16 @@
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
+ /** Materialization/RPC do not need a Python interpreter. */
9
+ readonly resolvePython?: boolean;
10
+ }
11
+ /**
12
+ * Resolve, confine, read, and project a notebook onto its virtual Python
13
+ * document. Shared by the RPC hook and ipynb_lsp so both use exactly the same
14
+ * real-path and option rules.
15
+ */
16
+ export declare const loadNotebookDocument: (context: LoadDocumentContext, filePath: string) => Promise<NotebookVirtualDocument>;
package/dist/lsp.d.ts ADDED
@@ -0,0 +1,97 @@
1
+ /**
2
+ * Minimal notebook shape accepted by the virtual-document builder.
3
+ *
4
+ * It is structurally compatible with the plugin's parsed `NotebookRaw`, but
5
+ * keeping it local means the `opencode-ipynb/lsp` entry has no zod/Effect
6
+ * dependency and stays lightweight for third-party LSP plugins.
7
+ */
8
+ export interface NotebookLike {
9
+ readonly metadata: {
10
+ readonly language_info?: unknown;
11
+ readonly kernelspec?: unknown;
12
+ };
13
+ readonly cells: ReadonlyArray<{
14
+ readonly cell_type: string;
15
+ readonly source: string | ReadonlyArray<string>;
16
+ }>;
17
+ }
18
+ /**
19
+ * A code cell projected into the notebook's virtual document.
20
+ *
21
+ * Line numbers are zero-based, matching LSP positions. `startLine` is the
22
+ * first virtual line for the cell and `endLine` is exclusive.
23
+ */
24
+ export interface NotebookCellDocument {
25
+ readonly cellIndex: number;
26
+ readonly cellType: "code" | "markdown" | "raw";
27
+ /** LSP language id for this cell (`python`, `markdown`, `plaintext`). */
28
+ readonly languageId: string;
29
+ /** Cell source, useful for native LSP 3.17 notebook sync. */
30
+ readonly text: string;
31
+ /** Stable cell document URI when the caller provides one. */
32
+ readonly uri?: string;
33
+ readonly startLine: number;
34
+ readonly endLine: number;
35
+ readonly lineCount: number;
36
+ }
37
+ /**
38
+ * A single virtual document containing the notebook's code cells.
39
+ *
40
+ * Language servers do not understand `.ipynb` JSON, so tools can send `text`
41
+ * as a normal document and use `cells` to map positions back to the notebook.
42
+ * This is intentionally provider-agnostic: pyright, jedi-language-server, or a
43
+ * future OpenCode notebook LSP can all consume it.
44
+ */
45
+ export interface NotebookVirtualDocument {
46
+ readonly filePath: string;
47
+ /** Notebook URI (for clients that model notebook documents explicitly). */
48
+ readonly notebookUri?: string;
49
+ readonly languageId: string;
50
+ /** Native language file extension from kernel metadata, e.g. `.py`. */
51
+ readonly fileExtension?: string;
52
+ /** Jupyter kernelspec name, when present, so an LSP can select the right env. */
53
+ readonly kernelName?: string;
54
+ /** Configured Python interpreter, when the plugin has one. */
55
+ readonly pythonPath?: string;
56
+ readonly text: string;
57
+ readonly cells: ReadonlyArray<NotebookCellDocument>;
58
+ }
59
+ export interface CellPosition {
60
+ readonly cellIndex: number;
61
+ readonly line: number;
62
+ readonly character: number;
63
+ }
64
+ export interface VirtualPosition {
65
+ readonly line: number;
66
+ readonly character: number;
67
+ }
68
+ export interface VirtualDocumentOptions {
69
+ readonly filePath?: string;
70
+ /** Include markdown/raw cells in the concatenated text. Defaults to false. */
71
+ readonly includeMarkdown?: boolean;
72
+ /** Python interpreter configured for this plugin instance. */
73
+ readonly pythonPath?: string;
74
+ /** URI representing the notebook itself. */
75
+ readonly notebookUri?: string;
76
+ /** Stable URI for a cell document (native LSP 3.17 notebook sync). */
77
+ readonly cellUri?: (cellIndex: number) => string;
78
+ }
79
+ export interface PositionMapper {
80
+ readonly toCellPosition: (line: number, character: number) => CellPosition | undefined;
81
+ readonly toVirtualPosition: (cellIndex: number, line: number, character: number) => VirtualPosition | undefined;
82
+ }
83
+ /**
84
+ * Build a virtual document from a parsed notebook.
85
+ *
86
+ * Code cells are separated by a newline, which preserves the cell-local line
87
+ * count and lets `toCellPosition`/`toVirtualPosition` map both directions.
88
+ * Each cell also carries its own text and optional URI so a client that
89
+ * supports LSP 3.17 notebook synchronization can use cell documents directly.
90
+ */
91
+ export declare const buildNotebookVirtualDocument: (notebook: NotebookLike, options?: VirtualDocumentOptions) => NotebookVirtualDocument;
92
+ /** Map a zero-based position in the virtual document back to a cell position. */
93
+ export declare const toCellPosition: (document: NotebookVirtualDocument, line: number, character: number) => CellPosition | undefined;
94
+ /** Map a zero-based position inside a cell to the virtual document. */
95
+ export declare const toVirtualPosition: (document: NotebookVirtualDocument, cellIndex: number, line: number, character: number) => VirtualPosition | undefined;
96
+ /** Convenience mapper bound to a built document. */
97
+ export declare const makePositionMapper: (document: NotebookVirtualDocument) => PositionMapper;
package/dist/lsp.js ADDED
@@ -0,0 +1,129 @@
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 toCellPosition = (document, line, character) => {
105
+ const cell = document.cells.find((candidate) => line >= candidate.startLine && line < candidate.endLine);
106
+ if (!cell)
107
+ return;
108
+ return {
109
+ cellIndex: cell.cellIndex,
110
+ line: line - cell.startLine,
111
+ character
112
+ };
113
+ };
114
+ var toVirtualPosition = (document, cellIndex, line, character) => {
115
+ const cell = document.cells.find((candidate) => candidate.cellIndex === cellIndex);
116
+ if (!cell || line < 0 || line >= cell.lineCount)
117
+ return;
118
+ return { line: cell.startLine + line, character };
119
+ };
120
+ var makePositionMapper = (document) => ({
121
+ toCellPosition: (line, character) => toCellPosition(document, line, character),
122
+ toVirtualPosition: (cellIndex, line, character) => toVirtualPosition(document, cellIndex, line, character)
123
+ });
124
+ export {
125
+ buildNotebookVirtualDocument,
126
+ makePositionMapper,
127
+ toCellPosition,
128
+ toVirtualPosition
129
+ };
@@ -0,0 +1,55 @@
1
+ import { type NotebookVirtualDocument } from "./lsp.js";
2
+ export interface NotebookDiagnostic {
3
+ readonly cellIndex: number;
4
+ readonly line: number;
5
+ readonly character: number;
6
+ readonly endLine: number;
7
+ readonly endCharacter: number;
8
+ readonly severity: "error";
9
+ readonly message: string;
10
+ readonly rule?: string;
11
+ }
12
+ export interface NotebookDiagnosticsOptions {
13
+ readonly filePath: string;
14
+ readonly document: NotebookVirtualDocument;
15
+ readonly displayPath?: string;
16
+ /** Heading used in the report; defaults to displayPath. */
17
+ readonly where?: string;
18
+ readonly tempFilePath?: string;
19
+ /** True when the plugin owns the temp file and may reuse/truncate it. */
20
+ readonly ownedTempFile?: boolean;
21
+ /** Ask the host for permission before writing the system-temp fallback. */
22
+ readonly requestFallbackPermission?: () => Promise<void>;
23
+ readonly pythonPath?: string;
24
+ readonly pyrightPath?: string;
25
+ readonly timeoutMs?: number;
26
+ readonly signal?: AbortSignal;
27
+ }
28
+ export interface NotebookDiagnosticsResult {
29
+ readonly filePath: string;
30
+ readonly diagnostics: ReadonlyArray<NotebookDiagnostic>;
31
+ readonly text: string;
32
+ readonly skipped?: "pyright-not-found" | "timeout" | "aborted" | "invalid-output" | "not-analyzed" | "temp-unwritable" | "pyright-not-executable";
33
+ }
34
+ /**
35
+ * IPython magics and shell escapes are not valid Python. Blank them while
36
+ * preserving line and column positions so diagnostics on other lines stay
37
+ * correctly mapped. Python-bodied cell magics (`%%time`, `%%capture`, ...)
38
+ * keep their body; non-Python cell magics (`%%bash`, `%%html`, ...) blank the
39
+ * whole cell.
40
+ */
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
+ /**
47
+ * Cheap availability check used before asking permission or creating a temp
48
+ * file. Absolute paths are checked without spawning; a bare command is probed
49
+ * once per TTL. This avoids permission prompts when pyright is not installed.
50
+ */
51
+ export declare const isPyrightAvailable: (configured: string | undefined, timeoutMs?: number, signal?: AbortSignal) => Promise<boolean>;
52
+ export declare const diagnosticTempPath: (filePath: string) => string;
53
+ /** Fallback used when the notebook directory is not writable. */
54
+ export declare const diagnosticFallbackTempPath: (filePath: string) => string;
55
+ export declare const diagnoseNotebook: (options: NotebookDiagnosticsOptions) => Promise<NotebookDiagnosticsResult>;
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Pure helpers for the notebook `execute.after` hook. Keeping the tool-name
3
+ * normalization and changed/no-op rules here makes the plugin entrypoint
4
+ * mostly lifecycle wiring and gives the tests a small unit to target.
5
+ */
6
+ export declare const notebookMutatingTools: Set<string>;
7
+ export declare const diagnosableTools: Set<string>;
8
+ export declare function toolName(tool: string): string;
9
+ export declare const changedNotebook: (tool: string, input: unknown, metadata?: Record<string, unknown>) => boolean;
10
+ export declare const changesCode: (name: string, metadata?: Record<string, unknown>) => boolean;
11
+ export type MutableResult = {
12
+ content?: string | ReadonlyArray<{
13
+ type: "text";
14
+ text: string;
15
+ } | {
16
+ type: "file";
17
+ uri: string;
18
+ mime: string;
19
+ name?: string;
20
+ }>;
21
+ metadata?: Record<string, unknown>;
22
+ };
23
+ 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,35 @@
1
+ import type { Plugin } from "@opencode/plugin";
2
+ import type { AnyToolDefinition, ToolContext, ToolResult } from "./tool.js";
3
+ type V2ToolEditor = Parameters<Plugin.Context["tool"]["transform"]>[0] extends (editor: infer Editor) => void ? Editor : never;
4
+ export type V2ToolInfo = Parameters<V2ToolEditor["add"]>[0];
5
+ export type V2ToolContext = Parameters<V2ToolInfo["execute"]>[1];
6
+ export interface V2ToolRegistration {
7
+ readonly name: string;
8
+ readonly definition: AnyToolDefinition;
9
+ readonly permission?: string;
10
+ }
11
+ export interface V2FileContent {
12
+ readonly type: "file";
13
+ readonly uri: string;
14
+ readonly mime: string;
15
+ readonly name?: string;
16
+ }
17
+ export type V2Content = {
18
+ readonly type: "text";
19
+ readonly text: string;
20
+ } | V2FileContent;
21
+ export interface V2ToolResult {
22
+ readonly content: string | ReadonlyArray<V2Content>;
23
+ readonly metadata?: Record<string, unknown>;
24
+ }
25
+ export declare const toV2Result: (result: ToolResult) => V2ToolResult;
26
+ /**
27
+ * V2 custom tools do not receive the V1 ToolContext shape. Adapt the V2 tool
28
+ * execution context, and route ctx.ask through the V2 permission domain so
29
+ * every write and execution still prompts (or is denied by explicit rules).
30
+ */
31
+ export declare const toToolContext: (pluginContext: Plugin.Context, context: V2ToolContext, pluginOptions: unknown) => ToolContext;
32
+ export declare const toV2Tool: (pluginContext: Plugin.Context, registration: V2ToolRegistration, pluginOptions?: unknown) => V2ToolInfo;
33
+ export declare const registerV2Tools: (context: Plugin.Context, registrations: ReadonlyArray<V2ToolRegistration>, pluginOptions?: unknown) => Promise<import("@opencode/plugin/promise/registration").Registration>;
34
+ export type V2Registration = Awaited<ReturnType<typeof registerV2Tools>>;
35
+ 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,141 @@
1
+ /**
2
+ * Public RPC contract for notebook/LSP integration.
3
+ *
4
+ * Other plugins can import this contract from `opencode-ipynb/rpc`, call
5
+ * `document` to get a provider-agnostic virtual document, and subscribe to
6
+ * `changed` to refresh diagnostics after the plugin edits a notebook.
7
+ */
8
+ export declare const NotebookRpc: {
9
+ readonly id: "opencode-ipynb";
10
+ readonly methods: {
11
+ readonly document: {
12
+ readonly input: {
13
+ readonly type: "object";
14
+ readonly properties: {
15
+ readonly filePath: {
16
+ readonly type: "string";
17
+ };
18
+ };
19
+ readonly required: readonly ["filePath"];
20
+ readonly additionalProperties: false;
21
+ };
22
+ readonly output: {
23
+ readonly type: "object";
24
+ readonly properties: {
25
+ readonly filePath: {
26
+ readonly type: "string";
27
+ };
28
+ readonly notebookUri: {
29
+ readonly type: "string";
30
+ };
31
+ readonly languageId: {
32
+ readonly type: "string";
33
+ };
34
+ readonly fileExtension: {
35
+ readonly type: "string";
36
+ };
37
+ readonly kernelName: {
38
+ readonly type: "string";
39
+ };
40
+ readonly pythonPath: {
41
+ readonly type: "string";
42
+ };
43
+ readonly text: {
44
+ readonly type: "string";
45
+ };
46
+ readonly sanitizedText: {
47
+ readonly type: "string";
48
+ };
49
+ readonly cells: {
50
+ readonly type: "array";
51
+ readonly items: {
52
+ readonly type: "object";
53
+ readonly properties: {
54
+ readonly cellIndex: {
55
+ readonly type: "integer";
56
+ readonly minimum: 0;
57
+ };
58
+ readonly cellType: {
59
+ readonly type: "string";
60
+ readonly enum: readonly ["code", "markdown", "raw"];
61
+ };
62
+ readonly languageId: {
63
+ readonly type: "string";
64
+ };
65
+ readonly text: {
66
+ readonly type: "string";
67
+ };
68
+ readonly uri: {
69
+ readonly type: "string";
70
+ };
71
+ readonly startLine: {
72
+ readonly type: "integer";
73
+ readonly minimum: 0;
74
+ };
75
+ readonly endLine: {
76
+ readonly type: "integer";
77
+ readonly minimum: 0;
78
+ };
79
+ readonly lineCount: {
80
+ readonly type: "integer";
81
+ readonly minimum: 0;
82
+ };
83
+ };
84
+ readonly required: readonly ["cellIndex", "cellType", "languageId", "text", "startLine", "endLine", "lineCount"];
85
+ readonly additionalProperties: false;
86
+ };
87
+ };
88
+ };
89
+ readonly required: readonly ["filePath", "languageId", "text", "cells"];
90
+ readonly additionalProperties: false;
91
+ };
92
+ readonly errors: {
93
+ readonly outside_worktree: {
94
+ readonly type: "object";
95
+ readonly properties: {
96
+ readonly message: {
97
+ readonly type: "string";
98
+ };
99
+ };
100
+ readonly required: readonly ["message"];
101
+ readonly additionalProperties: false;
102
+ };
103
+ readonly not_found: {
104
+ readonly type: "object";
105
+ readonly properties: {
106
+ readonly message: {
107
+ readonly type: "string";
108
+ };
109
+ };
110
+ readonly required: readonly ["message"];
111
+ readonly additionalProperties: false;
112
+ };
113
+ readonly invalid_notebook: {
114
+ readonly type: "object";
115
+ readonly properties: {
116
+ readonly message: {
117
+ readonly type: "string";
118
+ };
119
+ };
120
+ readonly required: readonly ["message"];
121
+ readonly additionalProperties: false;
122
+ };
123
+ };
124
+ };
125
+ };
126
+ readonly events: {
127
+ readonly changed: {
128
+ readonly schema: {
129
+ readonly type: "object";
130
+ readonly properties: {
131
+ readonly filePath: {
132
+ readonly type: "string";
133
+ };
134
+ };
135
+ readonly required: readonly ["filePath"];
136
+ readonly additionalProperties: false;
137
+ };
138
+ };
139
+ };
140
+ };
141
+ 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,36 @@
1
+ import { Effect } from "effect";
2
+ import { type NotebookError } from "../domain/errors.js";
3
+ import { type RunRequest, type RunResponse } from "../domain/execution.js";
4
+ export interface KernelManagerOptions {
5
+ readonly pythonPath: string;
6
+ readonly helperPath: string;
7
+ readonly workingDirectory: string | undefined;
8
+ readonly defaultTimeoutMs: number;
9
+ }
10
+ export interface KernelRuntimeOptions {
11
+ readonly pythonPath: string;
12
+ readonly helperPath: string;
13
+ }
14
+ export interface KernelInfo {
15
+ readonly filePath: string;
16
+ readonly pid: number;
17
+ readonly lastUsedAt: number;
18
+ readonly requestsHandled: number;
19
+ readonly stderrTail: string;
20
+ }
21
+ export interface KernelManagerStats {
22
+ readonly liveKernels: number;
23
+ readonly totalRequests: number;
24
+ }
25
+ export declare const makeKernelManager: (opts: KernelManagerOptions) => KernelManagerShape;
26
+ export interface KernelManagerShape {
27
+ readonly execute: (filePath: string, request: RunRequest, runtime?: KernelRuntimeOptions, options?: {
28
+ readonly signal?: AbortSignal;
29
+ }) => Effect.Effect<RunResponse, NotebookError>;
30
+ readonly isRunning: (filePath: string) => boolean;
31
+ readonly list: () => ReadonlyArray<KernelInfo>;
32
+ readonly restart: (filePath: string) => Effect.Effect<void, never>;
33
+ readonly shutdown: (filePath: string) => Effect.Effect<void, never>;
34
+ readonly disposeAll: () => Effect.Effect<void, never>;
35
+ readonly stats: () => KernelManagerStats;
36
+ }
@@ -1,7 +1,7 @@
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
7
  export interface CleanOptions {
@@ -26,9 +26,5 @@ export interface NotebookCleanServiceShape {
26
26
  readonly clean: (filePath: string, options?: Partial<CleanOptions>) => Effect.Effect<CleanResult, NotebookNotFoundError | NotebookParseError | NotebookValidationError | NotebookWriteError | PathOutsideWorktreeError | PermissionDeniedError>;
27
27
  }
28
28
  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
29
  declare const makeCleanImpl: (pathSvc: PathServiceShape, fileSvc: NotebookFileServiceShape, permSvc: PermissionServiceShape) => NotebookCleanServiceShape;
33
30
  export { makeCleanImpl };
34
- //# sourceMappingURL=NotebookCleanService.d.ts.map