@astera-app/plugin-sdk 0.0.0-stage → 0.2.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/CHANGELOG.md ADDED
@@ -0,0 +1,31 @@
1
+ # Changelog
2
+
3
+ `@astera-app/plugin-sdk` is versioned apart from the Astera app. [docs/plugins.md](https://github.com/parsingk/Astera/blob/main/docs/plugins.md)
4
+ is the guide.
5
+
6
+ ## 0.2.0
7
+
8
+ - `onEvent` on a plugin: the `event` capability, which hands the plugin each of Astera's events in order, from where
9
+ it left off, and tries an event again when the handler throws.
10
+ - `defineNotificationProvider` and its `send`: the `notification` capability, which hands the plugin each thing worth
11
+ telling a person (a question, a session waiting, a failed or finished Run, a usage limit), worded by Astera in the
12
+ person's language. `NOTIFICATION_KINDS` lists the kinds, for a provider's setting of the ones it leaves out.
13
+ - `defineJobSourceProvider` and its `listItems`, `getItem` and `buildJobContext`, with the types they answer
14
+ (`JobSourceItem`, `JobSourcePage`, `JobSourceItemDetail`, `JobSourceContext`): the `job-source` capability, from
15
+ which a person, the `astera sources` commands and MCP clients pick a ticket to make a Job from. The Job is named by
16
+ the first line of the context's `objective`, so a provider starts it with the item's title.
17
+ - `defineCompletionCheckProvider` and its `runCheck`, with the types it is asked with and answers
18
+ (`CompletionCheckInput`, `CompletionCheckResult`, `CompletionCheckDiagnostic`): the `completion-check` capability,
19
+ which a Task names among its checks as `plugin:<id>`. Its `failed` goes to the Task's repair loop with its findings
20
+ (Astera keeps the first 20; a check that found more sends 20 and its own `diagnosticsTotal`); its `error` is asked
21
+ once more, then put to a person.
22
+ - In a handler (`onEvent`, `send`, `listItems`, `getItem`, `buildJobContext`, `runCheck`), `ctx.signal` is that call's:
23
+ it also aborts when Astera stops waiting for the call, so a handler can stop the work it started.
24
+
25
+ All five need Astera 1.4.14 or later. The plugin SDK needs `@astera-app/client` 0.2.0 or later, whose events include the
26
+ session events.
27
+
28
+ ## 0.1.0
29
+
30
+ The first release on npm: `definePlugin` and the types of the plugin context, for Plugin API 1, which Astera 1.4.12
31
+ and later run. `ctx.astera` is typed by `@astera-app/client`, which npm installs beside it.
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 parsingk
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,42 @@
1
- # Temporary Holding Version
1
+ # @astera-app/plugin-sdk
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 [Astera](https://github.com/parsingk/Astera) plugins.
4
+
5
+ The guide, with a quick start and a sample plugin: [docs/plugins.md](https://github.com/parsingk/Astera/blob/main/docs/plugins.md).
6
+
7
+ ```bash
8
+ npm install @astera-app/plugin-sdk
9
+ ```
10
+
11
+ npm installs `@astera-app/client` beside it, whose types `ctx.astera` has. The example below imports `definePlugin`
12
+ when the plugin runs, so the package is a dependency; a plugin that imports only its types keeps it in
13
+ `devDependencies`, as [the guide](https://github.com/parsingk/Astera/blob/main/docs/plugins.md#typescript-and-bundling)
14
+ shows.
15
+
16
+ ```ts
17
+ import { definePlugin } from '@astera-app/plugin-sdk'
18
+
19
+ export default definePlugin({
20
+ async activate(ctx) {
21
+ const { items } = await ctx.astera.projects.list()
22
+ ctx.log.info(`${items.length} projects`)
23
+ }
24
+ })
25
+ ```
26
+
27
+ A plugin is a folder with a `package.json` whose `astera` field names its entry file, the Plugin API it is written for
28
+ (`"1"`) and the permissions it asks for. `ctx.astera` is a client from `@astera-app/client`, answered within the
29
+ permissions the person granted. A plugin that names the `event` capability gets each of Astera's events, in order, in
30
+ its `onEvent` ([event plugins](https://github.com/parsingk/Astera/blob/main/docs/plugins.md#event-plugins)), and one
31
+ that names the `notification` capability gets each notification, worded for a person, in its `send`
32
+ ([notification plugins](https://github.com/parsingk/Astera/blob/main/docs/plugins.md#notification-plugins)), which
33
+ `defineNotificationProvider` types. One that names the `job-source` capability is asked for tickets a Job can be made
34
+ from, in its `listItems`, `getItem` and `buildJobContext`
35
+ ([job source plugins](https://github.com/parsingk/Astera/blob/main/docs/plugins.md#job-source-plugins)), which
36
+ `defineJobSourceProvider` types. One that names the `completion-check` capability is asked whether a Task's work
37
+ passes, in its `runCheck`
38
+ ([completion check plugins](https://github.com/parsingk/Astera/blob/main/docs/plugins.md#completion-check-plugins)),
39
+ which `defineCompletionCheckProvider` types.
40
+
41
+ Plugins run trusted code on the person's machine: a plugin can do anything they can, and its permissions limit only
42
+ what it asks Astera for.
@@ -0,0 +1,195 @@
1
+ import type { AsteraClient, AsteraEvent, EventGap } from '@astera-app/client';
2
+ /** The Plugin API this package is written for: the manifest's `astera.apiVersion` (spec §28). */
3
+ export declare const PLUGIN_API_VERSION = "1";
4
+ /** Lines to the plugin's log, which `astera plugins logs` reads. Anything the plugin prints goes there too. */
5
+ export interface PluginLog {
6
+ info(message: string): void;
7
+ warn(message: string): void;
8
+ error(message: string): void;
9
+ }
10
+ /** Secrets the plugin keeps (spec §23): in Astera's store for this plugin alone, never shown to anyone, and redacted
11
+ * from the plugin's log. Names are letters, digits, `_`, `-` and `.`, at most 73, not starting or ending with `.`, and
12
+ * `Token` is the same name as `token`; values are text of at most 65,536 characters. */
13
+ export interface PluginSecrets {
14
+ get(name: string): Promise<string | undefined>;
15
+ set(name: string, value: string): Promise<void>;
16
+ delete(name: string): Promise<void>;
17
+ }
18
+ export interface PluginContext {
19
+ /** A client of the Host, answered within the permissions this plugin was granted. */
20
+ astera: AsteraClient;
21
+ /** The settings a person set for this plugin (`astera plugins configure`), with the manifest's defaults, secret ones
22
+ * included. Read when the plugin starts; a change restarts it. */
23
+ settings: Readonly<Record<string, string | number | boolean>>;
24
+ secrets: PluginSecrets;
25
+ /** This plugin as installed: its id (the package name), its version and its folder. */
26
+ plugin: {
27
+ id: string;
28
+ version: string;
29
+ dir: string;
30
+ };
31
+ /** The permissions the person granted, a subset of those the manifest asks for. */
32
+ permissions: readonly string[];
33
+ log: PluginLog;
34
+ /** Aborted when Astera stops the plugin: disabled, removed, updated, or the Host leaving. In a handler (`onEvent`,
35
+ * `send`, `listItems`, `getItem`, `buildJobContext`, `runCheck`) it is that call's: it also aborts when Astera stops
36
+ * waiting for the call (30 seconds for an event or a notification, 15 for a job source, 30 minutes for a check). */
37
+ signal: AbortSignal;
38
+ }
39
+ export interface PluginDefinition {
40
+ /** Called once the plugin is loaded. Astera counts the plugin as running when it resolves. */
41
+ activate?(ctx: PluginContext): void | Promise<void>;
42
+ /** Called before the plugin is stopped, with a few seconds to finish. */
43
+ deactivate?(): void | Promise<void>;
44
+ /** The `event` capability (`astera.capabilities: ["event"]`, with the `events.subscribe` permission): each of
45
+ * Astera's events, in order, one at a time, from where this plugin left off, once `activate` has resolved. A
46
+ * `{ type: 'gap' }` first means events were lost before the next one. Throw or reject to have the same event handed
47
+ * over again (after 1 s, doubling to 5 min, for an hour). It must settle within 30 s: past that the call's
48
+ * `ctx.signal` aborts, and a handler that does not stop runs beside the event's next try. An event can come twice: `event.id` never repeats, so drop one
49
+ * you have seen. A property rather than a method, so a handler that takes only `AsteraEvent` does not typecheck:
50
+ * it would throw on a gap. */
51
+ onEvent?: (event: AsteraEvent | EventGap, ctx: PluginContext) => void | Promise<void>;
52
+ }
53
+ /** The plugin an entry file exports as its default. */
54
+ export declare function definePlugin<T extends PluginDefinition>(definition: T): T;
55
+ /** The kinds of notification Astera sends a `notification` plugin, most pressing first. A provider offers a setting
56
+ * for the ones it leaves out; Astera sends all of them. Astera's own copy of this list is checked against this one. */
57
+ export declare const NOTIFICATION_KINDS: readonly ['question.created', 'session.input_needed', 'run.failed', 'completion.exhausted', 'session.limit_waiting', 'run.completed', 'session.account_switched'];
58
+ export type NotificationKind = (typeof NOTIFICATION_KINDS)[number];
59
+ /** How much it matters: `action` waits on the person, `error` failed, `warning` stopped for now, `info` went on. */
60
+ export type NotificationLevel = 'action' | 'error' | 'warning' | 'info';
61
+ /** Something worth telling a person, already worded by Astera in the language the app is set to: post `title` and
62
+ * `body` as they are. */
63
+ export interface AsteraNotification {
64
+ /** The event's id: a notification can come twice, so drop one you have seen. */
65
+ readonly id: string;
66
+ /** The event's type. A later Astera may send a kind this list does not name yet: post it by its title and body. */
67
+ readonly kind: NotificationKind | (string & {});
68
+ /** How much it matters. A later Astera may add a level: post it as the nearest one you know. */
69
+ readonly level: NotificationLevel | (string & {});
70
+ /** What it is about: a Job's objective, or a session's title. */
71
+ readonly title: string;
72
+ /** One sentence. */
73
+ readonly body: string;
74
+ readonly occurredAt: string;
75
+ /** The whole event, for its ids and detail. */
76
+ readonly event: AsteraEvent;
77
+ }
78
+ /** A plugin of the `notification` capability (`astera.capabilities: ["notification"]`, with the `events.subscribe`
79
+ * permission). */
80
+ export interface NotificationProvider extends PluginDefinition {
81
+ /** Each notification, in order, one at a time, once `activate` has resolved. Throw or reject to have it sent again
82
+ * (after 1 s, doubling to 5 min, for an hour); it must settle within 30 s. A notification older than an hour when
83
+ * its turn comes is not sent. */
84
+ send: (notification: AsteraNotification, ctx: PluginContext) => void | Promise<void>;
85
+ }
86
+ /** The provider an entry file exports as its default. */
87
+ export declare function defineNotificationProvider<T extends NotificationProvider>(provider: T): T;
88
+ /** What `listItems` is asked: the person's search, and the cursor of the page before when there is one. */
89
+ export interface JobSourceQuery {
90
+ query?: string;
91
+ cursor?: string;
92
+ }
93
+ /** One item of a job source: a ticket, an issue. Astera refuses an item whose `id` is not 1 to 200 characters with no
94
+ * control characters (it is your own, opaque id, `ENG-123` say), cuts `title` at 300 characters, `status` at 100 and
95
+ * `summary` at 1,000, and keeps `url` only when it is http or https. */
96
+ export interface JobSourceItem {
97
+ id: string;
98
+ title: string;
99
+ status?: string;
100
+ url?: string;
101
+ summary?: string;
102
+ }
103
+ /** A page of items: at most 100 are kept, and `nextCursor` (at most 2,000 characters) is handed back to `listItems`
104
+ * for the next page. No `nextCursor` means this is the last page. */
105
+ export interface JobSourcePage {
106
+ items: JobSourceItem[];
107
+ nextCursor?: string;
108
+ }
109
+ /** One item read whole: `body` cut at 20,000 characters, and at most 50 `fields` of short text (100 characters a name,
110
+ * 1,000 a value), shown beside it. */
111
+ export interface JobSourceItemDetail extends JobSourceItem {
112
+ body?: string;
113
+ fields?: Record<string, string>;
114
+ }
115
+ /** What a Job made from an item is to do. Astera writes the Job's objective itself: a first line naming
116
+ * `sourceLabel` (`Linear ENG-123`, at most 200 characters) and `sourceUrl`, then your `objective` (at most 20,000), each
117
+ * `evidence` entry under its label (at most 20 entries, 20,000 characters each and 100,000 in all) and the `metadata`
118
+ * (at most 50 pairs), quoted as data the Job's agent does not take orders from. The Job keeps the item as its source,
119
+ * and is named, in the app, the CLI and notifications, by the first line of your `objective` (at most 300 characters):
120
+ * start it with the item's title. */
121
+ export interface JobSourceContext {
122
+ objective: string;
123
+ sourceLabel: string;
124
+ sourceUrl?: string;
125
+ evidence?: Array<{
126
+ label: string;
127
+ content: string;
128
+ }>;
129
+ metadata?: Record<string, string>;
130
+ }
131
+ /** A plugin of the `job-source` capability (`astera.capabilities: ["job-source"]`, with no permission): Astera asks it
132
+ * for items when a person, the `astera sources` commands or an MCP client looks for a ticket to make a Job from. Each
133
+ * call has 15 seconds. Throw or reject to say why there is no answer ("401 Unauthorized"): the person reads that
134
+ * sentence, and Astera tries nothing again. A plugin missing any of the three does not start. */
135
+ export interface JobSourceProvider extends PluginDefinition {
136
+ /** A page of items, searched with `input.query`, from `input.cursor` on. */
137
+ listItems: (input: JobSourceQuery, ctx: PluginContext) => JobSourcePage | Promise<JobSourcePage>;
138
+ /** One item read whole, by the id `listItems` gave it. Throw for an id you do not know. */
139
+ getItem: (id: string, ctx: PluginContext) => JobSourceItemDetail | Promise<JobSourceItemDetail>;
140
+ /** What a Job made from the item is to do, by the id `listItems` gave it. */
141
+ buildJobContext: (id: string, ctx: PluginContext) => JobSourceContext | Promise<JobSourceContext>;
142
+ }
143
+ /** The provider an entry file exports as its default. */
144
+ export declare function defineJobSourceProvider<T extends JobSourceProvider>(provider: T): T;
145
+ /** What a completion check is asked about: the Task and the folder its checks run in. `root` is the Task's worktree, or
146
+ * the project folder; `base` is the commit the Task's work started from and `head` the one its last attempt reached,
147
+ * when Astera recorded them, so a check can look at what the Task changed. `branch` is not sent by this Astera: a
148
+ * check that needs it asks git in `root`. A check configured per project reads the project's own files under `root`;
149
+ * the plugin's settings are the rest of its configuration. */
150
+ export interface CompletionCheckInput {
151
+ projectId?: string;
152
+ jobId: string;
153
+ runId: string;
154
+ taskId: string;
155
+ task: {
156
+ title: string;
157
+ };
158
+ workspace: {
159
+ root: string;
160
+ base?: string;
161
+ head?: string;
162
+ branch?: string;
163
+ };
164
+ }
165
+ /** One finding. Astera keeps a `message` (required) of up to 1,000 characters, a `file` of up to 500, a `line` that is a
166
+ * positive integer and a `severity` that is one of the two, and drops what is not. */
167
+ export interface CompletionCheckDiagnostic {
168
+ file?: string;
169
+ line?: number;
170
+ message: string;
171
+ severity?: 'error' | 'warning';
172
+ }
173
+ /** A check's answer. `passed` lets the Task's next check run. `failed` is the code's fault: the Task's repair request
174
+ * carries your summary, your first 20 findings as `file:line message` and your link, and the Task fails where its Job
175
+ * repairs nothing. `error` says the check could not be made (a service down, a missing token): Astera asks once more,
176
+ * then puts it to a person, and no repair is spent on it. `summary` is cut at 1,000 characters (the status word when
177
+ * there is none), `diagnostics` keep the first 20 (Astera counts the rest, and keeps none of a `passed` check's: give
178
+ * the whole report as `externalUrl`), and `externalUrl` is kept when it is http or https within 2,048. */
179
+ export interface CompletionCheckResult {
180
+ status: 'passed' | 'failed' | 'error';
181
+ summary?: string;
182
+ diagnostics?: CompletionCheckDiagnostic[];
183
+ /** How many findings there are, when you send fewer: send the first 20 and the count, not thousands to be cut. */
184
+ diagnosticsTotal?: number;
185
+ externalUrl?: string;
186
+ }
187
+ /** A plugin of the `completion-check` capability (`astera.capabilities: ["completion-check"]`, with no permission):
188
+ * Astera asks it when a Task whose checks name `plugin:<its id>` is done, in the order the Task lists its checks. A
189
+ * call has 30 minutes. Throw or reject to say the check could not be made: it counts as `error`, with your message. A
190
+ * plugin missing `runCheck` does not start. */
191
+ export interface CompletionCheckProvider extends PluginDefinition {
192
+ runCheck: (input: CompletionCheckInput, ctx: PluginContext) => CompletionCheckResult | Promise<CompletionCheckResult>;
193
+ }
194
+ /** The provider an entry file exports as its default. */
195
+ export declare function defineCompletionCheckProvider<T extends CompletionCheckProvider>(provider: T): T;
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NOTIFICATION_KINDS = exports.PLUGIN_API_VERSION = void 0;
4
+ exports.definePlugin = definePlugin;
5
+ exports.defineNotificationProvider = defineNotificationProvider;
6
+ exports.defineJobSourceProvider = defineJobSourceProvider;
7
+ exports.defineCompletionCheckProvider = defineCompletionCheckProvider;
8
+ /** The Plugin API this package is written for: the manifest's `astera.apiVersion` (spec §28). */
9
+ exports.PLUGIN_API_VERSION = '1';
10
+ /** The plugin an entry file exports as its default. */
11
+ function definePlugin(definition) {
12
+ return definition;
13
+ }
14
+ /** The kinds of notification Astera sends a `notification` plugin, most pressing first. A provider offers a setting
15
+ * for the ones it leaves out; Astera sends all of them. Astera's own copy of this list is checked against this one. */
16
+ exports.NOTIFICATION_KINDS = [
17
+ 'question.created',
18
+ 'session.input_needed',
19
+ 'run.failed',
20
+ 'completion.exhausted',
21
+ 'session.limit_waiting',
22
+ 'run.completed',
23
+ 'session.account_switched'
24
+ ];
25
+ /** The provider an entry file exports as its default. */
26
+ function defineNotificationProvider(provider) {
27
+ return provider;
28
+ }
29
+ /** The provider an entry file exports as its default. */
30
+ function defineJobSourceProvider(provider) {
31
+ return provider;
32
+ }
33
+ /** The provider an entry file exports as its default. */
34
+ function defineCompletionCheckProvider(provider) {
35
+ return provider;
36
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }
@@ -0,0 +1,195 @@
1
+ import type { AsteraClient, AsteraEvent, EventGap } from '@astera-app/client';
2
+ /** The Plugin API this package is written for: the manifest's `astera.apiVersion` (spec §28). */
3
+ export declare const PLUGIN_API_VERSION = "1";
4
+ /** Lines to the plugin's log, which `astera plugins logs` reads. Anything the plugin prints goes there too. */
5
+ export interface PluginLog {
6
+ info(message: string): void;
7
+ warn(message: string): void;
8
+ error(message: string): void;
9
+ }
10
+ /** Secrets the plugin keeps (spec §23): in Astera's store for this plugin alone, never shown to anyone, and redacted
11
+ * from the plugin's log. Names are letters, digits, `_`, `-` and `.`, at most 73, not starting or ending with `.`, and
12
+ * `Token` is the same name as `token`; values are text of at most 65,536 characters. */
13
+ export interface PluginSecrets {
14
+ get(name: string): Promise<string | undefined>;
15
+ set(name: string, value: string): Promise<void>;
16
+ delete(name: string): Promise<void>;
17
+ }
18
+ export interface PluginContext {
19
+ /** A client of the Host, answered within the permissions this plugin was granted. */
20
+ astera: AsteraClient;
21
+ /** The settings a person set for this plugin (`astera plugins configure`), with the manifest's defaults, secret ones
22
+ * included. Read when the plugin starts; a change restarts it. */
23
+ settings: Readonly<Record<string, string | number | boolean>>;
24
+ secrets: PluginSecrets;
25
+ /** This plugin as installed: its id (the package name), its version and its folder. */
26
+ plugin: {
27
+ id: string;
28
+ version: string;
29
+ dir: string;
30
+ };
31
+ /** The permissions the person granted, a subset of those the manifest asks for. */
32
+ permissions: readonly string[];
33
+ log: PluginLog;
34
+ /** Aborted when Astera stops the plugin: disabled, removed, updated, or the Host leaving. In a handler (`onEvent`,
35
+ * `send`, `listItems`, `getItem`, `buildJobContext`, `runCheck`) it is that call's: it also aborts when Astera stops
36
+ * waiting for the call (30 seconds for an event or a notification, 15 for a job source, 30 minutes for a check). */
37
+ signal: AbortSignal;
38
+ }
39
+ export interface PluginDefinition {
40
+ /** Called once the plugin is loaded. Astera counts the plugin as running when it resolves. */
41
+ activate?(ctx: PluginContext): void | Promise<void>;
42
+ /** Called before the plugin is stopped, with a few seconds to finish. */
43
+ deactivate?(): void | Promise<void>;
44
+ /** The `event` capability (`astera.capabilities: ["event"]`, with the `events.subscribe` permission): each of
45
+ * Astera's events, in order, one at a time, from where this plugin left off, once `activate` has resolved. A
46
+ * `{ type: 'gap' }` first means events were lost before the next one. Throw or reject to have the same event handed
47
+ * over again (after 1 s, doubling to 5 min, for an hour). It must settle within 30 s: past that the call's
48
+ * `ctx.signal` aborts, and a handler that does not stop runs beside the event's next try. An event can come twice: `event.id` never repeats, so drop one
49
+ * you have seen. A property rather than a method, so a handler that takes only `AsteraEvent` does not typecheck:
50
+ * it would throw on a gap. */
51
+ onEvent?: (event: AsteraEvent | EventGap, ctx: PluginContext) => void | Promise<void>;
52
+ }
53
+ /** The plugin an entry file exports as its default. */
54
+ export declare function definePlugin<T extends PluginDefinition>(definition: T): T;
55
+ /** The kinds of notification Astera sends a `notification` plugin, most pressing first. A provider offers a setting
56
+ * for the ones it leaves out; Astera sends all of them. Astera's own copy of this list is checked against this one. */
57
+ export declare const NOTIFICATION_KINDS: readonly ['question.created', 'session.input_needed', 'run.failed', 'completion.exhausted', 'session.limit_waiting', 'run.completed', 'session.account_switched'];
58
+ export type NotificationKind = (typeof NOTIFICATION_KINDS)[number];
59
+ /** How much it matters: `action` waits on the person, `error` failed, `warning` stopped for now, `info` went on. */
60
+ export type NotificationLevel = 'action' | 'error' | 'warning' | 'info';
61
+ /** Something worth telling a person, already worded by Astera in the language the app is set to: post `title` and
62
+ * `body` as they are. */
63
+ export interface AsteraNotification {
64
+ /** The event's id: a notification can come twice, so drop one you have seen. */
65
+ readonly id: string;
66
+ /** The event's type. A later Astera may send a kind this list does not name yet: post it by its title and body. */
67
+ readonly kind: NotificationKind | (string & {});
68
+ /** How much it matters. A later Astera may add a level: post it as the nearest one you know. */
69
+ readonly level: NotificationLevel | (string & {});
70
+ /** What it is about: a Job's objective, or a session's title. */
71
+ readonly title: string;
72
+ /** One sentence. */
73
+ readonly body: string;
74
+ readonly occurredAt: string;
75
+ /** The whole event, for its ids and detail. */
76
+ readonly event: AsteraEvent;
77
+ }
78
+ /** A plugin of the `notification` capability (`astera.capabilities: ["notification"]`, with the `events.subscribe`
79
+ * permission). */
80
+ export interface NotificationProvider extends PluginDefinition {
81
+ /** Each notification, in order, one at a time, once `activate` has resolved. Throw or reject to have it sent again
82
+ * (after 1 s, doubling to 5 min, for an hour); it must settle within 30 s. A notification older than an hour when
83
+ * its turn comes is not sent. */
84
+ send: (notification: AsteraNotification, ctx: PluginContext) => void | Promise<void>;
85
+ }
86
+ /** The provider an entry file exports as its default. */
87
+ export declare function defineNotificationProvider<T extends NotificationProvider>(provider: T): T;
88
+ /** What `listItems` is asked: the person's search, and the cursor of the page before when there is one. */
89
+ export interface JobSourceQuery {
90
+ query?: string;
91
+ cursor?: string;
92
+ }
93
+ /** One item of a job source: a ticket, an issue. Astera refuses an item whose `id` is not 1 to 200 characters with no
94
+ * control characters (it is your own, opaque id, `ENG-123` say), cuts `title` at 300 characters, `status` at 100 and
95
+ * `summary` at 1,000, and keeps `url` only when it is http or https. */
96
+ export interface JobSourceItem {
97
+ id: string;
98
+ title: string;
99
+ status?: string;
100
+ url?: string;
101
+ summary?: string;
102
+ }
103
+ /** A page of items: at most 100 are kept, and `nextCursor` (at most 2,000 characters) is handed back to `listItems`
104
+ * for the next page. No `nextCursor` means this is the last page. */
105
+ export interface JobSourcePage {
106
+ items: JobSourceItem[];
107
+ nextCursor?: string;
108
+ }
109
+ /** One item read whole: `body` cut at 20,000 characters, and at most 50 `fields` of short text (100 characters a name,
110
+ * 1,000 a value), shown beside it. */
111
+ export interface JobSourceItemDetail extends JobSourceItem {
112
+ body?: string;
113
+ fields?: Record<string, string>;
114
+ }
115
+ /** What a Job made from an item is to do. Astera writes the Job's objective itself: a first line naming
116
+ * `sourceLabel` (`Linear ENG-123`, at most 200 characters) and `sourceUrl`, then your `objective` (at most 20,000), each
117
+ * `evidence` entry under its label (at most 20 entries, 20,000 characters each and 100,000 in all) and the `metadata`
118
+ * (at most 50 pairs), quoted as data the Job's agent does not take orders from. The Job keeps the item as its source,
119
+ * and is named, in the app, the CLI and notifications, by the first line of your `objective` (at most 300 characters):
120
+ * start it with the item's title. */
121
+ export interface JobSourceContext {
122
+ objective: string;
123
+ sourceLabel: string;
124
+ sourceUrl?: string;
125
+ evidence?: Array<{
126
+ label: string;
127
+ content: string;
128
+ }>;
129
+ metadata?: Record<string, string>;
130
+ }
131
+ /** A plugin of the `job-source` capability (`astera.capabilities: ["job-source"]`, with no permission): Astera asks it
132
+ * for items when a person, the `astera sources` commands or an MCP client looks for a ticket to make a Job from. Each
133
+ * call has 15 seconds. Throw or reject to say why there is no answer ("401 Unauthorized"): the person reads that
134
+ * sentence, and Astera tries nothing again. A plugin missing any of the three does not start. */
135
+ export interface JobSourceProvider extends PluginDefinition {
136
+ /** A page of items, searched with `input.query`, from `input.cursor` on. */
137
+ listItems: (input: JobSourceQuery, ctx: PluginContext) => JobSourcePage | Promise<JobSourcePage>;
138
+ /** One item read whole, by the id `listItems` gave it. Throw for an id you do not know. */
139
+ getItem: (id: string, ctx: PluginContext) => JobSourceItemDetail | Promise<JobSourceItemDetail>;
140
+ /** What a Job made from the item is to do, by the id `listItems` gave it. */
141
+ buildJobContext: (id: string, ctx: PluginContext) => JobSourceContext | Promise<JobSourceContext>;
142
+ }
143
+ /** The provider an entry file exports as its default. */
144
+ export declare function defineJobSourceProvider<T extends JobSourceProvider>(provider: T): T;
145
+ /** What a completion check is asked about: the Task and the folder its checks run in. `root` is the Task's worktree, or
146
+ * the project folder; `base` is the commit the Task's work started from and `head` the one its last attempt reached,
147
+ * when Astera recorded them, so a check can look at what the Task changed. `branch` is not sent by this Astera: a
148
+ * check that needs it asks git in `root`. A check configured per project reads the project's own files under `root`;
149
+ * the plugin's settings are the rest of its configuration. */
150
+ export interface CompletionCheckInput {
151
+ projectId?: string;
152
+ jobId: string;
153
+ runId: string;
154
+ taskId: string;
155
+ task: {
156
+ title: string;
157
+ };
158
+ workspace: {
159
+ root: string;
160
+ base?: string;
161
+ head?: string;
162
+ branch?: string;
163
+ };
164
+ }
165
+ /** One finding. Astera keeps a `message` (required) of up to 1,000 characters, a `file` of up to 500, a `line` that is a
166
+ * positive integer and a `severity` that is one of the two, and drops what is not. */
167
+ export interface CompletionCheckDiagnostic {
168
+ file?: string;
169
+ line?: number;
170
+ message: string;
171
+ severity?: 'error' | 'warning';
172
+ }
173
+ /** A check's answer. `passed` lets the Task's next check run. `failed` is the code's fault: the Task's repair request
174
+ * carries your summary, your first 20 findings as `file:line message` and your link, and the Task fails where its Job
175
+ * repairs nothing. `error` says the check could not be made (a service down, a missing token): Astera asks once more,
176
+ * then puts it to a person, and no repair is spent on it. `summary` is cut at 1,000 characters (the status word when
177
+ * there is none), `diagnostics` keep the first 20 (Astera counts the rest, and keeps none of a `passed` check's: give
178
+ * the whole report as `externalUrl`), and `externalUrl` is kept when it is http or https within 2,048. */
179
+ export interface CompletionCheckResult {
180
+ status: 'passed' | 'failed' | 'error';
181
+ summary?: string;
182
+ diagnostics?: CompletionCheckDiagnostic[];
183
+ /** How many findings there are, when you send fewer: send the first 20 and the count, not thousands to be cut. */
184
+ diagnosticsTotal?: number;
185
+ externalUrl?: string;
186
+ }
187
+ /** A plugin of the `completion-check` capability (`astera.capabilities: ["completion-check"]`, with no permission):
188
+ * Astera asks it when a Task whose checks name `plugin:<its id>` is done, in the order the Task lists its checks. A
189
+ * call has 30 minutes. Throw or reject to say the check could not be made: it counts as `error`, with your message. A
190
+ * plugin missing `runCheck` does not start. */
191
+ export interface CompletionCheckProvider extends PluginDefinition {
192
+ runCheck: (input: CompletionCheckInput, ctx: PluginContext) => CompletionCheckResult | Promise<CompletionCheckResult>;
193
+ }
194
+ /** The provider an entry file exports as its default. */
195
+ export declare function defineCompletionCheckProvider<T extends CompletionCheckProvider>(provider: T): T;
@@ -0,0 +1,29 @@
1
+ /** The Plugin API this package is written for: the manifest's `astera.apiVersion` (spec §28). */
2
+ export const PLUGIN_API_VERSION = '1';
3
+ /** The plugin an entry file exports as its default. */
4
+ export function definePlugin(definition) {
5
+ return definition;
6
+ }
7
+ /** The kinds of notification Astera sends a `notification` plugin, most pressing first. A provider offers a setting
8
+ * for the ones it leaves out; Astera sends all of them. Astera's own copy of this list is checked against this one. */
9
+ export const NOTIFICATION_KINDS = [
10
+ 'question.created',
11
+ 'session.input_needed',
12
+ 'run.failed',
13
+ 'completion.exhausted',
14
+ 'session.limit_waiting',
15
+ 'run.completed',
16
+ 'session.account_switched'
17
+ ];
18
+ /** The provider an entry file exports as its default. */
19
+ export function defineNotificationProvider(provider) {
20
+ return provider;
21
+ }
22
+ /** The provider an entry file exports as its default. */
23
+ export function defineJobSourceProvider(provider) {
24
+ return provider;
25
+ }
26
+ /** The provider an entry file exports as its default. */
27
+ export function defineCompletionCheckProvider(provider) {
28
+ return provider;
29
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "module"
3
+ }
package/package.json CHANGED
@@ -1,6 +1,56 @@
1
1
  {
2
2
  "name": "@astera-app/plugin-sdk",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.2.0",
4
+ "description": "Write Astera plugins: definePlugin and the plugin context's types.",
5
+ "keywords": [
6
+ "astera",
7
+ "plugin",
8
+ "sdk"
9
+ ],
10
+ "homepage": "https://github.com/parsingk/Astera/blob/main/docs/plugins.md",
11
+ "bugs": {
12
+ "url": "https://github.com/parsingk/Astera/issues"
13
+ },
14
+ "license": "Apache-2.0",
15
+ "type": "module",
16
+ "engines": {
17
+ "node": ">=22"
18
+ },
19
+ "sideEffects": false,
20
+ "main": "./dist/cjs/index.js",
21
+ "module": "./dist/esm/index.js",
22
+ "types": "./dist/esm/index.d.ts",
23
+ "exports": {
24
+ ".": {
25
+ "import": {
26
+ "types": "./dist/esm/index.d.ts",
27
+ "default": "./dist/esm/index.js"
28
+ },
29
+ "require": {
30
+ "types": "./dist/cjs/index.d.ts",
31
+ "default": "./dist/cjs/index.js"
32
+ }
33
+ },
34
+ "./package.json": "./package.json"
35
+ },
36
+ "files": [
37
+ "dist",
38
+ "README.md",
39
+ "LICENSE",
40
+ "CHANGELOG.md"
41
+ ],
42
+ "scripts": {
43
+ "prepublishOnly": "node ../../scripts/build-packages.mjs"
44
+ },
45
+ "peerDependencies": {
46
+ "@astera-app/client": ">=0.2.0 <1"
47
+ },
48
+ "publishConfig": {
49
+ "access": "public"
50
+ },
51
+ "repository": {
52
+ "type": "git",
53
+ "url": "git+https://github.com/parsingk/Astera.git",
54
+ "directory": "packages/plugin-sdk"
55
+ }
56
+ }