@repogo/plugins 0.0.0-stage → 0.1.25

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.md ADDED
@@ -0,0 +1,105 @@
1
+ # Functional Source License, Version 1.1, ALv2 Future License
2
+
3
+ ## Abbreviation
4
+
5
+ FSL-1.1-ALv2
6
+
7
+ ## Notice
8
+
9
+ Copyright 2026 RepoGo
10
+
11
+ ## Terms and Conditions
12
+
13
+ ### Licensor ("We")
14
+
15
+ The party offering the Software under these Terms and Conditions.
16
+
17
+ ### The Software
18
+
19
+ The "Software" is each version of the software that we make available under
20
+ these Terms and Conditions, as indicated by our inclusion of these Terms and
21
+ Conditions with the Software.
22
+
23
+ ### License Grant
24
+
25
+ Subject to your compliance with this License Grant and the Patents,
26
+ Redistribution and Trademark clauses below, we hereby grant you the right to
27
+ use, copy, modify, create derivative works, publicly perform, publicly display
28
+ and redistribute the Software for any Permitted Purpose identified below.
29
+
30
+ ### Permitted Purpose
31
+
32
+ A Permitted Purpose is any purpose other than a Competing Use. A Competing Use
33
+ means making the Software available to others in a commercial product or
34
+ service that:
35
+
36
+ 1. substitutes for the Software;
37
+
38
+ 2. substitutes for any other product or service we offer using the Software
39
+ that exists as of the date we make the Software available; or
40
+
41
+ 3. offers the same or substantially similar functionality as the Software.
42
+
43
+ Permitted Purposes specifically include using the Software:
44
+
45
+ 1. for your internal use and access;
46
+
47
+ 2. for non-commercial education;
48
+
49
+ 3. for non-commercial research; and
50
+
51
+ 4. in connection with professional services that you provide to a licensee
52
+ using the Software in accordance with these Terms and Conditions.
53
+
54
+ ### Patents
55
+
56
+ To the extent your use for a Permitted Purpose would necessarily infringe our
57
+ patents, the license grant above includes a license under our patents. If you
58
+ make a claim against any party that the Software infringes or contributes to
59
+ the infringement of any patent, then your patent license to the Software ends
60
+ immediately.
61
+
62
+ ### Redistribution
63
+
64
+ The Terms and Conditions apply to all copies, modifications and derivatives of
65
+ the Software.
66
+
67
+ If you redistribute any copies, modifications or derivatives of the Software,
68
+ you must include a copy of or a link to these Terms and Conditions and not
69
+ remove any copyright notices provided in or with the Software.
70
+
71
+ ### Disclaimer
72
+
73
+ THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR
74
+ IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR
75
+ PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
76
+
77
+ IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
78
+ SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES,
79
+ EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
80
+
81
+ ### Trademarks
82
+
83
+ Except for displaying the License Details and identifying us as the origin of
84
+ the Software, you have no right under these Terms and Conditions to use our
85
+ trademarks, trade names, service marks or product names.
86
+
87
+ ## Grant of Future License
88
+
89
+ We hereby irrevocably grant you an additional license to use the Software under
90
+ the Apache License, Version 2.0 that is effective on the second anniversary of
91
+ the date we make the Software available. On or after that date, you may use the
92
+ Software under the Apache License, Version 2.0, in which case the following
93
+ will apply:
94
+
95
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use
96
+ this file except in compliance with the License.
97
+
98
+ You may obtain a copy of the License at
99
+
100
+ http://www.apache.org/licenses/LICENSE-2.0
101
+
102
+ Unless required by applicable law or agreed to in writing, software distributed
103
+ under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
104
+ CONDITIONS OF ANY KIND, either express or implied. See the License for the
105
+ specific language governing permissions and limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,27 @@
1
- # Temporary Holding Version
1
+ # @repogo/plugins
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Write plugins for a [RepoGo](https://repogo.app) project: small apps on your
4
+ environment with their own SQLite data, that agents call as tools and cards
5
+ draw live on your phone.
6
+
7
+ ```ts
8
+ // .repogo/plugins/notes/app.ts
9
+ import { definePlugin, method, z } from "@repogo/plugins";
10
+
11
+ export default definePlugin({
12
+ description: "Notes for this project",
13
+ collections: { notes: z.object({ text: z.string() }) },
14
+ methods: {
15
+ search: method(z.object({ text: z.string() }), async ({ text }, ctx) =>
16
+ (await ctx.db.notes.list()).filter((note) => note.text.includes(text)), { kind: "query" }),
17
+ clear: method(z.object({}), async (_, ctx) => {
18
+ for (const note of await ctx.db.notes.list()) await ctx.db.notes.delete(note.id);
19
+ }, { confirm: "Delete every note?" }),
20
+ },
21
+ });
22
+ ```
23
+
24
+ Add it to `.repogo/plugins/package.json` (`bun add @repogo/plugins`) for types
25
+ and editor help. The RepoGo host runs plugins with its own copy of this
26
+ package, the version it shipped with, so a plugin always matches the host.
27
+ Plugins run on [Bun](https://bun.sh); install it on the environment.
@@ -0,0 +1,35 @@
1
+ import type { SQL } from "bun";
2
+ import type { z } from "zod";
3
+ import type { EventBus } from "./events";
4
+ export type Record_<T> = T & {
5
+ id: string;
6
+ createdAt: string;
7
+ updatedAt: string;
8
+ };
9
+ export type ListOptions = {
10
+ where?: Record<string, string | number | boolean | null>;
11
+ orderBy?: "createdAt" | "updatedAt";
12
+ order?: "asc" | "desc";
13
+ limit?: number;
14
+ };
15
+ export declare class Collection<S extends z.ZodObject> {
16
+ private sql;
17
+ private events;
18
+ private plugin;
19
+ private name;
20
+ private schema;
21
+ private table;
22
+ readonly tag: string;
23
+ /** Writes run one at a time, so an update's read and write can't interleave with another's. */
24
+ private writes;
25
+ constructor(sql: SQL, events: EventBus, plugin: string, name: string, schema: S);
26
+ setup(): Promise<void>;
27
+ private serial;
28
+ create(input: z.input<S>): Promise<Record_<z.infer<S>>>;
29
+ get(id: string): Promise<Record_<z.infer<S>> | null>;
30
+ update(id: string, patch: Partial<z.input<S>>): Promise<Record_<z.infer<S>>>;
31
+ delete(id: string): Promise<void>;
32
+ list(options?: ListOptions): Promise<Record_<z.infer<S>>[]>;
33
+ private eventName;
34
+ private toRecord;
35
+ }
@@ -0,0 +1,10 @@
1
+ import type { Collection } from "./collections";
2
+ export type Context = {
3
+ plugin: string;
4
+ /** The project's checkout, for a plugin that reads the project's files. */
5
+ root: string;
6
+ db: Record<string, Collection<any>>;
7
+ call: (method: string, input?: unknown) => Promise<unknown>;
8
+ emit: (name: string, payload: unknown) => Promise<void>;
9
+ log: (...args: unknown[]) => void;
10
+ };
@@ -0,0 +1,37 @@
1
+ import type { z } from "zod";
2
+ import type { Context } from "./context";
3
+ export type Collections = Record<string, z.ZodObject>;
4
+ /**
5
+ * A query only reads, so cards may run it on their own and again when its data
6
+ * changes. A mutation writes, and runs only when the user acts. Unmarked
7
+ * methods are mutations: repeating one is never assumed safe.
8
+ */
9
+ export type MethodKind = "query" | "mutation";
10
+ export type Method<I extends z.ZodType = z.ZodType, O extends z.ZodType = z.ZodType> = {
11
+ input: I;
12
+ /** What it returns; the agent and cards read field names from it. */
13
+ output?: O;
14
+ kind: MethodKind;
15
+ description?: string;
16
+ /**
17
+ * For what can't be undone: the question a card's button asks before it
18
+ * runs, such as "Delete every item?". Methods without one run on tap.
19
+ */
20
+ confirm?: string;
21
+ run: (input: z.infer<I>, ctx: Context) => unknown | Promise<unknown>;
22
+ };
23
+ export type Handler = (payload: any, ctx: Context) => unknown | Promise<unknown>;
24
+ export type PluginDefinition = {
25
+ /** One line, shown to the agent in the index of plugins. */
26
+ description?: string;
27
+ collections?: Collections;
28
+ methods?: Record<string, Method<any, any>>;
29
+ on?: Record<string, Handler>;
30
+ };
31
+ export declare function definePlugin<T extends PluginDefinition>(plugin: T): T;
32
+ export declare function method<I extends z.ZodType, O extends z.ZodType = z.ZodType>(input: I, run: (input: z.infer<I>, ctx: Context) => unknown | Promise<unknown>, options?: {
33
+ kind?: MethodKind;
34
+ output?: O;
35
+ description?: string;
36
+ confirm?: string;
37
+ }): Method<I, O>;
@@ -0,0 +1,14 @@
1
+ /** CONFIRM: the method asks first; its message is the question to put to the user. */
2
+ export type ErrorCode = "VALIDATION" | "NOT_FOUND" | "FORBIDDEN" | "CONFIRM" | "INTERNAL";
3
+ /** What a failed call returns: a code, a sentence, and per-field messages keyed by JSON pointer ("/minutes"). */
4
+ export type CallError = {
5
+ code: ErrorCode;
6
+ message: string;
7
+ fieldErrors?: Record<string, string>;
8
+ };
9
+ export declare class MethodError extends Error {
10
+ readonly code: ErrorCode;
11
+ readonly fieldErrors?: Record<string, string> | undefined;
12
+ constructor(code: ErrorCode, message: string, fieldErrors?: Record<string, string> | undefined);
13
+ }
14
+ export declare function toCallError(error: unknown): CallError;
@@ -0,0 +1,13 @@
1
+ export type Event = {
2
+ name: string;
3
+ payload: unknown;
4
+ at: string;
5
+ };
6
+ export type Listener = (event: Event) => unknown | Promise<unknown>;
7
+ export declare class EventBus {
8
+ private listeners;
9
+ private all;
10
+ on(name: string, listener: Listener): void;
11
+ onAny(listener: Listener): void;
12
+ emit(name: string, payload: unknown): Promise<void>;
13
+ }
@@ -0,0 +1,5 @@
1
+ export { definePlugin, method } from "./define";
2
+ export type { PluginDefinition, Method, MethodKind } from "./define";
3
+ export type { Context } from "./context";
4
+ export { MethodError, toCallError, type CallError } from "./errors";
5
+ export { z } from "zod";
package/dist/index.js ADDED
@@ -0,0 +1,49 @@
1
+ // @bun
2
+ // src/define.ts
3
+ function definePlugin(plugin) {
4
+ return plugin;
5
+ }
6
+ function method(input, run, options = {}) {
7
+ return {
8
+ input,
9
+ run,
10
+ kind: options.kind ?? "mutation",
11
+ output: options.output,
12
+ description: options.description,
13
+ confirm: options.confirm
14
+ };
15
+ }
16
+ // src/errors.ts
17
+ import { z } from "zod";
18
+
19
+ class MethodError extends Error {
20
+ code;
21
+ fieldErrors;
22
+ constructor(code, message, fieldErrors) {
23
+ super(message);
24
+ this.code = code;
25
+ this.fieldErrors = fieldErrors;
26
+ }
27
+ }
28
+ function toCallError(error) {
29
+ if (error instanceof MethodError) {
30
+ return { code: error.code, message: error.message, ...error.fieldErrors ? { fieldErrors: error.fieldErrors } : {} };
31
+ }
32
+ if (error instanceof z.ZodError) {
33
+ const fieldErrors = {};
34
+ for (const issue of error.issues)
35
+ fieldErrors["/" + issue.path.join("/")] ??= issue.message;
36
+ return { code: "VALIDATION", message: "Check the highlighted fields.", fieldErrors };
37
+ }
38
+ return { code: "INTERNAL", message: error instanceof Error ? error.message : String(error) };
39
+ }
40
+
41
+ // src/index.ts
42
+ import { z as z2 } from "zod";
43
+ export {
44
+ z2 as z,
45
+ toCallError,
46
+ method,
47
+ definePlugin,
48
+ MethodError
49
+ };
@@ -0,0 +1,35 @@
1
+ export type Access = {
2
+ reads: Set<string>;
3
+ writes: Set<string>;
4
+ /** Inside a query: nothing may write. */
5
+ readOnly: boolean;
6
+ /** The call returned; later writes (detached work) are announced on their own. */
7
+ done: {
8
+ value: boolean;
9
+ };
10
+ /** The runtime this call belongs to, which announces its late writes. */
11
+ announce: (tags: string[]) => void;
12
+ };
13
+ export declare function currentAccess(): Access | undefined;
14
+ export type Tracked<T> = {
15
+ ok: true;
16
+ value: T;
17
+ access: Access;
18
+ outermost: boolean;
19
+ } | {
20
+ ok: false;
21
+ error: unknown;
22
+ access: Access;
23
+ outermost: boolean;
24
+ };
25
+ /**
26
+ * Runs `work` tracking its reads and writes. A call inside another adds to the
27
+ * outer one's sets; a query inside a writable call gets a read-only scope over
28
+ * those same sets. The access comes back even when `work` throws, so writes
29
+ * that committed before the error are still announced.
30
+ */
31
+ export declare function tracked<T>(readOnly: boolean, announce: (tags: string[]) => void, work: () => Promise<T>): Promise<Tracked<T>>;
32
+ export declare function recordRead(tag: string): void;
33
+ /** Called before a write runs: a query, and anything it calls, may not write. */
34
+ export declare function assertWritable(tag: string): void;
35
+ export declare function recordWrite(tag: string): void;
package/package.json CHANGED
@@ -1,6 +1,42 @@
1
1
  {
2
2
  "name": "@repogo/plugins",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.25",
4
+ "description": "Write RepoGo plugins: collections and methods over SQLite that agents and cards call",
5
+ "type": "module",
6
+ "exports": {
7
+ ".": {
8
+ "types": "./dist/index.d.ts",
9
+ "import": "./dist/index.js"
10
+ }
11
+ },
12
+ "types": "./dist/index.d.ts",
13
+ "files": [
14
+ "dist",
15
+ "README.md",
16
+ "LICENSE.md"
17
+ ],
18
+ "scripts": {
19
+ "build": "rm -rf dist && bun build src/index.ts --target=bun --outdir dist --external zod && tsc -p tsconfig.build.json",
20
+ "build:runtime": "bun build src/run.ts src/worker.ts --target=bun --outdir ../internal/plugins/runtime",
21
+ "prepack": "cp ../LICENSE.md LICENSE.md && bun run build",
22
+ "test": "bun test",
23
+ "typecheck": "tsc --noEmit"
24
+ },
25
+ "dependencies": {
26
+ "zod": "^4.1.0"
27
+ },
28
+ "devDependencies": {
29
+ "@types/bun": "latest",
30
+ "typescript": "^5.9.0"
31
+ },
32
+ "license": "FSL-1.1-ALv2",
33
+ "homepage": "https://repogo.app",
34
+ "repository": {
35
+ "type": "git",
36
+ "url": "git+https://github.com/repogoapp/host.git",
37
+ "directory": "plugins-sdk"
38
+ },
39
+ "publishConfig": {
40
+ "access": "public"
41
+ }
42
+ }