@agimon-ai/po-domain 0.0.0-alpha.21 → 0.0.0-alpha.211
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 -149
- package/README.md +13 -50
- package/dist/agentArchive.cjs +120 -0
- package/dist/agentArchive.cjs.map +1 -0
- package/dist/agentArchive.d.mts +33 -0
- package/dist/agentArchive.d.mts.map +1 -0
- package/dist/agentArchive.mjs +115 -0
- package/dist/agentArchive.mjs.map +1 -0
- package/dist/apiContracts.cjs +131 -10
- package/dist/apiContracts.cjs.map +1 -1
- package/dist/apiContracts.d.mts +2 -2
- package/dist/apiContracts.d.mts.map +1 -1
- package/dist/apiContracts.mjs +131 -10
- package/dist/apiContracts.mjs.map +1 -1
- package/dist/apply.cjs +11 -9
- package/dist/apply.cjs.map +1 -1
- package/dist/apply.d.mts +2 -2
- package/dist/apply.d.mts.map +1 -1
- package/dist/apply.mjs +11 -9
- package/dist/apply.mjs.map +1 -1
- package/dist/domainText-CbpBLX_M.cjs.map +1 -1
- package/dist/domainText-D0iurn8D.mjs.map +1 -1
- package/dist/extensions/mcp.cjs +5 -5
- package/dist/extensions/mcp.cjs.map +1 -1
- package/dist/extensions/mcp.mjs +5 -5
- package/dist/extensions/mcp.mjs.map +1 -1
- package/dist/extensions/native.mjs +60 -7
- package/dist/extensions/native.mjs.map +1 -1
- package/dist/extensions/server.cjs +1124 -64
- package/dist/extensions/server.cjs.map +1 -1
- package/dist/extensions/server.d.mts.map +1 -1
- package/dist/extensions/server.mjs +1126 -68
- package/dist/extensions/server.mjs.map +1 -1
- package/dist/extensions/web.mjs +1406 -7
- package/dist/extensions/web.mjs.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.mts +7 -7
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/mcp.cjs +1 -1
- package/dist/mcp.d.mts +2 -2
- package/dist/mcp.mjs +1 -1
- package/dist/{mcpFilter-CghXZ2K-.cjs → mcpFilter-B0yUKptm.cjs} +8 -12
- package/dist/mcpFilter-B0yUKptm.cjs.map +1 -0
- package/dist/{mcpFilter-CKUbKmxz.mjs → mcpFilter-D45gSjkl.mjs} +3 -7
- package/dist/{mcpFilter-CKUbKmxz.mjs.map → mcpFilter-D45gSjkl.mjs.map} +1 -1
- package/dist/{pluginMaterializer-C8IZ1PSY.cjs → pluginMaterializer-BaOTKdoc.cjs} +86 -31
- package/dist/pluginMaterializer-BaOTKdoc.cjs.map +1 -0
- package/dist/{pluginMaterializer-D9-oDF-b.mjs → pluginMaterializer-CgRum-FB.mjs} +85 -30
- package/dist/pluginMaterializer-CgRum-FB.mjs.map +1 -0
- package/dist/plugins.cjs +1 -1
- package/dist/plugins.d.mts +6 -0
- package/dist/plugins.d.mts.map +1 -1
- package/dist/plugins.mjs +1 -1
- package/dist/po-runtime-identity.json +1 -0
- package/dist/{resourceCollector-YOEwhNIR.cjs → resourceCollector-DJNyXeyi.cjs} +105 -137
- package/dist/resourceCollector-DJNyXeyi.cjs.map +1 -0
- package/dist/{resourceCollector-CLxre4tE.mjs → resourceCollector-DfIpkhSS.mjs} +99 -137
- package/dist/resourceCollector-DfIpkhSS.mjs.map +1 -0
- package/dist/{resources-COT3OnLs.d.mts → resources-BhokhE4n.d.mts} +14 -3
- package/dist/resources-BhokhE4n.d.mts.map +1 -0
- package/dist/resources.cjs +9 -1
- package/dist/resources.d.mts +18 -5
- package/dist/resources.d.mts.map +1 -1
- package/dist/resources.mjs +1 -1
- package/dist/{toolNames-Cuu-u8r1.cjs → toolNames-CIp8IdhR.cjs} +9 -9
- package/dist/toolNames-CIp8IdhR.cjs.map +1 -0
- package/dist/{toolNames-Ckp5VLMD.mjs → toolNames-L4VE90mU.mjs} +9 -9
- package/dist/toolNames-L4VE90mU.mjs.map +1 -0
- package/dist/zip-Bl6pG9Ap.mjs +68 -0
- package/dist/zip-Bl6pG9Ap.mjs.map +1 -0
- package/dist/zip-DA9sck3v.cjs +75 -0
- package/dist/zip-DA9sck3v.cjs.map +1 -0
- package/llms.txt +5 -2
- package/locales/vi.json +108 -0
- package/locales/zh-CN.json +108 -0
- package/package.json +64 -17
- package/src/prompts/codemode-how-to-plugins/SKILL.md +26 -0
- package/src/prompts/{po-author-domain → help-how-to-domain}/SKILL.md +1 -1
- package/src/prompts/{po-author-domain → help-how-to-domain}/references/domains-contract.md +20 -1
- package/dist/mcpFilter-CghXZ2K-.cjs.map +0 -1
- package/dist/pluginMaterializer-C8IZ1PSY.cjs.map +0 -1
- package/dist/pluginMaterializer-D9-oDF-b.mjs.map +0 -1
- package/dist/resourceCollector-CLxre4tE.mjs.map +0 -1
- package/dist/resourceCollector-YOEwhNIR.cjs.map +0 -1
- package/dist/resources-COT3OnLs.d.mts.map +0 -1
- package/dist/toolNames-Ckp5VLMD.mjs.map +0 -1
- package/dist/toolNames-Cuu-u8r1.cjs.map +0 -1
package/LICENSE
CHANGED
|
@@ -1,149 +1,21 @@
|
|
|
1
|
-
License
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
other Organization. Use by an individual in the course of employment
|
|
23
|
-
or engagement by an Organization is use by that Organization.
|
|
24
|
-
|
|
25
|
-
(b) Small Organization Use. Use by or on behalf of an Organization whose
|
|
26
|
-
Annual Revenue is less than USD 1,000,000.
|
|
27
|
-
|
|
28
|
-
(c) Non-profit, Education and Research Use. Use, regardless of Annual
|
|
29
|
-
Revenue, by (i) an Organization registered or recognized as a
|
|
30
|
-
non-profit or charitable organization under the laws of its
|
|
31
|
-
jurisdiction, for its non-profit purposes; (ii) an accredited school,
|
|
32
|
-
college, or university, for teaching, learning, or academic research;
|
|
33
|
-
or (iii) a publicly funded research institution, for its research.
|
|
34
|
-
|
|
35
|
-
(d) Service Provider Use. Use by a consultant, contractor, agency, or other
|
|
36
|
-
service provider, regardless of its own Annual Revenue, solely to
|
|
37
|
-
build, deploy, host, operate, or support the Licensed Work for a client
|
|
38
|
-
whose own use would be Eligible Use under (a), (b), or (c). A service
|
|
39
|
-
provider's use for its own purposes is Eligible Use only if the service
|
|
40
|
-
provider itself qualifies under (b) or (c).
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
Hosted services. Offering the Licensed Work to third parties as a hosted
|
|
44
|
-
or managed service whose primary value is the Licensed Work is Eligible
|
|
45
|
-
Use only if each such third party's own use would be Eligible Use.
|
|
46
|
-
|
|
47
|
-
Definitions. "Organization" means any company, partnership, sole
|
|
48
|
-
proprietorship, trust, association, government body, or other entity, and
|
|
49
|
-
includes an individual acting in a business or professional capacity.
|
|
50
|
-
"Affiliate" means any entity that directly or indirectly controls, is
|
|
51
|
-
controlled by, or is under common control with an Organization, where
|
|
52
|
-
"control" means ownership of more than 50% of the voting interests of an
|
|
53
|
-
entity or the power to direct its management and policies by contract or
|
|
54
|
-
otherwise. "Annual Revenue" means the total gross revenue of an
|
|
55
|
-
Organization and all of its Affiliates combined, from all sources and
|
|
56
|
-
whether or not related to the Licensed Work, for its most recently
|
|
57
|
-
completed fiscal year, or, if it has not completed a fiscal year, for the
|
|
58
|
-
twelve months before the use (or since its formation, if shorter),
|
|
59
|
-
converted into US dollars at the average exchange rate for that period.
|
|
60
|
-
Proceeds of equity or debt financing are not revenue.
|
|
61
|
-
|
|
62
|
-
Threshold. If an Organization stops qualifying under (b), its existing
|
|
63
|
-
production use remains Eligible Use for 90 days after it stops
|
|
64
|
-
qualifying, after which it must obtain a commercial license or stop
|
|
65
|
-
production use. Use that was Eligible Use when it occurred never requires
|
|
66
|
-
a commercial license after the fact.
|
|
67
|
-
Change Date: Four years from the date a version of the Licensed Work
|
|
68
|
-
is first publicly released by the Licensor.
|
|
69
|
-
Change License: Apache License, Version 2.0
|
|
70
|
-
|
|
71
|
-
For information about alternative licensing arrangements for the Licensed
|
|
72
|
-
Work, please visit: https://agimon.ai/licensing
|
|
73
|
-
|
|
74
|
-
Notice
|
|
75
|
-
|
|
76
|
-
The Business Source License (this document, or the "License") is not an Open
|
|
77
|
-
Source license. However, the Licensed Work will eventually be made available
|
|
78
|
-
under an Open Source License, as stated in this License.
|
|
79
|
-
|
|
80
|
-
-----------------------------------------------------------------------------
|
|
81
|
-
|
|
82
|
-
Business Source License 1.1
|
|
83
|
-
|
|
84
|
-
Terms
|
|
85
|
-
|
|
86
|
-
The Licensor hereby grants you the right to copy, modify, create derivative
|
|
87
|
-
works, redistribute, and make non-production use of the Licensed Work. The
|
|
88
|
-
Licensor may make an Additional Use Grant, above, permitting limited
|
|
89
|
-
production use.
|
|
90
|
-
|
|
91
|
-
Effective on the Change Date, or the fourth anniversary of the first publicly
|
|
92
|
-
available distribution of a specific version of the Licensed Work under this
|
|
93
|
-
License, whichever comes first, the Licensor hereby grants you rights under
|
|
94
|
-
the terms of the Change License, and the rights granted in the paragraph
|
|
95
|
-
above terminate.
|
|
96
|
-
|
|
97
|
-
If your use of the Licensed Work does not comply with the requirements
|
|
98
|
-
currently in effect as described in this License, you must purchase a
|
|
99
|
-
commercial license from the Licensor, its affiliated entities, or authorized
|
|
100
|
-
resellers, or you must refrain from using the Licensed Work.
|
|
101
|
-
|
|
102
|
-
All copies of the original and modified Licensed Work, and derivative works
|
|
103
|
-
of the Licensed Work, are subject to this License. This License applies
|
|
104
|
-
separately for each version of the Licensed Work and the Change Date may vary
|
|
105
|
-
for each version of the Licensed Work released by Licensor.
|
|
106
|
-
|
|
107
|
-
You must conspicuously display this License on each original or modified copy
|
|
108
|
-
of the Licensed Work. If you receive the Licensed Work in original or
|
|
109
|
-
modified form from a third party, the terms and conditions set forth in this
|
|
110
|
-
License apply to your use of that work.
|
|
111
|
-
|
|
112
|
-
Any use of the Licensed Work in violation of this License will automatically
|
|
113
|
-
terminate your rights under this License for the current and all other
|
|
114
|
-
versions of the Licensed Work.
|
|
115
|
-
|
|
116
|
-
This License does not grant you any right in any trademark or logo of
|
|
117
|
-
Licensor or its affiliates (provided that you may use a trademark or logo of
|
|
118
|
-
Licensor as expressly required by this License).
|
|
119
|
-
|
|
120
|
-
TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON
|
|
121
|
-
AN “AS IS” BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS,
|
|
122
|
-
EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF
|
|
123
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND
|
|
124
|
-
TITLE.
|
|
125
|
-
|
|
126
|
-
MariaDB hereby grants you permission to use this License’s text to license
|
|
127
|
-
your works, and to refer to it using the trademark “Business Source License”,
|
|
128
|
-
as long as you comply with the Covenants of Licensor below.
|
|
129
|
-
|
|
130
|
-
Covenants of Licensor
|
|
131
|
-
|
|
132
|
-
In consideration of the right to use this License’s text and the “Business
|
|
133
|
-
Source License” name and trademark, Licensor covenants to MariaDB, and to all
|
|
134
|
-
other recipients of the licensed work to be provided by Licensor:
|
|
135
|
-
|
|
136
|
-
1. To specify as the Change License the GPL Version 2.0 or any later version,
|
|
137
|
-
or a license that is compatible with GPL Version 2.0 or a later version,
|
|
138
|
-
where “compatible” means that software provided under the Change License can
|
|
139
|
-
be included in a program with software provided under GPL Version 2.0 or a
|
|
140
|
-
later version. Licensor may specify additional Change Licenses without
|
|
141
|
-
limitation.
|
|
142
|
-
|
|
143
|
-
2. To either: (a) specify an additional grant of rights to use that does not
|
|
144
|
-
impose any additional restriction on the right granted in this License, as
|
|
145
|
-
the Additional Use Grant; or (b) insert the text “None”.
|
|
146
|
-
|
|
147
|
-
3. To specify a Change Date.
|
|
148
|
-
|
|
149
|
-
4. Not to modify this License in any other way.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Agimon Pty Ltd
|
|
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,71 +1,34 @@
|
|
|
1
1
|
# @agimon-ai/po-domain
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Domains select composable plugin content for a Po session: skills, agents, and MCP configuration. They are separate from the runtime layers selected by a preset.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
and the minor modes. Unlike a major mode, domains compose: a session selects a set of them, and
|
|
7
|
-
the union of what they contribute is what the model sees.
|
|
5
|
+
The distribution loads this package as fixed host infrastructure. It reads `.po/domains.yaml`; do not add the package to a layer.
|
|
8
6
|
|
|
9
7
|
```yaml
|
|
10
8
|
# .po/domains.yaml
|
|
11
9
|
plugins:
|
|
12
10
|
entries:
|
|
13
|
-
|
|
14
|
-
infra: plugins/infra
|
|
11
|
+
development: plugins/development
|
|
15
12
|
domains:
|
|
16
13
|
development:
|
|
17
|
-
description: Application code
|
|
18
|
-
plugins: [
|
|
19
|
-
mcp:
|
|
20
|
-
servers: [code-intel]
|
|
21
|
-
platform:
|
|
22
|
-
description: Deployment, infrastructure, and incident tooling.
|
|
23
|
-
plugins: [infra]
|
|
14
|
+
description: Application code and review guidance.
|
|
15
|
+
plugins: [development]
|
|
24
16
|
aliases:
|
|
25
|
-
|
|
17
|
+
coding: [development]
|
|
26
18
|
```
|
|
27
19
|
|
|
28
|
-
##
|
|
20
|
+
## Select domains
|
|
29
21
|
|
|
30
|
-
|
|
31
|
-
| ---------- | ----------------------------------------------------- |
|
|
32
|
-
| `/domains` | prints the selection, or switches to `name[,name...]` |
|
|
22
|
+
`/domains` shows or changes the selection. Domains compose: the model receives the union of their admitted content. Selecting a content plugin does not install the runtime capabilities its instructions mention.
|
|
33
23
|
|
|
34
|
-
|
|
35
|
-
`po-author-domain` skill. It provides package-owned guidance for plugin catalogs, domain
|
|
36
|
-
filters, aliases, defaults, shared skills, and MCP scopes in `domains.yaml`. The contribution is
|
|
37
|
-
registered through the session's `po/help` Cordis service and is withdrawn with this package's
|
|
38
|
-
plugin fiber.
|
|
24
|
+
Applying a selection prepares trusted plugin sources, discovered skills and agents, and the session's MCP projection. Config publishes that projection for MCP to consume; Domain does not operate the live MCP runtime directly.
|
|
39
25
|
|
|
40
|
-
|
|
26
|
+
MCP filtering applies only when every selected domain declares an `mcp` allowlist. Mixing an opted-in domain with one that omits it leaves the selection unfiltered. An empty server list is not a deny-all rule. Treat these filters as composition choices, not an execution sandbox.
|
|
41
27
|
|
|
42
|
-
|
|
43
|
-
`@agimon-ai/po-config/selectionSwitch` with the major-mode and profile switches. Applying a
|
|
44
|
-
selection:
|
|
28
|
+
## Authoring guidance
|
|
45
29
|
|
|
46
|
-
-
|
|
47
|
-
cache guarded by an install marker;
|
|
48
|
-
- discovers the exact `SKILL.md` files behind the selection, through a manifest cache keyed by
|
|
49
|
-
worktree so a second session does not rescan the tree;
|
|
50
|
-
- adapts each plugin's Claude-authored agent definitions into the form Pi loads, and stages them
|
|
51
|
-
privately (`0600`) beside a dispatcher agent;
|
|
52
|
-
- merges the repository and legacy plugin `.mcp.json` layers, and validates root `mcp.json` for
|
|
53
|
-
schema-gated Agent Plugins v1 (including plugin-relative commands, data directories, and transport
|
|
54
|
-
normalization);
|
|
55
|
-
- applies the selected domains' MCP allowlists and rewrites the proxy's upstream list into a
|
|
56
|
-
private per-run config; and
|
|
57
|
-
- atomically stores an immutable MCP projection in harness state. Config publishes that snapshot through the session Cordis registry for Po MCP to
|
|
58
|
-
consume; Domain never reaches into the live MCP runtime.
|
|
59
|
-
|
|
60
|
-
An allowlist only takes effect once **every** selected domain declares one. Mixing a scoped domain
|
|
61
|
-
with a domain that has not opted in leaves the session unfiltered, so an unmigrated domain cannot
|
|
62
|
-
silently lose its tools.
|
|
63
|
-
|
|
64
|
-
## Installation
|
|
65
|
-
|
|
66
|
-
Po depends on this package and activates it as fixed host core, so a Po install already has
|
|
67
|
-
it. It is not selectable from `.po/modes.yaml`; it reads `.po/domains.yaml`.
|
|
30
|
+
With Help active, `help-how-to-domain` explains plugin catalogs, aliases, defaults, shared skills, and MCP scopes. Start with the [domain guide](./src/prompts/help-how-to-domain/SKILL.md), published through [`llms.txt`](./llms.txt).
|
|
68
31
|
|
|
69
32
|
## License
|
|
70
33
|
|
|
71
|
-
|
|
34
|
+
MIT. See [LICENSE](LICENSE).
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_zip = require("./zip-DA9sck3v.cjs");
|
|
3
|
+
let node_buffer = require("node:buffer");
|
|
4
|
+
let _agimon_ai_po_config_domains = require("@agimon-ai/po-config/domains");
|
|
5
|
+
let _agimon_ai_po_core_verifiedArchive = require("@agimon-ai/po-core/verifiedArchive");
|
|
6
|
+
//#region src/services/agentArchive/index.ts
|
|
7
|
+
const MANIFEST_PATHS = [
|
|
8
|
+
"plugin.json",
|
|
9
|
+
".codex-plugin/plugin.json",
|
|
10
|
+
".claude-plugin/plugin.json",
|
|
11
|
+
".cursor-plugin/plugin.json"
|
|
12
|
+
];
|
|
13
|
+
const MAX_FILE_BYTES = 8388608;
|
|
14
|
+
const MAX_TAR_BYTES = 67108864;
|
|
15
|
+
const MAX_TGZ_BYTES = 33554432;
|
|
16
|
+
const BLOCK = 512;
|
|
17
|
+
const decoder = new TextDecoder("utf-8", { fatal: true });
|
|
18
|
+
/** Deterministic ustar, all files mode 0644, uid/gid/mtime zero. No input npm metadata survives. */
|
|
19
|
+
function npmTar(files) {
|
|
20
|
+
const chunks = [];
|
|
21
|
+
let size = BLOCK * 2;
|
|
22
|
+
for (const [relative, body] of [...files].sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0)) {
|
|
23
|
+
let name = `package/${relative}`;
|
|
24
|
+
let prefix = "";
|
|
25
|
+
if (node_buffer.Buffer.byteLength(name) > 100) {
|
|
26
|
+
const slash = name.lastIndexOf("/");
|
|
27
|
+
prefix = name.slice(0, slash);
|
|
28
|
+
name = name.slice(slash + 1);
|
|
29
|
+
}
|
|
30
|
+
if (node_buffer.Buffer.byteLength(name) > 100 || node_buffer.Buffer.byteLength(prefix) > 155) throw new Error("Agent archive path is too long.");
|
|
31
|
+
size += BLOCK + Math.ceil(body.length / BLOCK) * BLOCK;
|
|
32
|
+
if (size > MAX_TAR_BYTES) throw new Error("Normalized archive exceeds the expanded size limit.");
|
|
33
|
+
const header = node_buffer.Buffer.alloc(BLOCK);
|
|
34
|
+
const octal = (value, offset, width) => {
|
|
35
|
+
header.write(`${value.toString(8).padStart(width - 1, "0")}\0`, offset, width, "ascii");
|
|
36
|
+
};
|
|
37
|
+
header.write(name, 0, 100, "utf8");
|
|
38
|
+
octal(420, 100, 8);
|
|
39
|
+
octal(0, 108, 8);
|
|
40
|
+
octal(0, 116, 8);
|
|
41
|
+
octal(body.length, 124, 12);
|
|
42
|
+
octal(0, 136, 12);
|
|
43
|
+
header.fill(32, 148, 156);
|
|
44
|
+
header[156] = 48;
|
|
45
|
+
header.write("ustar\0", 257, 6, "ascii");
|
|
46
|
+
header.write("00", 263, 2, "ascii");
|
|
47
|
+
header.write(prefix, 345, 155, "utf8");
|
|
48
|
+
octal(header.reduce((sum, byte) => sum + byte, 0), 148, 8);
|
|
49
|
+
chunks.push(header, body, node_buffer.Buffer.alloc((BLOCK - body.length % BLOCK) % BLOCK));
|
|
50
|
+
}
|
|
51
|
+
chunks.push(node_buffer.Buffer.alloc(BLOCK * 2));
|
|
52
|
+
return chunks;
|
|
53
|
+
}
|
|
54
|
+
/** The one manifest Desktop activation reads. A root plugin.json counts only with the Agent Plugins schema. */
|
|
55
|
+
function agentManifest(files, root = "") {
|
|
56
|
+
const candidates = MANIFEST_PATHS.filter((path) => files.has(root + path));
|
|
57
|
+
if (candidates.length !== 1) throw new Error("An agent archive requires exactly one plugin manifest.");
|
|
58
|
+
const text = decoder.decode(files.get(root + candidates[0]));
|
|
59
|
+
if (candidates[0] === "plugin.json" && !(0, _agimon_ai_po_config_domains.isAgentPluginRootManifest)(text)) throw new Error("A root plugin.json needs an Agent Plugins $schema, or Desktop cannot enable it.");
|
|
60
|
+
const manifest = JSON.parse(text);
|
|
61
|
+
if (!manifest || typeof manifest !== "object" || Array.isArray(manifest)) throw new Error("Invalid agent manifest.");
|
|
62
|
+
return manifest;
|
|
63
|
+
}
|
|
64
|
+
async function normalizeAgentFiles(files) {
|
|
65
|
+
const candidates = [...files.keys()].filter((path) => MANIFEST_PATHS.some((manifest) => path === manifest || path.endsWith(`/${manifest}`)));
|
|
66
|
+
if (candidates.length !== 1) throw new Error("An agent ZIP requires exactly one plugin manifest.");
|
|
67
|
+
const manifestPath = candidates[0];
|
|
68
|
+
const root = MANIFEST_PATHS.includes(manifestPath) ? "" : manifestPath.slice(0, manifestPath.indexOf("/") + 1);
|
|
69
|
+
if (!MANIFEST_PATHS.includes(manifestPath.slice(root.length))) throw new Error("Agent manifest must be at root or inside one wrapper folder.");
|
|
70
|
+
if (root && [...files.keys()].some((path) => !path.startsWith(root))) throw new Error("Agent ZIP has files outside its wrapper folder.");
|
|
71
|
+
const { name, version } = agentManifest(files, root);
|
|
72
|
+
if (typeof name !== "string" || name.length > 214 || !_agimon_ai_po_core_verifiedArchive.npmPackageName.test(name) || typeof version !== "string" || version.length > 128 || !_agimon_ai_po_core_verifiedArchive.exactPackageVersion.test(version)) throw new Error("The agent manifest requires an exact npm name and version.");
|
|
73
|
+
const normalized = /* @__PURE__ */ new Map();
|
|
74
|
+
for (const [path, body] of files) {
|
|
75
|
+
const relative = path.slice(root.length);
|
|
76
|
+
if ([
|
|
77
|
+
"package.json",
|
|
78
|
+
"package-lock.json",
|
|
79
|
+
"npm-shrinkwrap.json",
|
|
80
|
+
".npmrc"
|
|
81
|
+
].includes(relative.split("/")[0])) continue;
|
|
82
|
+
normalized.set(relative, body);
|
|
83
|
+
}
|
|
84
|
+
normalized.set("package.json", new TextEncoder().encode(`${JSON.stringify({
|
|
85
|
+
name,
|
|
86
|
+
version
|
|
87
|
+
})}\n`));
|
|
88
|
+
return {
|
|
89
|
+
bytes: await packPluginFiles(normalized),
|
|
90
|
+
name,
|
|
91
|
+
version
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
/** Pack a bounded, already checked set of relative paths without running package scripts. */
|
|
95
|
+
async function packPluginFiles(files) {
|
|
96
|
+
const chunks = npmTar(files)[Symbol.iterator]();
|
|
97
|
+
const tar = new ReadableStream({ pull(controller) {
|
|
98
|
+
const next = chunks.next();
|
|
99
|
+
if (next.done) controller.close();
|
|
100
|
+
else controller.enqueue(next.value);
|
|
101
|
+
} });
|
|
102
|
+
return (0, _agimon_ai_po_core_verifiedArchive.readBoundedBody)(tar.pipeThrough(new CompressionStream("gzip")), MAX_TGZ_BYTES);
|
|
103
|
+
}
|
|
104
|
+
/** Accept one agent manifest at root or inside one wrapper folder. Package identity comes only from it. */
|
|
105
|
+
async function normalizeAgentZip(bytes) {
|
|
106
|
+
const files = /* @__PURE__ */ new Map();
|
|
107
|
+
for await (const member of require_zip.readBoundedZip(bytes, {
|
|
108
|
+
fileBytes: MAX_FILE_BYTES,
|
|
109
|
+
entries: 4095
|
|
110
|
+
})) if (!member.directory) files.set(member.path, member.bytes);
|
|
111
|
+
return normalizeAgentFiles(files);
|
|
112
|
+
}
|
|
113
|
+
//#endregion
|
|
114
|
+
exports.agentManifest = agentManifest;
|
|
115
|
+
exports.normalizeAgentFiles = normalizeAgentFiles;
|
|
116
|
+
exports.normalizeAgentZip = normalizeAgentZip;
|
|
117
|
+
exports.packPluginFiles = packPluginFiles;
|
|
118
|
+
exports.readBoundedZip = require_zip.readBoundedZip;
|
|
119
|
+
|
|
120
|
+
//# sourceMappingURL=agentArchive.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agentArchive.cjs","names":["Buffer","isAgentPluginRootManifest","npmPackageName","exactPackageVersion","readBoundedBody","readBoundedZip"],"sources":["../src/services/agentArchive/index.ts"],"sourcesContent":["import { Buffer } from 'node:buffer';\n\nimport { isAgentPluginRootManifest } from '@agimon-ai/po-config/domains';\nimport { exactPackageVersion, npmPackageName, readBoundedBody } from '@agimon-ai/po-core/verifiedArchive';\n\nimport type { NormalizedAgentArchive } from './type';\nimport { readBoundedZip } from './zip';\n\nconst MANIFEST_PATHS = [\n 'plugin.json',\n '.codex-plugin/plugin.json',\n '.claude-plugin/plugin.json',\n '.cursor-plugin/plugin.json',\n];\nconst MAX_FILE_BYTES = 8 * 1024 * 1024;\nconst MAX_TAR_BYTES = 64 * 1024 * 1024;\nconst MAX_TGZ_BYTES = 32 * 1024 * 1024;\nconst BLOCK = 512;\nconst decoder = new TextDecoder('utf-8', { fatal: true });\n\n/** Deterministic ustar, all files mode 0644, uid/gid/mtime zero. No input npm metadata survives. */\nfunction npmTar(files: ReadonlyMap<string, Uint8Array<ArrayBuffer>>): Uint8Array<ArrayBuffer>[] {\n const chunks: Uint8Array<ArrayBuffer>[] = [];\n let size = BLOCK * 2;\n for (const [relative, body] of [...files].sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))) {\n let name = `package/${relative}`;\n let prefix = '';\n if (Buffer.byteLength(name) > 100) {\n const slash = name.lastIndexOf('/');\n prefix = name.slice(0, slash);\n name = name.slice(slash + 1);\n }\n if (Buffer.byteLength(name) > 100 || Buffer.byteLength(prefix) > 155)\n throw new Error('Agent archive path is too long.');\n size += BLOCK + Math.ceil(body.length / BLOCK) * BLOCK;\n if (size > MAX_TAR_BYTES) throw new Error('Normalized archive exceeds the expanded size limit.');\n const header = Buffer.alloc(BLOCK);\n const octal = (value: number, offset: number, width: number) => {\n header.write(`${value.toString(8).padStart(width - 1, '0')}\\0`, offset, width, 'ascii');\n };\n header.write(name, 0, 100, 'utf8');\n octal(0o644, 100, 8);\n octal(0, 108, 8);\n octal(0, 116, 8);\n octal(body.length, 124, 12);\n octal(0, 136, 12);\n header.fill(32, 148, 156);\n header[156] = 48;\n header.write('ustar\\0', 257, 6, 'ascii');\n header.write('00', 263, 2, 'ascii');\n header.write(prefix, 345, 155, 'utf8');\n octal(\n header.reduce((sum, byte) => sum + byte, 0),\n 148,\n 8,\n );\n chunks.push(header, body, Buffer.alloc((BLOCK - (body.length % BLOCK)) % BLOCK));\n }\n chunks.push(Buffer.alloc(BLOCK * 2));\n return chunks;\n}\n\n/** The one manifest Desktop activation reads. A root plugin.json counts only with the Agent Plugins schema. */\nexport function agentManifest(files: ReadonlyMap<string, Uint8Array>, root = ''): Record<string, unknown> {\n const candidates = MANIFEST_PATHS.filter((path) => files.has(root + path));\n if (candidates.length !== 1) throw new Error('An agent archive requires exactly one plugin manifest.');\n const text = decoder.decode(files.get(root + candidates[0]!)!);\n if (candidates[0] === 'plugin.json' && !isAgentPluginRootManifest(text))\n throw new Error('A root plugin.json needs an Agent Plugins $schema, or Desktop cannot enable it.');\n const manifest: unknown = JSON.parse(text);\n if (!manifest || typeof manifest !== 'object' || Array.isArray(manifest)) throw new Error('Invalid agent manifest.');\n return manifest as Record<string, unknown>;\n}\nexport async function normalizeAgentFiles(\n files: ReadonlyMap<string, Uint8Array<ArrayBuffer>>,\n): Promise<NormalizedAgentArchive> {\n const candidates = [...files.keys()].filter((path) =>\n MANIFEST_PATHS.some((manifest) => path === manifest || path.endsWith(`/${manifest}`)),\n );\n if (candidates.length !== 1) throw new Error('An agent ZIP requires exactly one plugin manifest.');\n const manifestPath = candidates[0]!;\n const root = MANIFEST_PATHS.includes(manifestPath) ? '' : manifestPath.slice(0, manifestPath.indexOf('/') + 1);\n if (!MANIFEST_PATHS.includes(manifestPath.slice(root.length)))\n throw new Error('Agent manifest must be at root or inside one wrapper folder.');\n if (root && [...files.keys()].some((path) => !path.startsWith(root)))\n throw new Error('Agent ZIP has files outside its wrapper folder.');\n const { name, version } = agentManifest(files, root);\n if (\n typeof name !== 'string' ||\n name.length > 214 ||\n !npmPackageName.test(name) ||\n typeof version !== 'string' ||\n version.length > 128 ||\n !exactPackageVersion.test(version)\n ) {\n throw new Error('The agent manifest requires an exact npm name and version.');\n }\n const normalized = new Map<string, Uint8Array<ArrayBuffer>>();\n for (const [path, body] of files) {\n const relative = path.slice(root.length);\n if (['package.json', 'package-lock.json', 'npm-shrinkwrap.json', '.npmrc'].includes(relative.split('/')[0]!))\n continue;\n normalized.set(relative, body);\n }\n normalized.set('package.json', new TextEncoder().encode(`${JSON.stringify({ name, version })}\\n`));\n return { bytes: await packPluginFiles(normalized), name, version };\n}\n\n/** Pack a bounded, already checked set of relative paths without running package scripts. */\nexport async function packPluginFiles(\n files: ReadonlyMap<string, Uint8Array<ArrayBuffer>>,\n): Promise<Uint8Array<ArrayBuffer>> {\n // Stream tar headers and existing file buffers, never allocate another expanded archive in workerd.\n const chunks = npmTar(files)[Symbol.iterator]();\n const tar = new ReadableStream<Uint8Array<ArrayBuffer>>({\n pull(controller) {\n const next = chunks.next();\n if (next.done) controller.close();\n else controller.enqueue(next.value);\n },\n });\n return readBoundedBody(tar.pipeThrough(new CompressionStream('gzip')), MAX_TGZ_BYTES);\n}\n\n/** Accept one agent manifest at root or inside one wrapper folder. Package identity comes only from it. */\nexport async function normalizeAgentZip(bytes: Uint8Array): Promise<NormalizedAgentArchive> {\n const files = new Map<string, Uint8Array<ArrayBuffer>>();\n for await (const member of readBoundedZip(bytes, { fileBytes: MAX_FILE_BYTES, entries: 4095 })) {\n if (!member.directory) files.set(member.path, member.bytes);\n }\n return normalizeAgentFiles(files);\n}\n"],"mappings":";;;;;;AAQA,MAAM,iBAAiB;CACrB;CACA;CACA;CACA;AACF;AACA,MAAM,iBAAiB;AACvB,MAAM,gBAAgB;AACtB,MAAM,gBAAgB;AACtB,MAAM,QAAQ;AACd,MAAM,UAAU,IAAI,YAAY,SAAS,EAAE,OAAO,KAAK,CAAC;;AAGxD,SAAS,OAAO,OAAgF;CAC9F,MAAM,SAAoC,CAAC;CAC3C,IAAI,OAAO,QAAQ;CACnB,KAAK,MAAM,CAAC,UAAU,SAAS,CAAC,GAAG,KAAK,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,OAAQ,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI,CAAE,GAAG;EAC1F,IAAI,OAAO,WAAW;EACtB,IAAI,SAAS;EACb,IAAIA,YAAAA,OAAO,WAAW,IAAI,IAAI,KAAK;GACjC,MAAM,QAAQ,KAAK,YAAY,GAAG;GAClC,SAAS,KAAK,MAAM,GAAG,KAAK;GAC5B,OAAO,KAAK,MAAM,QAAQ,CAAC;EAC7B;EACA,IAAIA,YAAAA,OAAO,WAAW,IAAI,IAAI,OAAOA,YAAAA,OAAO,WAAW,MAAM,IAAI,KAC/D,MAAM,IAAI,MAAM,iCAAiC;EACnD,QAAQ,QAAQ,KAAK,KAAK,KAAK,SAAS,KAAK,I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I,YAAY,CAAC,CAAC,OAAO,GAAG,KAAK,UAAU;EAAE;EAAM;CAAQ,CAAC,EAAE,GAAG,CAAC;CACjG,OAAO;EAAE,OAAO,MAAM,gBAAgB,UAAU;EAAG;EAAM;CAAQ;AACnE;;AAGA,eAAsB,gBACpB,OACkC;CAElC,MAAM,SAAS,OAAO,KAAK,CAAC,CAAC,OAAO,SAAS,CAAC;CAC9C,MAAM,MAAM,IAAI,eAAwC,EACtD,KAAK,YAAY;EACf,MAAM,OAAO,OAAO,KAAK;EACzB,IAAI,KAAK,MAAM,WAAW,MAAM;OAC3B,WAAW,QAAQ,KAAK,KAAK;CACpC,EACF,CAAC;CACD,QAAA,GAAOC,mCAAAA,gBAAAA,CAAgB,IAAI,YAAY,IAAI,kBAAkB,MAAM,CAAC,GAAG,aAAa;AACtF;;AAGA,eAAsB,kBAAkB,OAAoD;CAC1F,MAAM,wBAAQ,IAAI,IAAqC;CACvD,WAAW,MAAM,UAAUC,YAAAA,eAAe,OAAO;EAAE,WAAW;EAAgB,SAAS;CAAK,CAAC,GAC3F,IAAI,CAAC,OAAO,WAAW,MAAM,IAAI,OAAO,MAAM,OAAO,KAAK;CAE5D,OAAO,oBAAoB,KAAK;AAClC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
//#region src/services/agentArchive/type.d.ts
|
|
2
|
+
interface ZipLimits {
|
|
3
|
+
archiveBytes?: number;
|
|
4
|
+
expandedBytes?: number;
|
|
5
|
+
fileBytes?: number;
|
|
6
|
+
entries?: number;
|
|
7
|
+
}
|
|
8
|
+
interface ZipMember {
|
|
9
|
+
path: string;
|
|
10
|
+
directory: boolean;
|
|
11
|
+
bytes: Uint8Array<ArrayBuffer>;
|
|
12
|
+
}
|
|
13
|
+
interface NormalizedAgentArchive {
|
|
14
|
+
bytes: Uint8Array<ArrayBuffer>;
|
|
15
|
+
name: string;
|
|
16
|
+
version: string;
|
|
17
|
+
}
|
|
18
|
+
//#endregion
|
|
19
|
+
//#region src/services/agentArchive/index.d.ts
|
|
20
|
+
/** The one manifest Desktop activation reads. A root plugin.json counts only with the Agent Plugins schema. */
|
|
21
|
+
export declare function agentManifest(files: ReadonlyMap<string, Uint8Array>, root?: string): Record<string, unknown>;
|
|
22
|
+
export declare function normalizeAgentFiles(files: ReadonlyMap<string, Uint8Array<ArrayBuffer>>): Promise<NormalizedAgentArchive>;
|
|
23
|
+
/** Pack a bounded, already checked set of relative paths without running package scripts. */
|
|
24
|
+
export declare function packPluginFiles(files: ReadonlyMap<string, Uint8Array<ArrayBuffer>>): Promise<Uint8Array<ArrayBuffer>>;
|
|
25
|
+
/** Accept one agent manifest at root or inside one wrapper folder. Package identity comes only from it. */
|
|
26
|
+
export declare function normalizeAgentZip(bytes: Uint8Array): Promise<NormalizedAgentArchive>;
|
|
27
|
+
//#endregion
|
|
28
|
+
//#region src/services/agentArchive/zip.d.ts
|
|
29
|
+
/** The single yauzl reader shared by local uploads and cloud normalization. Never executes archive content. */
|
|
30
|
+
export declare function readBoundedZip(bytes: Uint8Array, requested?: ZipLimits): AsyncGenerator<ZipMember>;
|
|
31
|
+
//#endregion
|
|
32
|
+
export type { NormalizedAgentArchive, ZipLimits, ZipMember };
|
|
33
|
+
//# sourceMappingURL=agentArchive.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agentArchive.d.mts","names":[],"sources":["../src/services/agentArchive/type.ts","../src/services/agentArchive/index.ts","../src/services/agentArchive/zip.ts"],"mappings":";UAAiB;EACf;EACA;EACA;EACA;;UAGe;EACf;EACA;EACA,OAAO,WAAW;;UAGH;EACf,OAAO,WAAW;EAClB;EACA;;;;;wBC+Cc,cAAc,OAAO,oBAAoB,aAAa,gBAAY;wBAU5D,oBACpB,OAAO,oBAAoB,WAAW,gBACrC,QAAQ;;wBAkCW,gBACpB,OAAO,oBAAoB,WAAW,gBACrC,QAAQ,WAAW;;wBAcA,kBAAkB,OAAO,aAAa,QAAQ;;;;wBCjH7C,eAAe,OAAO,YAAY,YAAW,YAAiB,eAAe"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { t as readBoundedZip } from "./zip-Bl6pG9Ap.mjs";
|
|
2
|
+
import { Buffer } from "node:buffer";
|
|
3
|
+
import { isAgentPluginRootManifest } from "@agimon-ai/po-config/domains";
|
|
4
|
+
import { exactPackageVersion, npmPackageName, readBoundedBody } from "@agimon-ai/po-core/verifiedArchive";
|
|
5
|
+
//#region src/services/agentArchive/index.ts
|
|
6
|
+
const MANIFEST_PATHS = [
|
|
7
|
+
"plugin.json",
|
|
8
|
+
".codex-plugin/plugin.json",
|
|
9
|
+
".claude-plugin/plugin.json",
|
|
10
|
+
".cursor-plugin/plugin.json"
|
|
11
|
+
];
|
|
12
|
+
const MAX_FILE_BYTES = 8388608;
|
|
13
|
+
const MAX_TAR_BYTES = 67108864;
|
|
14
|
+
const MAX_TGZ_BYTES = 33554432;
|
|
15
|
+
const BLOCK = 512;
|
|
16
|
+
const decoder = new TextDecoder("utf-8", { fatal: true });
|
|
17
|
+
/** Deterministic ustar, all files mode 0644, uid/gid/mtime zero. No input npm metadata survives. */
|
|
18
|
+
function npmTar(files) {
|
|
19
|
+
const chunks = [];
|
|
20
|
+
let size = BLOCK * 2;
|
|
21
|
+
for (const [relative, body] of [...files].sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0)) {
|
|
22
|
+
let name = `package/${relative}`;
|
|
23
|
+
let prefix = "";
|
|
24
|
+
if (Buffer.byteLength(name) > 100) {
|
|
25
|
+
const slash = name.lastIndexOf("/");
|
|
26
|
+
prefix = name.slice(0, slash);
|
|
27
|
+
name = name.slice(slash + 1);
|
|
28
|
+
}
|
|
29
|
+
if (Buffer.byteLength(name) > 100 || Buffer.byteLength(prefix) > 155) throw new Error("Agent archive path is too long.");
|
|
30
|
+
size += BLOCK + Math.ceil(body.length / BLOCK) * BLOCK;
|
|
31
|
+
if (size > MAX_TAR_BYTES) throw new Error("Normalized archive exceeds the expanded size limit.");
|
|
32
|
+
const header = Buffer.alloc(BLOCK);
|
|
33
|
+
const octal = (value, offset, width) => {
|
|
34
|
+
header.write(`${value.toString(8).padStart(width - 1, "0")}\0`, offset, width, "ascii");
|
|
35
|
+
};
|
|
36
|
+
header.write(name, 0, 100, "utf8");
|
|
37
|
+
octal(420, 100, 8);
|
|
38
|
+
octal(0, 108, 8);
|
|
39
|
+
octal(0, 116, 8);
|
|
40
|
+
octal(body.length, 124, 12);
|
|
41
|
+
octal(0, 136, 12);
|
|
42
|
+
header.fill(32, 148, 156);
|
|
43
|
+
header[156] = 48;
|
|
44
|
+
header.write("ustar\0", 257, 6, "ascii");
|
|
45
|
+
header.write("00", 263, 2, "ascii");
|
|
46
|
+
header.write(prefix, 345, 155, "utf8");
|
|
47
|
+
octal(header.reduce((sum, byte) => sum + byte, 0), 148, 8);
|
|
48
|
+
chunks.push(header, body, Buffer.alloc((BLOCK - body.length % BLOCK) % BLOCK));
|
|
49
|
+
}
|
|
50
|
+
chunks.push(Buffer.alloc(BLOCK * 2));
|
|
51
|
+
return chunks;
|
|
52
|
+
}
|
|
53
|
+
/** The one manifest Desktop activation reads. A root plugin.json counts only with the Agent Plugins schema. */
|
|
54
|
+
function agentManifest(files, root = "") {
|
|
55
|
+
const candidates = MANIFEST_PATHS.filter((path) => files.has(root + path));
|
|
56
|
+
if (candidates.length !== 1) throw new Error("An agent archive requires exactly one plugin manifest.");
|
|
57
|
+
const text = decoder.decode(files.get(root + candidates[0]));
|
|
58
|
+
if (candidates[0] === "plugin.json" && !isAgentPluginRootManifest(text)) throw new Error("A root plugin.json needs an Agent Plugins $schema, or Desktop cannot enable it.");
|
|
59
|
+
const manifest = JSON.parse(text);
|
|
60
|
+
if (!manifest || typeof manifest !== "object" || Array.isArray(manifest)) throw new Error("Invalid agent manifest.");
|
|
61
|
+
return manifest;
|
|
62
|
+
}
|
|
63
|
+
async function normalizeAgentFiles(files) {
|
|
64
|
+
const candidates = [...files.keys()].filter((path) => MANIFEST_PATHS.some((manifest) => path === manifest || path.endsWith(`/${manifest}`)));
|
|
65
|
+
if (candidates.length !== 1) throw new Error("An agent ZIP requires exactly one plugin manifest.");
|
|
66
|
+
const manifestPath = candidates[0];
|
|
67
|
+
const root = MANIFEST_PATHS.includes(manifestPath) ? "" : manifestPath.slice(0, manifestPath.indexOf("/") + 1);
|
|
68
|
+
if (!MANIFEST_PATHS.includes(manifestPath.slice(root.length))) throw new Error("Agent manifest must be at root or inside one wrapper folder.");
|
|
69
|
+
if (root && [...files.keys()].some((path) => !path.startsWith(root))) throw new Error("Agent ZIP has files outside its wrapper folder.");
|
|
70
|
+
const { name, version } = agentManifest(files, root);
|
|
71
|
+
if (typeof name !== "string" || name.length > 214 || !npmPackageName.test(name) || typeof version !== "string" || version.length > 128 || !exactPackageVersion.test(version)) throw new Error("The agent manifest requires an exact npm name and version.");
|
|
72
|
+
const normalized = /* @__PURE__ */ new Map();
|
|
73
|
+
for (const [path, body] of files) {
|
|
74
|
+
const relative = path.slice(root.length);
|
|
75
|
+
if ([
|
|
76
|
+
"package.json",
|
|
77
|
+
"package-lock.json",
|
|
78
|
+
"npm-shrinkwrap.json",
|
|
79
|
+
".npmrc"
|
|
80
|
+
].includes(relative.split("/")[0])) continue;
|
|
81
|
+
normalized.set(relative, body);
|
|
82
|
+
}
|
|
83
|
+
normalized.set("package.json", new TextEncoder().encode(`${JSON.stringify({
|
|
84
|
+
name,
|
|
85
|
+
version
|
|
86
|
+
})}\n`));
|
|
87
|
+
return {
|
|
88
|
+
bytes: await packPluginFiles(normalized),
|
|
89
|
+
name,
|
|
90
|
+
version
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
/** Pack a bounded, already checked set of relative paths without running package scripts. */
|
|
94
|
+
async function packPluginFiles(files) {
|
|
95
|
+
const chunks = npmTar(files)[Symbol.iterator]();
|
|
96
|
+
const tar = new ReadableStream({ pull(controller) {
|
|
97
|
+
const next = chunks.next();
|
|
98
|
+
if (next.done) controller.close();
|
|
99
|
+
else controller.enqueue(next.value);
|
|
100
|
+
} });
|
|
101
|
+
return readBoundedBody(tar.pipeThrough(new CompressionStream("gzip")), MAX_TGZ_BYTES);
|
|
102
|
+
}
|
|
103
|
+
/** Accept one agent manifest at root or inside one wrapper folder. Package identity comes only from it. */
|
|
104
|
+
async function normalizeAgentZip(bytes) {
|
|
105
|
+
const files = /* @__PURE__ */ new Map();
|
|
106
|
+
for await (const member of readBoundedZip(bytes, {
|
|
107
|
+
fileBytes: MAX_FILE_BYTES,
|
|
108
|
+
entries: 4095
|
|
109
|
+
})) if (!member.directory) files.set(member.path, member.bytes);
|
|
110
|
+
return normalizeAgentFiles(files);
|
|
111
|
+
}
|
|
112
|
+
//#endregion
|
|
113
|
+
export { agentManifest, normalizeAgentFiles, normalizeAgentZip, packPluginFiles, readBoundedZip };
|
|
114
|
+
|
|
115
|
+
//# sourceMappingURL=agentArchive.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agentArchive.mjs","names":[],"sources":["../src/services/agentArchive/index.ts"],"sourcesContent":["import { Buffer } from 'node:buffer';\n\nimport { isAgentPluginRootManifest } from '@agimon-ai/po-config/domains';\nimport { exactPackageVersion, npmPackageName, readBoundedBody } from '@agimon-ai/po-core/verifiedArchive';\n\nimport type { NormalizedAgentArchive } from './type';\nimport { readBoundedZip } from './zip';\n\nconst MANIFEST_PATHS = [\n 'plugin.json',\n '.codex-plugin/plugin.json',\n '.claude-plugin/plugin.json',\n '.cursor-plugin/plugin.json',\n];\nconst MAX_FILE_BYTES = 8 * 1024 * 1024;\nconst MAX_TAR_BYTES = 64 * 1024 * 1024;\nconst MAX_TGZ_BYTES = 32 * 1024 * 1024;\nconst BLOCK = 512;\nconst decoder = new TextDecoder('utf-8', { fatal: true });\n\n/** Deterministic ustar, all files mode 0644, uid/gid/mtime zero. No input npm metadata survives. */\nfunction npmTar(files: ReadonlyMap<string, Uint8Array<ArrayBuffer>>): Uint8Array<ArrayBuffer>[] {\n const chunks: Uint8Array<ArrayBuffer>[] = [];\n let size = BLOCK * 2;\n for (const [relative, body] of [...files].sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))) {\n let name = `package/${relative}`;\n let prefix = '';\n if (Buffer.byteLength(name) > 100) {\n const slash = name.lastIndexOf('/');\n prefix = name.slice(0, slash);\n name = name.slice(slash + 1);\n }\n if (Buffer.byteLength(name) > 100 || Buffer.byteLength(prefix) > 155)\n throw new Error('Agent archive path is too long.');\n size += BLOCK + Math.ceil(body.length / BLOCK) * BLOCK;\n if (size > MAX_TAR_BYTES) throw new Error('Normalized archive exceeds the expanded size limit.');\n const header = Buffer.alloc(BLOCK);\n const octal = (value: number, offset: number, width: number) => {\n header.write(`${value.toString(8).padStart(width - 1, '0')}\\0`, offset, width, 'ascii');\n };\n header.write(name, 0, 100, 'utf8');\n octal(0o644, 100, 8);\n octal(0, 108, 8);\n octal(0, 116, 8);\n octal(body.length, 124, 12);\n octal(0, 136, 12);\n header.fill(32, 148, 156);\n header[156] = 48;\n header.write('ustar\\0', 257, 6, 'ascii');\n header.write('00', 263, 2, 'ascii');\n header.write(prefix, 345, 155, 'utf8');\n octal(\n header.reduce((sum, byte) => sum + byte, 0),\n 148,\n 8,\n );\n chunks.push(header, body, Buffer.alloc((BLOCK - (body.length % BLOCK)) % BLOCK));\n }\n chunks.push(Buffer.alloc(BLOCK * 2));\n return chunks;\n}\n\n/** The one manifest Desktop activation reads. A root plugin.json counts only with the Agent Plugins schema. */\nexport function agentManifest(files: ReadonlyMap<string, Uint8Array>, root = ''): Record<string, unknown> {\n const candidates = MANIFEST_PATHS.filter((path) => files.has(root + path));\n if (candidates.length !== 1) throw new Error('An agent archive requires exactly one plugin manifest.');\n const text = decoder.decode(files.get(root + candidates[0]!)!);\n if (candidates[0] === 'plugin.json' && !isAgentPluginRootManifest(text))\n throw new Error('A root plugin.json needs an Agent Plugins $schema, or Desktop cannot enable it.');\n const manifest: unknown = JSON.parse(text);\n if (!manifest || typeof manifest !== 'object' || Array.isArray(manifest)) throw new Error('Invalid agent manifest.');\n return manifest as Record<string, unknown>;\n}\nexport async function normalizeAgentFiles(\n files: ReadonlyMap<string, Uint8Array<ArrayBuffer>>,\n): Promise<NormalizedAgentArchive> {\n const candidates = [...files.keys()].filter((path) =>\n MANIFEST_PATHS.some((manifest) => path === manifest || path.endsWith(`/${manifest}`)),\n );\n if (candidates.length !== 1) throw new Error('An agent ZIP requires exactly one plugin manifest.');\n const manifestPath = candidates[0]!;\n const root = MANIFEST_PATHS.includes(manifestPath) ? '' : manifestPath.slice(0, manifestPath.indexOf('/') + 1);\n if (!MANIFEST_PATHS.includes(manifestPath.slice(root.length)))\n throw new Error('Agent manifest must be at root or inside one wrapper folder.');\n if (root && [...files.keys()].some((path) => !path.startsWith(root)))\n throw new Error('Agent ZIP has files outside its wrapper folder.');\n const { name, version } = agentManifest(files, root);\n if (\n typeof name !== 'string' ||\n name.length > 214 ||\n !npmPackageName.test(name) ||\n typeof version !== 'string' ||\n version.length > 128 ||\n !exactPackageVersion.test(version)\n ) {\n throw new Error('The agent manifest requires an exact npm name and version.');\n }\n const normalized = new Map<string, Uint8Array<ArrayBuffer>>();\n for (const [path, body] of files) {\n const relative = path.slice(root.length);\n if (['package.json', 'package-lock.json', 'npm-shrinkwrap.json', '.npmrc'].includes(relative.split('/')[0]!))\n continue;\n normalized.set(relative, body);\n }\n normalized.set('package.json', new TextEncoder().encode(`${JSON.stringify({ name, version })}\\n`));\n return { bytes: await packPluginFiles(normalized), name, version };\n}\n\n/** Pack a bounded, already checked set of relative paths without running package scripts. */\nexport async function packPluginFiles(\n files: ReadonlyMap<string, Uint8Array<ArrayBuffer>>,\n): Promise<Uint8Array<ArrayBuffer>> {\n // Stream tar headers and existing file buffers, never allocate another expanded archive in workerd.\n const chunks = npmTar(files)[Symbol.iterator]();\n const tar = new ReadableStream<Uint8Array<ArrayBuffer>>({\n pull(controller) {\n const next = chunks.next();\n if (next.done) controller.close();\n else controller.enqueue(next.value);\n },\n });\n return readBoundedBody(tar.pipeThrough(new CompressionStream('gzip')), MAX_TGZ_BYTES);\n}\n\n/** Accept one agent manifest at root or inside one wrapper folder. Package identity comes only from it. */\nexport async function normalizeAgentZip(bytes: Uint8Array): Promise<NormalizedAgentArchive> {\n const files = new Map<string, Uint8Array<ArrayBuffer>>();\n for await (const member of readBoundedZip(bytes, { fileBytes: MAX_FILE_BYTES, entries: 4095 })) {\n if (!member.directory) files.set(member.path, member.bytes);\n }\n return normalizeAgentFiles(files);\n}\n"],"mappings":";;;;;AAQA,MAAM,iBAAiB;CACrB;CACA;CACA;CACA;AACF;AACA,MAAM,iBAAiB;AACvB,MAAM,gBAAgB;AACtB,MAAM,gBAAgB;AACtB,MAAM,QAAQ;AACd,MAAM,UAAU,IAAI,YAAY,SAAS,EAAE,OAAO,KAAK,CAAC;;AAGxD,SAAS,OAAO,OAAgF;CAC9F,MAAM,SAAoC,CAAC;CAC3C,IAAI,OAAO,QAAQ;CACnB,KAAK,MAAM,CAAC,UAAU,SAAS,CAAC,GAAG,KAAK,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,OAAQ,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI,CAAE,GAAG;EAC1F,IAAI,OAAO,WAAW;EACtB,IAAI,SAAS;EACb,IAAI,OAAO,WAAW,IAAI,IAAI,KAAK;GACjC,MAAM,QAAQ,KAAK,YAAY,GAAG;GAClC,SAAS,KAAK,MAAM,GAAG,KAAK;GAC5B,OAAO,KAAK,MAAM,QAAQ,CAAC;EAC7B;EACA,IAAI,OAAO,WAAW,IAAI,IAAI,OAAO,OAAO,WAAW,MAAM,IAAI,KAC/D,MAAM,IAAI,MAAM,iCAAiC;EACnD,QAAQ,QAAQ,KAAK,KAAK,KAAK,SAAS,KAAK,IAAI;EACjD,IAAI,OAAO,eAAe,MAAM,IAAI,MAAM,qDAAqD;EAC/F,MAAM,SAAS,OAAO,MAAM,KAAK;EACjC,MAAM,SAAS,OAAe,QAAgB,UAAkB;GAC9D,OAAO,MAAM,GA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