@skillstech/thunderlang 0.5.10 → 0.5.12
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/CHANGELOG.md +450 -0
- package/dist/core.cjs +30434 -7577
- package/dist/index.cjs +28576 -5328
- package/dist/learn.cjs +24201 -5367
- package/package.json +12 -3
- package/src/bicep.mjs +167 -0
- package/src/cli.mjs +169 -3
- package/src/commands.mjs +464 -0
- package/src/core.d.ts +12 -4
- package/src/core.mjs +12 -4
- package/src/emit.mjs +1 -1
- package/src/executed.d.mts +53 -0
- package/src/executed.mjs +465 -0
- package/src/faithful.mjs +137 -0
- package/src/file-formats.mjs +35 -0
- package/src/hcl.mjs +94 -0
- package/src/index.d.ts +7 -1
- package/src/index.mjs +6 -1
- package/src/infra-bicep.mjs +312 -0
- package/src/infra-cloud.mjs +348 -0
- package/src/infra-compose.mjs +315 -0
- package/src/infra-containers.mjs +100 -0
- package/src/infra-docker.mjs +267 -0
- package/src/infra-expr.mjs +509 -0
- package/src/infra-gha.mjs +350 -0
- package/src/infra-k8s.mjs +657 -0
- package/src/infra-terraform.mjs +499 -0
- package/src/infra-words.mjs +811 -0
- package/src/libraries.mjs +202 -0
- package/src/lift.mjs +49 -6
- package/src/meaning.d.mts +89 -0
- package/src/meaning.mjs +2544 -0
- package/src/model.d.mts +65 -14
- package/src/model.mjs +496 -80
- package/src/powershell.mjs +1361 -0
- package/src/read-repo-fs.mjs +29 -7
- package/src/read-repo.d.mts +5 -1
- package/src/read-repo.mjs +33 -7
- package/src/read.d.mts +21 -1
- package/src/read.mjs +1017 -42
- package/src/review.d.mts +35 -0
- package/src/review.mjs +671 -0
- package/src/rlang.mjs +1084 -0
- package/src/round-trip.d.mts +12 -0
- package/src/round-trip.mjs +174 -0
- package/src/runners/thunder-generate.mjs +56 -0
- package/src/runners/thunder-trace.cjs +284 -0
- package/src/runners/thunder_trace.py +599 -0
- package/src/running.d.mts +104 -0
- package/src/running.mjs +787 -0
- package/src/same.d.mts +1 -0
- package/src/same.mjs +24 -3
- package/src/shell.mjs +1212 -0
- package/src/sql.mjs +3 -2
- package/src/steps.d.mts +6 -1
- package/src/steps.mjs +1448 -86
- package/src/system.d.mts +12 -0
- package/src/system.mjs +845 -0
- package/src/things-langs.mjs +275 -0
- package/src/thunderize.mjs +3 -3
- package/src/visual.d.mts +5 -5
- package/src/visual.mjs +24 -3
- package/src/write-steps.d.mts +64 -0
- package/src/write-steps.mjs +1608 -0
- package/src/write.mjs +2 -1
- package/src/yaml.mjs +403 -0
package/src/commands.mjs
ADDED
|
@@ -0,0 +1,464 @@
|
|
|
1
|
+
// Well-known command-line tools in plain words, shared by the shell and PowerShell readers: docker, kubectl, helm,
|
|
2
|
+
// az, aws, gcloud, git, npm, curl, files and folders, and more. Each phrase says what the command does, never more
|
|
3
|
+
// than its arguments show. A command that is not here reads as "Runs <command>" and keeps its code.
|
|
4
|
+
//
|
|
5
|
+
// Callers pass the command's words as written (`args`, without the command name) and `v(word)`, which says one
|
|
6
|
+
// word in plain words: a literal as "quoted text", a variable as its name in words. Browser-safe, no dependencies.
|
|
7
|
+
|
|
8
|
+
export const words = (s) => String(s).replace(/([a-z0-9])([A-Z])/g, '$1 $2').replace(/[_-]+/g, ' ').toLowerCase().trim();
|
|
9
|
+
export const cap = (s) => (s ? s.charAt(0).toUpperCase() + s.slice(1) : s);
|
|
10
|
+
const list = (xs) => (xs.length <= 1 ? xs.join('') : `${xs.slice(0, -1).join(', ')}${xs.length > 2 ? ',' : ''} and ${xs.at(-1)}`);
|
|
11
|
+
|
|
12
|
+
/** The value of a flag: `-t x`, `--tag x`, `--tag=x`. Null when absent. */
|
|
13
|
+
export function opt(args, names) {
|
|
14
|
+
for (let i = 0; i < args.length; i++) {
|
|
15
|
+
const a = args[i];
|
|
16
|
+
for (const n of names) {
|
|
17
|
+
if (a === n) return args[i + 1] ?? null;
|
|
18
|
+
if (n.startsWith('--') && a.startsWith(`${n}=`)) return a.slice(n.length + 1);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
export const has = (args, ...names) => args.some((a) => names.includes(a) || names.some((n) => n.startsWith('--') && a.startsWith(`${n}=`)) || names.some((n) => /^-[A-Za-z]$/.test(n) && /^-[A-Za-z]{2,}$/.test(a) && a.includes(n[1])));
|
|
24
|
+
|
|
25
|
+
/** Words that are not flags, skipping the value after each flag in `valued` (flags that take a value). */
|
|
26
|
+
export function positional(args, valued = []) {
|
|
27
|
+
const out = [];
|
|
28
|
+
for (let i = 0; i < args.length; i++) {
|
|
29
|
+
const a = args[i];
|
|
30
|
+
if (/^--?[A-Za-z]/.test(a)) { if (valued.includes(a)) i++; continue; }
|
|
31
|
+
out.push(a);
|
|
32
|
+
}
|
|
33
|
+
return out;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* A verb phrase as a gerund, for questions: "Builds the image" -> "building the image", "Goes into" -> "going into".
|
|
38
|
+
*/
|
|
39
|
+
export function gerund(phrase) {
|
|
40
|
+
const m = String(phrase).match(/^(\S+)(.*)$/s);
|
|
41
|
+
if (!m) return String(phrase).toLowerCase();
|
|
42
|
+
const w = m[1].toLowerCase();
|
|
43
|
+
const special = { is: 'being', has: 'having', does: 'doing', goes: 'going', sees: 'seeing', lets: 'letting' };
|
|
44
|
+
let g;
|
|
45
|
+
if (special[w]) g = special[w];
|
|
46
|
+
else if (/ies$/.test(w)) g = `${w.slice(0, -3)}ying`;
|
|
47
|
+
else if (/(?:ss|sh|ch|x|z|o)es$/.test(w)) g = `${w.slice(0, -2)}ing`;
|
|
48
|
+
else if (/s$/.test(w)) {
|
|
49
|
+
let b = w.slice(0, -1);
|
|
50
|
+
if (/[^e]e$/.test(b)) b = b.slice(0, -1);
|
|
51
|
+
else if (/^[^aeiou]*[aeiou][bdgklmnprt]$/.test(b)) b += b.slice(-1);
|
|
52
|
+
g = `${b}ing`;
|
|
53
|
+
} else g = w;
|
|
54
|
+
return g + m[2];
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// ── Cloud and container tools ─────────────────────────────────────────────────────────────────────────
|
|
58
|
+
|
|
59
|
+
const VERBS = {
|
|
60
|
+
create: 'Creates', delete: 'Deletes', show: 'Shows', list: 'Lists', update: 'Updates', set: 'Sets', start: 'Starts',
|
|
61
|
+
stop: 'Stops', restart: 'Restarts', deploy: 'Deploys', upload: 'Uploads', download: 'Downloads', add: 'Adds',
|
|
62
|
+
remove: 'Removes', assign: 'Assigns', wait: 'Waits for', purge: 'Purges', import: 'Imports', export: 'Exports',
|
|
63
|
+
describe: 'Looks up', get: 'Gets', put: 'Puts', run: 'Runs', invoke: 'Runs', tag: 'Tags', attach: 'Attaches',
|
|
64
|
+
detach: 'Detaches', register: 'Registers', deregister: 'Removes the registration of', send: 'Sends', publish: 'Publishes',
|
|
65
|
+
receive: 'Receives', copy: 'Copies', modify: 'Changes', enable: 'Turns on', disable: 'Turns off', login: 'Signs in to',
|
|
66
|
+
scale: 'Scales', swap: 'Swaps', build: 'Builds', push: 'Uploads', pull: 'Downloads', install: 'Installs', apply: 'Applies',
|
|
67
|
+
exists: 'Checks whether there is', reset: 'Resets', rotate: 'Rotates', renew: 'Renews', associate: 'Connects', disassociate: 'Disconnects',
|
|
68
|
+
};
|
|
69
|
+
const plural = (n) => (/(?:s|sh|ch|x)$/.test(n) ? `${n}es` : /[^aeiou]y$/.test(n) ? `${n.slice(0, -1)}ies` : `${n}s`);
|
|
70
|
+
const thePhrase = (verb, noun, name, v) => {
|
|
71
|
+
const V = VERBS[verb] ?? cap(words(verb));
|
|
72
|
+
const many = verb === 'list' && !name;
|
|
73
|
+
const n = many ? plural(noun) : noun;
|
|
74
|
+
return `${V} the ${n}${name ? ` ${v(name)}` : ''}`;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const AZ_NOUNS = {
|
|
78
|
+
group: 'resource group', webapp: 'web app', functionapp: 'function app', acr: 'container registry', aks: 'Kubernetes cluster (AKS)',
|
|
79
|
+
vm: 'virtual machine', vmss: 'virtual machine scale set', keyvault: 'key vault', 'keyvault secret': 'key vault secret',
|
|
80
|
+
'storage account': 'storage account', 'storage container': 'storage container', 'storage blob': 'storage file (blob)',
|
|
81
|
+
'sql server': 'SQL server', 'sql db': 'SQL database', cosmosdb: 'Cosmos DB account', 'network vnet': 'virtual network',
|
|
82
|
+
'network nsg': 'network security group', 'network public-ip': 'public IP address', 'appservice plan': 'App Service plan',
|
|
83
|
+
containerapp: 'container app', 'role assignment': 'role assignment', 'ad sp': 'service principal', identity: 'managed identity',
|
|
84
|
+
'deployment group': 'deployment', 'deployment sub': 'subscription deployment', 'monitor log-analytics workspace': 'Log Analytics workspace',
|
|
85
|
+
'staticwebapp': 'static web app', 'apim': 'API Management service', 'servicebus namespace': 'Service Bus namespace', 'eventhubs namespace': 'Event Hubs namespace',
|
|
86
|
+
};
|
|
87
|
+
function azure(args, v) {
|
|
88
|
+
const groups = [];
|
|
89
|
+
for (const a of args) { if (/^-/.test(a)) break; groups.push(a); }
|
|
90
|
+
if (!groups.length) return null;
|
|
91
|
+
const name = opt(args, ['--name', '-n']);
|
|
92
|
+
const rg = opt(args, ['--resource-group', '-g']);
|
|
93
|
+
const inRg = rg && groups[0] !== 'group' ? ` in the resource group ${v(rg)}` : '';
|
|
94
|
+
const [g0, g1] = groups;
|
|
95
|
+
if (g0 === 'login') return has(args, '--service-principal') ? 'Signs in to Azure as a service principal' : has(args, '--identity') ? 'Signs in to Azure with its managed identity' : 'Signs in to Azure';
|
|
96
|
+
if (g0 === 'logout') return 'Signs out of Azure';
|
|
97
|
+
if (g0 === 'account' && g1 === 'set') return `Switches to the Azure subscription ${v(opt(args, ['--subscription', '-s']) ?? '?')}`;
|
|
98
|
+
if (g0 === 'account' && g1 === 'show') return 'Shows the Azure subscription in use';
|
|
99
|
+
if (g0 === 'acr' && g1 === 'login') return `Signs in to the Azure container registry ${v(name ?? '?')}`;
|
|
100
|
+
if (g0 === 'acr' && g1 === 'build') return `Builds the Docker image ${v(opt(args, ['--image', '-t']) ?? '?')} in the Azure container registry ${v(opt(args, ['--registry', '-r']) ?? '?')}`;
|
|
101
|
+
if (g0 === 'aks' && g1 === 'get-credentials') return `Gets the sign-in details for the Azure Kubernetes cluster ${v(name ?? '?')}${inRg}`;
|
|
102
|
+
if (g0 === 'deployment' && groups.at(-1) === 'create') {
|
|
103
|
+
const file = opt(args, ['--template-file', '-f']);
|
|
104
|
+
return `Deploys ${file ? `${v(file)} ` : ''}to ${rg ? `the Azure resource group ${v(rg)}` : 'Azure'}`;
|
|
105
|
+
}
|
|
106
|
+
if (g0 === 'group') {
|
|
107
|
+
const n = name ?? rg;
|
|
108
|
+
if (g1 === 'exists') return `Checks whether the Azure resource group ${v(n ?? '?')} exists`;
|
|
109
|
+
return `${thePhrase(g1 ?? 'show', 'Azure resource group', n, v)}${g1 === 'create' && opt(args, ['--location', '-l']) ? ` in ${v(opt(args, ['--location', '-l']))}` : ''}`;
|
|
110
|
+
}
|
|
111
|
+
const verb = groups.at(-1);
|
|
112
|
+
const nounKey = groups.slice(0, -1).join(' ');
|
|
113
|
+
const noun = AZ_NOUNS[nounKey] ?? AZ_NOUNS[groups.slice(0, 2).join(' ')] ?? AZ_NOUNS[g0] ?? words(nounKey || g0);
|
|
114
|
+
return `${thePhrase(verb, `Azure ${noun}`, name, v)}${inRg}`;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const AWS_SERVICES = { s3: 'Amazon S3', ec2: 'Amazon EC2', ecr: 'Amazon ECR', ecs: 'Amazon ECS', eks: 'Amazon EKS', lambda: 'AWS Lambda', cloudformation: 'AWS CloudFormation', iam: 'AWS IAM', sts: 'AWS', sqs: 'Amazon SQS', sns: 'Amazon SNS', dynamodb: 'Amazon DynamoDB', rds: 'Amazon RDS', ssm: 'AWS Systems Manager', secretsmanager: 'AWS Secrets Manager', logs: 'CloudWatch Logs', route53: 'Amazon Route 53', cloudfront: 'Amazon CloudFront', elbv2: 'load balancer', autoscaling: 'auto scaling' };
|
|
118
|
+
function amazon(args, v) {
|
|
119
|
+
const pos = positional(args, ['--region', '--profile', '--output', '--query']);
|
|
120
|
+
const [svc, op] = pos;
|
|
121
|
+
if (!svc) return null;
|
|
122
|
+
if (svc === 'configure') return 'Sets up the AWS command line';
|
|
123
|
+
const S = AWS_SERVICES[svc] ?? `AWS ${svc}`;
|
|
124
|
+
if (svc === 's3' && ['cp', 'mv', 'sync'].includes(op)) return `${{ cp: 'Copies', mv: 'Moves', sync: 'Syncs' }[op]} ${v(pos[2] ?? '?')} to ${v(pos[3] ?? '?')}${has(args, '--recursive') ? ', with everything inside' : ''} (Amazon S3)`;
|
|
125
|
+
if (svc === 's3' && op === 'rm') return `Deletes ${v(pos[2] ?? '?')}${has(args, '--recursive') ? ' and everything inside' : ''} (Amazon S3)`;
|
|
126
|
+
if (svc === 's3' && op === 'ls') return `Lists the files in ${v(pos[2] ?? 'Amazon S3')}`;
|
|
127
|
+
if (svc === 's3' && op === 'mb') return `Makes the Amazon S3 bucket ${v(pos[2] ?? '?')}`;
|
|
128
|
+
if (svc === 'cloudformation' && op === 'deploy') return `Deploys the AWS CloudFormation stack ${v(opt(args, ['--stack-name']) ?? '?')}${opt(args, ['--template-file']) ? ` from ${v(opt(args, ['--template-file']))}` : ''}`;
|
|
129
|
+
if (svc === 'ecr' && op === 'get-login-password') return 'Gets a password for signing in to Amazon ECR';
|
|
130
|
+
if (svc === 'sts' && op === 'get-caller-identity') return 'Gets who AWS sees it as (the caller identity)';
|
|
131
|
+
if (!op) return null;
|
|
132
|
+
const [verb, ...rest] = op.split('-');
|
|
133
|
+
const name = opt(args, ['--stack-name', '--function-name', '--name', '--cluster', '--repository-name', '--bucket', '--table-name', '--queue-url', '--topic-arn', '--secret-id', '--instance-ids', '--service', '--role-name']);
|
|
134
|
+
return thePhrase(verb, `${S} ${rest.join(' ') || 'resource'}`.trim(), name, v);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function google(args, v) {
|
|
138
|
+
const pos = positional(args, ['--project', '--region', '--zone', '--image', '--format', '--platform']);
|
|
139
|
+
const [g0, g1, g2] = pos;
|
|
140
|
+
if (g0 === 'auth' && (g1 === 'login' || g1 === 'activate-service-account')) return 'Signs in to Google Cloud';
|
|
141
|
+
if (g0 === 'config' && g1 === 'set' && g2 === 'project') return `Switches to the Google Cloud project ${v(pos[3] ?? '?')}`;
|
|
142
|
+
if (g0 === 'run' && g1 === 'deploy') return `Deploys the Google Cloud Run service ${v(g2 ?? '?')}${opt(args, ['--image']) ? ` from the image ${v(opt(args, ['--image']))}` : ''}`;
|
|
143
|
+
const at = pos.findIndex((p) => VERBS[p] || /^(describe|list|create|delete|update|deploy|get-credentials|submit|ssh)$/.test(p));
|
|
144
|
+
if (at < 1) return null;
|
|
145
|
+
const verb = pos[at];
|
|
146
|
+
if (verb === 'get-credentials') return `Gets the sign-in details for the Google Kubernetes cluster ${v(pos[at + 1] ?? '?')}`;
|
|
147
|
+
if (verb === 'submit') return `Sends a build to Google Cloud Build`;
|
|
148
|
+
return thePhrase(verb, `Google Cloud ${pos.slice(0, at).map(words).join(' ')}`, pos[at + 1], v);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const DOCKER_VALUED = ['-p', '--publish', '-e', '--env', '-v', '--volume', '--name', '-w', '--workdir', '--network', '--env-file', '-u', '--user', '--entrypoint', '--platform', '--mount', '-l', '--label', '--restart', '--memory', '-m', '--cpus', '-h', '--hostname', '-f', '--file', '-t', '--tag', '--build-arg', '--target', '--cache-from', '-a', '--add-host', '--pull', '--secret', '--progress', '-c'];
|
|
152
|
+
function docker(args, v) {
|
|
153
|
+
let [cmd, ...rest] = args;
|
|
154
|
+
if (cmd === 'buildx' && rest[0] === 'build') { cmd = 'build'; rest = rest.slice(1); }
|
|
155
|
+
if (cmd === 'image' || cmd === 'container') { cmd = rest[0]; rest = rest.slice(1); }
|
|
156
|
+
const pos = positional(rest, DOCKER_VALUED);
|
|
157
|
+
switch (cmd) {
|
|
158
|
+
case 'build': { const tag = opt(rest, ['-t', '--tag']); return tag ? `Builds the Docker image ${v(tag)}${has(rest, '--push') ? ' and uploads it' : ''}` : `Builds a Docker image from ${v(pos.at(-1) ?? '.')}`; }
|
|
159
|
+
case 'push': return `Uploads the Docker image ${v(pos[0] ?? '?')}`;
|
|
160
|
+
case 'pull': return `Downloads the Docker image ${v(pos[0] ?? '?')}`;
|
|
161
|
+
case 'run': return `Runs the Docker image ${v(pos[0] ?? '?')} in a new container${has(rest, '-d', '--detach') ? ', in the background' : ''}${has(rest, '--rm') ? ' (removed when it stops)' : ''}`;
|
|
162
|
+
case 'tag': return `Gives the Docker image ${v(pos[0] ?? '?')} the name ${v(pos[1] ?? '?')}`;
|
|
163
|
+
case 'login': return `Signs in to the Docker registry${pos[0] ? ` ${v(pos[0])}` : ''}`;
|
|
164
|
+
case 'logout': return 'Signs out of the Docker registry';
|
|
165
|
+
case 'exec': return `Runs a command inside the container ${v(pos[0] ?? '?')}`;
|
|
166
|
+
case 'stop': return `Stops the container ${v(pos[0] ?? '?')}`;
|
|
167
|
+
case 'start': return `Starts the container ${v(pos[0] ?? '?')}`;
|
|
168
|
+
case 'restart': return `Restarts the container ${v(pos[0] ?? '?')}`;
|
|
169
|
+
case 'rm': return `Removes the container ${v(pos[0] ?? '?')}`;
|
|
170
|
+
case 'rmi': return `Removes the Docker image ${v(pos[0] ?? '?')}`;
|
|
171
|
+
case 'ps': return 'Lists the running containers';
|
|
172
|
+
case 'images': return 'Lists the Docker images';
|
|
173
|
+
case 'logs': return `Shows what the container ${v(pos[0] ?? '?')} has printed`;
|
|
174
|
+
case 'inspect': return `Looks up the details of ${v(pos[0] ?? '?')}`;
|
|
175
|
+
case 'save': return `Saves the Docker image ${v(pos[0] ?? '?')} to a file`;
|
|
176
|
+
case 'load': return 'Loads a Docker image from a file';
|
|
177
|
+
case 'network': return pos[0] === 'create' ? `Makes the Docker network ${v(pos[1] ?? '?')}` : null;
|
|
178
|
+
case 'volume': return pos[0] === 'create' ? `Makes the Docker volume ${v(pos[1] ?? '?')}` : null;
|
|
179
|
+
case 'system': return pos[0] === 'prune' ? 'Clears out unused Docker data' : null;
|
|
180
|
+
case 'compose': return compose(rest, v);
|
|
181
|
+
default: return null;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
function compose(args, v) {
|
|
185
|
+
const pos = positional(args, ['-f', '--file', '-p', '--project-name', '--profile', '--env-file']);
|
|
186
|
+
const svc = pos.slice(1).filter((p) => !/^-/.test(p));
|
|
187
|
+
const which = svc.length ? `the service${svc.length > 1 ? 's' : ''} ${list(svc.map(v))}` : 'the services';
|
|
188
|
+
switch (pos[0]) {
|
|
189
|
+
case 'up': return `Starts ${which} in Docker Compose${has(args, '-d', '--detach') ? ', in the background' : ''}`;
|
|
190
|
+
case 'down': return 'Stops and removes the Docker Compose services';
|
|
191
|
+
case 'build': return `Builds ${which} in Docker Compose`;
|
|
192
|
+
case 'pull': return `Downloads the images for ${which}`;
|
|
193
|
+
case 'run': return `Runs a one-off command in the service ${v(svc[0] ?? '?')}`;
|
|
194
|
+
case 'exec': return `Runs a command inside the service ${v(svc[0] ?? '?')}`;
|
|
195
|
+
case 'logs': return `Shows what ${which} have printed`;
|
|
196
|
+
case 'restart': return `Restarts ${which}`;
|
|
197
|
+
case 'stop': return `Stops ${which}`;
|
|
198
|
+
case 'ps': return 'Lists the Docker Compose services';
|
|
199
|
+
default: return null;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
const K8S_KINDS = { deploy: 'deployment', deployment: 'deployment', deployments: 'deployment', po: 'pod', pod: 'pod', pods: 'pod', svc: 'service', service: 'service', ns: 'namespace', namespace: 'namespace', sts: 'stateful set', statefulset: 'stateful set', ds: 'daemon set', daemonset: 'daemon set', cm: 'config map', configmap: 'config map', secret: 'secret', job: 'job', cronjob: 'scheduled job', ing: 'ingress', ingress: 'ingress', node: 'node', nodes: 'node', pvc: 'storage claim' };
|
|
204
|
+
const k8sTarget = (pos, v) => {
|
|
205
|
+
const t = pos[0];
|
|
206
|
+
if (!t) return 'the Kubernetes resources';
|
|
207
|
+
const slash = String(t).match(/^([a-z]+)\/(.+)$/);
|
|
208
|
+
if (slash) return `the Kubernetes ${K8S_KINDS[slash[1]] ?? slash[1]} ${v(slash[2])}`;
|
|
209
|
+
if (K8S_KINDS[t]) return pos[1] ? `the Kubernetes ${K8S_KINDS[t]} ${v(pos[1])}` : `the Kubernetes ${plural(K8S_KINDS[t])}`;
|
|
210
|
+
return `the Kubernetes resource ${v(t)}`;
|
|
211
|
+
};
|
|
212
|
+
function kubectl(args, v) {
|
|
213
|
+
const KV = ['-n', '--namespace', '-f', '--filename', '-k', '-l', '--selector', '-o', '--output', '--context', '--timeout', '-c', '--container', '--replicas', '--for', '--type', '-p', '--patch', '--image'];
|
|
214
|
+
const ns = opt(args, ['-n', '--namespace']);
|
|
215
|
+
const inNs = ns ? ` in the namespace ${v(ns)}` : '';
|
|
216
|
+
const [verb, ...rest] = positional(args, KV);
|
|
217
|
+
const file = opt(args, ['-f', '--filename']) ?? opt(args, ['-k']);
|
|
218
|
+
switch (verb) {
|
|
219
|
+
case 'apply': return `Applies the Kubernetes settings in ${v(file ?? '?')}${inNs}`;
|
|
220
|
+
case 'create': return rest[0] === 'namespace' || rest[0] === 'ns' ? `Makes the Kubernetes namespace ${v(rest[1] ?? '?')}` : file ? `Creates the Kubernetes resources in ${v(file)}${inNs}` : `Creates ${k8sTarget(rest, v)}${inNs}`;
|
|
221
|
+
case 'delete': return file ? `Deletes the Kubernetes resources in ${v(file)}${inNs}` : `Deletes ${k8sTarget(rest, v)}${inNs}`;
|
|
222
|
+
case 'get': return `Lists ${k8sTarget(rest, v)}${inNs}`;
|
|
223
|
+
case 'describe': return `Looks up the details of ${k8sTarget(rest, v)}${inNs}`;
|
|
224
|
+
case 'logs': return `Shows what ${k8sTarget(rest, v)} has printed${inNs}`;
|
|
225
|
+
case 'exec': return `Runs a command inside ${k8sTarget(rest, v)}${inNs}`;
|
|
226
|
+
case 'port-forward': return `Connects a local port to ${k8sTarget(rest, v)}${inNs}`;
|
|
227
|
+
case 'wait': return `Waits until ${k8sTarget(rest, v)} is ${String(opt(args, ['--for']) ?? 'ready').replace(/^condition=/, '').toLowerCase()}${inNs}`;
|
|
228
|
+
case 'scale': return `Scales ${k8sTarget(rest, v)} to ${v(opt(args, ['--replicas']) ?? '?')} copies${inNs}`;
|
|
229
|
+
case 'rollout': {
|
|
230
|
+
const [sub, ...t] = rest;
|
|
231
|
+
const what = k8sTarget(t, v);
|
|
232
|
+
if (sub === 'status') return `Waits until ${what} has finished rolling out${inNs}`;
|
|
233
|
+
if (sub === 'restart') return `Restarts ${what}${inNs}`;
|
|
234
|
+
if (sub === 'undo') return `Rolls ${what} back to its previous version${inNs}`;
|
|
235
|
+
if (sub === 'history') return `Lists the versions of ${what}${inNs}`;
|
|
236
|
+
return null;
|
|
237
|
+
}
|
|
238
|
+
case 'set': return rest[0] === 'image' ? `Changes the image used by ${k8sTarget(rest.slice(1), v)}${inNs}` : null;
|
|
239
|
+
case 'config': return rest[0] === 'use-context' ? `Switches to the Kubernetes cluster ${v(rest[1] ?? '?')}` : rest[0] === 'set-context' ? 'Changes the Kubernetes cluster settings' : null;
|
|
240
|
+
case 'label': return `Labels ${k8sTarget(rest, v)}${inNs}`;
|
|
241
|
+
case 'annotate': return `Adds a note to ${k8sTarget(rest, v)}${inNs}`;
|
|
242
|
+
case 'patch': return `Changes part of ${k8sTarget(rest, v)}${inNs}`;
|
|
243
|
+
case 'cluster-info': return 'Shows which Kubernetes cluster it is connected to';
|
|
244
|
+
default: return null;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
function helm(args, v) {
|
|
249
|
+
const ns = opt(args, ['-n', '--namespace']);
|
|
250
|
+
const inNs = ns ? ` in the namespace ${v(ns)}` : '';
|
|
251
|
+
const [verb, ...pos] = positional(args, ['-n', '--namespace', '-f', '--values', '--set', '--set-string', '--version', '--timeout', '--kube-context', '-o', '--output', '--repo']);
|
|
252
|
+
switch (verb) {
|
|
253
|
+
case 'upgrade': return `${has(args, '--install', '-i') ? 'Installs or upgrades' : 'Upgrades'} the Helm release ${v(pos[0] ?? '?')}${pos[1] ? ` from the chart ${v(pos[1])}` : ''}${inNs}`;
|
|
254
|
+
case 'install': return `Installs the Helm release ${v(pos[0] ?? '?')}${pos[1] ? ` from the chart ${v(pos[1])}` : ''}${inNs}`;
|
|
255
|
+
case 'uninstall': case 'delete': return `Removes the Helm release ${v(pos[0] ?? '?')}${inNs}`;
|
|
256
|
+
case 'rollback': return `Rolls the Helm release ${v(pos[0] ?? '?')} back${pos[1] ? ` to version ${v(pos[1])}` : ''}${inNs}`;
|
|
257
|
+
case 'repo': return pos[0] === 'add' ? `Adds the Helm chart repository ${v(pos[1] ?? '?')}${pos[2] ? ` (${v(pos[2])})` : ''}` : pos[0] === 'update' ? 'Updates the list of Helm charts' : null;
|
|
258
|
+
case 'dependency': case 'dep': return 'Gets the charts this chart needs';
|
|
259
|
+
case 'template': return `Fills in the Helm chart ${v(pos[1] ?? pos[0] ?? '?')} without installing it`;
|
|
260
|
+
case 'lint': return `Checks the Helm chart ${v(pos[0] ?? '.')} for mistakes`;
|
|
261
|
+
case 'package': return `Packs the Helm chart ${v(pos[0] ?? '.')} into a file`;
|
|
262
|
+
case 'list': case 'ls': return `Lists the Helm releases${inNs}`;
|
|
263
|
+
default: return null;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
function git(args, v) {
|
|
268
|
+
const [verb, ...rest] = args.filter((a, i) => !(i === 0 && a === '-C'));
|
|
269
|
+
const pos = positional(rest, ['-m', '--message', '-b', '-B', '--branch', '--depth', '-o', '--format', '-c']);
|
|
270
|
+
switch (verb) {
|
|
271
|
+
case 'clone': return `Copies the Git repository ${v(pos[0] ?? '?')}${pos[1] ? ` into ${v(pos[1])}` : ''}`;
|
|
272
|
+
case 'push': return has(rest, '--tags') ? 'Uploads the version tags' : pos.length >= 2 ? `Uploads ${v(pos[1])} to ${v(pos[0])}` : pos[0] ? `Uploads the commits to ${v(pos[0])}` : 'Uploads the commits';
|
|
273
|
+
case 'pull': return 'Downloads and merges the latest changes';
|
|
274
|
+
case 'fetch': return 'Downloads the latest changes, without merging them';
|
|
275
|
+
case 'tag': return pos[0] ? (has(rest, '-d', '--delete') ? `Removes the version tag ${v(pos[0])}` : `Tags this version as ${v(pos[0])}`) : 'Lists the version tags';
|
|
276
|
+
case 'checkout': case 'switch': return opt(rest, ['-b', '-B']) ? `Makes and switches to the branch ${v(opt(rest, ['-b', '-B']))}` : `Switches to ${v(pos[0] ?? '?')}`;
|
|
277
|
+
case 'commit': { const msg = opt(rest, ['-m', '--message']); return msg ? `Saves a commit: ${v(msg)}` : 'Saves a commit'; }
|
|
278
|
+
case 'add': return has(rest, '-A', '--all') || pos[0] === '.' ? 'Marks every change to be committed' : `Marks ${list(pos.map(v))} to be committed`;
|
|
279
|
+
case 'merge': return `Merges ${v(pos[0] ?? '?')} into this branch`;
|
|
280
|
+
case 'rebase': return `Replays this branch on top of ${v(pos[0] ?? '?')}`;
|
|
281
|
+
case 'reset': return has(rest, '--hard') ? `Throws away local changes and goes back to ${v(pos[0] ?? 'the last commit')}` : 'Unmarks changes';
|
|
282
|
+
case 'status': return 'Shows what has changed';
|
|
283
|
+
case 'diff': return 'Shows the changes';
|
|
284
|
+
case 'log': return 'Shows the history';
|
|
285
|
+
case 'init': return 'Starts a new Git repository';
|
|
286
|
+
case 'stash': return pos[0] === 'pop' ? 'Brings back the set-aside changes' : 'Sets the changes aside for later';
|
|
287
|
+
case 'remote': return pos[0] === 'add' ? `Adds the remote ${v(pos[1] ?? '?')} (${v(pos[2] ?? '?')})` : null;
|
|
288
|
+
case 'submodule': return 'Gets the repositories this one includes (submodules)';
|
|
289
|
+
// `git config name` reads the setting; only `git config name value` sets it.
|
|
290
|
+
case 'config': return pos[1] ? `Sets the Git setting ${v(pos[0])} to ${v(pos[1])}` : pos[0] ? `Reads the Git setting ${v(pos[0])}` : null;
|
|
291
|
+
case 'rev-parse': return has(rest, '--show-toplevel') ? 'Finds the top folder of the repository' : 'Looks up the commit id';
|
|
292
|
+
case 'describe': return 'Looks up the latest version tag';
|
|
293
|
+
case 'branch': return pos[0] ? `Makes the branch ${v(pos[0])}` : 'Lists the branches';
|
|
294
|
+
default: return null;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
function npmLike(tool, args, v) {
|
|
299
|
+
const [verb, ...rest] = args;
|
|
300
|
+
const pos = positional(rest, ['--prefix', '-w', '--workspace', '--registry', '--tag']);
|
|
301
|
+
const pkgs = pos.length ? ` ${list(pos.map(v))}` : '';
|
|
302
|
+
switch (verb) {
|
|
303
|
+
case 'ci': return 'Installs the exact package versions in the lock file';
|
|
304
|
+
case undefined: return tool === 'yarn' ? 'Installs the packages' : null;
|
|
305
|
+
case 'install': case 'i': case 'add': return pkgs ? `Installs the package${pos.length > 1 ? 's' : ''}${pkgs}` : 'Installs the packages';
|
|
306
|
+
case 'run': case 'run-script': return `Runs the ${tool} script ${v(pos[0] ?? '?')}`;
|
|
307
|
+
case 'test': case 't': return 'Runs the tests';
|
|
308
|
+
case 'start': return 'Starts the app';
|
|
309
|
+
case 'build': return 'Builds the app';
|
|
310
|
+
case 'publish': return `Publishes the package to ${tool === 'npm' ? 'npm' : 'the registry'}`;
|
|
311
|
+
case 'uninstall': case 'remove': case 'rm': return `Removes the package${pkgs}`;
|
|
312
|
+
case 'version': return `Sets the package version${pos[0] ? ` to ${v(pos[0])}` : ''}`;
|
|
313
|
+
default: return tool === 'npm' ? null : `Runs the ${tool} script ${v(verb)}`;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
// ── Files, text, and everyday tools ───────────────────────────────────────────────────────────────────
|
|
318
|
+
|
|
319
|
+
function curl(args, v) {
|
|
320
|
+
if (has(args, '--version', '-V')) return 'Shows the version of curl';
|
|
321
|
+
// The address: a word with :// in it, else the first word that is not a flag or a flag's value.
|
|
322
|
+
const url = args.find((a) => /:\/\//.test(a) && !/^-/.test(a)) ?? positional(args, ['-X', '--request', '-H', '--header', '-d', '--data', '--data-raw', '--data-binary', '-o', '--output', '-u', '--user', '-F', '--form', '--json', '-A', '--user-agent', '-w', '--write-out', '--retry', '-m', '--max-time', '--connect-timeout', '-e', '--cert', '--key', '-T'])[0];
|
|
323
|
+
const sends = opt(args, ['-d', '--data', '--data-raw', '--data-binary', '-F', '--form', '--json', '--data-urlencode']) != null;
|
|
324
|
+
const method = String(opt(args, ['-X', '--request']) ?? (has(args, '-T', '--upload-file') ? 'PUT' : sends ? 'POST' : has(args, '-I', '--head') ? 'HEAD' : 'GET')).replace(/^["']|["']$/g, '').toUpperCase();
|
|
325
|
+
const out = opt(args, ['-o', '--output']);
|
|
326
|
+
return `Sends a ${method} request to ${v(url ?? '?')}${out ? ` and saves the answer to ${v(out)}` : has(args, '-O', '--remote-name') ? ' and saves the file' : ''}`;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
const FILE = (verb) => (args, v) => { const p = positional(args); return p.length ? `${verb} ${list(p.map(v))}` : null; };
|
|
330
|
+
|
|
331
|
+
/** head / tail's line count: -n 5, -n5, -5, --lines=5; 10 when none is given (their default). */
|
|
332
|
+
function lineCount(args, v) {
|
|
333
|
+
const n = opt(args, ['-n', '--lines']) ?? args.map((a) => a.match(/^-n?(\d+)$/)?.[1]).find(Boolean);
|
|
334
|
+
return n != null ? v(n) : args.some((a) => /^-[a-z]*[cn]/.test(a)) ? '(some)' : '10';
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
/** One command (name and its words) in plain words, or null when it is not a well-known command. */
|
|
338
|
+
export function sayCommand(name, args, v) {
|
|
339
|
+
const n = String(name).replace(/^.*\//, '');
|
|
340
|
+
const p = () => positional(args);
|
|
341
|
+
switch (n) {
|
|
342
|
+
case 'docker': return docker(args, v);
|
|
343
|
+
case 'docker-compose': return compose(args, v);
|
|
344
|
+
case 'podman': return docker(args, v)?.replace(/Docker/g, 'container') ?? null;
|
|
345
|
+
case 'kubectl': case 'oc': return kubectl(args, v);
|
|
346
|
+
case 'helm': return helm(args, v);
|
|
347
|
+
case 'az': return azure(args, v);
|
|
348
|
+
case 'aws': return amazon(args, v);
|
|
349
|
+
case 'gcloud': return google(args, v);
|
|
350
|
+
case 'gsutil': return args[0] === 'cp' ? `Copies ${v(p()[1] ?? '?')} to ${v(p()[2] ?? '?')} (Google Cloud Storage)` : null;
|
|
351
|
+
case 'git': return git(args, v);
|
|
352
|
+
case 'npm': case 'yarn': case 'pnpm': case 'bun': return npmLike(n, args, v);
|
|
353
|
+
case 'npx': return `Runs the tool ${v(p()[0] ?? '?')}`;
|
|
354
|
+
case 'pip': case 'pip3': {
|
|
355
|
+
if (args[0] !== 'install') return null;
|
|
356
|
+
const req = opt(args, ['-r', '--requirement']);
|
|
357
|
+
return req ? `Installs the Python packages listed in ${v(req)}` : `Installs the Python package${p().length > 2 ? 's' : ''} ${list(p().slice(1).map(v))}`;
|
|
358
|
+
}
|
|
359
|
+
case 'python': case 'python3': return args[0] === '-m' ? `Runs the Python module ${v(args[1] ?? '?')}` : p()[0] ? `Runs the Python program ${v(p()[0])}` : null;
|
|
360
|
+
case 'node': return p()[0] ? `Runs the JavaScript program ${v(p()[0])}` : null;
|
|
361
|
+
case 'ruby': return p()[0] ? `Runs the Ruby program ${v(p()[0])}` : null;
|
|
362
|
+
case 'Rscript': return p()[0] ? `Runs the R program ${v(p()[0])}` : null;
|
|
363
|
+
case 'go': return { build: 'Builds the Go program', test: 'Runs the Go tests', run: 'Runs the Go program', mod: 'Updates the Go modules', install: 'Installs the Go program', vet: 'Checks the Go code for mistakes' }[args[0]] ?? null;
|
|
364
|
+
case 'cargo': return { build: 'Builds the Rust program', test: 'Runs the Rust tests', run: 'Runs the Rust program', publish: 'Publishes the Rust crate', fmt: 'Formats the Rust code', clippy: 'Checks the Rust code for mistakes' }[args[0]] ?? null;
|
|
365
|
+
case 'dotnet': return { build: 'Builds the .NET project', test: 'Runs the .NET tests', run: 'Runs the .NET program', restore: 'Downloads the .NET packages', publish: 'Packs the .NET app for release', pack: 'Packs the .NET library' }[args[0]] ?? null;
|
|
366
|
+
case 'mvn': case 'mvnw': case './mvnw': return `Runs Maven (${list(p().map(v)) || 'the default build'})`;
|
|
367
|
+
case 'gradle': case 'gradlew': case './gradlew': return `Runs Gradle (${list(p().map(v)) || 'the default build'})`;
|
|
368
|
+
case 'make': return p().length ? `Runs the make target${p().length > 1 ? 's' : ''} ${list(p().map(v))}` : 'Runs make (the default target)';
|
|
369
|
+
case 'terraform': case 'tofu': return { init: 'Sets up Terraform', plan: 'Works out what Terraform would change', apply: 'Applies the Terraform changes', destroy: 'Deletes everything Terraform made', validate: 'Checks the Terraform files for mistakes', fmt: 'Formats the Terraform files', output: 'Reads the Terraform outputs', import: 'Brings an existing resource under Terraform' }[args[0]] ?? (args[0] === 'workspace' ? `Switches to the Terraform workspace ${v(args[2] ?? '?')}` : null);
|
|
370
|
+
case 'ansible-playbook': return `Runs the Ansible playbook ${v(p()[0] ?? '?')}`;
|
|
371
|
+
case 'ssh': return p().length > 1 ? `Runs a command on ${v(p()[0])} over SSH` : `Connects to ${v(p()[0] ?? '?')} over SSH`;
|
|
372
|
+
case 'scp': return `Copies ${v(p()[0] ?? '?')} to ${v(p()[1] ?? '?')} over SSH`;
|
|
373
|
+
case 'rsync': return `Copies ${v(p()[0] ?? '?')} to ${v(p()[1] ?? '?')}, sending only what changed`;
|
|
374
|
+
case 'curl': return curl(args, v);
|
|
375
|
+
case 'wget': {
|
|
376
|
+
if (has(args, '--version', '-V')) return 'Shows the version of wget';
|
|
377
|
+
const url = args.find((a) => /:\/\//.test(a) && !/^-/.test(a)) ?? positional(args, ['-O', '-o', '-P', '--output-document', '-T', '--timeout', '-t', '--tries', '-U', '--user-agent', '--header', '-e'])[0];
|
|
378
|
+
if (!url) return null;
|
|
379
|
+
const to = opt(args, ['-O', '--output-document']);
|
|
380
|
+
return `Downloads ${v(url)}${to === '-' ? ' and prints it' : to ? ` and saves it as ${v(to)}` : ''}`;
|
|
381
|
+
}
|
|
382
|
+
case 'tar': {
|
|
383
|
+
const f = opt(args, ['-f', '--file']) ?? (args[0] && /^-?[a-z]*f[a-z]*$/.test(args[0]) && !args[0].startsWith('--') ? args[1] : null);
|
|
384
|
+
const mode = args[0] ?? '';
|
|
385
|
+
if (/x/.test(mode)) return `Unpacks ${v(f ?? '?')}${opt(args, ['-C']) ? ` into ${v(opt(args, ['-C']))}` : ''}`;
|
|
386
|
+
if (/c/.test(mode)) return `Packs ${list(p().slice(f ? 1 : 0).map(v)) || 'the files'} into ${v(f ?? '?')}`;
|
|
387
|
+
return null;
|
|
388
|
+
}
|
|
389
|
+
case 'unzip': return `Unpacks ${v(p()[0] ?? '?')}`;
|
|
390
|
+
case 'zip': return `Packs ${list(p().slice(1).map(v)) || 'the files'} into ${v(p()[0] ?? '?')}`;
|
|
391
|
+
case 'mkdir': return `Makes the folder${p().length > 1 ? 's' : ''} ${list(p().map(v))}${has(args, '-p', '--parents') ? ' (and any missing parent folders)' : ''}`;
|
|
392
|
+
case 'rmdir': return `Removes the empty folder ${v(p()[0] ?? '?')}`;
|
|
393
|
+
case 'rm': {
|
|
394
|
+
const what = list(p().map(v));
|
|
395
|
+
return has(args, '-r', '-R', '--recursive') ? `Deletes ${what} and everything in it${has(args, '-f', '--force') ? ', without asking' : ''}` : `Deletes ${what}`;
|
|
396
|
+
}
|
|
397
|
+
case 'cp': return `Copies ${list(p().slice(0, -1).map(v))} to ${v(p().at(-1) ?? '?')}${has(args, '-r', '-R', '-a', '--recursive') ? ', with everything inside' : ''}`;
|
|
398
|
+
case 'mv': return `Moves ${list(p().slice(0, -1).map(v))} to ${v(p().at(-1) ?? '?')}`;
|
|
399
|
+
case 'ln': return has(args, '-s', '--symbolic') ? `Makes ${v(p()[1] ?? '?')} a link to ${v(p()[0] ?? '?')}` : `Makes ${v(p()[1] ?? '?')} another name for ${v(p()[0] ?? '?')}`;
|
|
400
|
+
case 'touch': return `Makes the file ${list(p().map(v))} (or updates its time)`;
|
|
401
|
+
case 'chmod': return /\+x|^[0-7]*[157]$/.test(p()[0] ?? '') ? `Lets ${list(p().slice(1).map(v))} run as a program` : `Changes who may use ${list(p().slice(1).map(v))}`;
|
|
402
|
+
case 'chown': return `Changes the owner of ${list(p().slice(1).map(v))} to ${v(p()[0] ?? '?')}`;
|
|
403
|
+
case 'cat': return p().length ? `Shows ${list(p().map(v))}` : null;
|
|
404
|
+
case 'ls': return `Lists the files in ${v(p()[0] ?? '.')}`;
|
|
405
|
+
case 'pwd': return 'Shows the current folder';
|
|
406
|
+
case 'cd': return p()[0] === '-' ? 'Goes back to the previous folder' : p()[0] ? `Goes into the folder ${v(p()[0])}` : 'Goes to the home folder';
|
|
407
|
+
case 'pushd': return `Goes into the folder ${v(p()[0] ?? '?')}, remembering where it was`;
|
|
408
|
+
case 'popd': return 'Goes back to the folder it was in before';
|
|
409
|
+
case 'grep': case 'egrep': case 'rg': {
|
|
410
|
+
const files = positional(args, ['-e', '-f', '-m', '-A', '-B', '-C', '--include', '--exclude']);
|
|
411
|
+
const pat = opt(args, ['-e']) ?? files.shift();
|
|
412
|
+
return `Finds the lines${has(args, '-v', '--invert-match') ? ' not' : ''} matching ${v(pat ?? '?')}${files.length ? ` in ${list(files.map(v))}` : ''}`;
|
|
413
|
+
}
|
|
414
|
+
case 'sed': return has(args, '-i') ? `Edits ${list(positional(args, ['-e', '-f']).slice(opt(args, ['-e']) ? 0 : 1).map(v)) || 'the file'} in place` : 'Changes the text';
|
|
415
|
+
case 'awk': case 'gawk': return 'Picks out and rearranges parts of the text';
|
|
416
|
+
case 'find': {
|
|
417
|
+
// Tests Thunder does not put into words (`!`, -o, -prune, -links, -exec …) are shown as code, never dropped.
|
|
418
|
+
const tests = args.slice(1);
|
|
419
|
+
if (tests.some((a) => !/^(?:-name|-iname|-type|-maxdepth|-mindepth|-delete|-print)$/.test(a) && /^[-!(]/.test(a) && a !== '-L')) return `Finds the files in ${v(p()[0] ?? '.')} that match \`${tests.join(' ')}\``;
|
|
420
|
+
return `Finds the ${{ d: 'folders', f: 'files', l: 'links' }[opt(args, ['-type'])] ?? 'files'} in ${v(p()[0] ?? '.')}${opt(args, ['-name', '-iname']) ? ` named ${v(opt(args, ['-name', '-iname']))}` : ''}${has(args, '-delete') ? ', and deletes them' : ''}`;
|
|
421
|
+
}
|
|
422
|
+
case 'sort': return 'Sorts the lines';
|
|
423
|
+
case 'uniq': return 'Removes repeated lines';
|
|
424
|
+
case 'wc': return has(args, '-l') ? 'Counts the lines' : 'Counts the words';
|
|
425
|
+
case 'head': return `Takes the first ${lineCount(args, v)} lines`;
|
|
426
|
+
case 'tail': return has(args, '-f') ? `Shows the end of ${v(p()[0] ?? '?')} as it grows` : `Takes the last ${lineCount(args, v)} lines`;
|
|
427
|
+
case 'cut': return 'Takes out part of each line';
|
|
428
|
+
case 'tr': return 'Changes characters in the text';
|
|
429
|
+
case 'tee': return `Writes it to ${list(p().map(v))} too`;
|
|
430
|
+
case 'xargs': return p()[0] ? `Runs ${v(p()[0])} with each of them` : 'Runs a command with each of them';
|
|
431
|
+
case 'jq': return `Reads ${v(p()[0] ?? '?')} from the JSON`;
|
|
432
|
+
case 'yq': return `Reads ${v(p()[0] ?? '?')} from the YAML`;
|
|
433
|
+
case 'envsubst': return 'Fills in the settings in the text';
|
|
434
|
+
case 'base64': return has(args, '-d', '--decode', '-D') ? 'Decodes the text from base64' : 'Encodes the text as base64';
|
|
435
|
+
case 'openssl': return `Uses OpenSSL (${v(args[0] ?? '?')})`;
|
|
436
|
+
case 'date': return 'Gets the date and time';
|
|
437
|
+
case 'sleep': return `Waits ${v(p()[0] ?? '?')} second${p()[0] === '1' ? '' : 's'}`;
|
|
438
|
+
case 'wait': return 'Waits for the background commands to finish';
|
|
439
|
+
case 'kill': return `Stops the process ${v(p()[0] ?? '?')}`;
|
|
440
|
+
case 'pkill': case 'killall': return `Stops the processes named ${v(p()[0] ?? '?')}`;
|
|
441
|
+
case 'systemctl': return p()[0] && p()[1] ? `${{ start: 'Starts', stop: 'Stops', restart: 'Restarts', reload: 'Reloads', enable: 'Turns on', disable: 'Turns off', status: 'Shows the state of' }[p()[0]] ?? cap(words(p()[0]))} the service ${v(p()[1])}` : null;
|
|
442
|
+
case 'service': return p()[1] ? `${{ start: 'Starts', stop: 'Stops', restart: 'Restarts', reload: 'Reloads', status: 'Shows the state of' }[p()[1]] ?? cap(words(p()[1]))} the service ${v(p()[0])}` : null;
|
|
443
|
+
case 'apt-get': case 'apt': case 'yum': case 'dnf': case 'apk': case 'brew': case 'choco': case 'winget': case 'snap': {
|
|
444
|
+
const verb = p()[0];
|
|
445
|
+
// The value after -s / --source (and a --version written apart from its value) is not a package.
|
|
446
|
+
const pkgs = positional(args, ['-s', '--source', '--version']).slice(1);
|
|
447
|
+
if (verb === 'install' || verb === 'add') return `Installs ${pkgs.length ? list(pkgs.map(v)) : 'the packages'} (${n})`;
|
|
448
|
+
if (verb === 'update') return `Updates the list of packages (${n})`;
|
|
449
|
+
if (verb === 'upgrade') return `Upgrades the installed packages (${n})`;
|
|
450
|
+
if (verb === 'remove' || verb === 'uninstall' || verb === 'del') return `Removes ${list(pkgs.map(v))} (${n})`;
|
|
451
|
+
return null;
|
|
452
|
+
}
|
|
453
|
+
case 'useradd': case 'adduser': return `Adds the user ${v(p().at(-1) ?? '?')}`;
|
|
454
|
+
case 'logger': return 'Writes to the system log';
|
|
455
|
+
case 'crontab': return 'Changes the scheduled jobs';
|
|
456
|
+
case 'clear': return 'Clears the screen';
|
|
457
|
+
default: return null;
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
/** A path or file argument that names a script: "./build.sh" -> "Runs the script ./build.sh". */
|
|
462
|
+
export const scriptPath = (name) => /(?:^\.{0,2}\/|\.(?:sh|bash|ps1|py|rb|pl|js|R)$)/.test(String(name));
|
|
463
|
+
|
|
464
|
+
export { list as listWords, FILE };
|
package/src/core.d.ts
CHANGED
|
@@ -10,11 +10,19 @@ export { runTests, TEST_SCHEMA, TestReport, resolveObligations, ObligationResolu
|
|
|
10
10
|
export { HumanContractPreview, compileHumanContract, previewHumanContract, renderHumanContract, renderExampleTable } from './human-contract.mjs';
|
|
11
11
|
export { ANCHOR_SCHEMA, spanRange, spanText, replaceSpan, editStep, anchorReport } from './anchor.mjs';
|
|
12
12
|
export { WRITE_SCHEMA, writeRule, changedCases, ruleParts, joinRuleParts, COMPARISON_CHOICES } from './write.mjs';
|
|
13
|
+
export { WRITE_STEPS_SCHEMA, WRITE_STEPS_LANGUAGES, EDIT_OPS, thunderWrite, proveChange, describeEdit, unifiedDiff } from './write-steps.mjs';
|
|
14
|
+
export type { ThunderEdit, ThunderWriteResult, WriteProof } from './write-steps.mjs';
|
|
13
15
|
export { STEPS_SCHEMA, classifyStatement } from './steps.mjs';
|
|
16
|
+
export { EXPR_SCHEMA, RENDER_LANGUAGES, parseExpr, parseStatement, renderExpr, renderStatement, sayFull, detailParts, detailOf, exprCounts, normalizeExpr, sameExpr, wordsAgree } from './meaning.mjs';
|
|
17
|
+
export type { Expr } from './meaning.mjs';
|
|
14
18
|
export { VISUAL_SCHEMA, THUNDER_VISUAL, LEVELS, PLACES, visualFor, visualForStep, thunderText, thunderTokens } from './visual.mjs';
|
|
15
|
-
export { MODEL_SCHEMA, THING_LANGUAGES, thunderModel, modelText, readLevel, flowOf, ruleFlow, askAsQuestion, stepDoes } from './model.mjs';
|
|
19
|
+
export { MODEL_SCHEMA, THING_LANGUAGES, thunderModel, modelText, readLevel, flowOf, ruleFlow, askAsQuestion, stepDoes, pathsOf } from './model.mjs';
|
|
20
|
+
export { RUNNING_SCHEMA, runtimeOverlay, runtimeText, explainError, parseStack, parseStacks, fromTrace, fromStack, fromLogs, fromOtlp, nodeNote } from './running.mjs';
|
|
21
|
+
export type { RunEvent, RuntimeOverlay, MemberRun, NodeRun, ParsedStack, ErrorExplanation } from './running.mjs';
|
|
22
|
+
export { linkSystem, callsSummary, areaOf } from './system.mjs';
|
|
16
23
|
export { THUNDERIZE_SCHEMA, THUNDER_TEXT_EXT, thunderizeFile, thunderizeFiles } from './thunderize.mjs';
|
|
17
|
-
export { SAME_SCHEMA, sameMeaning, compareRules, renderSame } from './same.mjs';
|
|
24
|
+
export { SAME_SCHEMA, sameMeaning, compareRules, comparePlainRules, renderSame } from './same.mjs';
|
|
25
|
+
export { REVIEW_SCHEMA, REVIEW_MARKER, thunderReview, renderReview } from './review.mjs';
|
|
18
26
|
export type { ColorRole, ElementKind, Provenance as VisualProvenance, Visual } from './visual.mjs';
|
|
19
27
|
export { plainFromReading } from './plain-contract.mjs';
|
|
20
28
|
export function conditionText(model: unknown, condition: unknown): string;
|
|
@@ -122,11 +130,11 @@ export { translateDecisions, TRANSLATE_LANGUAGES } from './translate.mjs';
|
|
|
122
130
|
export type { TranslateLanguage } from './translate.mjs';
|
|
123
131
|
|
|
124
132
|
// Read code you don't know.
|
|
125
|
-
export { readCode, searchReading, detectLanguage, READ_SCHEMA, READ_LANGUAGES } from './read.mjs';
|
|
133
|
+
export { readCode, searchReading, detectLanguage, READ_SCHEMA, READ_LANGUAGES, INFRA_LANGUAGES } from './read.mjs';
|
|
126
134
|
export type { Reading, ReadItem, ReadKind } from './read.mjs';
|
|
127
135
|
export function completenessOf(item: unknown): { level: 'explained' | 'partly explained' | 'found' | 'executed'; reasons: string[] };
|
|
128
136
|
export function displayLabel(name: string): string;
|
|
129
|
-
export { readRepo, searchRepo, groupByFile, readableLanguage, readFiles, readingOf, READ_REPO_SCHEMA, READ_SKIP_DIRS } from './read-repo.mjs';
|
|
137
|
+
export { readRepo, searchRepo, groupByFile, readableLanguage, readableFile, readFiles, readingOf, READ_REPO_SCHEMA, READ_SKIP_DIRS } from './read-repo.mjs';
|
|
130
138
|
export type { RepoItem, RepoFacet, RepoReading, RepoFilter } from './read-repo.mjs';
|
|
131
139
|
export { promoteDecision, PROMOTE_SCHEMA } from './promote.mjs';
|
|
132
140
|
export type { Promotion } from './promote.mjs';
|
package/src/core.mjs
CHANGED
|
@@ -10,10 +10,18 @@ export { compileHumanContract, previewHumanContract, renderHumanContract, render
|
|
|
10
10
|
export { ANCHOR_SCHEMA, spanRange, spanText, replaceSpan, editStep, anchorReport } from './anchor.mjs';
|
|
11
11
|
export { WRITE_SCHEMA, writeRule, changedCases, ruleParts, joinRuleParts, COMPARISON_CHOICES } from './write.mjs';
|
|
12
12
|
export { STEPS_SCHEMA, classifyStatement } from './steps.mjs';
|
|
13
|
+
export { WRITE_STEPS_SCHEMA, WRITE_STEPS_LANGUAGES, EDIT_OPS, thunderWrite, proveChange, describeEdit, unifiedDiff } from './write-steps.mjs';
|
|
14
|
+
// The meaning model under every step (thunder-expr-v1): parse, write back, and say every detail. Browser-safe.
|
|
15
|
+
export { EXPR_SCHEMA, RENDER_LANGUAGES, parseExpr, parseStatement, renderExpr, renderStatement, sayFull, detailParts, detailOf, exprCounts, normalizeExpr, sameExpr, wordsAgree } from './meaning.mjs';
|
|
13
16
|
export { VISUAL_SCHEMA, THUNDER_VISUAL, LEVELS, PLACES, visualFor, visualForStep, thunderText, thunderTokens } from './visual.mjs';
|
|
14
|
-
export { MODEL_SCHEMA, THING_LANGUAGES, thunderModel, modelText, readLevel, flowOf, ruleFlow, askAsQuestion, stepDoes } from './model.mjs';
|
|
17
|
+
export { MODEL_SCHEMA, THING_LANGUAGES, thunderModel, modelText, readLevel, flowOf, ruleFlow, askAsQuestion, stepDoes, pathsOf } from './model.mjs';
|
|
18
|
+
// The running system (browser-safe): runs, stack traces, logs, and spans placed on Thunder's flows.
|
|
19
|
+
export { RUNNING_SCHEMA, runtimeOverlay, runtimeText, explainError, parseStack, parseStacks, fromTrace, fromStack, fromLogs, fromOtlp, nodeNote } from './running.mjs';
|
|
20
|
+
export { linkSystem, callsSummary, areaOf } from './system.mjs';
|
|
15
21
|
export { THUNDERIZE_SCHEMA, THUNDER_TEXT_EXT, thunderizeFile, thunderizeFiles } from './thunderize.mjs';
|
|
16
|
-
export { SAME_SCHEMA, sameMeaning, compareRules, renderSame } from './same.mjs';
|
|
22
|
+
export { SAME_SCHEMA, sameMeaning, compareRules, comparePlainRules, renderSame } from './same.mjs';
|
|
23
|
+
// Review in Thunder: what a change did to the meaning of the code, in plain sentences (pure; the CLI does the git work).
|
|
24
|
+
export { REVIEW_SCHEMA, REVIEW_MARKER, thunderReview, renderReview } from './review.mjs';
|
|
17
25
|
export { plainFromReading, conditionText } from './plain-contract.mjs';
|
|
18
26
|
// Editor help (browser-safe): completions, hover, autocorrect, quick fixes, and the semantic type vocabulary.
|
|
19
27
|
export { getCompletions, getHover, autocorrectSource, getCodeActions, SEMANTIC_TYPES } from './intellisense.mjs';
|
|
@@ -109,7 +117,7 @@ export { runTests, TEST_SCHEMA } from './testing.mjs';
|
|
|
109
117
|
// Decisions -> readable typed source in six languages (browser-safe; same translators as the targets).
|
|
110
118
|
export { translateDecisions, TRANSLATE_LANGUAGES } from './translate.mjs';
|
|
111
119
|
// Read code you don't know: decisions recovered from six languages as ThunderLang + plain English.
|
|
112
|
-
export { readCode, searchReading, detectLanguage, READ_SCHEMA, READ_LANGUAGES, completenessOf, displayLabel } from './read.mjs';
|
|
120
|
+
export { readCode, searchReading, detectLanguage, READ_SCHEMA, READ_LANGUAGES, INFRA_LANGUAGES, completenessOf, displayLabel } from './read.mjs';
|
|
113
121
|
// Read a whole repository (pure: the caller passes file contents) and turn a recovered decision into a contract.
|
|
114
|
-
export { readRepo, searchRepo, groupByFile, readableLanguage, readFiles, readingOf, READ_REPO_SCHEMA, READ_SKIP_DIRS } from './read-repo.mjs';
|
|
122
|
+
export { readRepo, searchRepo, groupByFile, readableLanguage, readableFile, readFiles, readingOf, READ_REPO_SCHEMA, READ_SKIP_DIRS } from './read-repo.mjs';
|
|
115
123
|
export { promoteDecision, PROMOTE_SCHEMA } from './promote.mjs';
|
package/src/emit.mjs
CHANGED
|
@@ -30,7 +30,7 @@ export function notesSummary(ast) {
|
|
|
30
30
|
};
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
export const COMPILER_VERSION = '0.5.
|
|
33
|
+
export const COMPILER_VERSION = '0.5.12';
|
|
34
34
|
export const PROOF_SCHEMA_VERSION = '0.1.0';
|
|
35
35
|
// Identifies which ecosystem product emitted this proof. Consumed by SkillsTech
|
|
36
36
|
// Certified to key cert proofs to the compiler. Stable slug per the coordination bus.
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { ThunderModel } from './model.d.mts';
|
|
2
|
+
|
|
3
|
+
export const EXECUTED_SCHEMA: 'thunder-executed-v1';
|
|
4
|
+
export const PY_TRACER: string;
|
|
5
|
+
export const JS_TRACER: string;
|
|
6
|
+
|
|
7
|
+
/** What a recorder writes: per file, per function (by its first line) and per decision (by its line). */
|
|
8
|
+
export interface Trace {
|
|
9
|
+
files: Record<string, {
|
|
10
|
+
functions: Record<string, { runs: number; returns: Record<string, { count: number; values: string[] }>; raises: Record<string, { count: number; types: Record<string, string[]> }>; fellOff: number; fellOffAt?: Record<string, number>; unwound?: number }>;
|
|
11
|
+
/** obs keys are `<where>|<next line>`: where is body, orelse, after, end, or case:<line>. */
|
|
12
|
+
decisions: Record<string, { kind: 'if' | 'while' | 'for' | 'match' | 'handler'; obs: Record<string, number> }>;
|
|
13
|
+
/** Python: each return line -> the line of the innermost if / case holding it. */
|
|
14
|
+
returns?: Record<string, number | null>;
|
|
15
|
+
/** Python: first line of a compound statement -> its last line. */
|
|
16
|
+
spans?: Record<string, number>;
|
|
17
|
+
}>;
|
|
18
|
+
runs?: RunInfo[];
|
|
19
|
+
}
|
|
20
|
+
export interface RunInfo { how: string; language: 'python' | 'js'; seconds: number; calls?: number; capped?: boolean; errors?: string[]; exit?: number | null; [k: string]: unknown }
|
|
21
|
+
|
|
22
|
+
export interface Mismatch { line: number; question: string | null; side: string; expected: string; observed: string; times: number }
|
|
23
|
+
export interface MemberResult {
|
|
24
|
+
id: string; file: string; name: string; lines: [number, number]; language: string;
|
|
25
|
+
/** executed: ran, and every claim the runs reached matched. not checked: ran, but reached nothing Thunder claims. */
|
|
26
|
+
status: 'executed' | 'contradicted' | 'not checked' | 'not run';
|
|
27
|
+
runs: number;
|
|
28
|
+
questions: { drawn: number; checked: number };
|
|
29
|
+
matched: number; notDrawn: number;
|
|
30
|
+
decisions: { line: number; question: string | null; kind: string; observed: Record<string, number>; result: 'matched' | 'contradicted' | 'not drawn' }[];
|
|
31
|
+
endings: { line: number | null; kind: 'return' | 'raise' | 'end of function'; count: number; values?: string[]; types?: string[]; after?: number[]; result: 'matched' | 'contradicted' | 'not drawn' }[];
|
|
32
|
+
mismatches: Mismatch[];
|
|
33
|
+
}
|
|
34
|
+
export interface ExecutedResult {
|
|
35
|
+
schema: 'thunder-executed-v1';
|
|
36
|
+
members: MemberResult[];
|
|
37
|
+
summary: { members: number; run: number; executed: number; contradicted: number; notChecked: number; notRun: number; questions: number; questionsChecked: number; claims: { matched: number; mismatched: number; notDrawn: number } };
|
|
38
|
+
language?: 'python' | 'js';
|
|
39
|
+
runs?: RunInfo[];
|
|
40
|
+
}
|
|
41
|
+
export interface VerifyRunOptions {
|
|
42
|
+
lang?: 'python' | 'js'; tests?: string; pytest?: string | string[]; command?: string; cwd?: string; python?: string;
|
|
43
|
+
trace?: string | Trace; generate?: boolean; maxSeconds?: number; maxCalls?: number;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function compareRun(model: ThunderModel, trace: Trace, options?: { languages?: string[] | null }): ExecutedResult;
|
|
47
|
+
export function markExecuted(model: ThunderModel, result: ExecutedResult): ThunderModel;
|
|
48
|
+
export function mergeTraces(into: Trace, add: Trace): Trace;
|
|
49
|
+
export function runPython(root: string, options?: { mode?: 'generate' | 'discover' | 'pytest'; tests?: string; pytestArgs?: string[]; python?: string; maxSeconds?: number; maxCalls?: number; cwd?: string }): Trace;
|
|
50
|
+
export function runJs(root: string, options?: { mode?: 'generate' | 'command'; command?: string; node?: string; maxSeconds?: number; maxCalls?: number; cwd?: string }): Trace;
|
|
51
|
+
export function languageOf(root: string): 'python' | 'js';
|
|
52
|
+
export function verifyRun(root: string, options?: VerifyRunOptions): { result: ExecutedResult; model: ThunderModel; trace: Trace };
|
|
53
|
+
export function executedText(result: ExecutedResult, options?: { all?: boolean }): string;
|