pallas-ads 0.2.0-alpha.1
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 +201 -0
- package/NOTICE +4 -0
- package/README.md +42 -0
- package/bin/pallas-ads.mjs +6 -0
- package/lib/installer.mjs +191 -0
- package/package.json +16 -0
- package/resources/install_macos.py +114 -0
- package/resources/npm-runtime.json +9 -0
- package/resources/pallas_ads-0.2.0a1-py3-none-any.whl +0 -0
- package/resources/release-manifest.json +11 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/NOTICE
ADDED
package/README.md
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# Pallas npm installer
|
|
2
|
+
|
|
3
|
+
A small Node.js launcher installs the existing Python Pallas runtime, local MCP configuration, `pallas-workflow` and `pallas-analysis` Skills, and synthetic samples. The analysis engine is not rewritten in JavaScript.
|
|
4
|
+
|
|
5
|
+
**macOS (Apple Silicon / Intel), Node.js 22+, internet access.** There are no npm dependencies or installation lifecycle scripts. Runtime installation happens only when you explicitly invoke `install`.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
After npm registry publication:
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
npx pallas-ads install
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
The interactive installer asks for Codex or Claude Code and a new project directory. For an agent or script:
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
npx pallas-ads install --client codex --directory "$HOME/pallas-codex"
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
The equivalent GitHub package entry is `npx github:Jieyi-Deng/Pallas-ads install`. Registry publication and GitHub availability are tracked separately; do not assume the short registry command works before publication.
|
|
22
|
+
|
|
23
|
+
A supported local Python 3.12/3.13 is reused. Otherwise the installer downloads a pinned, SHA-256-verified uv binary from Astral's official GitHub release and uses it to provision Python 3.13 alongside the project's runtime. It does not change system Python, shell profiles or global agent configuration. Use `--managed-python` to explicitly choose this isolated Python, or `--python /absolute/python3.13` to select an existing one.
|
|
24
|
+
|
|
25
|
+
The installed project, adjacent `-runtime` and optional `-runtime-tools` directories must remain in place. Files and reports live in the project's `.pallas`. Installation targets a new/empty dedicated workspace; it does not merge into an existing coding project or install globally for every project.
|
|
26
|
+
|
|
27
|
+
After installation, open the generated folder in your agent, confirm project trust and start a new task. Ask Pallas to preview `samples/meta_campaign_daily.csv`; confirm the interpretation to generate a report. Default installation does not connect media, request API keys or change certificates. Live media access remains optional and separately verified.
|
|
28
|
+
|
|
29
|
+
## Check and update
|
|
30
|
+
|
|
31
|
+
```sh
|
|
32
|
+
npx pallas-ads doctor --directory "$HOME/pallas-codex"
|
|
33
|
+
npx pallas-ads@latest update --directory "$HOME/pallas-codex"
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Updating uses the runtime bundled with the installer version you selected. The first release wraps Python runtime 0.2.0a1; it does not silently fetch a newer Python package. Saved data and MCP configuration remain in place; Skills updates keep a backup. Back up the project before upgrading. Update manages projects installed by this launcher, not unrelated installations.
|
|
37
|
+
|
|
38
|
+
Interrupted installs preserve partial state and report the affected step. Do not delete existing projects to retry. Diagnose the partial environment or choose a fresh project name. Re-running install on a successfully installed project checks it without overwriting files.
|
|
39
|
+
|
|
40
|
+
Only a publisher needs an npm account; users can install public packages without logging in. The full development repository is private; the distributed wheel includes readable runtime code under Apache-2.0. This is a local Alpha, not an unattended cloud service.
|
|
41
|
+
|
|
42
|
+
See https://github.com/Jieyi-Deng/Pallas-ads for file formats, media limitations and feedback instructions.
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import {createHash} from 'node:crypto';
|
|
2
|
+
import {spawn, spawnSync} from 'node:child_process';
|
|
3
|
+
import {existsSync, lstatSync, mkdirSync, readFileSync, readdirSync, realpathSync, writeFileSync, chmodSync, rmSync} from 'node:fs';
|
|
4
|
+
import {dirname, join, resolve, basename, parse} from 'node:path';
|
|
5
|
+
import {homedir} from 'node:os';
|
|
6
|
+
import {fileURLToPath} from 'node:url';
|
|
7
|
+
import {createInterface} from 'node:readline/promises';
|
|
8
|
+
|
|
9
|
+
const ROOT = resolve(dirname(fileURLToPath(import.meta.url)), '..');
|
|
10
|
+
const RECEIPT = '.pallas/npm-install.json';
|
|
11
|
+
export const UV = {
|
|
12
|
+
version: '0.10.8',
|
|
13
|
+
arm64: {target: 'aarch64-apple-darwin', sha256: 'c3a6fff5b6b4abddff863117878194e35dbc6b0267d61ad259ab9896f9b8dcbb'},
|
|
14
|
+
x64: {target: 'x86_64-apple-darwin', sha256: 'e0a1b22b039f8155765f5bc8c13df03a5f994a901901179791572e8e5f053281'},
|
|
15
|
+
};
|
|
16
|
+
export function sha256(data) { return createHash('sha256').update(data).digest('hex'); }
|
|
17
|
+
export function parseArgs(args) {
|
|
18
|
+
const result = {command: args[0] ?? 'help'};
|
|
19
|
+
if (['--help', '-h'].includes(result.command)) result.command = 'help';
|
|
20
|
+
if (result.command === '--version') result.command = 'version';
|
|
21
|
+
if (!['install', 'doctor', 'update', 'help', 'version'].includes(result.command)) throw Error('Use install, doctor, update, --help or --version.');
|
|
22
|
+
const names = {'--client': 'client', '--directory': 'directory', '--python': 'python'};
|
|
23
|
+
for (let i = 1; i < args.length; i++) {
|
|
24
|
+
const option = args[i];
|
|
25
|
+
if (option === '--managed-python') { result.managedPython = true; continue; }
|
|
26
|
+
if (!names[option] || !args[i + 1] || args[i + 1].startsWith('--')) throw Error(`Unknown or incomplete option: ${option}`);
|
|
27
|
+
if (result[names[option]] !== undefined) throw Error(`Repeated option: ${option}`);
|
|
28
|
+
result[names[option]] = args[++i];
|
|
29
|
+
}
|
|
30
|
+
if (result.client && !['codex', 'claude'].includes(result.client)) throw Error('--client must be codex or claude.');
|
|
31
|
+
if (result.python && result.managedPython) throw Error('Choose --python or --managed-python, not both.');
|
|
32
|
+
if (result.command !== 'install' && (result.python || result.managedPython || result.client)) throw Error('Client/Python options apply only to install.');
|
|
33
|
+
return result;
|
|
34
|
+
}
|
|
35
|
+
export function canonicalDirectory(input) {
|
|
36
|
+
const expanded = input === '~' ? homedir() : input.startsWith('~/') ? join(homedir(), input.slice(2)) : input;
|
|
37
|
+
let current = resolve(expanded);
|
|
38
|
+
const missing = [];
|
|
39
|
+
// Canonicalize existing parents, including macOS's /tmp alias, before storing paths.
|
|
40
|
+
while (!existsSync(current)) {
|
|
41
|
+
if (lstatSafe(current)?.isSymbolicLink()) throw Error('Broken symlink in destination.');
|
|
42
|
+
missing.unshift(basename(current)); current = dirname(current);
|
|
43
|
+
}
|
|
44
|
+
const path = join(realpathSync(current), ...missing);
|
|
45
|
+
if ([parse(path).root, realpathSync(homedir())].includes(path)) throw Error('Choose a dedicated project directory, not your home or filesystem root.');
|
|
46
|
+
return path;
|
|
47
|
+
}
|
|
48
|
+
function lstatSafe(path) { try { return lstatSync(path); } catch (error) { if (error.code === 'ENOENT') return null; throw error; } }
|
|
49
|
+
export function validateFresh(directory) {
|
|
50
|
+
const state = lstatSafe(directory);
|
|
51
|
+
if (state && (!state.isDirectory() || state.isSymbolicLink() || readdirSync(directory).length)) throw Error('Choose a new or empty project directory. Existing project files are never replaced.');
|
|
52
|
+
for (const suffix of ['-runtime', '-runtime-tools']) {
|
|
53
|
+
if (lstatSafe(directory + suffix)) throw Error(`The adjacent ${suffix} directory already exists. Use doctor for an existing install; preserve partial state and choose a new name to retry.`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
export function verifiedResources(root = ROOT) {
|
|
57
|
+
const directory = join(root, 'resources');
|
|
58
|
+
const manifest = JSON.parse(readFileSync(join(directory, 'npm-runtime.json'), 'utf8'));
|
|
59
|
+
if (!/^pallas_ads-[a-zA-Z0-9.]+-py3-none-any\.whl$/.test(manifest.wheel)) throw Error('Invalid bundled wheel filename.');
|
|
60
|
+
for (const name of [manifest.wheel, 'install_macos.py', 'release-manifest.json']) {
|
|
61
|
+
const file = join(directory, name);
|
|
62
|
+
if (lstatSync(file).isSymbolicLink() || sha256(readFileSync(file)) !== manifest.files[name]) throw Error('Bundled runtime checksum mismatch; obtain a fresh package.');
|
|
63
|
+
}
|
|
64
|
+
return {directory, manifest};
|
|
65
|
+
}
|
|
66
|
+
function pythonCandidate(command) {
|
|
67
|
+
const run = spawnSync(command, ['-I', '-c', 'import sys,json; print(json.dumps({"version":list(sys.version_info[:2]),"executable":sys.executable}))'], {encoding: 'utf8', timeout: 15000});
|
|
68
|
+
if (run.status !== 0) return null;
|
|
69
|
+
try {
|
|
70
|
+
const result = JSON.parse(run.stdout.trim());
|
|
71
|
+
return result.version[0] === 3 && [12, 13].includes(result.version[1]) ? result.executable : null;
|
|
72
|
+
} catch { return null; }
|
|
73
|
+
}
|
|
74
|
+
export function findPython(explicit, candidate = pythonCandidate) {
|
|
75
|
+
if (explicit) {
|
|
76
|
+
const found = candidate(explicit);
|
|
77
|
+
if (!found) throw Error('--python must point to Python 3.12 or 3.13.');
|
|
78
|
+
return found;
|
|
79
|
+
}
|
|
80
|
+
for (const name of ['python3.13', 'python3.12', 'python3']) { const found = candidate(name); if (found) return found; }
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
async function run(command, args, options = {}) {
|
|
84
|
+
return new Promise((done, fail) => {
|
|
85
|
+
const child = spawn(command, args, {stdio: 'inherit', shell: false, ...options});
|
|
86
|
+
child.on('error', () => fail(Error(`Could not start ${basename(command)}.`)));
|
|
87
|
+
child.on('exit', code => code === 0 ? done() : fail(Error(`${basename(command)} exited with status ${code}. Existing files were preserved; inspect the displayed error before retrying.`)));
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
export async function downloadPinned(url, digest, destination) {
|
|
91
|
+
if (!url.startsWith('https://github.com/astral-sh/uv/releases/download/')) throw Error('Unapproved bootstrap download URL.');
|
|
92
|
+
const response = await fetch(url, {signal: AbortSignal.timeout(120000)});
|
|
93
|
+
if (!response.ok || !response.url.startsWith('https://') || !response.body) throw Error('Could not download the pinned Python bootstrap.');
|
|
94
|
+
const chunks = []; let bytes = 0;
|
|
95
|
+
for await (const chunk of response.body) {
|
|
96
|
+
bytes += chunk.length;
|
|
97
|
+
if (bytes > 40 * 1024 * 1024) throw Error('Bootstrap download exceeds its size limit.');
|
|
98
|
+
chunks.push(chunk);
|
|
99
|
+
}
|
|
100
|
+
const data = Buffer.concat(chunks);
|
|
101
|
+
if (sha256(data) !== digest) throw Error('Bootstrap checksum mismatch; no downloaded code was executed.');
|
|
102
|
+
writeFileSync(destination, data, {flag: 'wx', mode: 0o600});
|
|
103
|
+
}
|
|
104
|
+
async function managedPython(directory) {
|
|
105
|
+
const platform = UV[process.arch];
|
|
106
|
+
if (!platform) throw Error('Managed Python supports Apple Silicon and Intel Macs.');
|
|
107
|
+
const tools = directory + '-runtime-tools';
|
|
108
|
+
mkdirSync(tools, {recursive: false, mode: 0o700});
|
|
109
|
+
console.log('Preparing a Pallas-local Python 3.13. No system Python or shell profile will be changed.');
|
|
110
|
+
const archive = join(tools, 'uv.tar.gz');
|
|
111
|
+
await downloadPinned(`https://github.com/astral-sh/uv/releases/download/${UV.version}/uv-${platform.target}.tar.gz`, platform.sha256, archive);
|
|
112
|
+
await run('/usr/bin/tar', ['-xzf', archive, '-C', tools]);
|
|
113
|
+
const uv = join(tools, `uv-${platform.target}`, 'uv');
|
|
114
|
+
chmodSync(uv, 0o700);
|
|
115
|
+
const pythonDir = join(tools, 'python');
|
|
116
|
+
const env = {...process.env, UV_PYTHON_INSTALL_DIR: pythonDir, UV_CACHE_DIR: join(tools, 'cache')};
|
|
117
|
+
await run(uv, ['python', 'install', '3.13', '--no-bin', '--no-config'], {env});
|
|
118
|
+
const found = spawnSync(uv, ['python', 'find', '3.13', '--managed-python', '--no-config'], {env, encoding: 'utf8', timeout: 15000});
|
|
119
|
+
const executable = found.stdout?.trim();
|
|
120
|
+
if (found.status !== 0 || !executable?.startsWith(pythonDir + '/') || !pythonCandidate(executable)) throw Error('Managed Python is incomplete. Preserve the runtime-tools directory and inspect the download error.');
|
|
121
|
+
rmSync(archive);
|
|
122
|
+
return executable;
|
|
123
|
+
}
|
|
124
|
+
function receiptFor(directory) {
|
|
125
|
+
const path = join(directory, RECEIPT);
|
|
126
|
+
if (!existsSync(path) || lstatSync(path).isSymbolicLink()) throw Error('No npm-managed Pallas installation here. Supply --directory for the installed project.');
|
|
127
|
+
const receipt = JSON.parse(readFileSync(path, 'utf8'));
|
|
128
|
+
if (receipt.project !== directory || receipt.runtime !== directory + '-runtime' || !['codex', 'claude'].includes(receipt.client)) throw Error('Installation receipt does not match this directory.');
|
|
129
|
+
return receipt;
|
|
130
|
+
}
|
|
131
|
+
async function doctor(directory) {
|
|
132
|
+
const receipt = receiptFor(directory);
|
|
133
|
+
await run(join(receipt.runtime, 'bin/pallas'), ['agent', 'doctor', '--directory', directory]);
|
|
134
|
+
return receipt;
|
|
135
|
+
}
|
|
136
|
+
async function selectInstall(options) {
|
|
137
|
+
if (options.client && options.directory) return options;
|
|
138
|
+
if (!process.stdin.isTTY) throw Error('Non-interactive install requires --client codex|claude and --directory PATH.');
|
|
139
|
+
const prompt = createInterface({input: process.stdin, output: process.stdout});
|
|
140
|
+
try {
|
|
141
|
+
if (!options.client) {
|
|
142
|
+
const answer = (await prompt.question('Agent / 客户端: 1) Codex 2) Claude Code [1]: ')).trim();
|
|
143
|
+
if (!['', '1', '2', 'codex', 'claude'].includes(answer)) throw Error('Choose 1 (Codex) or 2 (Claude Code).');
|
|
144
|
+
options.client = ['2', 'claude'].includes(answer) ? 'claude' : 'codex';
|
|
145
|
+
}
|
|
146
|
+
if (!options.directory) options.directory = (await prompt.question(`New project / 新项目目录 [~/pallas-${options.client}]: `)).trim() || `~/pallas-${options.client}`;
|
|
147
|
+
return options;
|
|
148
|
+
} finally { prompt.close(); }
|
|
149
|
+
}
|
|
150
|
+
export async function main(args = process.argv.slice(2)) {
|
|
151
|
+
const options = parseArgs(args);
|
|
152
|
+
const pkg = JSON.parse(readFileSync(join(ROOT, 'package.json'), 'utf8'));
|
|
153
|
+
if (options.command === 'version') { console.log(pkg.version); return; }
|
|
154
|
+
if (options.command === 'help') {
|
|
155
|
+
console.log(`Pallas ${pkg.version} — local analysis installer (macOS, Node.js 22+)\n\nCommands: install | doctor | update\n install [--client codex|claude] [--directory PATH]\n [--python EXECUTABLE | --managed-python]\n doctor --directory PATH\n update --directory PATH\n\nInstall prompts for client and a new project. Existing projects/global settings are not overwritten.\nA missing supported Python is provisioned locally; downloads require internet.\nDefault setup does not authorize media, install certificates or request API keys.\nReload your agent in the generated project and confirm host trust after installation.`);
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
if (process.platform !== 'darwin' || !UV[process.arch]) throw Error('This Alpha installer supports macOS on Apple Silicon or Intel.');
|
|
159
|
+
if (options.command === 'doctor') { await doctor(canonicalDirectory(options.directory || process.cwd())); return; }
|
|
160
|
+
const {directory: resources, manifest} = verifiedResources();
|
|
161
|
+
if (options.command === 'update') {
|
|
162
|
+
const directory = canonicalDirectory(options.directory || process.cwd());
|
|
163
|
+
const receipt = await doctor(directory);
|
|
164
|
+
if (receipt.installerVersion === pkg.version && receipt.wheelSha256 === manifest.files[manifest.wheel]) {
|
|
165
|
+
console.log('This project already has the runtime and Skills supplied by this installer version.'); return;
|
|
166
|
+
}
|
|
167
|
+
console.log('Updating the runtime; saved data and MCP configuration remain in place.');
|
|
168
|
+
await run(join(receipt.runtime, 'bin/python'), ['-m', 'pip', 'install', join(resources, manifest.wheel)]);
|
|
169
|
+
await run(join(receipt.runtime, 'bin/pallas'), ['agent', 'refresh-skills', '--directory', directory]);
|
|
170
|
+
await doctor(directory);
|
|
171
|
+
writeReceipt(directory, {...receipt, installerVersion: pkg.version, runtimeVersion: manifest.runtimeVersion, wheelSha256: manifest.files[manifest.wheel]});
|
|
172
|
+
console.log('Update complete. Review the Skills backup and restart your agent task.'); return;
|
|
173
|
+
}
|
|
174
|
+
await selectInstall(options);
|
|
175
|
+
const directory = canonicalDirectory(options.directory);
|
|
176
|
+
if (existsSync(join(directory, RECEIPT))) {
|
|
177
|
+
const receipt = await doctor(directory);
|
|
178
|
+
if (receipt.client !== options.client) throw Error('This project belongs to a different client. Choose a separate new project.');
|
|
179
|
+
console.log('Pallas is already installed here. Use update to change versions.'); return;
|
|
180
|
+
}
|
|
181
|
+
validateFresh(directory);
|
|
182
|
+
mkdirSync(dirname(directory), {recursive: true});
|
|
183
|
+
let python = options.managedPython ? null : findPython(options.python);
|
|
184
|
+
console.log(`Installing Pallas ${manifest.runtimeVersion} for ${options.client} in ${directory}`);
|
|
185
|
+
if (!python) python = await managedPython(directory);
|
|
186
|
+
await run(python, [join(resources, 'install_macos.py'), '--directory', directory, '--client', options.client]);
|
|
187
|
+
writeReceipt(directory, {project: directory, runtime: directory + '-runtime', client: options.client,
|
|
188
|
+
installerVersion: pkg.version, runtimeVersion: manifest.runtimeVersion, wheelSha256: manifest.files[manifest.wheel]});
|
|
189
|
+
console.log(`\nReady / 安装完成: ${directory}\nOpen this project, confirm host trust and start a new task.\nTry / 试用: 请用 Pallas 预览 samples/meta_campaign_daily.csv,确认后生成分析报告。`);
|
|
190
|
+
}
|
|
191
|
+
function writeReceipt(directory, receipt) { writeFileSync(join(directory, RECEIPT), JSON.stringify(receipt, null, 2) + '\n', {mode: 0o600}); }
|
package/package.json
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "pallas-ads",
|
|
3
|
+
"version": "0.2.0-alpha.1",
|
|
4
|
+
"description": "Install Pallas local advertising analysis for Codex and Claude Code",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {"pallas-ads": "bin/pallas-ads.mjs"},
|
|
7
|
+
"engines": {"node": ">=22"},
|
|
8
|
+
"os": ["darwin"],
|
|
9
|
+
"cpu": ["arm64", "x64"],
|
|
10
|
+
"files": ["bin/", "lib/", "resources/", "LICENSE", "NOTICE", "README.md"],
|
|
11
|
+
"scripts": {"test": "node --test test/*.test.mjs"},
|
|
12
|
+
"license": "Apache-2.0",
|
|
13
|
+
"repository": {"type": "git", "url": "git+https://github.com/Jieyi-Deng/Pallas-ads.git"},
|
|
14
|
+
"bugs": {"url": "https://github.com/Jieyi-Deng/Pallas-ads/issues"},
|
|
15
|
+
"publishConfig": {"access": "public", "registry": "https://registry.npmjs.org/"}
|
|
16
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"""Install a self-contained Pallas test bundle on a new Mac. Run with Python 3.12 or 3.13.
|
|
2
|
+
|
|
3
|
+
Core installation needs no media application identity. Live connections are optional.
|
|
4
|
+
No old workspaces, certificates or user OAuth tokens are imported.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import argparse
|
|
8
|
+
import hashlib
|
|
9
|
+
import json
|
|
10
|
+
import subprocess
|
|
11
|
+
import sys
|
|
12
|
+
import venv
|
|
13
|
+
import zipfile
|
|
14
|
+
from pathlib import Path
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def install(args):
|
|
18
|
+
if sys.platform != "darwin" or sys.version_info[:2] not in ((3, 12), (3, 13)):
|
|
19
|
+
raise ValueError(
|
|
20
|
+
"Use Python 3.12 or 3.13 on macOS. The agent can install that prerequisite."
|
|
21
|
+
)
|
|
22
|
+
if args.meta_client_id and args.client != "codex":
|
|
23
|
+
raise ValueError("Pre-registered Meta setup requires Codex.")
|
|
24
|
+
if args.enable_meta and args.client == "codex" and not args.meta_client_id:
|
|
25
|
+
raise ValueError("Codex live Meta requires an explicitly provided registered App ID.")
|
|
26
|
+
if args.trust_local_certificate and not args.meta_client_id:
|
|
27
|
+
raise ValueError("Certificate trust is only for explicit Codex Meta setup.")
|
|
28
|
+
bundle = Path(__file__).resolve().parent
|
|
29
|
+
wheels = list(bundle.glob("pallas_ads-*.whl"))
|
|
30
|
+
if len(wheels) != 1:
|
|
31
|
+
raise ValueError("The test bundle must contain exactly one Pallas wheel.")
|
|
32
|
+
wheel = wheels[0]
|
|
33
|
+
expected = json.loads((bundle / "release-manifest.json").read_text())
|
|
34
|
+
if (
|
|
35
|
+
expected["wheel"] != wheel.name
|
|
36
|
+
or expected["sha256"] != hashlib.sha256(wheel.read_bytes()).hexdigest()
|
|
37
|
+
):
|
|
38
|
+
raise ValueError("Wheel checksum mismatch; obtain a fresh bundle from the operator.")
|
|
39
|
+
directory = args.directory.expanduser().absolute()
|
|
40
|
+
if directory.exists() and (not directory.is_dir() or any(directory.iterdir())):
|
|
41
|
+
raise ValueError("Choose a new or empty project directory; no existing state is replaced.")
|
|
42
|
+
runtime = directory.with_name(directory.name + "-runtime")
|
|
43
|
+
if runtime.exists():
|
|
44
|
+
raise ValueError("The adjacent runtime already exists. Choose a new project name.")
|
|
45
|
+
if args.require_google:
|
|
46
|
+
with zipfile.ZipFile(wheel) as archive:
|
|
47
|
+
name = "pallas_ads/resources/google-desktop.json"
|
|
48
|
+
if name not in archive.namelist() or archive.getinfo(name).file_size > 65536:
|
|
49
|
+
raise ValueError("Obtain a configured release wheel from the publisher.")
|
|
50
|
+
app = json.loads(archive.read(name)).get("installed", {})
|
|
51
|
+
if not app.get("client_id", "").endswith(".apps.googleusercontent.com") or not app.get(
|
|
52
|
+
"client_secret"
|
|
53
|
+
):
|
|
54
|
+
raise ValueError("Invalid release application configuration.")
|
|
55
|
+
# Managed macOS Python distributions resolve libpython relative to their real
|
|
56
|
+
# executable. Copying that executable into a venv can break its dylib path.
|
|
57
|
+
venv.EnvBuilder(with_pip=True, symlinks=True).create(runtime)
|
|
58
|
+
python = runtime / "bin/python"
|
|
59
|
+
pallas = runtime / "bin/pallas"
|
|
60
|
+
subprocess.run([str(python), "-m", "pip", "install", str(wheel)], check=True)
|
|
61
|
+
command = [
|
|
62
|
+
str(pallas),
|
|
63
|
+
"agent",
|
|
64
|
+
"setup",
|
|
65
|
+
"--client",
|
|
66
|
+
args.client,
|
|
67
|
+
"--directory",
|
|
68
|
+
str(directory),
|
|
69
|
+
]
|
|
70
|
+
if args.enable_meta:
|
|
71
|
+
command.extend(["--mode", "live"])
|
|
72
|
+
if args.meta_client_id:
|
|
73
|
+
command.extend(["--meta-client-id", args.meta_client_id])
|
|
74
|
+
subprocess.run(command, check=True)
|
|
75
|
+
if args.meta_client_id:
|
|
76
|
+
command = [str(pallas), "agent", "prepare-meta", "--directory", str(directory)]
|
|
77
|
+
if args.trust_local_certificate:
|
|
78
|
+
command.append("--trust-local-certificate")
|
|
79
|
+
subprocess.run(command, check=True)
|
|
80
|
+
subprocess.run([str(pallas), "agent", "doctor", "--directory", str(directory)], check=True)
|
|
81
|
+
print("Open this project in your Agent and start a new task:", directory)
|
|
82
|
+
print("Local analysis is installed. Live media access is optional and separately verified.")
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def main():
|
|
86
|
+
parser = argparse.ArgumentParser(description=__doc__)
|
|
87
|
+
parser.add_argument("--directory", type=Path, required=True)
|
|
88
|
+
parser.add_argument("--client", choices=["codex", "claude"], default="codex")
|
|
89
|
+
parser.add_argument("--meta-client-id")
|
|
90
|
+
parser.add_argument(
|
|
91
|
+
"--enable-meta",
|
|
92
|
+
action="store_true",
|
|
93
|
+
help="Enable Claude host Meta; Codex requires --meta-client-id",
|
|
94
|
+
)
|
|
95
|
+
parser.add_argument("--require-google", action="store_true")
|
|
96
|
+
parser.add_argument("--trust-local-certificate", action="store_true")
|
|
97
|
+
args = parser.parse_args()
|
|
98
|
+
try:
|
|
99
|
+
install(args)
|
|
100
|
+
except (ValueError, OSError, KeyError, subprocess.SubprocessError):
|
|
101
|
+
# Third-party errors may contain sensitive input. Do not print traceback or JSON.
|
|
102
|
+
print(
|
|
103
|
+
"Installation incomplete. Check macOS/Python version, wheel checksum, embedded "
|
|
104
|
+
"application configuration, fresh destination and system permissions. Existing files "
|
|
105
|
+
"were not replaced. If a project was created, use its pallas agent doctor to resume "
|
|
106
|
+
"the remaining setup; do not rerun over it.",
|
|
107
|
+
file=sys.stderr,
|
|
108
|
+
)
|
|
109
|
+
return 1
|
|
110
|
+
return 0
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
if __name__ == "__main__":
|
|
114
|
+
raise SystemExit(main())
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
{
|
|
2
|
+
"runtimeVersion": "0.2.0a1",
|
|
3
|
+
"wheel": "pallas_ads-0.2.0a1-py3-none-any.whl",
|
|
4
|
+
"files": {
|
|
5
|
+
"pallas_ads-0.2.0a1-py3-none-any.whl": "1eaf69945a04199061825c2475d4ca367c04604b1bb71fc10a4c49cb25ed3380",
|
|
6
|
+
"install_macos.py": "729e077f3abb2983c5ad6551a4c03e60a23cfa020199d462e92ede545d3581b8",
|
|
7
|
+
"release-manifest.json": "2bb76827ca1b0f372ae652bbdbabac67217f075d87581fc9972514a3d9b57673"
|
|
8
|
+
}
|
|
9
|
+
}
|
|
Binary file
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": "0.2.0a1",
|
|
3
|
+
"wheel": "pallas_ads-0.2.0a1-py3-none-any.whl",
|
|
4
|
+
"sha256": "1eaf69945a04199061825c2475d4ca367c04604b1bb71fc10a4c49cb25ed3380",
|
|
5
|
+
"target": "macOS + Codex / Claude Code",
|
|
6
|
+
"default_mode": "core",
|
|
7
|
+
"google_application_embedded": false,
|
|
8
|
+
"requires_google_configuration_file": false,
|
|
9
|
+
"contains_user_oauth_tokens": false,
|
|
10
|
+
"contains_localhost_private_key": false
|
|
11
|
+
}
|