@hydraharness/harness-optional-plugins 0.0.0-stage → 0.1.1-rc.10
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 +21 -0
- package/README.md +15 -2
- package/lib/index.js +67 -0
- package/lib/invariant.js +17 -0
- package/lib/types/index.d.ts +37 -0
- package/lib/types/invariant.d.ts +12 -0
- package/package.json +49 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 DeepSeek
|
|
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
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Optional plugin policy
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The `optional-plugins.enabled` preference defaults to On and preserves individual enablement records. Consumers acquire a completion lease before starting optional work. Off rejects new work immediately. Lifetime owners await `drain()` before removing contributions; enabling plugins again cancels pending removal. Required plugins remain available independently of the restart classification `pluginType`.
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
## Model Experience
|
|
7
|
+
|
|
8
|
+
Indirectly, through the owning optional plugins whose contributions and new invocations this policy controls.
|
|
9
|
+
|
|
10
|
+
#### KV Cache effect
|
|
11
|
+
|
|
12
|
+
Disabling optional tools can change the next request's tool context; each owning plugin controls its rendered contribution.
|
|
13
|
+
|
|
14
|
+
## Known Limitations and Deferred Work
|
|
15
|
+
|
|
16
|
+
- Work admitted before disablement finishes under its existing lease. Turning the common policy back on preserves individual choices.
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { Service } from "@hydraharness/cordis";
|
|
2
|
+
import z from "@hydraharness/schemastery";
|
|
3
|
+
import { settingsNamespace } from "@hydraharness/harness-settings";
|
|
4
|
+
//#region lib/types/index.js
|
|
5
|
+
/** Global optional-plugin invocation gate; lifetime owners drain before removing contributions. */
|
|
6
|
+
/** Immediate disablement and leases for operations that may already be running. */
|
|
7
|
+
var OptionalPluginPolicy = class extends Service {
|
|
8
|
+
static inject = ["settings"];
|
|
9
|
+
settings;
|
|
10
|
+
active = 0;
|
|
11
|
+
waiters = /* @__PURE__ */ new Set();
|
|
12
|
+
listeners = /* @__PURE__ */ new Set();
|
|
13
|
+
/**
|
|
14
|
+
* @param ctx - global settings and owning plugin lifetime.
|
|
15
|
+
*/
|
|
16
|
+
constructor(ctx) {
|
|
17
|
+
super(ctx, "optionalPlugins");
|
|
18
|
+
this.settings = ctx.settings.register(settingsNamespace("optional-plugins"), z.object({ enabled: z.boolean().default(true) }));
|
|
19
|
+
ctx.effect(() => this.settings.watch((value) => {
|
|
20
|
+
if (value.enabled) this.releaseWaiters();
|
|
21
|
+
for (const listener of this.listeners) listener(value.enabled);
|
|
22
|
+
}), "optional-plugins: accepted policy");
|
|
23
|
+
}
|
|
24
|
+
/** Committed policy, read synchronously before every invocation. */
|
|
25
|
+
get enabled() {
|
|
26
|
+
return this.settings.get().enabled;
|
|
27
|
+
}
|
|
28
|
+
/** Rejects new optional work while disabled and tracks work already admitted.
|
|
29
|
+
* @returns an idempotent completion lease; rejects a new operation immediately while disabled.
|
|
30
|
+
*/
|
|
31
|
+
acquire() {
|
|
32
|
+
if (!this.enabled) throw new Error("Optional plugins are disabled");
|
|
33
|
+
this.active += 1;
|
|
34
|
+
let released = false;
|
|
35
|
+
return () => {
|
|
36
|
+
if (released) return;
|
|
37
|
+
released = true;
|
|
38
|
+
this.active -= 1;
|
|
39
|
+
if (this.active === 0) this.releaseWaiters();
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/** Waits for owned work before a contribution can be removed.
|
|
43
|
+
* @returns settlement when existing optional operations finish, or the user enables plugins again.
|
|
44
|
+
*/
|
|
45
|
+
drain() {
|
|
46
|
+
if (this.active === 0 || this.enabled) return Promise.resolve();
|
|
47
|
+
return new Promise((resolve) => {
|
|
48
|
+
this.waiters.add(resolve);
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
/** Observes accepted common-policy changes.
|
|
52
|
+
* @param listener - callback after an accepted policy change.
|
|
53
|
+
* @returns subscription disposer.
|
|
54
|
+
*/
|
|
55
|
+
subscribe(listener) {
|
|
56
|
+
this.listeners.add(listener);
|
|
57
|
+
return () => {
|
|
58
|
+
this.listeners.delete(listener);
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
releaseWaiters() {
|
|
62
|
+
for (const waiter of this.waiters) waiter();
|
|
63
|
+
this.waiters.clear();
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
//#endregion
|
|
67
|
+
export { OptionalPluginPolicy, OptionalPluginPolicy as default };
|
package/lib/invariant.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
//#region lib/types/invariant.js
|
|
2
|
+
/** Cordis companion plugin name. */
|
|
3
|
+
const name = "optional-plugins-invariant";
|
|
4
|
+
/** Service required before reserving package ownership. */
|
|
5
|
+
const inject = ["invariants"];
|
|
6
|
+
/**
|
|
7
|
+
* No runtime invariant: admitted operations return private idempotent leases; consumers own their operation streams, so
|
|
8
|
+
* the lease counter has no independent membership stream to compare.
|
|
9
|
+
*/
|
|
10
|
+
const install = () => {};
|
|
11
|
+
/** Registers this package's invariant ownership.
|
|
12
|
+
* @param ctx - Cordis context carrying the invariant service.
|
|
13
|
+
* @returns registration disposer.
|
|
14
|
+
*/
|
|
15
|
+
const apply = (ctx) => Promise.resolve(ctx.invariants.register("@hydraharness/harness-optional-plugins", install));
|
|
16
|
+
//#endregion
|
|
17
|
+
export { apply, inject, name };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/** Global optional-plugin invocation gate; lifetime owners drain before removing contributions. */
|
|
2
|
+
import { Service, type Context } from '@hydraharness/cordis';
|
|
3
|
+
declare module '@hydraharness/cordis' {
|
|
4
|
+
interface Context {
|
|
5
|
+
optionalPlugins: OptionalPluginPolicy;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
/** Immediate disablement and leases for operations that may already be running. */
|
|
9
|
+
export declare class OptionalPluginPolicy extends Service {
|
|
10
|
+
static inject: string[];
|
|
11
|
+
private readonly settings;
|
|
12
|
+
private active;
|
|
13
|
+
private readonly waiters;
|
|
14
|
+
private readonly listeners;
|
|
15
|
+
/**
|
|
16
|
+
* @param ctx - global settings and owning plugin lifetime.
|
|
17
|
+
*/
|
|
18
|
+
constructor(ctx: Context);
|
|
19
|
+
/** Committed policy, read synchronously before every invocation. */
|
|
20
|
+
get enabled(): boolean;
|
|
21
|
+
/** Rejects new optional work while disabled and tracks work already admitted.
|
|
22
|
+
* @returns an idempotent completion lease; rejects a new operation immediately while disabled.
|
|
23
|
+
*/
|
|
24
|
+
acquire(): () => void;
|
|
25
|
+
/** Waits for owned work before a contribution can be removed.
|
|
26
|
+
* @returns settlement when existing optional operations finish, or the user enables plugins again.
|
|
27
|
+
*/
|
|
28
|
+
drain(): Promise<void>;
|
|
29
|
+
/** Observes accepted common-policy changes.
|
|
30
|
+
* @param listener - callback after an accepted policy change.
|
|
31
|
+
* @returns subscription disposer.
|
|
32
|
+
*/
|
|
33
|
+
subscribe(listener: (enabled: boolean) => void): () => void;
|
|
34
|
+
private releaseWaiters;
|
|
35
|
+
}
|
|
36
|
+
export default OptionalPluginPolicy;
|
|
37
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** Package-owned invariant companion for `@hydraharness/harness-optional-plugins`. */
|
|
2
|
+
import type { Context } from '@hydraharness/cordis';
|
|
3
|
+
/** Cordis companion plugin name. */
|
|
4
|
+
export declare const name = "optional-plugins-invariant";
|
|
5
|
+
/** Service required before reserving package ownership. */
|
|
6
|
+
export declare const inject: string[];
|
|
7
|
+
/** Registers this package's invariant ownership.
|
|
8
|
+
* @param ctx - Cordis context carrying the invariant service.
|
|
9
|
+
* @returns registration disposer.
|
|
10
|
+
*/
|
|
11
|
+
export declare const apply: (ctx: Context) => Promise<() => void>;
|
|
12
|
+
//# sourceMappingURL=invariant.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,52 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hydraharness/harness-optional-plugins",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.1-rc.10",
|
|
4
|
+
"description": "Immediate optional-plugin invocation policy and draining lifecycle",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"publishConfig": {
|
|
8
|
+
"access": "public"
|
|
9
|
+
},
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/MaiHongPhong2010/Hydra-Harness.git",
|
|
13
|
+
"directory": "packages/host/optional-plugins"
|
|
14
|
+
},
|
|
15
|
+
"main": "lib/index.js",
|
|
16
|
+
"types": "lib/types/index.d.ts",
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./lib/types/index.d.ts",
|
|
20
|
+
"default": "./lib/index.js"
|
|
21
|
+
},
|
|
22
|
+
"./invariant": {
|
|
23
|
+
"types": "./lib/types/invariant.d.ts",
|
|
24
|
+
"default": "./lib/invariant.js"
|
|
25
|
+
},
|
|
26
|
+
"./src/*": "./src/*",
|
|
27
|
+
"./package.json": "./package.json"
|
|
28
|
+
},
|
|
29
|
+
"files": [
|
|
30
|
+
"lib/index.js",
|
|
31
|
+
"lib/invariant.js",
|
|
32
|
+
"lib/types/**/*.d.ts"
|
|
33
|
+
],
|
|
34
|
+
"hydra": {
|
|
35
|
+
"plugin": {
|
|
36
|
+
"application": "Suspend optional plugins without changing their individual choices."
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
"peerDependencies": {
|
|
40
|
+
"@hydraharness/harness-settings": "^0.1.1-rc.10",
|
|
41
|
+
"@hydraharness/cordis": "^4.0.2",
|
|
42
|
+
"@hydraharness/harness-invariants": "^0.1.1-rc.10"
|
|
43
|
+
},
|
|
44
|
+
"dependencies": {
|
|
45
|
+
"@hydraharness/schemastery": "^3.18.2"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@hydraharness/harness-settings": "^0.1.1-rc.10",
|
|
49
|
+
"@hydraharness/harness-invariants": "^0.1.1-rc.10",
|
|
50
|
+
"@hydraharness/cordis": "^4.0.2"
|
|
51
|
+
}
|
|
6
52
|
}
|