tauri-agent-tools 0.5.1 → 0.7.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/.agents/skills/tauri-agent-tools/SKILL.md +195 -13
- package/.agents/skills/tauri-bridge-setup/SKILL.md +82 -14
- package/.agents/skills/tauri-debug-quickstart/SKILL.md +80 -0
- package/AGENTS.md +9 -7
- package/README.md +119 -11
- package/dist/bridge/client.d.ts +21 -2
- package/dist/bridge/client.js +119 -3
- package/dist/bridge/client.js.map +1 -1
- package/dist/cli.js +47 -0
- package/dist/cli.js.map +1 -1
- package/dist/commands/appPaths.d.ts +2 -0
- package/dist/commands/appPaths.js +97 -0
- package/dist/commands/appPaths.js.map +1 -0
- package/dist/commands/capabilitiesAudit.d.ts +2 -0
- package/dist/commands/capabilitiesAudit.js +105 -0
- package/dist/commands/capabilitiesAudit.js.map +1 -0
- package/dist/commands/capture.d.ts +3 -0
- package/dist/commands/capture.js +218 -0
- package/dist/commands/capture.js.map +1 -0
- package/dist/commands/check.d.ts +5 -0
- package/dist/commands/check.js +174 -0
- package/dist/commands/check.js.map +1 -0
- package/dist/commands/configInspect.d.ts +2 -0
- package/dist/commands/configInspect.js +223 -0
- package/dist/commands/configInspect.js.map +1 -0
- package/dist/commands/diagnose.d.ts +2 -0
- package/dist/commands/diagnose.js +311 -0
- package/dist/commands/diagnose.js.map +1 -0
- package/dist/commands/eval.js +16 -3
- package/dist/commands/eval.js.map +1 -1
- package/dist/commands/forensics.d.ts +2 -0
- package/dist/commands/forensics.js +331 -0
- package/dist/commands/forensics.js.map +1 -0
- package/dist/commands/health.d.ts +2 -0
- package/dist/commands/health.js +39 -0
- package/dist/commands/health.js.map +1 -0
- package/dist/commands/interact/click.d.ts +6 -0
- package/dist/commands/interact/click.js +102 -0
- package/dist/commands/interact/click.js.map +1 -0
- package/dist/commands/interact/focus.d.ts +3 -0
- package/dist/commands/interact/focus.js +40 -0
- package/dist/commands/interact/focus.js.map +1 -0
- package/dist/commands/interact/navigate.d.ts +3 -0
- package/dist/commands/interact/navigate.js +49 -0
- package/dist/commands/interact/navigate.js.map +1 -0
- package/dist/commands/interact/scroll.d.ts +11 -0
- package/dist/commands/interact/scroll.js +110 -0
- package/dist/commands/interact/scroll.js.map +1 -0
- package/dist/commands/interact/select.d.ts +3 -0
- package/dist/commands/interact/select.js +59 -0
- package/dist/commands/interact/select.js.map +1 -0
- package/dist/commands/interact/shared.d.ts +23 -0
- package/dist/commands/interact/shared.js +62 -0
- package/dist/commands/interact/shared.js.map +1 -0
- package/dist/commands/interact/type.d.ts +6 -0
- package/dist/commands/interact/type.js +59 -0
- package/dist/commands/interact/type.js.map +1 -0
- package/dist/commands/invoke.d.ts +3 -0
- package/dist/commands/invoke.js +53 -0
- package/dist/commands/invoke.js.map +1 -0
- package/dist/commands/osLogs.d.ts +2 -0
- package/dist/commands/osLogs.js +130 -0
- package/dist/commands/osLogs.js.map +1 -0
- package/dist/commands/probe.d.ts +2 -0
- package/dist/commands/probe.js +117 -0
- package/dist/commands/probe.js.map +1 -0
- package/dist/commands/processTree.d.ts +2 -0
- package/dist/commands/processTree.js +45 -0
- package/dist/commands/processTree.js.map +1 -0
- package/dist/commands/shared.d.ts +10 -4
- package/dist/commands/shared.js +23 -3
- package/dist/commands/shared.js.map +1 -1
- package/dist/commands/sidecarReplay.d.ts +7 -0
- package/dist/commands/sidecarReplay.js +93 -0
- package/dist/commands/sidecarReplay.js.map +1 -0
- package/dist/commands/sidecarTap.d.ts +2 -0
- package/dist/commands/sidecarTap.js +118 -0
- package/dist/commands/sidecarTap.js.map +1 -0
- package/dist/commands/storeInspect.d.ts +13 -0
- package/dist/commands/storeInspect.js +156 -0
- package/dist/commands/storeInspect.js.map +1 -0
- package/dist/commands/webviewAttach.d.ts +2 -0
- package/dist/commands/webviewAttach.js +64 -0
- package/dist/commands/webviewAttach.js.map +1 -0
- package/dist/platform/oslog/darwin.d.ts +21 -0
- package/dist/platform/oslog/darwin.js +72 -0
- package/dist/platform/oslog/darwin.js.map +1 -0
- package/dist/platform/oslog/linux.d.ts +16 -0
- package/dist/platform/oslog/linux.js +47 -0
- package/dist/platform/oslog/linux.js.map +1 -0
- package/dist/platform/oslog/windows.d.ts +15 -0
- package/dist/platform/oslog/windows.js +16 -0
- package/dist/platform/oslog/windows.js.map +1 -0
- package/dist/schemas/bridge.d.ts +256 -0
- package/dist/schemas/bridge.js +57 -0
- package/dist/schemas/bridge.js.map +1 -1
- package/dist/schemas/commands.d.ts +126 -0
- package/dist/schemas/commands.js +28 -0
- package/dist/schemas/commands.js.map +1 -1
- package/dist/schemas/index.d.ts +3 -2
- package/dist/schemas/index.js +3 -2
- package/dist/schemas/index.js.map +1 -1
- package/dist/schemas/interact.d.ts +118 -0
- package/dist/schemas/interact.js +31 -0
- package/dist/schemas/interact.js.map +1 -0
- package/dist/schemas/osLog.d.ts +34 -0
- package/dist/schemas/osLog.js +18 -0
- package/dist/schemas/osLog.js.map +1 -0
- package/dist/schemas/sidecar.d.ts +33 -0
- package/dist/schemas/sidecar.js +17 -0
- package/dist/schemas/sidecar.js.map +1 -0
- package/dist/schemas/tauriConfig.d.ts +825 -0
- package/dist/schemas/tauriConfig.js +102 -0
- package/dist/schemas/tauriConfig.js.map +1 -0
- package/dist/util/ndjson.d.ts +37 -0
- package/dist/util/ndjson.js +82 -0
- package/dist/util/ndjson.js.map +1 -0
- package/dist/util/tauriConfig.d.ts +63 -0
- package/dist/util/tauriConfig.js +235 -0
- package/dist/util/tauriConfig.js.map +1 -0
- package/examples/frontend-stub/index.html +1 -0
- package/examples/tauri-bridge/Cargo.toml +6 -0
- package/examples/tauri-bridge/build.rs +3 -0
- package/examples/tauri-bridge/icons/icon.png +0 -0
- package/examples/tauri-bridge/src/dev_bridge.rs +509 -10
- package/examples/tauri-bridge/tauri.conf.json +25 -0
- package/package.json +3 -1
- package/rust-bridge/README.md +7 -5
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { readFile } from 'node:fs/promises';
|
|
3
|
+
import { existsSync } from 'node:fs';
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
import { loadCapability, resolveTauriProject } from '../util/tauriConfig.js';
|
|
6
|
+
const OVERBROAD_PERMISSIONS = new Set([
|
|
7
|
+
'fs:allow-all',
|
|
8
|
+
'fs:default',
|
|
9
|
+
'shell:allow-execute',
|
|
10
|
+
'shell:allow-spawn',
|
|
11
|
+
'http:allow-all',
|
|
12
|
+
]);
|
|
13
|
+
export function registerConfigInspect(program) {
|
|
14
|
+
const cmd = new Command('config')
|
|
15
|
+
.description('Inspect a Tauri app config (paths, capabilities, sidecars)');
|
|
16
|
+
cmd
|
|
17
|
+
.command('inspect')
|
|
18
|
+
.description('Emit a structured snapshot of tauri.conf.json + capabilities')
|
|
19
|
+
.option('--config <path>', 'Path to tauri.conf.json (or its directory). Auto-detected if omitted.')
|
|
20
|
+
.option('--capabilities-dir <path>', 'Directory holding capability *.json files (default: <project>/src-tauri/capabilities/)')
|
|
21
|
+
.option('--cargo-toml <path>', 'Path to the Rust crate\'s Cargo.toml (default: <project>/src-tauri/Cargo.toml). Used to cross-check plugin declarations.')
|
|
22
|
+
.option('--json', 'Output as JSON')
|
|
23
|
+
.action(async (opts) => {
|
|
24
|
+
const resolved = await resolveTauriProject({
|
|
25
|
+
configPath: opts.config,
|
|
26
|
+
capabilitiesDir: opts.capabilitiesDir,
|
|
27
|
+
});
|
|
28
|
+
const capabilities = await loadAllCapabilities(resolved.capabilityFiles);
|
|
29
|
+
const cargoTomlPath = opts.cargoToml ?? defaultCargoToml(resolved.configPath);
|
|
30
|
+
const cargoTomlExists = existsSync(cargoTomlPath);
|
|
31
|
+
const declaredPlugins = cargoTomlExists ? await readDeclaredPlugins(cargoTomlPath) : [];
|
|
32
|
+
const warnings = collectWarnings(capabilities, declaredPlugins, resolved.sidecars, cargoTomlExists);
|
|
33
|
+
const out = {
|
|
34
|
+
identifier: resolved.identifier,
|
|
35
|
+
productName: resolved.productName,
|
|
36
|
+
version: resolved.version,
|
|
37
|
+
mainBinaryName: resolved.mainBinaryName,
|
|
38
|
+
devUrl: resolved.devUrl,
|
|
39
|
+
devPort: resolved.devPort,
|
|
40
|
+
frontendDist: resolved.frontendDist,
|
|
41
|
+
sidecars: resolved.sidecars,
|
|
42
|
+
windows: resolved.windows,
|
|
43
|
+
configPath: resolved.configPath,
|
|
44
|
+
capabilities,
|
|
45
|
+
declaredPlugins,
|
|
46
|
+
warnings,
|
|
47
|
+
};
|
|
48
|
+
if (opts.json) {
|
|
49
|
+
console.log(JSON.stringify(out, null, 2));
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
printHumanReadable(out);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
program.addCommand(cmd);
|
|
56
|
+
}
|
|
57
|
+
async function loadAllCapabilities(files) {
|
|
58
|
+
const out = [];
|
|
59
|
+
for (const file of files) {
|
|
60
|
+
let cap;
|
|
61
|
+
try {
|
|
62
|
+
cap = await loadCapability(file);
|
|
63
|
+
}
|
|
64
|
+
catch (err) {
|
|
65
|
+
// Surface as a degenerate entry rather than aborting — the warning collector
|
|
66
|
+
// wants to know about malformed capability files too.
|
|
67
|
+
out.push({
|
|
68
|
+
file,
|
|
69
|
+
identifier: '<parse-error>',
|
|
70
|
+
description: err instanceof Error ? err.message : String(err),
|
|
71
|
+
windows: [],
|
|
72
|
+
platforms: [],
|
|
73
|
+
permissions: [],
|
|
74
|
+
permissionCount: 0,
|
|
75
|
+
});
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
const perms = cap.permissions.map(permissionToEntry);
|
|
79
|
+
out.push({
|
|
80
|
+
file,
|
|
81
|
+
identifier: cap.identifier,
|
|
82
|
+
description: cap.description ?? null,
|
|
83
|
+
windows: cap.windows ?? [],
|
|
84
|
+
platforms: cap.platforms ?? [],
|
|
85
|
+
permissions: perms,
|
|
86
|
+
permissionCount: perms.length,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
return out;
|
|
90
|
+
}
|
|
91
|
+
function permissionToEntry(p) {
|
|
92
|
+
if (typeof p === 'string') {
|
|
93
|
+
return { identifier: p, hasAllow: false, hasDeny: false };
|
|
94
|
+
}
|
|
95
|
+
return {
|
|
96
|
+
identifier: p.identifier,
|
|
97
|
+
hasAllow: Array.isArray(p.allow) && p.allow.length > 0,
|
|
98
|
+
hasDeny: Array.isArray(p.deny) && p.deny.length > 0,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
function defaultCargoToml(configPath) {
|
|
102
|
+
// configPath is .../src-tauri/tauri.conf.json → Cargo.toml lives alongside.
|
|
103
|
+
return join(configPath, '..', 'Cargo.toml');
|
|
104
|
+
}
|
|
105
|
+
async function readDeclaredPlugins(cargoToml) {
|
|
106
|
+
const text = await readFile(cargoToml, 'utf-8');
|
|
107
|
+
// Match `tauri-plugin-<name>` package names in dependencies. Conservative regex —
|
|
108
|
+
// doesn't try to parse TOML; just grabs the plugin family that matters for the
|
|
109
|
+
// capability/plugin cross-check.
|
|
110
|
+
const matches = text.matchAll(/\b(tauri-plugin-[a-z0-9_-]+)\b/g);
|
|
111
|
+
const plugins = new Set();
|
|
112
|
+
for (const m of matches) {
|
|
113
|
+
const name = m[1];
|
|
114
|
+
if (name)
|
|
115
|
+
plugins.add(name);
|
|
116
|
+
}
|
|
117
|
+
return Array.from(plugins).sort();
|
|
118
|
+
}
|
|
119
|
+
function collectWarnings(capabilities, declaredPlugins, sidecars, cargoTomlPresent) {
|
|
120
|
+
const out = [];
|
|
121
|
+
for (const cap of capabilities) {
|
|
122
|
+
if (cap.identifier === '<parse-error>') {
|
|
123
|
+
out.push({
|
|
124
|
+
level: 'error',
|
|
125
|
+
message: `Capability file failed to parse: ${cap.file}`,
|
|
126
|
+
context: { error: cap.description ?? '' },
|
|
127
|
+
});
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
if (cap.permissions.length === 0) {
|
|
131
|
+
out.push({
|
|
132
|
+
level: 'info',
|
|
133
|
+
message: `Capability "${cap.identifier}" has no permissions declared`,
|
|
134
|
+
context: { file: cap.file },
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
for (const perm of cap.permissions) {
|
|
138
|
+
if (perm.identifier === '*') {
|
|
139
|
+
out.push({
|
|
140
|
+
level: 'error',
|
|
141
|
+
message: `Capability "${cap.identifier}" grants wildcard permission "*"`,
|
|
142
|
+
context: { file: cap.file },
|
|
143
|
+
});
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
if (OVERBROAD_PERMISSIONS.has(perm.identifier)) {
|
|
147
|
+
out.push({
|
|
148
|
+
level: 'warn',
|
|
149
|
+
message: `Capability "${cap.identifier}" uses over-broad permission "${perm.identifier}"`,
|
|
150
|
+
context: { file: cap.file },
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
// Cross-check: if the permission references a plugin family, that plugin
|
|
154
|
+
// should also be declared in Cargo.toml. (Built-in `core:*` permissions are
|
|
155
|
+
// exempt — they don't map to a tauri-plugin-* crate.) Skip the check entirely
|
|
156
|
+
// when Cargo.toml is missing — we have no ground truth, so reporting would
|
|
157
|
+
// be a false positive.
|
|
158
|
+
const [family] = perm.identifier.split(':');
|
|
159
|
+
if (family && family !== 'core' && cargoTomlPresent) {
|
|
160
|
+
const expectedCrate = `tauri-plugin-${family}`;
|
|
161
|
+
if (!declaredPlugins.includes(expectedCrate)) {
|
|
162
|
+
out.push({
|
|
163
|
+
level: 'warn',
|
|
164
|
+
message: `Capability "${cap.identifier}" references plugin "${family}" but ${expectedCrate} is not in Cargo.toml`,
|
|
165
|
+
context: { file: cap.file },
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
// Sidecars declared in bundle.externalBin but no shell plugin → unusable.
|
|
172
|
+
if (sidecars.length > 0 && cargoTomlPresent && !declaredPlugins.includes('tauri-plugin-shell')) {
|
|
173
|
+
out.push({
|
|
174
|
+
level: 'warn',
|
|
175
|
+
message: `bundle.externalBin declares ${sidecars.length} sidecar(s) but tauri-plugin-shell is not in Cargo.toml — sidecars are launched through the shell plugin`,
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
return out;
|
|
179
|
+
}
|
|
180
|
+
function printHumanReadable(out) {
|
|
181
|
+
console.log(`Identifier: ${out.identifier}`);
|
|
182
|
+
console.log(`Product name: ${out.productName}`);
|
|
183
|
+
if (out.version)
|
|
184
|
+
console.log(`Version: ${out.version}`);
|
|
185
|
+
if (out.devUrl)
|
|
186
|
+
console.log(`Dev URL: ${out.devUrl} (port ${out.devPort ?? 'unknown'})`);
|
|
187
|
+
if (out.frontendDist)
|
|
188
|
+
console.log(`Frontend dist: ${out.frontendDist}`);
|
|
189
|
+
if (out.sidecars.length > 0) {
|
|
190
|
+
console.log(`\nSidecars (${out.sidecars.length}):`);
|
|
191
|
+
for (const s of out.sidecars)
|
|
192
|
+
console.log(` • ${s}`);
|
|
193
|
+
}
|
|
194
|
+
if (out.windows.length > 0) {
|
|
195
|
+
console.log(`\nWindows (${out.windows.length}):`);
|
|
196
|
+
for (const w of out.windows)
|
|
197
|
+
console.log(` • ${w}`);
|
|
198
|
+
}
|
|
199
|
+
if (out.declaredPlugins.length > 0) {
|
|
200
|
+
console.log(`\nDeclared plugins (${out.declaredPlugins.length}):`);
|
|
201
|
+
for (const p of out.declaredPlugins)
|
|
202
|
+
console.log(` • ${p}`);
|
|
203
|
+
}
|
|
204
|
+
console.log(`\nCapabilities (${out.capabilities.length}):`);
|
|
205
|
+
for (const cap of out.capabilities) {
|
|
206
|
+
console.log(` [${cap.identifier}] ${cap.permissionCount} permission(s)`);
|
|
207
|
+
if (cap.description)
|
|
208
|
+
console.log(` ${cap.description}`);
|
|
209
|
+
if (cap.windows.length > 0)
|
|
210
|
+
console.log(` windows: ${cap.windows.join(', ')}`);
|
|
211
|
+
}
|
|
212
|
+
if (out.warnings.length > 0) {
|
|
213
|
+
console.log(`\nWarnings (${out.warnings.length}):`);
|
|
214
|
+
for (const w of out.warnings) {
|
|
215
|
+
const tag = w.level.toUpperCase().padEnd(5);
|
|
216
|
+
console.log(` ${tag} ${w.message}`);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
else {
|
|
220
|
+
console.log(`\nNo warnings.`);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
//# sourceMappingURL=configInspect.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"configInspect.js","sourceRoot":"","sources":["../../src/commands/configInspect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAgD7E,MAAM,qBAAqB,GAAG,IAAI,GAAG,CAAC;IACpC,cAAc;IACd,YAAY;IACZ,qBAAqB;IACrB,mBAAmB;IACnB,gBAAgB;CACjB,CAAC,CAAC;AAEH,MAAM,UAAU,qBAAqB,CAAC,OAAgB;IACpD,MAAM,GAAG,GAAG,IAAI,OAAO,CAAC,QAAQ,CAAC;SAC9B,WAAW,CAAC,4DAA4D,CAAC,CAAC;IAC7E,GAAG;SACA,OAAO,CAAC,SAAS,CAAC;SAClB,WAAW,CAAC,8DAA8D,CAAC;SAC3E,MAAM,CAAC,iBAAiB,EAAE,uEAAuE,CAAC;SAClG,MAAM,CACL,2BAA2B,EAC3B,wFAAwF,CACzF;SACA,MAAM,CACL,qBAAqB,EACrB,0HAA0H,CAC3H;SACA,MAAM,CAAC,QAAQ,EAAE,gBAAgB,CAAC;SAClC,MAAM,CAAC,KAAK,EAAE,IAAuB,EAAE,EAAE;QACxC,MAAM,QAAQ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AO,CAAC,GAAG,CAAC,QAAQ,GAAG,CAAC,WAAW,EAAE,CAAC,CAAC;QAC5D,IAAI,GAAG,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC;YAAE,OAAO,CAAC,GAAG,CAAC,iBAAiB,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACrF,CAAC;IACD,IAAI,GAAG,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC5B,OAAO,CAAC,GAAG,CAAC,eAAe,GAAG,CAAC,QAAQ,CAAC,MAAM,IAAI,CAAC,CAAC;QACpD,KAAK,MAAM,CAAC,IAAI,GAAG,CAAC,QAAQ,EAAE,CAAC;YAC7B,MAAM,GAAG,GAAG,CAAC,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;YAC5C,OAAO,CAAC,GAAG,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;QACvC,CAAC;IACH,CAAC;SAAM,CAAC;QACN,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;IAChC,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { spawn } from 'node:child_process';
|
|
3
|
+
import { mkdir, readFile, writeFile } from 'node:fs/promises';
|
|
4
|
+
import { existsSync } from 'node:fs';
|
|
5
|
+
import { join } from 'node:path';
|
|
6
|
+
import { addBridgeOptions } from './shared.js';
|
|
7
|
+
import { BridgeClient } from '../bridge/client.js';
|
|
8
|
+
import { discoverBridge, discoverBridgesByPid } from '../bridge/tokenDiscovery.js';
|
|
9
|
+
import { resolveTauriProject } from '../util/tauriConfig.js';
|
|
10
|
+
export function registerDiagnose(program) {
|
|
11
|
+
const cmd = new Command('diagnose')
|
|
12
|
+
.description("Full diagnostic bundle: composes `forensics` with live bridge data when available. Best-effort — degrades cleanly when the bridge isn't reachable.")
|
|
13
|
+
.option('--config <path>', 'Path to tauri.conf.json (or its directory). Auto-detected if omitted.')
|
|
14
|
+
.option('--identifier <id>', 'Bundle identifier override')
|
|
15
|
+
.option('-o, --out <dir>', 'Output directory (default: ./diagnose-<timestamp>)')
|
|
16
|
+
.option('--since <duration>', 'How far back to pull from app log files (forensics phase, default: 10m)')
|
|
17
|
+
.option('--logs-duration <ms>', 'Time budget for live OS-log tail in milliseconds (default: 3000)')
|
|
18
|
+
.option('--no-bridge', 'Skip bridge-enrichment phase even if a bridge is reachable')
|
|
19
|
+
.option('--json', 'Print the master summary as JSON in addition to writing to disk');
|
|
20
|
+
addBridgeOptions(cmd);
|
|
21
|
+
cmd.action(async (opts) => {
|
|
22
|
+
const outDir = opts.out ?? `./diagnose-${timestampSlug()}`;
|
|
23
|
+
await mkdir(outDir, { recursive: true });
|
|
24
|
+
const forensicsDir = join(outDir, 'forensics');
|
|
25
|
+
await mkdir(forensicsDir, { recursive: true });
|
|
26
|
+
const outcomes = [];
|
|
27
|
+
// ── Phase A: Resolve project (for the summary header) ──────────────────
|
|
28
|
+
let identifier = '<unknown>';
|
|
29
|
+
let productName = '<unknown>';
|
|
30
|
+
try {
|
|
31
|
+
const resolved = await resolveTauriProject({
|
|
32
|
+
configPath: opts.config,
|
|
33
|
+
identifierOverride: opts.identifier,
|
|
34
|
+
});
|
|
35
|
+
identifier = resolved.identifier;
|
|
36
|
+
productName = resolved.productName;
|
|
37
|
+
outcomes.push({
|
|
38
|
+
phase: 'resolve-config',
|
|
39
|
+
ok: true,
|
|
40
|
+
detail: `identifier=${identifier} productName=${productName}`,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
catch (err) {
|
|
44
|
+
outcomes.push({
|
|
45
|
+
phase: 'resolve-config',
|
|
46
|
+
ok: false,
|
|
47
|
+
detail: err instanceof Error ? err.message : String(err),
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
// ── Phase B: Forensics subprocess (Tier 1 bundle) ──────────────────────
|
|
51
|
+
const forensicsArgs = ['forensics', '-o', forensicsDir, '--logs-duration', String(opts.logsDuration ?? 3000)];
|
|
52
|
+
if (opts.config)
|
|
53
|
+
forensicsArgs.push('--config', opts.config);
|
|
54
|
+
if (opts.identifier)
|
|
55
|
+
forensicsArgs.push('--identifier', opts.identifier);
|
|
56
|
+
if (opts.since)
|
|
57
|
+
forensicsArgs.push('--since', opts.since);
|
|
58
|
+
try {
|
|
59
|
+
await runSelf(forensicsArgs);
|
|
60
|
+
outcomes.push({ phase: 'forensics', ok: true, detail: `→ ${forensicsDir}` });
|
|
61
|
+
}
|
|
62
|
+
catch (err) {
|
|
63
|
+
outcomes.push({
|
|
64
|
+
phase: 'forensics',
|
|
65
|
+
ok: false,
|
|
66
|
+
detail: err instanceof Error ? err.message : String(err),
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
// ── Phase C: Bridge enrichment (Tier 2) — optional, best-effort ────────
|
|
70
|
+
const bridgeData = await collectBridgeData(opts, outcomes);
|
|
71
|
+
await writeFile(join(outDir, 'bridge.json'), JSON.stringify(bridgeData, null, 2));
|
|
72
|
+
// ── Phase D: Master summary ────────────────────────────────────────────
|
|
73
|
+
const forensicsSummary = await tryReadJson(join(forensicsDir, 'summary.json'));
|
|
74
|
+
const master = {
|
|
75
|
+
identifier,
|
|
76
|
+
productName,
|
|
77
|
+
outDir,
|
|
78
|
+
forensicsDir,
|
|
79
|
+
phases: outcomes,
|
|
80
|
+
bridgeReachable: bridgeData.reachable,
|
|
81
|
+
bridgeVersion: bridgeData.version,
|
|
82
|
+
forensicsSummary: forensicsSummary ?? null,
|
|
83
|
+
};
|
|
84
|
+
await writeFile(join(outDir, 'summary.json'), JSON.stringify(master, null, 2));
|
|
85
|
+
await writeFile(join(outDir, 'summary.md'), renderMaster(master, bridgeData, outcomes));
|
|
86
|
+
if (opts.json) {
|
|
87
|
+
console.log(JSON.stringify(master, null, 2));
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
const ok = outcomes.filter((o) => o.ok).length;
|
|
91
|
+
console.log(`✓ Diagnostic bundle written to ${outDir}`);
|
|
92
|
+
console.log(` ${ok}/${outcomes.length} phases succeeded`);
|
|
93
|
+
console.log(` Bridge: ${bridgeData.reachable ? `reachable (v${bridgeData.version})` : 'unreachable — bundle is forensics-only'}`);
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
program.addCommand(cmd);
|
|
97
|
+
}
|
|
98
|
+
function timestampSlug() {
|
|
99
|
+
return new Date().toISOString().replace(/[:.]/g, '-');
|
|
100
|
+
}
|
|
101
|
+
/** Spawn the same CLI binary that's currently running, for one-level composition. */
|
|
102
|
+
function runSelf(args) {
|
|
103
|
+
return new Promise((resolve, reject) => {
|
|
104
|
+
const cliPath = process.argv[1];
|
|
105
|
+
if (!cliPath) {
|
|
106
|
+
reject(new Error('Could not locate the current CLI binary (process.argv[1] is empty)'));
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
const child = spawn(process.execPath, [cliPath, ...args], {
|
|
110
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
111
|
+
});
|
|
112
|
+
let stderr = '';
|
|
113
|
+
child.stderr.setEncoding('utf-8');
|
|
114
|
+
child.stderr.on('data', (chunk) => (stderr += chunk));
|
|
115
|
+
child.on('error', reject);
|
|
116
|
+
child.on('close', (code) => {
|
|
117
|
+
if (code === 0)
|
|
118
|
+
resolve();
|
|
119
|
+
else
|
|
120
|
+
reject(new Error(`subprocess exited ${code}${stderr ? ': ' + stderr.trim() : ''}`));
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
async function tryReadJson(path) {
|
|
125
|
+
if (!existsSync(path))
|
|
126
|
+
return null;
|
|
127
|
+
try {
|
|
128
|
+
return JSON.parse(await readFile(path, 'utf-8'));
|
|
129
|
+
}
|
|
130
|
+
catch {
|
|
131
|
+
return null;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
async function collectBridgeData(opts, outcomes) {
|
|
135
|
+
const data = {
|
|
136
|
+
reachable: false,
|
|
137
|
+
version: null,
|
|
138
|
+
process: null,
|
|
139
|
+
capabilities: null,
|
|
140
|
+
devtools: null,
|
|
141
|
+
health: null,
|
|
142
|
+
errors: {},
|
|
143
|
+
};
|
|
144
|
+
if (opts.noBridge) {
|
|
145
|
+
outcomes.push({ phase: 'bridge', ok: true, detail: 'skipped (--no-bridge)' });
|
|
146
|
+
return data;
|
|
147
|
+
}
|
|
148
|
+
// Resolve a bridge config without throwing — diagnose tolerates absence.
|
|
149
|
+
const cfg = await tryResolveBridgeConfig(opts);
|
|
150
|
+
if (!cfg) {
|
|
151
|
+
outcomes.push({ phase: 'bridge', ok: false, detail: 'no live bridge discovered' });
|
|
152
|
+
return data;
|
|
153
|
+
}
|
|
154
|
+
const client = new BridgeClient(cfg, opts.windowLabel);
|
|
155
|
+
const version = await client.version();
|
|
156
|
+
if (!version) {
|
|
157
|
+
outcomes.push({ phase: 'bridge', ok: false, detail: `bridge at port ${cfg.port} did not respond to /version` });
|
|
158
|
+
return data;
|
|
159
|
+
}
|
|
160
|
+
data.reachable = true;
|
|
161
|
+
data.version = version.version;
|
|
162
|
+
// Each endpoint is best-effort; record per-endpoint failures rather than aborting.
|
|
163
|
+
for (const [name, fn] of [
|
|
164
|
+
['process', () => client.process()],
|
|
165
|
+
['capabilities', () => client.capabilities()],
|
|
166
|
+
['devtools', () => client.devtools()],
|
|
167
|
+
['health', () => client.health()],
|
|
168
|
+
]) {
|
|
169
|
+
try {
|
|
170
|
+
const result = await fn();
|
|
171
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
172
|
+
data[name] = result;
|
|
173
|
+
outcomes.push({ phase: `bridge:${name}`, ok: true, detail: 'ok' });
|
|
174
|
+
}
|
|
175
|
+
catch (err) {
|
|
176
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
177
|
+
data.errors[name] = msg;
|
|
178
|
+
outcomes.push({ phase: `bridge:${name}`, ok: false, detail: msg });
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
return data;
|
|
182
|
+
}
|
|
183
|
+
async function tryResolveBridgeConfig(opts) {
|
|
184
|
+
try {
|
|
185
|
+
if (opts.port && opts.token) {
|
|
186
|
+
return { port: opts.port, token: opts.token };
|
|
187
|
+
}
|
|
188
|
+
if (opts.pid !== undefined) {
|
|
189
|
+
const bridges = await discoverBridgesByPid();
|
|
190
|
+
const match = bridges.get(opts.pid);
|
|
191
|
+
if (!match)
|
|
192
|
+
return null;
|
|
193
|
+
return {
|
|
194
|
+
port: opts.port ?? match.port,
|
|
195
|
+
token: opts.token ?? match.token,
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
const discovered = await discoverBridge();
|
|
199
|
+
if (!discovered)
|
|
200
|
+
return null;
|
|
201
|
+
return {
|
|
202
|
+
port: opts.port ?? discovered.port,
|
|
203
|
+
token: opts.token ?? discovered.token,
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
catch {
|
|
207
|
+
return null;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
function renderMaster(master, bridge, outcomes) {
|
|
211
|
+
const phaseRows = outcomes
|
|
212
|
+
.map((o) => `- ${o.ok ? '✓' : '✗'} **${o.phase}** — ${o.detail}`)
|
|
213
|
+
.join('\n');
|
|
214
|
+
const bridgeSection = bridge.reachable ? renderBridgeSection(bridge) : NO_BRIDGE_HINT;
|
|
215
|
+
return `# Diagnose: ${master.productName}
|
|
216
|
+
|
|
217
|
+
- **Identifier:** \`${master.identifier}\`
|
|
218
|
+
- **Output:** \`${master.outDir}\`
|
|
219
|
+
- **Forensics bundle:** [\`${master.forensicsDir}/summary.md\`](./forensics/summary.md)
|
|
220
|
+
|
|
221
|
+
## Phases
|
|
222
|
+
|
|
223
|
+
${phaseRows}
|
|
224
|
+
|
|
225
|
+
## Bridge enrichment
|
|
226
|
+
|
|
227
|
+
${bridgeSection}
|
|
228
|
+
|
|
229
|
+
## Next steps
|
|
230
|
+
|
|
231
|
+
${suggestNext(master, bridge, outcomes)}
|
|
232
|
+
`;
|
|
233
|
+
}
|
|
234
|
+
const NO_BRIDGE_HINT = `_No live dev bridge was reachable._ The bundle in \`forensics/\` is still useful for post-mortem analysis (OS log tail, panic markers, app data file listing). To get richer data next time:
|
|
235
|
+
|
|
236
|
+
- Confirm the app is running in dev mode (\`cfg!(debug_assertions)\` must be true)
|
|
237
|
+
- Check for token files: \`ls /tmp/tauri-dev-bridge-*.token\`
|
|
238
|
+
- If you have a PID, pass \`--pid <n>\` explicitly
|
|
239
|
+
`;
|
|
240
|
+
function renderBridgeSection(bridge) {
|
|
241
|
+
const parts = [`_Bridge v${bridge.version} responded._`, ''];
|
|
242
|
+
if (bridge.health) {
|
|
243
|
+
parts.push('### Health');
|
|
244
|
+
parts.push('');
|
|
245
|
+
parts.push(`- Uptime: ${Math.floor(bridge.health.uptime_ms / 1000)}s`);
|
|
246
|
+
parts.push(`- Webview ready: ${bridge.health.webview_ready ? 'yes' : '**NO**'}`);
|
|
247
|
+
parts.push(`- Sidecars alive: ${bridge.health.sidecars_alive ? 'yes' : '**NO**'}`);
|
|
248
|
+
parts.push('');
|
|
249
|
+
}
|
|
250
|
+
if (bridge.process) {
|
|
251
|
+
parts.push('### Process tree');
|
|
252
|
+
parts.push('');
|
|
253
|
+
parts.push(`- Tauri pid \`${bridge.process.tauri.pid}\` (uptime ${Math.floor(bridge.process.tauri.uptime_ms / 1000)}s)`);
|
|
254
|
+
if (bridge.process.sidecars.length === 0) {
|
|
255
|
+
parts.push('- No sidecars registered');
|
|
256
|
+
}
|
|
257
|
+
else {
|
|
258
|
+
for (const s of bridge.process.sidecars) {
|
|
259
|
+
const alive = s.alive === null || s.alive === undefined ? '?' : s.alive ? 'alive' : '**DEAD**';
|
|
260
|
+
parts.push(`- Sidecar \`${s.name}\` pid \`${s.pid}\` — ${alive}`);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
parts.push('');
|
|
264
|
+
}
|
|
265
|
+
if (bridge.devtools) {
|
|
266
|
+
parts.push('### Webview devtools');
|
|
267
|
+
parts.push('');
|
|
268
|
+
parts.push(`- Platform: ${bridge.devtools.platform}`);
|
|
269
|
+
parts.push(`- Inspectable: ${bridge.devtools.inspectable ? 'yes' : 'no'}`);
|
|
270
|
+
if (bridge.devtools.url)
|
|
271
|
+
parts.push(`- URL: ${bridge.devtools.url}`);
|
|
272
|
+
parts.push(`- Hint: ${bridge.devtools.hint}`);
|
|
273
|
+
parts.push('');
|
|
274
|
+
}
|
|
275
|
+
if (bridge.capabilities) {
|
|
276
|
+
parts.push('### Capabilities');
|
|
277
|
+
parts.push('');
|
|
278
|
+
parts.push(`- Windows: ${bridge.capabilities.windows.join(', ') || '(none)'}`);
|
|
279
|
+
parts.push(`- Declared: ${bridge.capabilities.declared.length}`);
|
|
280
|
+
parts.push('');
|
|
281
|
+
}
|
|
282
|
+
if (Object.keys(bridge.errors).length > 0) {
|
|
283
|
+
parts.push('### Bridge endpoint errors');
|
|
284
|
+
parts.push('');
|
|
285
|
+
for (const [endpoint, err] of Object.entries(bridge.errors)) {
|
|
286
|
+
parts.push(`- \`${endpoint}\`: ${err}`);
|
|
287
|
+
}
|
|
288
|
+
parts.push('');
|
|
289
|
+
}
|
|
290
|
+
return parts.join('\n');
|
|
291
|
+
}
|
|
292
|
+
function suggestNext(master, bridge, outcomes) {
|
|
293
|
+
const tips = [];
|
|
294
|
+
if (!bridge.reachable) {
|
|
295
|
+
tips.push(`- Bridge was not reachable; the bundle in \`forensics/\` is your best evidence. Inspect \`forensics/summary.md\` first.`);
|
|
296
|
+
}
|
|
297
|
+
if (bridge.health && !bridge.health.webview_ready) {
|
|
298
|
+
tips.push(`- The bridge reports the webview is **not ready**. Likely a pre-webview-boot failure — check \`forensics/app-log-tail.txt\` for the last Rust messages before the webview was supposed to come up.`);
|
|
299
|
+
}
|
|
300
|
+
if (bridge.health && !bridge.health.sidecars_alive) {
|
|
301
|
+
tips.push(`- One or more sidecars are dead. Run \`tauri-agent-tools sidecar tap --schema <path> -- <cmd>\` against the failing sidecar to see exactly what envelope it emits before exiting.`);
|
|
302
|
+
}
|
|
303
|
+
if (outcomes.some((o) => o.phase === 'forensics' && !o.ok)) {
|
|
304
|
+
tips.push(`- The forensics subprocess failed. Run \`tauri-agent-tools forensics --config ${master.identifier === '<unknown>' ? '<path>' : 'auto'} -o /tmp/forensics\` directly to surface the error.`);
|
|
305
|
+
}
|
|
306
|
+
if (tips.length === 0) {
|
|
307
|
+
tips.push(`- No specific anomalies detected. Browse \`${'forensics/summary.md'}\` and the per-endpoint JSON in \`bridge.json\` for context.`);
|
|
308
|
+
}
|
|
309
|
+
return tips.join('\n');
|
|
310
|
+
}
|
|
311
|
+
//# sourceMappingURL=diagnose.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diagnose.js","sourceRoot":"","sources":["../../src/commands/diagnose.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC9D,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,gBAAgB,EAAmB,MAAM,aAAa,CAAC;AAChE,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AAOnF,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AA6B7D,MAAM,UAAU,gBAAgB,CAAC,OAAgB;IAC/C,MAAM,GAAG,GAAG,IAAI,OAAO,CAAC,UAAU,CAAC;SAChC,WAAW,CACV,oJAAoJ,CACrJ;SACA,MAAM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AI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACzB,CAAC"}
|
package/dist/commands/eval.js
CHANGED
|
@@ -1,18 +1,31 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
1
2
|
import { Command } from 'commander';
|
|
2
3
|
import { addBridgeOptions, resolveBridge } from './shared.js';
|
|
3
4
|
export function registerEval(program) {
|
|
4
5
|
const cmd = new Command('eval')
|
|
5
6
|
.description('Evaluate a JavaScript expression in the Tauri app')
|
|
6
|
-
.argument('
|
|
7
|
+
.argument('[expression]', 'JavaScript expression to evaluate')
|
|
8
|
+
.option('--file <path>', 'Read JavaScript from a file instead of argument')
|
|
7
9
|
.addHelpText('after', `
|
|
8
10
|
Examples:
|
|
9
11
|
$ tauri-agent-tools eval "document.title"
|
|
10
12
|
$ tauri-agent-tools eval "window.location.href"
|
|
11
|
-
$ tauri-agent-tools eval "document.querySelectorAll('button').length"
|
|
13
|
+
$ tauri-agent-tools eval "document.querySelectorAll('button').length"
|
|
14
|
+
$ tauri-agent-tools eval --file script.js`);
|
|
12
15
|
addBridgeOptions(cmd);
|
|
13
16
|
cmd.action(async (expression, opts) => {
|
|
17
|
+
let js;
|
|
18
|
+
if (opts.file) {
|
|
19
|
+
js = await readFile(opts.file, 'utf-8');
|
|
20
|
+
}
|
|
21
|
+
else if (expression) {
|
|
22
|
+
js = expression;
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
throw new Error('Provide either an <expression> argument or --file <path>');
|
|
26
|
+
}
|
|
14
27
|
const bridge = await resolveBridge(opts);
|
|
15
|
-
const result = await bridge.eval(
|
|
28
|
+
const result = await bridge.eval(js);
|
|
16
29
|
if (typeof result === 'string') {
|
|
17
30
|
// Try to pretty-print if it's JSON
|
|
18
31
|
try {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"eval.js","sourceRoot":"","sources":["../../src/commands/eval.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WA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