maxc-cli 0.2.0__tar.gz → 0.2.1__tar.gz

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.
Files changed (71) hide show
  1. {maxc_cli-0.2.0 → maxc_cli-0.2.1}/PKG-INFO +1 -1
  2. {maxc_cli-0.2.0 → maxc_cli-0.2.1}/setup.py +1 -1
  3. {maxc_cli-0.2.0 → maxc_cli-0.2.1}/src/maxc_cli/__init__.py +1 -1
  4. maxc_cli-0.2.1/src/maxc_cli/skills/SKILL.md +241 -0
  5. {maxc_cli-0.2.0 → maxc_cli-0.2.1}/src/maxc_cli/skills/references/bootstrap-auth.md +4 -73
  6. maxc_cli-0.2.1/src/maxc_cli/skills/references/bootstrap-flow.md +100 -0
  7. maxc_cli-0.2.1/src/maxc_cli/skills/references/command-patterns.md +383 -0
  8. {maxc_cli-0.2.0 → maxc_cli-0.2.1}/src/maxc_cli/skills/references/migrate-from-odpscmd.md +10 -28
  9. maxc_cli-0.2.1/src/maxc_cli/skills/references/red-lines.md +94 -0
  10. {maxc_cli-0.2.0 → maxc_cli-0.2.1}/src/maxc_cli.egg-info/PKG-INFO +1 -1
  11. {maxc_cli-0.2.0 → maxc_cli-0.2.1}/src/maxc_cli.egg-info/SOURCES.txt +2 -5
  12. maxc_cli-0.2.0/src/maxc_cli/skills/SKILL.md +0 -456
  13. maxc_cli-0.2.0/src/maxc_cli/skills/nohup.out +0 -0
  14. maxc_cli-0.2.0/src/maxc_cli/skills/references/cache-mechanism.md +0 -15
  15. maxc_cli-0.2.0/src/maxc_cli/skills/references/command-patterns.md +0 -274
  16. maxc_cli-0.2.0/src/maxc_cli/skills/references/diff-workflow.md +0 -21
  17. maxc_cli-0.2.0/src/maxc_cli/skills/references/error-recovery.md +0 -23
  18. maxc_cli-0.2.0/src/maxc_cli/skills/references/semantic-metadata.md +0 -24
  19. {maxc_cli-0.2.0 → maxc_cli-0.2.1}/MANIFEST.in +0 -0
  20. {maxc_cli-0.2.0 → maxc_cli-0.2.1}/README.md +0 -0
  21. {maxc_cli-0.2.0 → maxc_cli-0.2.1}/pyproject.toml +0 -0
  22. {maxc_cli-0.2.0 → maxc_cli-0.2.1}/scripts/regression_test.py +0 -0
  23. {maxc_cli-0.2.0 → maxc_cli-0.2.1}/setup.cfg +0 -0
  24. {maxc_cli-0.2.0 → maxc_cli-0.2.1}/src/maxc_cli/__main__.py +0 -0
  25. {maxc_cli-0.2.0 → maxc_cli-0.2.1}/src/maxc_cli/app.py +0 -0
  26. {maxc_cli-0.2.0 → maxc_cli-0.2.1}/src/maxc_cli/audit.py +0 -0
  27. {maxc_cli-0.2.0 → maxc_cli-0.2.1}/src/maxc_cli/auth_providers.py +0 -0
  28. {maxc_cli-0.2.0 → maxc_cli-0.2.1}/src/maxc_cli/backend/__init__.py +0 -0
  29. {maxc_cli-0.2.0 → maxc_cli-0.2.1}/src/maxc_cli/backend/auth.py +0 -0
  30. {maxc_cli-0.2.0 → maxc_cli-0.2.1}/src/maxc_cli/backend/catalog.py +0 -0
  31. {maxc_cli-0.2.0 → maxc_cli-0.2.1}/src/maxc_cli/backend/data.py +0 -0
  32. {maxc_cli-0.2.0 → maxc_cli-0.2.1}/src/maxc_cli/backend/job.py +0 -0
  33. {maxc_cli-0.2.0 → maxc_cli-0.2.1}/src/maxc_cli/backend/meta.py +0 -0
  34. {maxc_cli-0.2.0 → maxc_cli-0.2.1}/src/maxc_cli/backend/odps.py +0 -0
  35. {maxc_cli-0.2.0 → maxc_cli-0.2.1}/src/maxc_cli/backend/query.py +0 -0
  36. {maxc_cli-0.2.0 → maxc_cli-0.2.1}/src/maxc_cli/cache.py +0 -0
  37. {maxc_cli-0.2.0 → maxc_cli-0.2.1}/src/maxc_cli/cli.py +0 -0
  38. {maxc_cli-0.2.0 → maxc_cli-0.2.1}/src/maxc_cli/config.py +0 -0
  39. {maxc_cli-0.2.0 → maxc_cli-0.2.1}/src/maxc_cli/exceptions.py +0 -0
  40. {maxc_cli-0.2.0 → maxc_cli-0.2.1}/src/maxc_cli/helpers.py +0 -0
  41. {maxc_cli-0.2.0 → maxc_cli-0.2.1}/src/maxc_cli/masking.py +0 -0
  42. {maxc_cli-0.2.0 → maxc_cli-0.2.1}/src/maxc_cli/models.py +0 -0
  43. {maxc_cli-0.2.0 → maxc_cli-0.2.1}/src/maxc_cli/output.py +0 -0
  44. {maxc_cli-0.2.0 → maxc_cli-0.2.1}/src/maxc_cli/setting_parser.py +0 -0
  45. {maxc_cli-0.2.0 → maxc_cli-0.2.1}/src/maxc_cli/skills/agents/openai.yaml +0 -0
  46. {maxc_cli-0.2.0 → maxc_cli-0.2.1}/src/maxc_cli/skills/references/json-output-format.md +0 -0
  47. {maxc_cli-0.2.0 → maxc_cli-0.2.1}/src/maxc_cli/skills/references/maxcompute-sql-notes.md +0 -0
  48. {maxc_cli-0.2.0 → maxc_cli-0.2.1}/src/maxc_cli/skills/references/partition-guide.md +0 -0
  49. {maxc_cli-0.2.0 → maxc_cli-0.2.1}/src/maxc_cli/skills/references/setup-install.md +0 -0
  50. {maxc_cli-0.2.0 → maxc_cli-0.2.1}/src/maxc_cli/store.py +0 -0
  51. {maxc_cli-0.2.0 → maxc_cli-0.2.1}/src/maxc_cli/utils.py +0 -0
  52. {maxc_cli-0.2.0 → maxc_cli-0.2.1}/src/maxc_cli.egg-info/dependency_links.txt +0 -0
  53. {maxc_cli-0.2.0 → maxc_cli-0.2.1}/src/maxc_cli.egg-info/entry_points.txt +0 -0
  54. {maxc_cli-0.2.0 → maxc_cli-0.2.1}/src/maxc_cli.egg-info/requires.txt +0 -0
  55. {maxc_cli-0.2.0 → maxc_cli-0.2.1}/src/maxc_cli.egg-info/top_level.txt +0 -0
  56. {maxc_cli-0.2.0 → maxc_cli-0.2.1}/tests/test_agent_hints_and_cli.py +0 -0
  57. {maxc_cli-0.2.0 → maxc_cli-0.2.1}/tests/test_agent_skill_commands_context.py +0 -0
  58. {maxc_cli-0.2.0 → maxc_cli-0.2.1}/tests/test_cache.py +0 -0
  59. {maxc_cli-0.2.0 → maxc_cli-0.2.1}/tests/test_catalog.py +0 -0
  60. {maxc_cli-0.2.0 → maxc_cli-0.2.1}/tests/test_cli_mock.py +0 -0
  61. {maxc_cli-0.2.0 → maxc_cli-0.2.1}/tests/test_compat.py +0 -0
  62. {maxc_cli-0.2.0 → maxc_cli-0.2.1}/tests/test_e2e_smoke.py +0 -0
  63. {maxc_cli-0.2.0 → maxc_cli-0.2.1}/tests/test_error_self_correction.py +0 -0
  64. {maxc_cli-0.2.0 → maxc_cli-0.2.1}/tests/test_external_auth.py +0 -0
  65. {maxc_cli-0.2.0 → maxc_cli-0.2.1}/tests/test_integration.py +0 -0
  66. {maxc_cli-0.2.0 → maxc_cli-0.2.1}/tests/test_integration_real.py +0 -0
  67. {maxc_cli-0.2.0 → maxc_cli-0.2.1}/tests/test_job_improvements.py +0 -0
  68. {maxc_cli-0.2.0 → maxc_cli-0.2.1}/tests/test_masking.py +0 -0
  69. {maxc_cli-0.2.0 → maxc_cli-0.2.1}/tests/test_phase1_improvements.py +0 -0
  70. {maxc_cli-0.2.0 → maxc_cli-0.2.1}/tests/test_query_auto_promote.py +0 -0
  71. {maxc_cli-0.2.0 → maxc_cli-0.2.1}/tests/test_setting_parser.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: maxc-cli
