@inventarch/distribution 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/NOTICE +4 -0
- package/README.md +2 -2
- package/SPEC.md +3 -0
- package/assets/host-launcher.mjs +167 -0
- package/dist/acquire.d.ts +13 -0
- package/dist/acquire.d.ts.map +1 -0
- package/dist/acquire.js +46 -0
- package/dist/acquire.js.map +1 -0
- package/dist/archive.d.ts +20 -0
- package/dist/archive.d.ts.map +1 -0
- package/dist/archive.js +158 -0
- package/dist/archive.js.map +1 -0
- package/dist/authoring-assets.d.ts +11 -0
- package/dist/authoring-assets.d.ts.map +1 -0
- package/dist/authoring-assets.js +251 -0
- package/dist/authoring-assets.js.map +1 -0
- package/dist/bounded-fetch.d.ts +17 -0
- package/dist/bounded-fetch.d.ts.map +1 -0
- package/dist/bounded-fetch.js +67 -0
- package/dist/bounded-fetch.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +29 -0
- package/dist/cli.js.map +1 -0
- package/dist/command.d.ts +6 -0
- package/dist/command.d.ts.map +1 -0
- package/dist/command.js +189 -0
- package/dist/command.js.map +1 -0
- package/dist/config.d.ts +4 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +43 -0
- package/dist/config.js.map +1 -0
- package/dist/decisions.d.ts +26 -0
- package/dist/decisions.d.ts.map +1 -0
- package/dist/decisions.js +119 -0
- package/dist/decisions.js.map +1 -0
- package/dist/files.d.ts +38 -0
- package/dist/files.d.ts.map +1 -0
- package/dist/files.js +224 -0
- package/dist/files.js.map +1 -0
- package/dist/guard-registration.d.ts +95 -0
- package/dist/guard-registration.d.ts.map +1 -0
- package/dist/guard-registration.js +282 -0
- package/dist/guard-registration.js.map +1 -0
- package/dist/host-home.d.ts +33 -0
- package/dist/host-home.d.ts.map +1 -0
- package/dist/host-home.js +116 -0
- package/dist/host-home.js.map +1 -0
- package/dist/host-modes.d.ts +13 -0
- package/dist/host-modes.d.ts.map +1 -0
- package/dist/host-modes.js +36 -0
- package/dist/host-modes.js.map +1 -0
- package/dist/host-observe.d.ts +24 -0
- package/dist/host-observe.d.ts.map +1 -0
- package/dist/host-observe.js +233 -0
- package/dist/host-observe.js.map +1 -0
- package/dist/host.d.ts +100 -0
- package/dist/host.d.ts.map +1 -0
- package/dist/host.js +505 -0
- package/dist/host.js.map +1 -0
- package/dist/hosts.d.ts +66 -0
- package/dist/hosts.d.ts.map +1 -0
- package/dist/hosts.js +39 -0
- package/dist/hosts.js.map +1 -0
- package/dist/ia-home.d.ts +15 -0
- package/dist/ia-home.d.ts.map +1 -0
- package/dist/ia-home.js +101 -0
- package/dist/ia-home.js.map +1 -0
- package/dist/install.d.ts +56 -0
- package/dist/install.d.ts.map +1 -0
- package/dist/install.js +402 -0
- package/dist/install.js.map +1 -0
- package/dist/installation-core.d.ts +41 -0
- package/dist/installation-core.d.ts.map +1 -0
- package/dist/installation-core.js +163 -0
- package/dist/installation-core.js.map +1 -0
- package/dist/inventory.d.ts +3 -0
- package/dist/inventory.d.ts.map +1 -0
- package/dist/inventory.js +49 -0
- package/dist/inventory.js.map +1 -0
- package/dist/json-edit.d.ts +19 -0
- package/dist/json-edit.d.ts.map +1 -0
- package/dist/json-edit.js +81 -0
- package/dist/json-edit.js.map +1 -0
- package/dist/lifecycle-registration.d.ts +46 -0
- package/dist/lifecycle-registration.d.ts.map +1 -0
- package/dist/lifecycle-registration.js +332 -0
- package/dist/lifecycle-registration.js.map +1 -0
- package/dist/minting.d.ts +46 -0
- package/dist/minting.d.ts.map +1 -0
- package/dist/minting.js +192 -0
- package/dist/minting.js.map +1 -0
- package/dist/native-command.d.ts +6 -0
- package/dist/native-command.d.ts.map +1 -0
- package/dist/native-command.js +273 -0
- package/dist/native-command.js.map +1 -0
- package/dist/pack.d.ts +4 -0
- package/dist/pack.d.ts.map +1 -0
- package/dist/pack.js +30 -0
- package/dist/pack.js.map +1 -0
- package/dist/plugin-home.d.ts +45 -0
- package/dist/plugin-home.d.ts.map +1 -0
- package/dist/plugin-home.js +371 -0
- package/dist/plugin-home.js.map +1 -0
- package/dist/projection.d.ts +45 -0
- package/dist/projection.d.ts.map +1 -0
- package/dist/projection.js +218 -0
- package/dist/projection.js.map +1 -0
- package/dist/publication.d.ts +20 -0
- package/dist/publication.d.ts.map +1 -0
- package/dist/publication.js +284 -0
- package/dist/publication.js.map +1 -0
- package/dist/registry-admission.d.ts +5 -0
- package/dist/registry-admission.d.ts.map +1 -0
- package/dist/registry-admission.js +17 -0
- package/dist/registry-admission.js.map +1 -0
- package/dist/registry-build.d.ts +35 -0
- package/dist/registry-build.d.ts.map +1 -0
- package/dist/registry-build.js +156 -0
- package/dist/registry-build.js.map +1 -0
- package/dist/registry-config.d.ts +32 -0
- package/dist/registry-config.d.ts.map +1 -0
- package/dist/registry-config.js +191 -0
- package/dist/registry-config.js.map +1 -0
- package/dist/registry-layout.d.ts +41 -0
- package/dist/registry-layout.d.ts.map +1 -0
- package/dist/registry-layout.js +142 -0
- package/dist/registry-layout.js.map +1 -0
- package/dist/registry-resolve.d.ts +56 -0
- package/dist/registry-resolve.d.ts.map +1 -0
- package/dist/registry-resolve.js +406 -0
- package/dist/registry-resolve.js.map +1 -0
- package/dist/registry-source.d.ts +37 -0
- package/dist/registry-source.d.ts.map +1 -0
- package/dist/registry-source.js +101 -0
- package/dist/registry-source.js.map +1 -0
- package/dist/registry.d.ts +10 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/registry.js +6 -0
- package/dist/registry.js.map +1 -0
- package/dist/resolve.d.ts +31 -0
- package/dist/resolve.d.ts.map +1 -0
- package/dist/resolve.js +115 -0
- package/dist/resolve.js.map +1 -0
- package/dist/services.d.ts +179 -0
- package/dist/services.d.ts.map +1 -0
- package/dist/services.js +290 -0
- package/dist/services.js.map +1 -0
- package/dist/snapshot.d.ts +19 -0
- package/dist/snapshot.d.ts.map +1 -0
- package/dist/snapshot.js +309 -0
- package/dist/snapshot.js.map +1 -0
- package/dist/transfer.d.ts +22 -0
- package/dist/transfer.d.ts.map +1 -0
- package/dist/transfer.js +98 -0
- package/dist/transfer.js.map +1 -0
- package/dist/updates.d.ts +57 -0
- package/dist/updates.d.ts.map +1 -0
- package/dist/updates.js +174 -0
- package/dist/updates.js.map +1 -0
- package/dist/ustar.d.ts +28 -0
- package/dist/ustar.d.ts.map +1 -0
- package/dist/ustar.js +145 -0
- package/dist/ustar.js.map +1 -0
- package/package.json +305 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/NOTICE
ADDED
package/README.md
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @inventarch/distribution
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
See [the package contract](SPEC.md) and the exported TypeScript declarations.
|
package/SPEC.md
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
# @inventarch/distribution
|
|
2
|
+
|
|
3
|
+
Public language mechanism. The [language reference](../../docs/reference/language/README.md) defines vocabulary and evaluation limits. Package exports describe the installed API. Curated agent methods and hosted services are supplied independently.
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
// Packaged artifact entrypoint. Its inventory pin is inserted by release assembly.
|
|
2
|
+
import { createHash } from 'node:crypto';
|
|
3
|
+
import { lstatSync, readFileSync, readdirSync, realpathSync, statSync } from 'node:fs';
|
|
4
|
+
import { dirname, isAbsolute, join, relative, resolve } from 'node:path';
|
|
5
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
6
|
+
const root = resolve(dirname(fileURLToPath(import.meta.url)), '..'),
|
|
7
|
+
pin = '__INVENTORY_DIGEST__';
|
|
8
|
+
const hash = (bytes) => createHash('sha256').update(bytes).digest('hex');
|
|
9
|
+
// `child` is `parent` or under it on disk, compared by device and inode from its deepest existing ancestor up, so another
|
|
10
|
+
// spelling a case- or normalization-folding volume opens as the same directory is inside too (#315).
|
|
11
|
+
const within = (parent, child) => {
|
|
12
|
+
const target = statSync(parent, { bigint: true });
|
|
13
|
+
let entry = child;
|
|
14
|
+
while (!statSync(entry, { throwIfNoEntry: false })) {
|
|
15
|
+
if (dirname(entry) === entry) return false;
|
|
16
|
+
entry = dirname(entry);
|
|
17
|
+
}
|
|
18
|
+
for (entry = realpathSync.native(entry); ; entry = dirname(entry)) {
|
|
19
|
+
const stat = statSync(entry, { bigint: true });
|
|
20
|
+
if (stat.dev === target.dev && stat.ino === target.ino) return true;
|
|
21
|
+
if (dirname(entry) === entry) return false;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
const deny = (message) => ({
|
|
25
|
+
hookSpecificOutput: {
|
|
26
|
+
hookEventName: 'PreToolUse',
|
|
27
|
+
permissionDecision: 'deny',
|
|
28
|
+
permissionDecisionReason: 'IA-HOOK-INPUT-INVALID: ' + message,
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
const mode = process.argv[2];
|
|
32
|
+
try {
|
|
33
|
+
if (Number(process.versions.node.split('.')[0]) < 22) throw Error('Node 22 or later required');
|
|
34
|
+
if (realpathSync(root) !== root) throw Error('Aliased plugin cache');
|
|
35
|
+
const bytes = readFileSync(join(root, 'inventory.json'));
|
|
36
|
+
if (bytes.length > 4 * 1024 * 1024 || hash(bytes) !== pin)
|
|
37
|
+
throw Error('Plugin inventory differs from pinned release');
|
|
38
|
+
const inventory = JSON.parse(bytes),
|
|
39
|
+
expected = new Map(inventory.files.map((f) => [f.path, f]));
|
|
40
|
+
let count = 0,
|
|
41
|
+
total = 0,
|
|
42
|
+
entries = 0;
|
|
43
|
+
const visit = (path = '', depth = 0) => {
|
|
44
|
+
if (depth > 32) throw Error('Plugin cache directory depth exceeds 32');
|
|
45
|
+
for (const name of readdirSync(join(root, path))) {
|
|
46
|
+
if (++entries > 20000) throw Error('Plugin cache filesystem inventory exceeds its bound');
|
|
47
|
+
const rel = path ? path + '/' + name : name,
|
|
48
|
+
full = join(root, rel),
|
|
49
|
+
stat = lstatSync(full);
|
|
50
|
+
if (stat.isSymbolicLink()) throw Error('Plugin cache links are unsupported');
|
|
51
|
+
if (stat.isDirectory()) visit(rel, depth + 1);
|
|
52
|
+
else {
|
|
53
|
+
if (!stat.isFile() || stat.nlink !== 1) throw Error('Plugin cache file is aliased');
|
|
54
|
+
if (rel === 'inventory.json' || rel === 'scripts/ia.mjs' || rel === 'release.json') continue;
|
|
55
|
+
const file = expected.get(rel);
|
|
56
|
+
if (!file && (name === '.DS_Store' || name.startsWith('._'))) continue;
|
|
57
|
+
if (
|
|
58
|
+
!file ||
|
|
59
|
+
stat.size !== file.bytes ||
|
|
60
|
+
(total += stat.size) > 256 * 1024 * 1024 ||
|
|
61
|
+
hash(readFileSync(full)) !== file.sha256
|
|
62
|
+
)
|
|
63
|
+
throw Error('Plugin cache payload differs: ' + rel);
|
|
64
|
+
count++;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
visit();
|
|
69
|
+
if (count !== expected.size) throw Error('Plugin cache payload is missing');
|
|
70
|
+
const args = process.argv.slice(3);
|
|
71
|
+
if (mode === 'verify') {
|
|
72
|
+
if (args.length) throw Error('verify takes no arguments');
|
|
73
|
+
process.stdout.write(
|
|
74
|
+
JSON.stringify({
|
|
75
|
+
status: 'verified',
|
|
76
|
+
inventory: pin,
|
|
77
|
+
native: inventory.native ?? null,
|
|
78
|
+
host: inventory.host ?? null,
|
|
79
|
+
}) + '\n',
|
|
80
|
+
);
|
|
81
|
+
} else if (mode === 'context') {
|
|
82
|
+
const identity = args.length === 1 && args[0] === 'identity';
|
|
83
|
+
if (
|
|
84
|
+
!identity &&
|
|
85
|
+
(![4, 6].includes(args.length) ||
|
|
86
|
+
(args.length === 6 && (args[4] !== '--part' || !/^(?:[0-9]|1[01])$/.test(args[5]))) ||
|
|
87
|
+
args[0] !== '--root' ||
|
|
88
|
+
!isAbsolute(args[1]) ||
|
|
89
|
+
resolve(args[1]) === root ||
|
|
90
|
+
args[2] !== '--binding' ||
|
|
91
|
+
!isAbsolute(args[3]))
|
|
92
|
+
)
|
|
93
|
+
throw Error('Context requires identity or exact absolute root and binding');
|
|
94
|
+
const chunks = [];
|
|
95
|
+
let size = 0;
|
|
96
|
+
if (!identity)
|
|
97
|
+
for await (const chunk of process.stdin) {
|
|
98
|
+
const bytes = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
|
|
99
|
+
if ((size += bytes.length) > 1024 * 1024) throw Error('Context stdin exceeds 1 MiB');
|
|
100
|
+
chunks.push(bytes);
|
|
101
|
+
}
|
|
102
|
+
const input = new TextDecoder('utf-8', { fatal: true }).decode(Buffer.concat(chunks));
|
|
103
|
+
const { runContextHook } = await import('../runtime/node_modules/@inventarch/steward-hook/dist/context.js');
|
|
104
|
+
process.stdout.write(JSON.stringify(await runContextHook(args, input)) + '\n');
|
|
105
|
+
} else {
|
|
106
|
+
const argsFor = mode === 'claude-guard' ? ['--root', process.env.CLAUDE_PROJECT_DIR] : args;
|
|
107
|
+
if (!['distribution', 'mcp', 'door', 'guard', 'claude-guard'].includes(mode))
|
|
108
|
+
throw Error('Expected verify, distribution, mcp, door or guard');
|
|
109
|
+
const index = argsFor.indexOf('--root');
|
|
110
|
+
if (index < 0 || !argsFor[index + 1] || !isAbsolute(argsFor[index + 1]))
|
|
111
|
+
throw Error('Explicit absolute consumer --root required');
|
|
112
|
+
const consumerRoot = resolve(argsFor[index + 1]),
|
|
113
|
+
consumerRel = relative(root, consumerRoot);
|
|
114
|
+
if (consumerRel === '' || (!consumerRel.startsWith('..') && !isAbsolute(consumerRel)) || within(root, consumerRoot))
|
|
115
|
+
throw Error('Explicit absolute consumer --root required');
|
|
116
|
+
if (mode === 'distribution') {
|
|
117
|
+
process.argv = [
|
|
118
|
+
process.argv[0],
|
|
119
|
+
join(root, 'runtime/node_modules/@inventarch/distribution/dist/cli.js'),
|
|
120
|
+
...args,
|
|
121
|
+
];
|
|
122
|
+
await import(pathToFileURL(process.argv[1]).href);
|
|
123
|
+
} else if (mode === 'door') {
|
|
124
|
+
const [operation, ...rest] = args,
|
|
125
|
+
seen = new Set();
|
|
126
|
+
for (let i = 0; i < rest.length; i += 2) {
|
|
127
|
+
const flag = rest[i];
|
|
128
|
+
if (!['--root', '--params'].includes(flag) || rest[i + 1] === undefined || seen.has(flag))
|
|
129
|
+
throw Error('door requires <operation> --root <absolute> [--params <JSON|->]');
|
|
130
|
+
seen.add(flag);
|
|
131
|
+
}
|
|
132
|
+
if (!operation || operation.startsWith('-') || rest.length % 2 !== 0 || !seen.has('--root'))
|
|
133
|
+
throw Error('door requires <operation> --root <absolute> [--params <JSON|->]');
|
|
134
|
+
const { runCli } = await import('../runtime/node_modules/@inventarch/cli/dist/main.js');
|
|
135
|
+
const result = runCli(args);
|
|
136
|
+
process.stdout.write(result.stdout);
|
|
137
|
+
process.exitCode = result.exitCode;
|
|
138
|
+
} else if (mode === 'mcp') {
|
|
139
|
+
if (args.length !== 2 || args[0] !== '--root') throw Error('mcp requires exactly --root');
|
|
140
|
+
const { serve } = await import('../runtime/node_modules/@inventarch/mcp-door/dist/main.js');
|
|
141
|
+
await serve(args[1]);
|
|
142
|
+
} else {
|
|
143
|
+
if (mode === 'claude-guard' && args.length) throw Error('Claude binding accepts no event-selected arguments');
|
|
144
|
+
let input = '';
|
|
145
|
+
for await (const chunk of process.stdin) {
|
|
146
|
+
input += chunk;
|
|
147
|
+
if (Buffer.byteLength(input) > 1024 * 1024) throw Error('Hook input exceeds 1 MiB');
|
|
148
|
+
}
|
|
149
|
+
const { runHook } = await import('../runtime/node_modules/@inventarch/steward-hook/dist/main.js');
|
|
150
|
+
process.stdout.write(JSON.stringify(runHook(argsFor, input)) + '\n');
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
} catch (error) {
|
|
154
|
+
if (mode === 'context') {
|
|
155
|
+
process.stdout.write(
|
|
156
|
+
JSON.stringify({
|
|
157
|
+
systemMessage: 'IA lifecycle context unavailable (IA-LIFECYCLE-UNAVAILABLE). No context was generated.',
|
|
158
|
+
}) + '\n',
|
|
159
|
+
);
|
|
160
|
+
if (process.argv[3] === 'identity') process.exitCode = 1;
|
|
161
|
+
} else if (mode === 'guard' || mode === 'claude-guard')
|
|
162
|
+
process.stdout.write(JSON.stringify(deny(error.message)) + '\n');
|
|
163
|
+
else {
|
|
164
|
+
process.stderr.write(JSON.stringify({ status: 'refused', message: error.message }) + '\n');
|
|
165
|
+
process.exitCode = 1;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ReleaseCandidate } from './resolve.js';
|
|
2
|
+
export interface ArtifactRequest {
|
|
3
|
+
readonly root: string;
|
|
4
|
+
readonly url: string;
|
|
5
|
+
readonly digest: string;
|
|
6
|
+
readonly offline?: boolean;
|
|
7
|
+
readonly signal?: AbortSignal | undefined;
|
|
8
|
+
}
|
|
9
|
+
/** Bounded transport only: no verification/readiness claim and no cache writes. */
|
|
10
|
+
export declare function readArtifactBytes(request: ArtifactRequest): Promise<Buffer>;
|
|
11
|
+
/** One immutable HTTPS archive: verified independently before any cache write. */
|
|
12
|
+
export declare function acquireArtifact(request: ArtifactRequest): Promise<ReleaseCandidate>;
|
|
13
|
+
//# sourceMappingURL=acquire.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"acquire.d.ts","sourceRoot":"","sources":["../src/acquire.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAErD,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;IAC3B,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,GAAG,SAAS,CAAC;CAC3C;AACD,mFAAmF;AACnF,wBAAsB,iBAAiB,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,MAAM,CAAC,CA4BjF;AAED,kFAAkF;AAClF,wBAAsB,eAAe,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAQzF"}
|
package/dist/acquire.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { DISTRIBUTION_LIMITS } from '@inventarch/db/distribution';
|
|
2
|
+
import { fetchBounded } from './bounded-fetch.js';
|
|
3
|
+
import { bytes, fail, workspace } from './files.js';
|
|
4
|
+
import { cacheArchive } from './install.js';
|
|
5
|
+
/** Bounded transport only: no verification/readiness claim and no cache writes. */
|
|
6
|
+
export async function readArtifactBytes(request) {
|
|
7
|
+
request.signal?.throwIfAborted();
|
|
8
|
+
const { url, digest } = request;
|
|
9
|
+
if (!/^[a-f0-9]{64}$/.test(digest))
|
|
10
|
+
fail('INPUT-INVALID', 'Expected immutable artifact digest');
|
|
11
|
+
const parsed = new URL(url);
|
|
12
|
+
if (parsed.protocol !== 'https:' ||
|
|
13
|
+
parsed.username ||
|
|
14
|
+
parsed.password ||
|
|
15
|
+
parsed.search ||
|
|
16
|
+
parsed.hash ||
|
|
17
|
+
parsed.href !== url ||
|
|
18
|
+
!parsed.pathname.endsWith(`/${digest}.ia.tgz`))
|
|
19
|
+
fail('INPUT-INVALID', 'Expected immutable credential-free HTTPS artifact URL');
|
|
20
|
+
const root = workspace(request.root);
|
|
21
|
+
const cached = bytes(root, `.ia/distributions/cache/${digest}.ia.tgz`, DISTRIBUTION_LIMITS.compressed);
|
|
22
|
+
if (cached)
|
|
23
|
+
return cached;
|
|
24
|
+
if (request.offline === true)
|
|
25
|
+
fail('RESTORE-REQUIRED', `Offline cache lacks ${digest}`);
|
|
26
|
+
// §6.4: every transport refusal names the artifact URL; the "Remote archive" prefix is what the consumer CLI maps to class 4.
|
|
27
|
+
const content = await fetchBounded({
|
|
28
|
+
url,
|
|
29
|
+
signal: request.signal,
|
|
30
|
+
limit: DISTRIBUTION_LIMITS.compressed,
|
|
31
|
+
label: 'Artifact request',
|
|
32
|
+
oversize: (grew) => `Remote archive ${grew ? 'grew beyond' : 'exceeds'} its byte ceiling: ${url}`,
|
|
33
|
+
});
|
|
34
|
+
return content;
|
|
35
|
+
}
|
|
36
|
+
/** One immutable HTTPS archive: verified independently before any cache write. */
|
|
37
|
+
export async function acquireArtifact(request) {
|
|
38
|
+
const content = await readArtifactBytes(request);
|
|
39
|
+
request.signal?.throwIfAborted();
|
|
40
|
+
return {
|
|
41
|
+
release: cacheArchive(workspace(request.root), content, request.digest),
|
|
42
|
+
location: request.url,
|
|
43
|
+
withdrawn: false,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=acquire.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"acquire.js","sourceRoot":"","sources":["../src/acquire.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAU5C,mFAAmF;AACnF,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,OAAwB;IAC9D,OAAO,CAAC,MAAM,EAAE,cAAc,EAAE,CAAC;IACjC,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;IAChC,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,MAAM,CAAC;QAAE,IAAI,CAAC,eAAe,EAAE,oCAAoC,CAAC,CAAC;IAChG,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;IAC5B,IACE,MAAM,CAAC,QAAQ,KAAK,QAAQ;QAC5B,MAAM,CAAC,QAAQ;QACf,MAAM,CAAC,QAAQ;QACf,MAAM,CAAC,MAAM;QACb,MAAM,CAAC,IAAI;QACX,MAAM,CAAC,IAAI,KAAK,GAAG;QACnB,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,MAAM,SAAS,CAAC;QAE9C,IAAI,CAAC,eAAe,EAAE,uDAAuD,CAAC,CAAC;IACjF,MAAM,IAAI,GAAG,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACrC,MAAM,MAAM,GAAG,KAAK,CAAC,IAAI,EAAE,2BAA2B,MAAM,SAAS,EAAE,mBAAmB,CAAC,UAAU,CAAC,CAAC;IACvG,IAAI,MAAM;QAAE,OAAO,MAAM,CAAC;IAC1B,IAAI,OAAO,CAAC,OAAO,KAAK,IAAI;QAAE,IAAI,CAAC,kBAAkB,EAAE,uBAAuB,MAAM,EAAE,CAAC,CAAC;IACxF,8HAA8H;IAC9H,MAAM,OAAO,GAAG,MAAM,YAAY,CAAC;QACjC,GAAG;QACH,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,KAAK,EAAE,mBAAmB,CAAC,UAAU;QACrC,KAAK,EAAE,kBAAkB;QACzB,QAAQ,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,kBAAkB,IAAI,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,SAAS,sBAAsB,GAAG,EAAE;KAClG,CAAC,CAAC;IACH,OAAO,OAAQ,CAAC;AAClB,CAAC;AAED,kFAAkF;AAClF,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,OAAwB;IAC5D,MAAM,OAAO,GAAG,MAAM,iBAAiB,CAAC,OAAO,CAAC,CAAC;IACjD,OAAO,CAAC,MAAM,EAAE,cAAc,EAAE,CAAC;IACjC,OAAO;QACL,OAAO,EAAE,YAAY,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,MAAM,CAAC;QACvE,QAAQ,EAAE,OAAO,CAAC,GAAG;QACrB,SAAS,EAAE,KAAK;KACjB,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { BundleManifest, BundleMetadata } from '@inventarch/db/distribution';
|
|
2
|
+
interface ArchiveContent {
|
|
3
|
+
readonly manifest: BundleManifest;
|
|
4
|
+
readonly files: ReadonlyMap<string, Buffer>;
|
|
5
|
+
readonly archiveDigest: string;
|
|
6
|
+
readonly manifestDigest: string;
|
|
7
|
+
}
|
|
8
|
+
export interface VerifiedArchive extends ArchiveContent {
|
|
9
|
+
}
|
|
10
|
+
export declare function buildArchive(input: BundleManifest, inputFiles: ReadonlyMap<string, Uint8Array>): Buffer;
|
|
11
|
+
/** Integrity-only metadata for selection. This wrapper makes no authoring/readiness claim and omits payload files. */
|
|
12
|
+
export declare function inspectArchiveMetadata(input: Uint8Array, expectedDigest?: string): {
|
|
13
|
+
readonly pending: BundleMetadata;
|
|
14
|
+
};
|
|
15
|
+
/** Standalone guarantee is unchanged: unresolved dependent authoring assets refuse. */
|
|
16
|
+
export declare function verifyArchive(input: Uint8Array, expectedDigest?: string): VerifiedArchive;
|
|
17
|
+
/** Exact selected closure only; no deferred archive escapes as verified/ready. */
|
|
18
|
+
export declare function verifySelectedArchiveClosure(lockInput: unknown, input: ReadonlyMap<string, Uint8Array>): ReadonlyMap<string, VerifiedArchive>;
|
|
19
|
+
export {};
|
|
20
|
+
//# sourceMappingURL=archive.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"archive.d.ts","sourceRoot":"","sources":["../src/archive.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAMlF,UAAU,cAAc;IACtB,QAAQ,CAAC,QAAQ,EAAE,cAAc,CAAC;IAClC,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC5C,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;CACjC;AACD,MAAM,WAAW,eAAgB,SAAQ,cAAc;CAAG;AAiC1D,wBAAgB,YAAY,CAAC,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,WAAW,CAAC,MAAM,EAAE,UAAU,CAAC,GAAG,MAAM,CAOvG;AA8DD,sHAAsH;AACtH,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,UAAU,EACjB,cAAc,CAAC,EAAE,MAAM,GACtB;IAAE,QAAQ,CAAC,OAAO,EAAE,cAAc,CAAA;CAAE,CAStC;AAED,uFAAuF;AACvF,wBAAgB,aAAa,CAAC,KAAK,EAAE,UAAU,EAAE,cAAc,CAAC,EAAE,MAAM,GAAG,eAAe,CAazF;AAED,kFAAkF;AAClF,wBAAgB,4BAA4B,CAC1C,SAAS,EAAE,OAAO,EAClB,KAAK,EAAE,WAAW,CAAC,MAAM,EAAE,UAAU,CAAC,GACrC,WAAW,CAAC,MAAM,EAAE,eAAe,CAAC,CAkBtC"}
|
package/dist/archive.js
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { gzipSync } from 'node:zlib';
|
|
2
|
+
import { canonicalDistributionJson, decodeBundleManifest, decodeDistributionLock, deriveGenerationInputs, DISTRIBUTION_LIMITS, portablePath, sha256, } from '@inventarch/db/distribution';
|
|
3
|
+
import { fail, utf8 } from './files.js';
|
|
4
|
+
import { verifyAuthoringAssetClosure, verifySelectedAuthoringAssetClosure } from './authoring-assets.js';
|
|
5
|
+
import { KERNEL_SOURCES } from '@inventarch/language';
|
|
6
|
+
import { inflateCanonical, ustarHeader } from './ustar.js';
|
|
7
|
+
const block = 512;
|
|
8
|
+
// Successful immutable structural joins only. Every call still checks complete
|
|
9
|
+
// canonical archive content, gzip envelope and payload pins before consulting this bounded cache.
|
|
10
|
+
const authoringClosures = new Map();
|
|
11
|
+
const header = (path, size, epoch) => {
|
|
12
|
+
portablePath(path);
|
|
13
|
+
return ustarHeader(path, size, epoch);
|
|
14
|
+
};
|
|
15
|
+
function archiveTar(input, inputFiles) {
|
|
16
|
+
const manifest = decodeBundleManifest(input), files = new Map([...inputFiles].map(([path, bytes]) => [path, Buffer.from(bytes)]));
|
|
17
|
+
if (manifest.source.recipe !== 'ustar-v1')
|
|
18
|
+
fail('ARCHIVE-INVALID', 'Unsupported archive recipe');
|
|
19
|
+
if (files.size !== manifest.files.length || manifest.files.some((p) => !files.has(p.path)))
|
|
20
|
+
fail('ARCHIVE-INVALID', 'Payload differs from exact manifest inventory');
|
|
21
|
+
for (const pin of manifest.files) {
|
|
22
|
+
const content = files.get(pin.path);
|
|
23
|
+
if (content.length !== pin.bytes || sha256(content) !== pin.sha256)
|
|
24
|
+
fail('ARCHIVE-INVALID', `Payload pin mismatch: ${pin.path}`);
|
|
25
|
+
if (pin.role === 'source')
|
|
26
|
+
utf8(content);
|
|
27
|
+
}
|
|
28
|
+
files.set('distribution.json', Buffer.from(canonicalDistributionJson(manifest)));
|
|
29
|
+
const chunks = [];
|
|
30
|
+
let expanded = 2 * block;
|
|
31
|
+
for (const [path, content] of [...files].sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))) {
|
|
32
|
+
const padding = (block - (content.length % block)) % block;
|
|
33
|
+
expanded += block + content.length + padding;
|
|
34
|
+
if (expanded > DISTRIBUTION_LIMITS.expanded)
|
|
35
|
+
fail('LIMIT-EXCEEDED', 'Expanded archive exceeds its ceiling');
|
|
36
|
+
chunks.push(header(path, content.length, manifest.source.epoch), content, Buffer.alloc(padding));
|
|
37
|
+
}
|
|
38
|
+
chunks.push(Buffer.alloc(2 * block));
|
|
39
|
+
return Buffer.concat(chunks);
|
|
40
|
+
}
|
|
41
|
+
export function buildArchive(input, inputFiles) {
|
|
42
|
+
const packed = gzipSync(archiveTar(input, inputFiles), { level: 9 });
|
|
43
|
+
// RFC 1952's informational OS byte must not make identical releases differ
|
|
44
|
+
// between Windows and Unix. 255 means unspecified; payload/CRC stay unchanged.
|
|
45
|
+
packed[9] = 255;
|
|
46
|
+
if (packed.length > DISTRIBUTION_LIMITS.compressed)
|
|
47
|
+
fail('LIMIT-EXCEEDED', 'Compressed archive exceeds its ceiling');
|
|
48
|
+
return packed;
|
|
49
|
+
}
|
|
50
|
+
// Deliberately wrapped: pending bytes cannot be returned as a VerifiedArchive.
|
|
51
|
+
function verifyArchiveBytes(input, expectedDigest) {
|
|
52
|
+
if (input.length > DISTRIBUTION_LIMITS.compressed)
|
|
53
|
+
fail('LIMIT-EXCEEDED', 'Compressed archive exceeds its ceiling');
|
|
54
|
+
const archive = Buffer.from(input), archiveDigest = sha256(archive);
|
|
55
|
+
if (expectedDigest !== undefined && archiveDigest !== expectedDigest)
|
|
56
|
+
fail('ARCHIVE-INVALID', 'Archive digest mismatch');
|
|
57
|
+
const tar = inflateCanonical(archive, DISTRIBUTION_LIMITS.expanded, {
|
|
58
|
+
invalid: 'Invalid or oversized compressed archive',
|
|
59
|
+
outside: 'Archive is outside the canonical format-1 recipe',
|
|
60
|
+
});
|
|
61
|
+
if (tar.length < 1024 || tar.length % block)
|
|
62
|
+
fail('ARCHIVE-INVALID', 'Invalid USTAR length');
|
|
63
|
+
const files = new Map(), aliases = new Set();
|
|
64
|
+
let at = 0;
|
|
65
|
+
while (at < tar.length - 1024) {
|
|
66
|
+
const h = tar.subarray(at, at + block);
|
|
67
|
+
if (h.every((byte) => byte === 0))
|
|
68
|
+
break;
|
|
69
|
+
const field = (start, length) => {
|
|
70
|
+
const bytes = h.subarray(start, start + length), zero = bytes.indexOf(0);
|
|
71
|
+
return utf8(zero < 0 ? bytes : bytes.subarray(0, zero));
|
|
72
|
+
};
|
|
73
|
+
const prefix = field(345, 155), path = portablePath(`${prefix ? prefix + '/' : ''}${field(0, 100)}`);
|
|
74
|
+
if (h[156] !== 48 || field(257, 6) !== 'ustar' || field(263, 2) !== '00' || aliases.has(path.toLowerCase()))
|
|
75
|
+
fail('ARCHIVE-INVALID', 'Nonregular, duplicate or unsupported archive entry');
|
|
76
|
+
const sizeField = field(124, 12), epochField = field(136, 12);
|
|
77
|
+
if (!/^[0-7]{11}$/.test(sizeField) || !/^[0-7]{11}$/.test(epochField))
|
|
78
|
+
fail('ARCHIVE-INVALID', 'Invalid USTAR integer');
|
|
79
|
+
const size = parseInt(sizeField, 8), epoch = parseInt(epochField, 8);
|
|
80
|
+
if (size > DISTRIBUTION_LIMITS.file ||
|
|
81
|
+
files.size >= DISTRIBUTION_LIMITS.files ||
|
|
82
|
+
at + block + size > tar.length - 1024 ||
|
|
83
|
+
!h.equals(header(path, size, epoch)))
|
|
84
|
+
fail('ARCHIVE-INVALID', 'Invalid header, size, checksum or metadata');
|
|
85
|
+
const next = at + block + Math.ceil(size / block) * block;
|
|
86
|
+
if (tar.subarray(at + block + size, next).some((byte) => byte !== 0))
|
|
87
|
+
fail('ARCHIVE-INVALID', 'Nonzero file padding');
|
|
88
|
+
files.set(path, Buffer.from(tar.subarray(at + block, at + block + size)));
|
|
89
|
+
aliases.add(path.toLowerCase());
|
|
90
|
+
at = next;
|
|
91
|
+
}
|
|
92
|
+
if (at !== tar.length - 1024 || tar.subarray(at).some((byte) => byte !== 0))
|
|
93
|
+
fail('ARCHIVE-INVALID', 'Unexpected trailing archive data');
|
|
94
|
+
const content = files.get('distribution.json');
|
|
95
|
+
if (!content)
|
|
96
|
+
fail('ARCHIVE-INVALID', 'Missing manifest');
|
|
97
|
+
const manifest = decodeBundleManifest(utf8(content));
|
|
98
|
+
if (canonicalDistributionJson(manifest) !== utf8(content))
|
|
99
|
+
fail('ARCHIVE-INVALID', 'Noncanonical manifest');
|
|
100
|
+
files.delete('distribution.json');
|
|
101
|
+
// One canonical USTAR per manifest and payload; inflateCanonical already held it to the recipe's gzip envelope. The deflate bytes
|
|
102
|
+
// are not compared: zlib builds encode the same tar differently (Homebrew's Node links the system zlib). A pinned digest still binds exact bytes.
|
|
103
|
+
if (!archiveTar(manifest, files).equals(tar))
|
|
104
|
+
fail('ARCHIVE-INVALID', 'Archive is outside the canonical format-1 recipe');
|
|
105
|
+
return { pending: Object.freeze({ manifest, files, archiveDigest, manifestDigest: sha256(content) }) };
|
|
106
|
+
}
|
|
107
|
+
/** Integrity-only metadata for selection. This wrapper makes no authoring/readiness claim and omits payload files. */
|
|
108
|
+
export function inspectArchiveMetadata(input, expectedDigest) {
|
|
109
|
+
const { pending } = verifyArchiveBytes(input, expectedDigest);
|
|
110
|
+
return Object.freeze({
|
|
111
|
+
pending: Object.freeze({
|
|
112
|
+
manifest: pending.manifest,
|
|
113
|
+
archiveDigest: pending.archiveDigest,
|
|
114
|
+
manifestDigest: pending.manifestDigest,
|
|
115
|
+
}),
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
/** Standalone guarantee is unchanged: unresolved dependent authoring assets refuse. */
|
|
119
|
+
export function verifyArchive(input, expectedDigest) {
|
|
120
|
+
const { pending } = verifyArchiveBytes(input, expectedDigest);
|
|
121
|
+
const { manifest, files, archiveDigest } = pending;
|
|
122
|
+
const authoringKey = sha256(`${archiveDigest}:${sha256(JSON.stringify(KERNEL_SOURCES))}`);
|
|
123
|
+
if (!authoringClosures.has(authoringKey)) {
|
|
124
|
+
verifyAuthoringAssetClosure(manifest, files);
|
|
125
|
+
authoringClosures.set(authoringKey, true);
|
|
126
|
+
if (authoringClosures.size > 32)
|
|
127
|
+
authoringClosures.delete(authoringClosures.keys().next().value);
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
authoringClosures.delete(authoringKey);
|
|
131
|
+
authoringClosures.set(authoringKey, true);
|
|
132
|
+
}
|
|
133
|
+
return pending;
|
|
134
|
+
}
|
|
135
|
+
/** Exact selected closure only; no deferred archive escapes as verified/ready. */
|
|
136
|
+
export function verifySelectedArchiveClosure(lockInput, input) {
|
|
137
|
+
const lock = decodeDistributionLock(lockInput);
|
|
138
|
+
if (!(input instanceof Map) || input.size !== new Set(lock.packages.map((pkg) => pkg.archive)).size)
|
|
139
|
+
fail('RESTORE-REQUIRED', 'Supply the exact selected archive inventory');
|
|
140
|
+
const pending = new Map();
|
|
141
|
+
let total = 0;
|
|
142
|
+
for (const pkg of lock.packages) {
|
|
143
|
+
const content = input.get(pkg.archive);
|
|
144
|
+
if (!(content instanceof Uint8Array))
|
|
145
|
+
fail('RESTORE-REQUIRED', `Missing exact archive ${pkg.archive}`);
|
|
146
|
+
total += content.length;
|
|
147
|
+
if (total > DISTRIBUTION_LIMITS.expanded)
|
|
148
|
+
fail('LIMIT-EXCEEDED', 'Combined archive selection exceeds its ceiling');
|
|
149
|
+
const decoded = verifyArchiveBytes(content, pkg.archive);
|
|
150
|
+
if (decoded.pending.manifestDigest !== pkg.manifest)
|
|
151
|
+
fail('ARCHIVE-INVALID', 'Selected manifest differs from lock');
|
|
152
|
+
pending.set(pkg.id, decoded.pending);
|
|
153
|
+
}
|
|
154
|
+
deriveGenerationInputs(lock, pending);
|
|
155
|
+
verifySelectedAuthoringAssetClosure(lock, pending);
|
|
156
|
+
return pending;
|
|
157
|
+
}
|
|
158
|
+
//# sourceMappingURL=archive.js.map
|