ide-agents 0.1.1 → 0.3.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/README.md +22 -17
- package/dist/adapters/create.d.ts +9 -0
- package/dist/adapters/create.js +33 -0
- package/dist/adapters/index.d.ts +6 -0
- package/dist/adapters/index.js +16 -0
- package/dist/adapters/types.d.ts +7 -0
- package/dist/adapters/types.js +1 -0
- package/dist/apply.js +38 -11
- package/dist/config.js +48 -13
- package/dist/git.d.ts +1 -0
- package/dist/git.js +41 -1
- package/dist/gitignore.d.ts +5 -0
- package/dist/gitignore.js +105 -0
- package/dist/ides.d.ts +5 -0
- package/dist/ides.js +52 -0
- package/dist/paths.d.ts +1 -0
- package/dist/paths.js +10 -0
- package/dist/scan.js +58 -29
- package/dist/server.js +111 -6
- package/dist/targets.d.ts +2 -1
- package/dist/targets.js +24 -6
- package/dist/template.d.ts +12 -0
- package/dist/template.js +86 -0
- package/dist/types.d.ts +16 -2
- package/dist/types.js +1 -1
- package/dist/version.d.ts +1 -0
- package/dist/version.js +6 -0
- package/package.json +17 -9
- package/template/.agents/AGENTS.md +51 -0
- package/template/.claude/CLAUDE.md +37 -0
- package/template/.cursor/rules/agents.mdc +72 -0
- package/template/.cursor/rules/repo-structure.mdc +46 -0
- package/template/.cursor/rules/scripts.mdc +101 -0
- package/template/README.md +60 -0
- package/template/agents/oracle.md +38 -0
- package/template/skills/hello/SKILL.md +43 -0
- package/template/skills/hello/scripts/now.mjs +49 -0
- package/web/dist/assets/index-BSBPsDYY.css +1 -0
- package/web/dist/assets/index-C-SOo38e.js +51 -0
- package/web/dist/index.html +2 -2
- package/web/dist/assets/index-D7KhBlEO.js +0 -124
- package/web/dist/assets/index-JihkyerF.css +0 -1
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Agent authoring — orchestration, reports, and script-backed generators
|
|
3
|
+
globs: agents/**/*.md
|
|
4
|
+
alwaysApply: false
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Agent authoring
|
|
8
|
+
|
|
9
|
+
Agents in `agents/*.md` are **orchestrators**: they define role, workflow, and output format. They are not a place for ad-hoc code generation.
|
|
10
|
+
|
|
11
|
+
## Generators → `scripts/`
|
|
12
|
+
|
|
13
|
+
For anything that must be **stable, repeatable, and testable** (scanners, profile builders, report writers, stack detectors), put logic in bundled scripts under the **related skill folder**:
|
|
14
|
+
|
|
15
|
+
```
|
|
16
|
+
skills/<skill-id>/
|
|
17
|
+
├── SKILL.md
|
|
18
|
+
├── scripts/ # node *.mjs — run these, do not re-implement in chat
|
|
19
|
+
└── assets/ # optional JSON/markers the scripts read
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Pattern from [repo-audit-skills](https://github.com/sergeychernov/repo-audit-skills):
|
|
23
|
+
|
|
24
|
+
- `skills/audit-init/scripts/detect-stack.mjs` — read-only scan, writes structured JSON
|
|
25
|
+
- `skills/audit-debt/scripts/run-audit.mjs` — reads profile, runs checks, writes report
|
|
26
|
+
|
|
27
|
+
### Why agents call scripts
|
|
28
|
+
|
|
29
|
+
| In chat (avoid) | In `scripts/` (prefer) |
|
|
30
|
+
|-----------------|------------------------|
|
|
31
|
+
| Re-parsing repo layout each turn | Same repo state → same output |
|
|
32
|
+
| Drifting flags and file paths | Documented CLI in script header |
|
|
33
|
+
| Large inline bash one-liners | `#!/usr/bin/env node`, ESM `.mjs` |
|
|
34
|
+
|
|
35
|
+
Agent body should tell the model to **resolve `<SKILL_DIR>`**, run `node <SKILL_DIR>/scripts/<name>.mjs`, then **read the artifact** (stdout JSON or a known output path). See `scripts.mdc` for script conventions.
|
|
36
|
+
|
|
37
|
+
## Agent file format
|
|
38
|
+
|
|
39
|
+
YAML frontmatter (filename stem must match `name`, e.g. `agents/oracle.md` → `name: oracle`):
|
|
40
|
+
|
|
41
|
+
```yaml
|
|
42
|
+
---
|
|
43
|
+
name: my-agent # required — lowercase id; Cursor subagent identity (/my-agent)
|
|
44
|
+
description: When to delegate to this subagent. Be specific — the IDE uses this for auto-delegation.
|
|
45
|
+
scope: any # optional — ide-agents only: global | project | any (default any)
|
|
46
|
+
---
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
| Field | Required | Used by |
|
|
50
|
+
|-------|----------|---------|
|
|
51
|
+
| `name` | yes | Cursor / Claude / Codex subagent id (defaults to filename if omitted — prefer explicit) |
|
|
52
|
+
| `description` | yes | IDE delegation — when the main agent should hand off to this subagent |
|
|
53
|
+
| `scope` | no | ide-agents UI — which install toggles are enabled |
|
|
54
|
+
|
|
55
|
+
Subagents are **not** skills: they live in `agents/*.md`, install to `~/.cursor/agents/`, and are invoked by name in Agent mode (e.g. `/oracle …` or “use the oracle subagent”), not via the `/` skill picker.
|
|
56
|
+
|
|
57
|
+
Body structure:
|
|
58
|
+
|
|
59
|
+
1. **Role** — one paragraph
|
|
60
|
+
2. **Inputs** — what the user or upstream skill must provide
|
|
61
|
+
3. **Workflow** — numbered steps; step that runs a script must include the exact `node …mjs` command
|
|
62
|
+
4. **Output contract** — fixed sections (e.g. summary, findings, gaps); use consistent severity markers if reporting issues
|
|
63
|
+
|
|
64
|
+
## Do not
|
|
65
|
+
|
|
66
|
+
- Embed multi-step filesystem scans or JSON schema logic in the agent markdown
|
|
67
|
+
- Write into the target project except paths documented by the skill (e.g. `.audit/`)
|
|
68
|
+
- Duplicate script behavior in prose — link to `SKILL.md` quick start instead
|
|
69
|
+
|
|
70
|
+
## Shared helpers
|
|
71
|
+
|
|
72
|
+
Cross-skill utilities may live in `skills/_shared/` (e.g. `generated-by.mjs`). Import from scripts via relative paths; agents reference the skill that owns the script.
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Skills and agents repository layout for ide-agents catalogs
|
|
3
|
+
alwaysApply: true
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Repository structure
|
|
7
|
+
|
|
8
|
+
This repository is an **ide-agents skill catalog** — not an application codebase.
|
|
9
|
+
|
|
10
|
+
## Directories
|
|
11
|
+
|
|
12
|
+
| Path | Purpose |
|
|
13
|
+
|------|---------|
|
|
14
|
+
| `skills/<id>/SKILL.md` | Installable skills (required `SKILL.md` per folder) |
|
|
15
|
+
| `skills/<id>/scripts/` | Optional bundled generators (`*.mjs`) — see `scripts.mdc` |
|
|
16
|
+
| `skills/<id>/assets/` | Optional JSON/markers read by scripts |
|
|
17
|
+
| `skills/_shared/` | Optional cross-skill helpers (imported by scripts) |
|
|
18
|
+
| `agents/<id>.md` | Subagent orchestrators — call scripts, do not re-implement generators |
|
|
19
|
+
| `.cursor/rules/` | Cursor project rules (this file) |
|
|
20
|
+
|
|
21
|
+
## SKILL.md conventions
|
|
22
|
+
|
|
23
|
+
- YAML frontmatter: `name`, `description`, `scope` (`global`, `project`, or `any`).
|
|
24
|
+
- Body: instructions the IDE agent follows when the skill is invoked.
|
|
25
|
+
- One skill per directory under `skills/`.
|
|
26
|
+
|
|
27
|
+
## Agents
|
|
28
|
+
|
|
29
|
+
- One markdown file per agent in `agents/` (e.g. `agents/oracle.md`).
|
|
30
|
+
- YAML frontmatter: `name`, `description`, optional `scope` (`global`, `project`, or `any`).
|
|
31
|
+
- `name` must match the filename stem; used by Cursor/Claude/Codex as the subagent id.
|
|
32
|
+
- Agents **orchestrate**; deterministic generators live in `skills/<id>/scripts/` (see `agents.mdc`).
|
|
33
|
+
|
|
34
|
+
## Scripts (generators)
|
|
35
|
+
|
|
36
|
+
Stable scanners and report writers belong in `skills/<skill-id>/scripts/`, not inline in agent prompts. Follow `scripts.mdc` (ESM `.mjs`, stdlib only, `--json` / `--dry-run`, resolve paths via `import.meta.url`).
|
|
37
|
+
|
|
38
|
+
## Do not
|
|
39
|
+
|
|
40
|
+
- Put application source code here unless it supports the catalog itself.
|
|
41
|
+
- Rename skill folders casually — `artifactId` in ide-agents matches the directory name.
|
|
42
|
+
- Remove `SKILL.md` from a skill folder (scan ignores directories without it).
|
|
43
|
+
|
|
44
|
+
## Installing
|
|
45
|
+
|
|
46
|
+
Use [ide-agents](https://github.com/sergeychernov/ide-agents): add this repo, then toggle **Global** or **Project** on Skills / Agents pages.
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Conventions for skill scripts (generators, scanners, report writers)
|
|
3
|
+
globs: skills/**/scripts/**
|
|
4
|
+
alwaysApply: false
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Skill scripts
|
|
8
|
+
|
|
9
|
+
Bundled under `skills/<skill-id>/scripts/`. Invoked by skills and agents — not installed separately by ide-agents.
|
|
10
|
+
|
|
11
|
+
Reference implementation: [repo-audit-skills](https://github.com/sergeychernov/repo-audit-skills) (`detect-stack.mjs`, `run-audit.mjs`, modular `checks/`).
|
|
12
|
+
|
|
13
|
+
## Runtime
|
|
14
|
+
|
|
15
|
+
- ESM: `*.mjs`, `#!/usr/bin/env node`
|
|
16
|
+
- Node 18+, **zero npm dependencies** in scripts (stdlib only)
|
|
17
|
+
- Resolve skill assets via `import.meta.url` — never assume cwd for skill paths
|
|
18
|
+
|
|
19
|
+
```javascript
|
|
20
|
+
import { dirname, join } from 'node:path';
|
|
21
|
+
import { fileURLToPath } from 'node:url';
|
|
22
|
+
|
|
23
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
24
|
+
const assetsDir = join(here, '..', 'assets');
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Target repo discovery
|
|
28
|
+
|
|
29
|
+
Scripts run **from anywhere inside the user's project** (after skill symlink install). Discover the audited repo root explicitly:
|
|
30
|
+
|
|
31
|
+
```javascript
|
|
32
|
+
import { execSync } from 'node:child_process';
|
|
33
|
+
|
|
34
|
+
const repoRoot = execSync('git rev-parse --show-toplevel', { encoding: 'utf8' }).trim();
|
|
35
|
+
process.chdir(repoRoot);
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Exit `1` with a clear message if not a git repo.
|
|
39
|
+
|
|
40
|
+
## File header (required)
|
|
41
|
+
|
|
42
|
+
Every entry script documents usage at the top:
|
|
43
|
+
|
|
44
|
+
```javascript
|
|
45
|
+
#!/usr/bin/env node
|
|
46
|
+
// my-skill: one-line purpose
|
|
47
|
+
//
|
|
48
|
+
// Usage (from anywhere inside a git repo):
|
|
49
|
+
// node <SKILL_DIR>/scripts/my-script.mjs
|
|
50
|
+
// node <SKILL_DIR>/scripts/my-script.mjs --json
|
|
51
|
+
// node <SKILL_DIR>/scripts/my-script.mjs --dry-run
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
`<SKILL_DIR>` is the installed skill folder path (global or project symlink).
|
|
55
|
+
|
|
56
|
+
## CLI flags (standard)
|
|
57
|
+
|
|
58
|
+
| Flag | Effect |
|
|
59
|
+
|------|--------|
|
|
60
|
+
| `--json` | Machine-readable stdout |
|
|
61
|
+
| `--dry-run` | Run logic without writing output files |
|
|
62
|
+
| `--force` | Overwrite existing generated files (when applicable) |
|
|
63
|
+
|
|
64
|
+
Add skill-specific flags (`--offline`, `--verbose`, …) only when documented in the header.
|
|
65
|
+
|
|
66
|
+
## Scan and write rules
|
|
67
|
+
|
|
68
|
+
- Prefer `git ls-files` over unbounded filesystem walks
|
|
69
|
+
- **Read-only** toward source files in the target repo by default
|
|
70
|
+
- Writable outputs only under paths the skill documents (e.g. `.audit/profile.json`, `.audit/reports/*.json`)
|
|
71
|
+
- Static config and schemas stay in `skills/<id>/assets/` — edit markers here, not in the target project
|
|
72
|
+
- No network calls in scan scripts unless the skill explicitly requires it
|
|
73
|
+
|
|
74
|
+
## Output
|
|
75
|
+
|
|
76
|
+
- Human mode: short labeled summary for the terminal
|
|
77
|
+
- JSON mode: stable schema for agents to parse
|
|
78
|
+
- JSON files: 2-space indent, trailing newline
|
|
79
|
+
- Stamp artifacts with `generatedBy`, `version`, `generatedAt` when writing reports
|
|
80
|
+
|
|
81
|
+
## Layout inside a skill
|
|
82
|
+
|
|
83
|
+
```
|
|
84
|
+
skills/<name>/
|
|
85
|
+
├── SKILL.md
|
|
86
|
+
├── scripts/
|
|
87
|
+
│ ├── run-*.mjs # entry points
|
|
88
|
+
│ ├── load-*.mjs # shared loaders
|
|
89
|
+
│ └── checks/ # optional modular checks
|
|
90
|
+
└── assets/ # JSON registries, markers, schemas
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
Split large generators into `scripts/checks/` modules (see `audit-debt/scripts/checks/`).
|
|
94
|
+
|
|
95
|
+
## SKILL.md integration
|
|
96
|
+
|
|
97
|
+
Each skill with scripts must include in `SKILL.md`:
|
|
98
|
+
|
|
99
|
+
1. Folder tree showing `scripts/` and `assets/`
|
|
100
|
+
2. **Quick start** — copy-pasteable `node <SKILL_DIR>/scripts/….mjs`
|
|
101
|
+
3. **Agent instructions** — resolve skill dir, run script, read output
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# Skills & agents catalog
|
|
2
|
+
|
|
3
|
+
A git repository of **IDE skills** and **agents** for Cursor, Claude Code, and Codex.
|
|
4
|
+
|
|
5
|
+
Managed with [ide-agents](https://github.com/sergeychernov/ide-agents) — clone this repo in the UI, then install artifacts globally or per project.
|
|
6
|
+
|
|
7
|
+
## Layout
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
.
|
|
11
|
+
├── skills/
|
|
12
|
+
│ └── <skill-id>/
|
|
13
|
+
│ ├── SKILL.md # required — frontmatter: name, description, scope
|
|
14
|
+
│ ├── scripts/ # optional — *.mjs generators (see .cursor/rules/scripts.mdc)
|
|
15
|
+
│ └── assets/ # optional — JSON/markers for scripts
|
|
16
|
+
├── agents/
|
|
17
|
+
│ └── <agent-id>.md # orchestrators — call scripts, not inline generators
|
|
18
|
+
├── .cursor/rules/ # Cursor project rules (repo structure)
|
|
19
|
+
├── .claude/CLAUDE.md # Claude Code project instructions
|
|
20
|
+
└── .agents/AGENTS.md # Codex project instructions
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## SKILL.md frontmatter
|
|
24
|
+
|
|
25
|
+
```yaml
|
|
26
|
+
---
|
|
27
|
+
name: my-skill
|
|
28
|
+
description: What this skill does.
|
|
29
|
+
scope: any # global | project | any
|
|
30
|
+
---
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Agents
|
|
34
|
+
|
|
35
|
+
Agent files live in `agents/<agent-id>.md`. YAML frontmatter:
|
|
36
|
+
|
|
37
|
+
```yaml
|
|
38
|
+
---
|
|
39
|
+
name: my-agent
|
|
40
|
+
description: When the IDE should delegate to this subagent.
|
|
41
|
+
scope: any # global | project | any — ide-agents install toggles only
|
|
42
|
+
---
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
`name` must match the filename stem (`agents/oracle.md` → `name: oracle`). Subagents install to `~/.cursor/agents/<name>.md` (or project `.cursor/agents/`); invoke in Agent mode by name, not via the `/` skill menu.
|
|
46
|
+
|
|
47
|
+
## Sample artifacts
|
|
48
|
+
|
|
49
|
+
This repo was bootstrapped with a demo skill and a starter agent. Extend or replace them as you build your catalog.
|
|
50
|
+
|
|
51
|
+
| Kind | ID | Purpose |
|
|
52
|
+
|------|-----|---------|
|
|
53
|
+
| skill | `hello` | Install smoke-test + `scripts/now.mjs` (system clock) |
|
|
54
|
+
| agent | `oracle` | Joke fortune-teller — always upbeat predictions |
|
|
55
|
+
|
|
56
|
+
## Next steps
|
|
57
|
+
|
|
58
|
+
1. Edit or add skills under `skills/` and agents under `agents/`.
|
|
59
|
+
2. Commit and push to your remote.
|
|
60
|
+
3. In ide-agents, open **Skills** / **Agents** and toggle **Global** or **Project** to symlink into your IDE.
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: oracle
|
|
3
|
+
description: Playful fortune-teller subagent — upbeat predictions only, never doom.
|
|
4
|
+
scope: any
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Oracle
|
|
8
|
+
|
|
9
|
+
You are a cheerful, slightly theatrical fortune teller for **entertainment only**. You read the vibes, squint at the horizon, and deliver short prophecies — always **optimistic**, never alarming.
|
|
10
|
+
|
|
11
|
+
This is not financial, medical, or legal advice. Say so once if the user asks about money, health, or lawsuits.
|
|
12
|
+
|
|
13
|
+
## Workflow
|
|
14
|
+
|
|
15
|
+
1. Optional anchor in the present: if the `hello` skill is available, run
|
|
16
|
+
`node <SKILL_DIR>/scripts/now.mjs --json`
|
|
17
|
+
and weave the real timestamp into your opening (“The stars align at …”).
|
|
18
|
+
2. Ask for a topic if missing (career, side project, weekend, coffee, code review — anything goes).
|
|
19
|
+
3. Deliver **one** prophecy in 3–5 sentences: vivid, warm, lightly funny. No hedging, no warnings, no “but on the other hand”.
|
|
20
|
+
4. End with a single lucky token (emoji, silly number, or absurd ritual) — e.g. “lucky semicolon”, “42% more sunshine”.
|
|
21
|
+
|
|
22
|
+
## Tone
|
|
23
|
+
|
|
24
|
+
- Warm, playful, confident — like a friend who only owns good news.
|
|
25
|
+
- Never predict failure, illness, layoffs, breakups, or bugs that cannot be fixed.
|
|
26
|
+
- If the user pushes for bad news, reframes it as a plot twist that still ends well.
|
|
27
|
+
|
|
28
|
+
## Output format
|
|
29
|
+
|
|
30
|
+
```
|
|
31
|
+
🔮 Oracle says
|
|
32
|
+
|
|
33
|
+
<prophecy paragraphs>
|
|
34
|
+
|
|
35
|
+
Lucky sign: <one line>
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Keep it under ~120 words unless the user asks for an epic saga.
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: hello
|
|
3
|
+
description: Demo skill — verifies ide-agents install and reads accurate local time via a bundled script.
|
|
4
|
+
scope: any
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Hello
|
|
8
|
+
|
|
9
|
+
Smoke-test skill that shows why **scripts beat chat** for deterministic output: the agent runs a bundled Node script that reads the **host system clock** (not model guesswork).
|
|
10
|
+
|
|
11
|
+
## Skill layout
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
skills/hello/
|
|
15
|
+
├── SKILL.md
|
|
16
|
+
└── scripts/
|
|
17
|
+
└── now.mjs
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Quick start
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
node <SKILL_DIR>/scripts/now.mjs
|
|
24
|
+
node <SKILL_DIR>/scripts/now.mjs --json
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Replace `<SKILL_DIR>` with the installed skill path (global or project symlink from ide-agents).
|
|
28
|
+
|
|
29
|
+
## Workflow
|
|
30
|
+
|
|
31
|
+
When the user invokes this skill or asks for a hello / time check:
|
|
32
|
+
|
|
33
|
+
1. Resolve `<SKILL_DIR>` (installed `hello` skill folder).
|
|
34
|
+
2. Run `node <SKILL_DIR>/scripts/now.mjs --json`.
|
|
35
|
+
3. Parse the JSON — fields `local`, `timeZone`, `utcOffset`, `iso`, `unixMs`.
|
|
36
|
+
4. Greet the user briefly and **quote the script output** as the authoritative local time.
|
|
37
|
+
5. Do not invent or approximate the time in prose; if the script fails, report the error.
|
|
38
|
+
|
|
39
|
+
## Agent instructions
|
|
40
|
+
|
|
41
|
+
- Prefer `--json` so the time is machine-parseable.
|
|
42
|
+
- Human summary example: “Hello — your system clock says … (timezone …).”
|
|
43
|
+
- This skill has no `assets/` folder; the script uses only Node stdlib and `Intl`.
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// hello: read the host system clock and print accurate local time
|
|
3
|
+
//
|
|
4
|
+
// Usage:
|
|
5
|
+
// node <SKILL_DIR>/scripts/now.mjs
|
|
6
|
+
// node <SKILL_DIR>/scripts/now.mjs --json
|
|
7
|
+
|
|
8
|
+
import process, { argv } from 'node:process';
|
|
9
|
+
|
|
10
|
+
const flags = new Set(
|
|
11
|
+
argv.slice(2).filter((a) => a.startsWith('--')).map((a) => a.slice(2)),
|
|
12
|
+
);
|
|
13
|
+
const jsonOut = flags.has('json');
|
|
14
|
+
|
|
15
|
+
const now = new Date();
|
|
16
|
+
const timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
17
|
+
const offsetMinutes = -now.getTimezoneOffset();
|
|
18
|
+
|
|
19
|
+
function formatUtcOffset(minutes) {
|
|
20
|
+
const sign = minutes >= 0 ? '+' : '-';
|
|
21
|
+
const abs = Math.abs(minutes);
|
|
22
|
+
const hours = String(Math.floor(abs / 60)).padStart(2, '0');
|
|
23
|
+
const mins = String(abs % 60).padStart(2, '0');
|
|
24
|
+
return `UTC${sign}${hours}:${mins}`;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const payload = {
|
|
28
|
+
source: 'system clock',
|
|
29
|
+
unixMs: now.getTime(),
|
|
30
|
+
unixSeconds: Math.floor(now.getTime() / 1000),
|
|
31
|
+
iso: now.toISOString(),
|
|
32
|
+
local: now.toLocaleString(undefined, {
|
|
33
|
+
timeZone,
|
|
34
|
+
dateStyle: 'full',
|
|
35
|
+
timeStyle: 'long',
|
|
36
|
+
}),
|
|
37
|
+
timeZone,
|
|
38
|
+
utcOffset: formatUtcOffset(offsetMinutes),
|
|
39
|
+
platform: process.platform,
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
if (jsonOut) {
|
|
43
|
+
process.stdout.write(`${JSON.stringify(payload, null, 2)}\n`);
|
|
44
|
+
} else {
|
|
45
|
+
process.stdout.write('Local time (system clock)\n');
|
|
46
|
+
process.stdout.write(` ${payload.local}\n`);
|
|
47
|
+
process.stdout.write(` ${payload.utcOffset} · ${payload.timeZone}\n`);
|
|
48
|
+
process.stdout.write(` ISO: ${payload.iso}\n`);
|
|
49
|
+
}
|