@yama662607/obsidian-companion-plugin 0.1.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Daisuke Yamashiki
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,16 @@
1
+ # @yama662607/obsidian-companion-plugin
2
+
3
+ Obsidian plugin package for Companion MCP integration.
4
+
5
+ ## Installation
6
+
7
+ Install as an Obsidian community/development plugin build output.
8
+
9
+ ## Usage
10
+
11
+ - Build the plugin with the project build command.
12
+ - Place output artifacts into your Obsidian vault plugin directory.
13
+
14
+ ## Notes
15
+
16
+ - Exposes editor context and semantic operations to the bridge over local transport.
@@ -0,0 +1,24 @@
1
+ import process from "node:process";
2
+ import esbuild from "esbuild";
3
+ import { builtinModules } from "node:module";
4
+
5
+ const production = process.argv[2] === "production";
6
+
7
+ const context = await esbuild.context({
8
+ entryPoints: ["src/main.ts"],
9
+ bundle: true,
10
+ external: ["obsidian", "electron", ...builtinModules],
11
+ format: "cjs",
12
+ target: "es2018",
13
+ logLevel: "info",
14
+ sourcemap: production ? false : "inline",
15
+ treeShaking: true,
16
+ outfile: "main.js",
17
+ });
18
+
19
+ if (production) {
20
+ await context.rebuild();
21
+ await context.dispose();
22
+ } else {
23
+ await context.watch();
24
+ }
package/main.js ADDED
@@ -0,0 +1,147 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
21
+
22
+ // src/main.ts
23
+ var main_exports = {};
24
+ __export(main_exports, {
25
+ default: () => ObsidianCompanionPlugin
26
+ });
27
+ module.exports = __toCommonJS(main_exports);
28
+ var import_obsidian = require("obsidian");
29
+
30
+ // ../shared/protocol.ts
31
+ var PROTOCOL_VERSION = "1.0.0";
32
+
33
+ // src/main.ts
34
+ var LocalJsonRpcHost = class {
35
+ constructor(apiKey) {
36
+ this.apiKey = apiKey;
37
+ __publicField(this, "context", {
38
+ activeFile: null,
39
+ cursor: { line: 0, ch: 0 },
40
+ selection: "",
41
+ content: ""
42
+ });
43
+ }
44
+ async handle(request, authorization) {
45
+ if (request.method !== "health.ping" && authorization !== this.apiKey) {
46
+ return {
47
+ jsonrpc: "2.0",
48
+ id: request.id,
49
+ error: {
50
+ code: "AUTH",
51
+ message: "Invalid API key",
52
+ data: { correlationId: `corr-${Date.now()}` }
53
+ }
54
+ };
55
+ }
56
+ if (request.method === "health.ping") {
57
+ const result = {
58
+ capabilities: ["health.ping", "editor.getContext", "editor.applyCommand", "semantic.search", "notes.read"],
59
+ availability: "normal"
60
+ };
61
+ return {
62
+ jsonrpc: "2.0",
63
+ id: request.id,
64
+ protocolVersion: PROTOCOL_VERSION,
65
+ result
66
+ };
67
+ }
68
+ if (request.method === "editor.getContext") {
69
+ return {
70
+ jsonrpc: "2.0",
71
+ id: request.id,
72
+ protocolVersion: PROTOCOL_VERSION,
73
+ result: this.context
74
+ };
75
+ }
76
+ if (request.method === "editor.applyCommand") {
77
+ const payload = request.params;
78
+ if (payload.command === "insertText") {
79
+ if (payload.pos.line < 0 || payload.pos.ch < 0) {
80
+ return {
81
+ jsonrpc: "2.0",
82
+ id: request.id,
83
+ error: {
84
+ code: "VALIDATION",
85
+ message: "Invalid insert position",
86
+ data: { correlationId: `corr-${Date.now()}` }
87
+ }
88
+ };
89
+ }
90
+ this.context = {
91
+ ...this.context,
92
+ content: `${this.context.content}${payload.text}`,
93
+ cursor: payload.pos
94
+ };
95
+ }
96
+ if (payload.command === "replaceRange") {
97
+ const invalid = payload.range.from.line < 0 || payload.range.from.ch < 0 || payload.range.to.line < 0 || payload.range.to.ch < 0;
98
+ if (invalid) {
99
+ return {
100
+ jsonrpc: "2.0",
101
+ id: request.id,
102
+ error: {
103
+ code: "VALIDATION",
104
+ message: "Invalid replace range",
105
+ data: { correlationId: `corr-${Date.now()}` }
106
+ }
107
+ };
108
+ }
109
+ this.context = {
110
+ ...this.context,
111
+ content: payload.text,
112
+ cursor: payload.range.to
113
+ };
114
+ }
115
+ return {
116
+ jsonrpc: "2.0",
117
+ id: request.id,
118
+ protocolVersion: PROTOCOL_VERSION,
119
+ result: this.context
120
+ };
121
+ }
122
+ return {
123
+ jsonrpc: "2.0",
124
+ id: request.id,
125
+ protocolVersion: PROTOCOL_VERSION,
126
+ result: {}
127
+ };
128
+ }
129
+ };
130
+ var ObsidianCompanionPlugin = class extends import_obsidian.Plugin {
131
+ constructor() {
132
+ super(...arguments);
133
+ __publicField(this, "host", null);
134
+ __publicField(this, "apiKey", "local-dev-key");
135
+ }
136
+ async onload() {
137
+ this.host = new LocalJsonRpcHost(this.apiKey);
138
+ this.registerEvent(this.app.workspace.on("active-leaf-change", () => {
139
+ }));
140
+ }
141
+ onunload() {
142
+ this.host = null;
143
+ }
144
+ getHostForTesting() {
145
+ return this.host;
146
+ }
147
+ };
package/manifest.json ADDED
@@ -0,0 +1,10 @@
1
+ {
2
+ "id": "obsidian-companion-mcp",
3
+ "name": "Obsidian Companion MCP",
4
+ "version": "0.1.0",
5
+ "minAppVersion": "1.5.0",
6
+ "description": "Enables AI agents to semantically search and interact with your vault via MCP.",
7
+ "author": "Daisuke Yamashiki",
8
+ "authorUrl": "https://github.com/yama662607",
9
+ "isDesktopOnly": true
10
+ }
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "@yama662607/obsidian-companion-plugin",
3
+ "version": "0.1.0",
4
+ "description": "Obsidian Companion Plugin for Semantic Intelligence",
5
+ "author": "Daisuke Yamashiki",
6
+ "license": "MIT",
7
+ "keywords": [
8
+ "obsidian",
9
+ "plugin",
10
+ "mcp",
11
+ "semantic-search"
12
+ ],
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+https://github.com/yama662607/obsidian-companion-mcp.git",
16
+ "directory": "plugin"
17
+ },
18
+ "main": "main.js",
19
+ "exports": {
20
+ ".": "./main.js"
21
+ },
22
+ "scripts": {
23
+ "dev": "node esbuild.config.mjs",
24
+ "build": "node esbuild.config.mjs production"
25
+ },
26
+ "dependencies": {
27
+ "obsidian": "latest"
28
+ },
29
+ "devDependencies": {
30
+ "@types/node": "^20.0.0",
31
+ "builtin-modules": "^3.3.0",
32
+ "esbuild": "0.21.5",
33
+ "obsidian": "latest",
34
+ "tslib": "2.6.2",
35
+ "typescript": "^5.4.5"
36
+ }
37
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,23 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ESNext",
4
+ "module": "ESNext",
5
+ "moduleResolution": "bundler",
6
+ "strict": true,
7
+ "esModuleInterop": true,
8
+ "skipLibCheck": true,
9
+ "forceConsistentCasingInFileNames": true,
10
+ "lib": [
11
+ "DOM",
12
+ "ESNext"
13
+ ],
14
+ "types": [
15
+ "node",
16
+ "obsidian"
17
+ ]
18
+ },
19
+ "include": [
20
+ "**/*.ts",
21
+ "../shared/**/*.ts"
22
+ ]
23
+ }
package/versions.json ADDED
@@ -0,0 +1,3 @@
1
+ {
2
+ "0.1.0": "1.5.0"
3
+ }