{"_id":"@1kb/aliyun-sls","name":"@1kb/aliyun-sls","dist-tags":{"latest":"0.1.0"},"versions":{"0.1.0":{"name":"@1kb/aliyun-sls","version":"0.1.0","description":"API2CLI-style command line client for Alibaba Cloud Simple Log Service.","license":"MIT","author":{"name":"1kb contributors"},"homepage":"https://github.com/onekb/aliyun-sls#readme","repository":{"type":"git","url":"git+https://github.com/onekb/aliyun-sls.git"},"bugs":{"url":"https://github.com/onekb/aliyun-sls/issues"},"keywords":["aliyun","alibaba-cloud","sls","simple-log-service","log-service","cli","api2cli"],"type":"commonjs","bin":{"aliyun-sls":"scripts/run.js","sls":"scripts/run.js"},"scripts":{"install:local":"node scripts/install.js","smoke":"node scripts/run.js --version && node scripts/run.js ops --format json","test":"python -m unittest discover -s tests"},"engines":{"node":">=18"},"publishConfig":{"access":"public"},"_id":"@1kb/aliyun-sls@0.1.0","gitHead":"8f0280409f9e5ea326cb48000d5e6783a84ccb96","_nodeVersion":"20.20.1","_npmVersion":"10.8.2","dist":{"integrity":"sha512-fGOJf2giPSo0JMBo/2r9Lb6kN37fZ4z7rrzvjxABaAdbM+SDrMJFEUkxxrsrmg1DrwxmWsGODMxNcG7G+6IK3A==","shasum":"3f7339d65c3a49e907e38f44ecf89a76a9d69e3e","tarball":"https://registry.npmjs.org/@1kb/aliyun-sls/-/aliyun-sls-0.1.0.tgz","fileCount":21,"unpackedSize":99926,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQDvTK9ARR9vt2uvS8DkNP4A2p3ZJwe1KyHZfaUylttjPQIgMO4crdF7RnnN4xQ312Cie0lENKfEPhDCvdPTNWr8lyg="}]},"_npmUser":{"name":"1kb","email":"1@1kb.ren"},"directories":{},"maintainers":[{"name":"1kb","email":"1@1kb.ren"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/aliyun-sls_0.1.0_1779780923249_0.6944443582321556"},"_hasShrinkwrap":false}},"time":{"created":"2026-05-26T07:35:23.075Z","0.1.0":"2026-05-26T07:35:23.382Z","modified":"2026-05-26T07:35:23.626Z"},"maintainers":[{"name":"1kb","email":"1@1kb.ren"}],"description":"API2CLI-style command line client for Alibaba Cloud Simple Log Service.","homepage":"https://github.com/onekb/aliyun-sls#readme","keywords":["aliyun","alibaba-cloud","sls","simple-log-service","log-service","cli","api2cli"],"repository":{"type":"git","url":"git+https://github.com/onekb/aliyun-sls.git"},"author":{"name":"1kb contributors"},"bugs":{"url":"https://github.com/onekb/aliyun-sls/issues"},"license":"MIT","readme":"# Alibaba Cloud SLS CLI\n\n`aliyun-sls` is an API2CLI-style CLI for Alibaba Cloud Simple Log Service. It exposes signed SLS REST APIs as a stable command line interface for humans, scripts, and AI agents.\n\nThe CLI is self-contained Python and uses the SLS `LOG <AccessKeyId>:<Signature>` HMAC-SHA1 request signature, so it does not require Alibaba Cloud SDK packages. The recommended installation path is an npm/npx wrapper that installs the runtime and command shims.\n\n## 中文介绍\n\n`aliyun-sls` 是一个面向阿里云日志服务 SLS 的命令行工具。它把 SLS REST API 封装成稳定、可脚本化、适合 AI Agent 调用的 CLI，默认输出 JSON envelope，方便在终端、自动化脚本和 Agent 工作流里组合使用。\n\n这个工具不依赖阿里云 SDK，运行时使用标准库实现 SLS `LOG <AccessKeyId>:<Signature>` HMAC-SHA1 签名。它提供三层能力：\n\n- Raw API：任意未封装接口都可以通过 `api METHOD PATH --params --data` 调用。\n- 元数据命令：常用 Project、Logstore、Logs、Index、Shard 接口已经整理成稳定命令。\n- Shortcut：`+query`、`+stores`、`+histograms` 覆盖日常查日志和排障场景。\n\n配置默认落在 `~/.api2cli/aliyun-sls/config.json`，支持 profile、环境变量、私有文件、secret manager 命令和本机 inline 配置。写操作支持 `--dry-run`，删除等高风险操作需要显式 `--yes`。\n\n## Install\n\nRecommended:\n\n```bash\nnpx @1kb/aliyun-sls@latest install\n```\n\nThe installer checks Node.js and Python, copies the CLI runtime to:\n\n```text\n~/.api2cli/aliyun-sls/runtime\n```\n\nand creates command shims in:\n\n```text\n~/.api2cli/bin\n```\n\nIf that bin directory is not already on `PATH`, add it:\n\n```bash\nexport PATH=\"$HOME/.api2cli/bin:$PATH\"\n```\n\nLocal source install:\n\n```bash\ncd aliyun-sls\nnode scripts/install.js\n```\n\nDeveloper mode without installing:\n\n```bash\ncd aliyun-sls\npython -m aliyun_sls --help\n```\n\n## Quick Start\n\nSLS uses AccessKey credentials rather than OAuth. Prefer RAM user AccessKeys with the least privileges needed for the SLS project.\n\n```bash\n# 1. Configure non-sensitive defaults\naliyun-sls config init \\\n  --region cn-hangzhou \\\n  --endpoint cn-hangzhou.log.aliyuncs.com \\\n  --project my-project \\\n  --logstore app \\\n  --topic mineadmin\n\n# 2. Provide credentials through environment variables\nexport ALIYUN_SLS_ACCESS_KEY_ID=...\nexport ALIYUN_SLS_ACCESS_KEY_SECRET=...\n\n# 3. Store env-var references in the user config\naliyun-sls auth env\n\n# 4. Verify auth and installation\naliyun-sls auth status\naliyun-sls ops --format table\n\n# 5. Run a read-only API command\naliyun-sls project list --format table\n```\n\nThe CLI also reads Alibaba Cloud standard env vars directly:\n\n```bash\nexport ALIYUN_ACCESS_KEY_ID=...\nexport ALIYUN_ACCESS_KEY_SECRET=...\nexport ALIYUN_SECURITY_TOKEN=...\n```\n\n## AI Agent Quick Start\n\nAll setup commands support JSON output, so an agent can run them without relying on an interactive UI.\n\n```bash\nnpx @1kb/aliyun-sls@latest install --json\n\naliyun-sls config init \\\n  --region cn-hangzhou \\\n  --endpoint cn-hangzhou.log.aliyuncs.com \\\n  --project my-project \\\n  --logstore app \\\n  --format json\n\naliyun-sls auth env --format json\naliyun-sls auth status --format json\naliyun-sls ops --format json\n```\n\nIf the user prefers private local files or a secret manager, store references instead of plaintext credentials:\n\n```bash\naliyun-sls auth file \\\n  --access-key-id-file ~/.secrets/aliyun-sls/access-key-id \\\n  --access-key-secret-file ~/.secrets/aliyun-sls/access-key-secret\n```\n\n```bash\naliyun-sls auth command \\\n  --access-key-id-command \"security find-generic-password -s aliyun-sls-access-key-id -w\" \\\n  --access-key-secret-command \"security find-generic-password -s aliyun-sls-access-key-secret -w\"\n```\n\n## Configuration\n\nThe default user config path is:\n\n```text\n~/.api2cli/aliyun-sls/config.json\n```\n\nOverride the config root:\n\n```bash\nAPI2CLI_CONFIG_DIR=/custom/path aliyun-sls config show\n```\n\nOverride the exact config file:\n\n```bash\nALIYUN_SLS_CONFIG=/custom/path/config.json aliyun-sls config show\n```\n\nThe project config template is `api2cli.config.yaml`. It describes defaults and environment variables, but it must not contain real AccessKey secrets.\n\nCredentials should be stored as references:\n\n- `auth env`: read from env vars such as `ALIYUN_SLS_ACCESS_KEY_ID`.\n- `auth file`: read from private local files.\n- `auth command`: read from a secret manager command.\n- `auth inline`: available for controlled local use, but not recommended for shared machines.\n\nProfiles:\n\n```bash\naliyun-sls profile add staging --use\naliyun-sls config set endpoint cn-shenzhen.log.aliyuncs.com\naliyun-sls profile use default\n```\n\nIf your Python distribution has no default CA bundle configured, set `ALIYUN_SLS_CA_BUNDLE` or install `certifi`. The runtime uses `certifi` automatically when it is available.\n\n## API Layers\n\nRaw API fallback:\n\n```bash\naliyun-sls api GET /logstores \\\n  --project my-project \\\n  --params '{\"offset\":0,\"size\":10}' \\\n  --format pretty\n```\n\nGenerated operations:\n\n```bash\naliyun-sls project list --format table\naliyun-sls logstore list --project my-project --format table\naliyun-sls logstore get --project my-project --logstore app --format pretty\naliyun-sls logs get --project my-project --logstore app \\\n  --from \"15m ago\" --to now --query \"* | select count(1) as c\" --format pretty\n```\n\nShortcuts:\n\n```bash\naliyun-sls +stores --project my-project --format table\naliyun-sls +query --project my-project --logstore app \\\n  --from \"15m ago\" --query \"error\" --line 20 --reverse true --format pretty\naliyun-sls +histograms --project my-project --logstore app \\\n  --from \"1h ago\" --to now --query \"status: 500\" --format table\n```\n\n## Safety\n\nDry-run and high-risk confirmations:\n\n```bash\naliyun-sls logstore create --project my-project \\\n  --logstoreName app --shardCount 2 --ttl 30 --dry-run --format pretty\naliyun-sls logstore delete --project my-project --logstore app --dry-run\naliyun-sls logstore delete --project my-project --logstore app --yes\n```\n\nRules:\n\n- Default output is a JSON envelope: `{ \"ok\": true, \"data\": ..., \"meta\": ... }`.\n- `config show` masks credentials unless `--reveal` is explicitly used.\n- High-risk operations such as delete require `--yes`, unless `--dry-run` is used.\n- Do not commit AccessKey secrets to this platform directory.\n\n## Uninstall\n\nRemove installed command shims and runtime:\n\n```bash\nrm -f \"$HOME/.api2cli/bin/aliyun-sls\" \"$HOME/.api2cli/bin/sls\"\nrm -rf \"$HOME/.api2cli/aliyun-sls/runtime\"\n```\n\nRemove user config only when you no longer need the profiles:\n\n```bash\nrm -f \"$HOME/.api2cli/aliyun-sls/config.json\"\n```\n\n## Architecture\n\nThis platform follows `API2CLI_PLAYBOOK.md`:\n\n- Raw API layer: `api METHOD PATH --params --data --file --output`.\n- Metadata-driven command layer: operations in `metadata/sls-core.json` exposed as `project`, `logstore`, `logs`, `index`, and `shard` commands.\n- Shortcut layer: `+query`, `+stores`, and `+histograms`.\n- Shared runtime: config, signing, request execution, output envelopes, pagination, and risk checks are centralized in `aliyun_sls/`.\n- Install layer: `package.json`, `scripts/install.js`, `scripts/run.js`, and `dist/manifest.json` provide the npm/npx entrypoint.\n\n## References\n\n- Alibaba Cloud SLS API overview: https://www.alibabacloud.com/help/en/sls/developer-reference/api-sls-2020-12-30-overview\n- SLS request signatures: https://www.alibabacloud.com/help/en/sls/developer-reference/request-signatures\n- GetLogs API: https://www.alibabacloud.com/help/en/sls/developer-reference/api-sls-2020-12-30-getlogs\n","readmeFilename":"README.md","_rev":"1-4ac65933c97bcbf3458ee140304ce76b"}