3
- Version: 0.2.0
3
+ Version: 0.2.1
4
4
  Summary: Agent-native MaxCompute CLI for external coding agents
5
5
  Classifier: Programming Language :: Python :: 3
6
6
  Classifier: Programming Language :: Python :: 3.8
@@ -9,7 +9,7 @@ README = ROOT / "README.md"
9
9
 
10
10
  setup(
11
11
  name="maxc-cli",
12
- version="0.2.0",
12
+ version="0.2.1",
13
13
  description="Agent-native MaxCompute CLI for external coding agents",
14
14
  long_description=README.read_text(encoding="utf-8"),
15
15
  long_description_content_type="text/markdown",
@@ -2,4 +2,4 @@
2
2
 
3
3
  __all__ = ["__version__"]
4
4
 
5
- __version__ = "0.2.0"
5
+ __version__ = "0.2.1"
@@ -0,0 +1,241 @@
1
+ ---
2
+ name: maxcompute-cli-guidance
3
+ description: Use when the task involves MaxCompute, ODPS, or maxc — querying tables, viewing table schema, listing tables, searching metadata, executing SQL, checking partitions, sampling data, or managing jobs.
4
+ description_zh: 当用户需要查询 MaxCompute/ODPS 中的表、查看表结构、列出项目中的表、搜索元数据、执行 SQL、查看分区、预览数据、跟踪任务时使用。适用于提到 ODPS、MaxCompute、maxc、数据仓库表查询等场景。
5
+ name_zh: MaxCompute数据查询
6
+ category: database
7
+ keywords: [MaxCompute, ODPS, maxc, 表, 查表, 查数据, SQL, 数据仓库, 元数据, 分区, odps sql, 阿里云]
8
+ requires: MaxCompute account with AK/SK or environment variables
9
+ entry_point: maxc
10
+ min_cli_version: "0.1.5"
11
+ ---
12
+
13
+ # Use MaxC CLI
14
+
15
+ Use the live CLI instead of inventing a separate MaxCompute adapter. Prefer `maxc ...`; fall back to `python3 -m maxc_cli ...` when the console script is not on `PATH`.
16
+
17
+ ## When To Use
18
+
19
+ - First-time setup or repair of Python or `maxc-cli`
20
+ - Auth bootstrap or identity inspection (AK/SK or env vars)
21
+ - Migrating from odpscmd (reusing existing ODPS Console credentials)
22
+ - Session project or schema overrides
23
+ - Metadata discovery, schema inspection, cache-backed search
24
+ - Read-only query execution or job tracking
25
+ - Cache and semantic-metadata workflows
26
+
27
+ Do **not** use when the task is to implement `maxc-cli` itself, or when the user wants raw pyodps/SDK code.
28
+
29
+ ## Core Principles
30
+
31
+ These are non-negotiable. See [references/red-lines.md](references/red-lines.md) for the full list including common mistakes, anti-patterns, and error recovery.
32
+
33
+ 1. **Always use `--json`** for machine work. Use `--format markdown` for user-facing output, `--format brief` in token-tight contexts. `--json` is shorthand for `--format json`.
34
+ 2. **Never invent names** — table, schema, project, or endpoint. Verify with `meta` commands and `auth whoami`.
35
+ 3. **Default to `--project` for the user's target workspace.** The configured project (in `~/.maxc/config.yaml`) is the user's **home dev workspace** — the data they actually want to query usually lives in a *different* workspace (often the corresponding production one). When the user mentions a table/project without specifying which workspace, **ask first**, then pass `--project <name>` on every meta/data command and use `project.table` in SQL.
36
+ 4. **Workspace naming convention is a fixed pair:** `<name>_dev` is the dev workspace; the same `<name>` **without** the `_dev` suffix is its corresponding **production** workspace. They share metadata structure but hold different data and different permissions. See Dev vs Production Workspaces below.
37
+ 5. **Never re-prompt for credentials** when `auth whoami` shows `authenticated=true`. Permission errors are almost always a workspace/project issue, not a credential issue.
38
+ 6. **Always discover partitions** via `meta latest-partition` before querying partitioned tables. Format varies per table.
39
+ 7. **Always read `error.suggestion`** before retrying a failed command. Same input → same error.
40
+ 8. **Never install or upgrade Python** without explicit user confirmation.
41
+ 9. **Never log AK/SK** in output, even in error context.
42
+
43
+ ## Bootstrap Flow
44
+
45
+ When `auth whoami --json` returns `configured=false` (no auth set up), follow [references/bootstrap-flow.md](references/bootstrap-flow.md) step by step. Two principles:
46
+
47
+ 1. **Never pick the auth method yourself** — always ask the user to choose between AK/SK and environment variables.
48
+ 2. **If the user already has `odpscmd` configured**, proactively offer to migrate those credentials before asking them to enter anything new — see [references/migrate-from-odpscmd.md](references/migrate-from-odpscmd.md).
49
+ 3. **If `auth whoami` shows `auth_type=external`, the user is on an externally-managed credential provider — do NOT modify the auth config.** Treat the bootstrap as already done. Only `project`/`endpoint`/`schema` are safe to change (via `session set` or by re-running `auth login-external` with the same `--process-command`).
50
+
51
+ ## First Pass
52
+
53
+ 1. Prefer `maxc ...`; use `python3 -m maxc_cli ...` if not on `PATH`. If the machine may not be bootstrapped, read [references/setup-install.md](references/setup-install.md) first.
54
+ 2. Run `maxc auth whoami --json`. Check `data.identity`:
55
+ - `authenticated=true, validation_status=verified` → ready, continue.
56
+ - `configured=false` → no auth set up → follow Bootstrap Flow above.
57
+ - `configured=true, validation_status=failed` → config exists but remote check failed → inspect warnings, then fix or re-login.
58
+ 3. For exact command syntax and output shapes, see [references/command-patterns.md](references/command-patterns.md).
59
+
60
+ ## JSON Output Format
61
+
62
+ All `--json` output follows the envelope format. Always check `status` first — on `failure`, read `error.code` and `error.suggestion`; on `success`/`pending`, check `agent_hints.next_actions` and `agent_hints.warnings`.
63
+
64
+ Key paths:
65
+
66
+ - `data.result.rows` (query)
67
+ - `data.analysis` (query cost/explain)
68
+ - `data.identity` (auth whoami)
69
+ - `data.table` (meta describe)
70
+ - `data.sample` (data sample)
71
+ - `metadata.job_id` (async)
72
+
73
+ `--json` stdout is one final envelope. Exception: `job wait --stream` emits NDJSON events. `cache build --json` emits progress to `stderr`, one final envelope to `stdout`.
74
+
75
+ See [references/json-output-format.md](references/json-output-format.md) for full examples and [references/command-patterns.md](references/command-patterns.md) §JSON Contract for all data shapes.
76
+
77
+ ## Dev vs Production Workspaces
78
+
79
+ MaxCompute workspaces come in **fixed pairs**: a dev workspace and its corresponding production workspace. Confusing the two is the #1 source of permission errors.
80
+
81
+ ### The naming pair (memorize this)
82
+
83
+ | Workspace type | Name pattern | Example | Who can access | What lives there |
84
+ |----------------|--------------|---------|----------------|------------------|
85
+ | **Dev** | `<name>_dev` | `my_project_dev` | Personal accounts (the user themselves) | Test data, scratch tables, the user's own work |
86
+ | **Production** | `<name>` | `my_project` | Usually only service accounts / DataWorks pipelines | The real business data the user actually wants to query |
87
+
88
+ The dev workspace and the production workspace **share metadata structure but hold different data**. A table that exists in `my_project_dev` almost always exists in `my_project` too — but the rows, partitions, and freshness will differ.
89
+
90
+ ### Other key facts
91
+
92
+ - The project configured in `~/.maxc/config.yaml` or env vars is always the **dev** workspace — this is the user's home workspace.
93
+ - Personal accounts usually only have *write* access to dev and *read* access to production (varies by org policy). Pointing a session directly at production often results in `PERMISSION_DENIED`.
94
+ - `--project` is the canonical way to access **another project's** tables — most often the corresponding production workspace, occasionally a different team's project.
95
+ - When the user asks about a table without naming the workspace, **ask whether they mean the dev or production copy** before guessing.
96
+
97
+ ### How to tell which workspace you are in
98
+
99
+ ```bash
100
+ maxc auth whoami --json # check data.identity.project — ends with _dev?
101
+ maxc session show --json # check current session project
102
+ ```
103
+
104
+ If the project name does NOT end with `_dev`, you may be pointed at a production workspace by mistake.
105
+
106
+ ### Accessing production tables from dev workspace
107
+
108
+ Use `--project` to read metadata from the production workspace without switching session:
109
+
110
+ ```bash
111
+ maxc meta list-tables --project my_project --json
112
+ maxc meta describe my_table --project my_project --json
113
+ maxc data sample my_table --project my_project --json
114
+ ```
115
+
116
+ When writing SQL, use `project.table` format to reference tables in another workspace:
117
+
118
+ ```sql
119
+ -- From dev workspace, query a production table
120
+ SELECT * FROM my_project.my_table WHERE ds = '20260418' LIMIT 100
121
+ ```
122
+
123
+ Do NOT use bare table names (`FROM my_table`) when the target table lives in a different project — the query will fail with `TABLE_NOT_FOUND`.
124
+
125
+ ### Common permission error scenarios
126
+
127
+ | Scenario | Symptom | Fix |
128
+ |----------|---------|-----|
129
+ | Config points to production workspace | `PERMISSION_DENIED` on most operations | `maxc session set --project my_project_dev` |
130
+ | Need to read production table metadata | `PERMISSION_DENIED` on `meta describe` | `maxc meta describe my_table --project my_project --json` |
131
+ | SQL references a table in another project without project prefix | `TABLE_NOT_FOUND` | Use `project.table` format in SQL |
132
+ | Mixed access: dev metadata + production data | Confusing results | Be explicit: use `--project` for metadata commands, `project.table` in SQL |
133
+
134
+ ## NL2SQL Workflow
135
+
136
+ Standard flow for answering data questions:
137
+
138
+ ```
139
+ 1. meta list-tables --schema <s> --json → get table names + schema_name
140
+ 2. meta describe <schema.table> --json → get ALL columns (--json returns full schema)
141
+ 3. query cost "SELECT ..." --json → estimate cost (skip for simple queries)
142
+ 4. query "SELECT ..." --json → execute query
143
+ ```
144
+
145
+ Add `--project <p>` to any step when working with a non-default project.
146
+
147
+ **Critical rules:**
148
+
149
+ - Always use schema-qualified table names in SQL: `<schema>.<table>` (e.g. `california_schools.frpm`), not bare table names. The `list-tables` output includes `schema_name` for each table.
150
+ - `meta describe --json` returns **all columns** automatically. Without `--json`, use `--full` to avoid truncation.
151
+ - Column names with spaces or special characters must be backtick-escaped: `` `column name` ``.
152
+ - When filtering by column values, first check actual values with `data sample` or a `SELECT DISTINCT` query — don't guess enum values.
153
+ - For partitioned tables, always filter by partition column in WHERE (e.g. `WHERE ds = '20260415'`) to avoid full-table scans.
154
+ - When accessing tables from another project, use `project.table` format in SQL (see Dev vs Production Workspaces).
155
+
156
+ For dialect notes (SET options, type coercion, date functions, common error codes), see [references/maxcompute-sql-notes.md](references/maxcompute-sql-notes.md).
157
+
158
+ ## Partition Strategy
159
+
160
+ Before querying a partitioned table, always determine the correct partition value:
161
+
162
+ ```
163
+ 1. maxc meta describe <table> --json → check partition_columns
164
+ - No partitions? → Query directly with LIMIT
165
+ - Has partitions? → Continue to step 2
166
+
167
+ 2. maxc meta latest-partition <table> --json → get latest value and format
168
+ - Note the exact format (e.g. "20260415" vs "2026-04-15")
169
+
170
+ 3. Construct WHERE clause using exact value from step 2
171
+ - Example: WHERE ds = '20260415' LIMIT 100
172
+
173
+ 4. For "_df" tables: latest partition = latest full snapshot
174
+ For "_di" tables: may need date range for complete picture
175
+ ```
176
+
177
+ Prefer `meta latest-partition` over `MAX_PT()` for ad-hoc queries — `MAX_PT` may return incomplete partitions or only consider the first partition level.
178
+
179
+ See [references/partition-guide.md](references/partition-guide.md) for naming conventions, MAX_PT() guidance, and ambiguity handling.
180
+
181
+ ## "I want to X → Use Y" Decision Table
182
+
183
+ For full command syntax and options, see [references/command-patterns.md](references/command-patterns.md).
184
+
185
+ | I want to... | Use |
186
+ |--------------|-----|
187
+ | Check who I am and where I'm pointed | `maxc auth whoami --json` |
188
+ | Set up auth from scratch | See Bootstrap Flow above |
189
+ | Switch project/schema for this session | `maxc session set --project P --schema S --json` |
190
+ | List tables | `maxc meta list-tables --schema S --json` |
191
+ | Get full schema of a table | `maxc meta describe T --json` |
192
+ | Find tables by keyword | `maxc meta search KW --json` |
193
+ | Find columns by keyword | `maxc meta search-columns KW --json` |
194
+ | Get latest partition value | `maxc meta latest-partition T --json` |
195
+ | Sample data | `maxc data sample T --rows 10 --json` |
196
+ | Run a query | `maxc query "SELECT ..." --json` |
197
+ | Estimate cost first | `maxc query cost "SELECT ..." --json` |
198
+ | Run a long query async | `maxc query "..." --wait 0 --json`, then `maxc job wait <id> --json` |
199
+ | Auto-abort if too costly | `maxc query "..." --cost-check 10.0 --json` |
200
+ | Read another project's tables | Add `--project P` to any meta/data command; use `project.table` in SQL |
201
+ | Build/refresh metadata cache | `maxc cache build --json` |
202
+ | Check permission for an op | `maxc auth can-i --table T --operation SELECT --json` |
203
+ | Diagnose a failed job | `maxc job diagnose <id> --json` |
204
+ | Add semantic metadata to a table | `maxc meta semantic set T ... --json` (see command-patterns.md §Semantic Metadata) |
205
+ | Compare two tables | `maxc diff schema|partition|data ...` (see command-patterns.md §Diffs) |
206
+ | Migrate from odpscmd | See [references/migrate-from-odpscmd.md](references/migrate-from-odpscmd.md) |
207
+
208
+ ## Capability Boundaries
209
+
210
+ | Boundary | Detail | Alternative |
211
+ |----------|--------|-------------|
212
+ | Read-only enforcement | Client-side SQL keyword detection; write operations blocked before reaching MaxCompute | Use odpscmd, pyodps SDK, or DataWorks |
213
+ | No permission management | `auth can-i` checks one table+operation; cannot enumerate accessible tables | MaxCompute console or project admin tools |
214
+ | No complete permission inventory | Cannot iterate projects to discover all readable tables | Ask user for target project/table |
215
+ | No data upload/import | Read-only tool | Use odpscmd tunnel or DataWorks |
216
+ | No lineage API | Returns `supported: false` placeholder | Use DataWorks lineage |
217
+ | No resource/UDF management | No upload/registration | Use odpscmd or DataWorks |
218
+
219
+ ## Known Limitations
220
+
221
+ | Feature | Status | Detail |
222
+ |---------|--------|--------|
223
+ | `meta search` | Catalog API preferred | Server-side FTS via pyodps RestClient (auto-routed); falls back to cache/live substring match |
224
+ | `list-tables` pagination | Not implemented | CLI-side `--cursor` is offset token, not server-side cursor |
225
+ | `diff data` | Snapshot compare | Keyed snapshot compare, not exhaustive diff |
226
+ | `auth login` | Plaintext YAML | AccessKey stored in `~/.maxc/config.yaml` (file permissions 0600) |
227
+ | Write operations | Client-side read-only | Write operations blocked by CLI before submission; `--force` bypasses |
228
+
229
+ ## References Index
230
+
231
+ | File | When to read |
232
+ |------|--------------|
233
+ | [bootstrap-flow.md](references/bootstrap-flow.md) | First-time setup or `configured=false` |
234
+ | [setup-install.md](references/setup-install.md) | Python / maxc-cli install detail |
235
+ | [bootstrap-auth.md](references/bootstrap-auth.md) | Per-method auth setup (AK/SK, env vars) |
236
+ | [migrate-from-odpscmd.md](references/migrate-from-odpscmd.md) | User has `odpscmd` configured |
237
+ | [command-patterns.md](references/command-patterns.md) | Full command syntax, output shapes, cache/diff/semantic, multi-project, schema, async |
238
+ | [json-output-format.md](references/json-output-format.md) | JSON envelope examples |
239
+ | [partition-guide.md](references/partition-guide.md) | Partition naming, MAX_PT() guidance, ambiguity |
240
+ | [maxcompute-sql-notes.md](references/maxcompute-sql-notes.md) | SQL dialect, SET options, date functions, error codes |
241
+ | [red-lines.md](references/red-lines.md) | What not to do; common mistakes; anti-patterns; error code → recovery; symptom troubleshooting |
@@ -73,6 +73,10 @@ If `data.metadata.config_sources` is present, it lists which config files are ac
73
73
 
74
74
  Then follow the matching section below.
75
75
 
76
+ ### If `auth_type=external` is already configured
77
+
78
+ If `auth whoami` shows `auth_type=external` (or the saved config has `provider: external`), the user is on an externally-managed credential provider set up by another tool. **Do not run Step 2 or write a new auth block.** Treat the auth as already valid. Only `project`/`endpoint`/`schema` may be changed — via `maxc session set ...` or by re-running `auth login-external` with the *same* `--process-command` and the new project/endpoint values.
79
+
76
80
  ### Always ask for project and endpoint
77
81
 
78
82
  **Regardless of auth method, always ask the user for `project` and `endpoint` explicitly.** Do not silently reuse values from an existing config file or environment variables.
@@ -200,79 +204,6 @@ If env vars and config file are both active, env vars win for `access_id`, `secr
200
204
 
201
205
  ---
202
206
 
203
- ## Path C: External Credential Provider (NCS)
204
-
205
- Use when the user authenticates via an external command — most commonly `ncs` (Alibaba internal credential service). The command outputs JSON with `AccessKeyId`, `AccessKeySecret`, and optionally `SecurityToken` / `Expiration`.
206
-
207
- This is the recommended path for internal users who already use `ncs` with odpscmd.
208
-
209
- ### What you need
210
-
211
- - `process_command` — the command that outputs credentials (e.g. `ncs create credential odpsuser --employee-id 123456 -o template -t odpscmd`)
212
- - `project`
213
- - `endpoint`
214
-
215
- ### Migrating from odpscmd
216
-
217
- If the user has odpscmd already configured with `account_provider=external`, reuse their settings — see [migrate-from-odpscmd.md](migrate-from-odpscmd.md). The key mapping:
218
-
219
- | odpscmd field | maxc field |
220
- |---|---|
221
- | `account_provider=external` | `provider: external` |
222
- | `processCommand=ncs create credential ...` | `process_command: ncs create credential ...` |
223
- | `processCommandTimeout=20` | `process_timeout: 20` |
224
-
225
- ### Login command
226
-
227
- ```bash
228
- maxc auth login-external \
229
- --process-command "ncs create credential odpsuser --employee-id <employee_id> -o template -t odpscmd" \
230
- --project "<project>" \
231
- --endpoint "<endpoint>" \
232
- --json
233
- ```
234
-
235
- For department or app accounts:
236
-
237
- ```bash
238
- # Department account
239
- maxc auth login-external \
240
- --process-command "ncs create credential odpsaccount --account-name <account_name> -o template -t odpscmd" \
241
- --project "<project>" \
242
- --endpoint "<endpoint>" \
243
- --json
244
-
245
- # App account
246
- maxc auth login-external \
247
- --process-command "ncs create credential odpsapp --app-name <app_name> -o template -t odpscmd" \
248
- --project "<project>" \
249
- --endpoint "<endpoint>" \
250
- --json
251
- ```
252
-
253
- ### What it saves
254
-
255
- ```yaml
256
- auth:
257
- provider: external
258
- project: "<project>"
259
- endpoint: "<endpoint>"
260
- external:
261
- process_command: "ncs create credential odpsuser --employee-id 123456 -o template -t odpscmd"
262
- process_timeout: 60
263
- ```
264
-
265
- ### Backward compatibility with `provider: ncs`
266
-
267
- Old config files with `provider: ncs` continue to work — at runtime, maxc transparently converts them to `provider: external` and uses the same `ExternalCredentialProvider`. No manual migration needed.
268
-
269
- ### Credential caching
270
-
271
- - **L1 (in-process)**: Credentials are cached in memory and refreshed when they approach expiration.
272
- - **L2 (kv_store)**: Temporary credentials (with `Expiration`) are persisted to `~/.maxc/cache/cache.db`, avoiding repeated command execution across processes. Long-lived AKs (no `Expiration`) are NOT cached in kv_store to ensure revocation is respected.
273
-
274
- ---
275
-
276
207
  ## Step 3: Verify Auth After Login
277
208
 
278
209
  After any login command, always re-run:
@@ -0,0 +1,100 @@
1
+ # Bootstrap Flow
2
+
3
+ When `auth whoami --json` returns `configured=false`, follow the three phases below in order. Each phase delegates to a focused reference — read those for command-level detail.
4
+
5
+ ```
6
+ Phase 1: Prerequisites → setup-install.md
7
+
8
+ Phase 2: Auth → bootstrap-auth.md (or migrate-from-odpscmd.md)
9
+
10
+ Phase 3: Verify → maxc auth whoami --json
11
+ ```
12
+
13
+ ---
14
+
15
+ ## Phase 1: Ensure Prerequisites
16
+
17
+ Goal: `python3` (>= 3.8), `pip`, and `maxc` available.
18
+
19
+ ```bash
20
+ python3 --version
21
+ maxc --version 2>/dev/null || python3 -m maxc_cli --version
22
+ ```
23
+
24
+ - Missing or too-old Python / missing `maxc` → see [setup-install.md](setup-install.md). Never install or upgrade Python without explicit user confirmation.
25
+ - `maxc` not on PATH but `python3 -m maxc_cli` works → continue with the module form, do not block on PATH cleanup.
26
+
27
+ Skip whatever the user already has.
28
+
29
+ ---
30
+
31
+ ## Phase 2: Configure Auth
32
+
33
+ **Always ask the user which method first — never pick one yourself.**
34
+
35
+ > "Which auth method would you like to use?
36
+ > **(A) Access Key / Secret Key** — long-lived AK/SK pair
37
+ > **(B) Environment variables** — keys already exported in the current shell"
38
+
39
+ Then jump to the matching path in [bootstrap-auth.md](bootstrap-auth.md):
40
+
41
+ | User chose | Section in `bootstrap-auth.md` |
42
+ |---|---|
43
+ | (A) AK/SK | Path A: Access Key / Secret Key |
44
+ | (B) Env vars | Path B: Environment Variables |
45
+
46
+ ### If `auth_type=external` is already configured
47
+
48
+ If `auth whoami --json` shows `auth_type=external` (or `provider: external` in the saved config), the user is on an externally-managed credential provider. **Do not run Phase 2.** The auth is already set up — only `project`/`endpoint`/`schema` are safe to change via `session set` or by re-running the original `auth login-external` with updated `--project`/`--endpoint`. Treat bootstrap as complete and move to Phase 3.
49
+
50
+ ### Shortcut for users with `odpscmd` already configured
51
+
52
+ Before asking the question above, check whether the user already has `odpscmd` set up. If yes:
53
+
54
+ > "Do you already have `odpscmd` configured? We can migrate the existing credentials without you re-entering anything."
55
+
56
+ Then follow [migrate-from-odpscmd.md](migrate-from-odpscmd.md).
57
+
58
+ ### Always confirm project and endpoint
59
+
60
+ Regardless of method, ask the user explicitly for `project` and `endpoint`. If a value is already in the config or env, present it as a default but require confirmation. See [bootstrap-auth.md](bootstrap-auth.md) §"Always ask for project and endpoint".
61
+
62
+ ### Dev vs production workspace check
63
+
64
+ If the project name does **not** end with `_dev`, warn the user:
65
+
66
+ > "Project `<project>` does not end with `_dev`. Personal accounts usually only have access to dev workspaces — would you like to switch to `<project>_dev`?"
67
+
68
+ See SKILL.md §"Dev vs Production Workspaces" for the full rationale.
69
+
70
+ ---
71
+
72
+ ## Phase 3: Verify
73
+
74
+ ```bash
75
+ maxc auth whoami --json
76
+ ```
77
+
78
+ Expected: `data.identity.authenticated=true`. `validation_status` interpretation:
79
+
80
+ | `validation_status` | Meaning | Action |
81
+ |---|---|---|
82
+ | `verified` | Remote check passed | ✓ ready |
83
+ | `configuration_only` | Saved but not remote-checked | ✓ ready, credentials resolve at first query |
84
+ | `validation_failed` | Remote check failed | Recheck AK/SK and endpoint |
85
+ | `missing_configuration` | Phase 2 did not save anything | Go back to Phase 2 |
86
+
87
+ ### Common pitfalls when `whoami` looks wrong
88
+
89
+ - **Session override wins**: `~/.maxc/session_override.yaml` overrides config. Run `maxc session show --json` to inspect; `maxc session unset --json` to clear.
90
+ - **Env vars override config**: `ALIBABA_CLOUD_ACCESS_KEY_ID` / `MAXCOMPUTE_PROJECT` etc. shadow saved values. `auth whoami` reports `identity_source=mixed` when this happens. Ask the user before unsetting.
91
+ - **Wrong project default**: if `project` shows production name but you wanted dev, `maxc session set --project <name>_dev`.
92
+
93
+ ---
94
+
95
+ ## What this file does NOT cover
96
+
97
+ - Step-by-step Python / maxc-cli installation — see [setup-install.md](setup-install.md).
98
+ - Each auth method's exact CLI flags and saved YAML — see [bootstrap-auth.md](bootstrap-auth.md).
99
+ - odpscmd field-by-field migration — see [migrate-from-odpscmd.md](migrate-from-odpscmd.md).
100
+ - Public cloud endpoint catalog — present in [bootstrap-auth.md](bootstrap-auth.md) Path A.