ctx_cli 0.3.0 → 0.5.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/README.md +7 -1
- data/docs/migration.md +8 -0
- data/lib/ctx_cli/apply.rb +92 -0
- data/lib/ctx_cli/review.rb +1 -1
- data/lib/ctx_cli/version.rb +1 -1
- data/lib/ctx_cli.rb +1 -0
- metadata +16 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: eeebcf82656b7023ca54cdd295baa04ccf6cab2f1ce6b847bb62edddda4f98e0
|
|
4
|
+
data.tar.gz: 70ccbf7fff2bdd31215ba7efa452e4d2fb54ccea64907b886a5393208241c06c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 20a49938c00e94f93181f5a3c2630093368d4d6827fa9ad49f30bfcd42b47d9aa50bfec886e575c89b9560cfd783551a08f1f9e34c6d183469983f739490ca86
|
|
7
|
+
data.tar.gz: 29fed8d776392667dfb900b405647c2359757905146f0a4bc41fb1ebe7577726e967c203c55076934a43d4800c5076def9fd6aa45349e5be8a23d427c2da680b
|
data/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
## 0.5.0 (2026-10-30)
|
|
6
|
+
|
|
7
|
+
- Use `target` in controlled apply documents and accept JSON nesting up to the shared 128-level evidence budget. Host adapters must use schema 4 plans.
|
|
8
|
+
|
|
9
|
+
## 0.4.0 (2026-10-29)
|
|
10
|
+
|
|
11
|
+
- Add an injected Apply entry point for checksummed plans, explicit item selection, interactive confirmation and safe failure reporting, without domain, runner or connector dependencies.
|
|
12
|
+
|
|
5
13
|
## 0.3.0 (2026-10-24)
|
|
6
14
|
|
|
7
15
|
- Use JSON Pointer keys in configuration field provenance, separating literal dots, slashes, tildes, empty keys and nested mappings.
|
data/README.md
CHANGED
|
@@ -75,7 +75,7 @@ Options 协作者沿用现有入口协议:`informational?`、`validate_interac
|
|
|
75
75
|
bundle install
|
|
76
76
|
bundle exec rake
|
|
77
77
|
bundle exec rake build
|
|
78
|
-
ruby script/verify_package.rb pkg/ctx_cli-0.
|
|
78
|
+
ruby script/verify_package.rb pkg/ctx_cli-0.4.0.gem
|
|
79
79
|
```
|
|
80
80
|
|
|
81
81
|
默认任务包括 RSpec、RuboCop 和离线示例。安装验证在独立 GEM_HOME/GEM_PATH 下运行普通与最小 Bundler 应用,检查实际加载来源。CI 参照 ctx_parser 的固定 action 提交和候选制品校验;发布需另行明确授权。
|
|
@@ -94,3 +94,9 @@ Input reads default to a 16 MiB byte budget (`CtxCli::Input.read(max_bytes:)`).
|
|
|
94
94
|
失败只输出异常类型,返回 2;中断返回 130;诊断流失败不覆盖原始退出码。帮助不加载证据或调用适配器。此类不读取凭据、连接设备或判断业务健康。默认单文件 16 MiB、批次原始正文总计 64 MiB、文件数 10000;宿主可通过 `max_bytes:`、`max_total_bytes:`、`max_files:` 调整。JSON 默认嵌套限制保持开启;上述限制不是进程 RSS 的精确上限。
|
|
95
95
|
|
|
96
96
|
`Collection` 对普通参数/依赖异常只显示类型;宿主需要公开操作提示时使用 `CtxCli::Collection::Error`,其正文必须由宿主构造,不得直接包装外部异常正文、凭据或设备回显。该类型继承 ArgumentError,既有库调用方仍可按参数错误捕获。
|
|
97
|
+
|
|
98
|
+
`CtxCli::Apply` 负责版本计划的校验和、`--item` 选择、终端确认及退出码;通过 `adapter:` 和 `execution:` 注入领域校验、凭据、会话、日志及执行器。ctx_cli 不依赖 ctx_runner 或连接器。
|
|
99
|
+
|
|
100
|
+
## Domain contract migration (2026-10-30)
|
|
101
|
+
|
|
102
|
+
Use `target` in controlled apply documents and accept JSON nesting up to the shared 128-level evidence budget. Host adapters must use schema 4 plans. See the [schema 4 migration and module contracts](https://github.com/gatework/ctx_runner/blob/main/docs/contracts-2026-10-30.md). Regenerate old collection reports and change plans; changing only their version number is not supported.
|
data/docs/migration.md
CHANGED
|
@@ -24,3 +24,11 @@ ctx_cli 初始版本为 0.1.0。首次发布依赖顺序先 ctx_cli,再 net-co
|
|
|
24
24
|
`Configuration#sources["fields"]` 的键统一使用 [JSON Pointer](https://www.rfc-editor.org/rfc/rfc6901):`parallel` 改为 `/parallel`,`ssh.port` 的嵌套路径改为 `/ssh/port`。字面键 `ssh.port` 则为 `/ssh.port`,两者拥有独立来源。空键为 `/`;每段中的 `~` 编为 `~0`,`/` 编为 `~1`,不作 Unicode 归一化。
|
|
25
25
|
|
|
26
26
|
来源值仍是 YAML 文件路径;数组整体替换,来源记在数组字段上。空映射合并不覆盖既有非空映射的来源。宿主透传的 `--show-config` 同步采用此结构;外部来源索引调用方须迁移键查找,不提供点分键回退或格式开关。`path_fields` 仍是宿主声明哪些字段要解析为文件路径的独立语法。
|
|
27
|
+
|
|
28
|
+
## 0.4.0 Apply
|
|
29
|
+
|
|
30
|
+
VXLAN/Wireless 的交互执行入口组合 `CtxCli::Apply`;宿主注入 adapter 和 execution 协作者,领域命令和会话仍由宿主维护。统一要求具名 `--item`、plan.json.sha256 和绑定设备/摘要/所选项的终端确认,取消为 1、预检或执行失败为 2、中断为 130。ctx_cli 自身不加载 Runner 或连接器。
|
|
31
|
+
|
|
32
|
+
## 0.5.0 目标身份
|
|
33
|
+
|
|
34
|
+
受控执行读取 `plan["target"]`,旧 `device` 字段不再识别。领域宿主须升级 schema 4、重新生成计划;CLI 只负责输入边界,平台与身份验证仍由 Runner/领域负责。JSON 读取的最大嵌套为 128,与公共证据深度预算一致。
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "digest"
|
|
4
|
+
require "json"
|
|
5
|
+
require_relative "command"
|
|
6
|
+
require_relative "configuration"
|
|
7
|
+
require_relative "terminal"
|
|
8
|
+
require_relative "input"
|
|
9
|
+
require_relative "output"
|
|
10
|
+
|
|
11
|
+
module CtxCli
|
|
12
|
+
# 单项交互变更的终端入口;领域校验与会话、执行账本均通过显式协作者提供。
|
|
13
|
+
class Apply
|
|
14
|
+
def initialize(adapter:, execution:, name:, out: $stdout, error: $stderr, input: $stdin)
|
|
15
|
+
@adapter, @execution_class, @name = adapter, execution, name
|
|
16
|
+
@out, @error, @input = out, error, input
|
|
17
|
+
@output = Output.new(out: out, error: error)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def run(argv)
|
|
21
|
+
@execution = nil
|
|
22
|
+
command = options
|
|
23
|
+
values = command.parse(argv)
|
|
24
|
+
return 0 if command.informational?
|
|
25
|
+
terminal = Terminal.new(input: @input, out: @out)
|
|
26
|
+
terminal.require_tty!(@error)
|
|
27
|
+
unless values[:plan] && values[:item] && values[:port].between?(1, 65_535)
|
|
28
|
+
raise ArgumentError, "A plan and explicit --item are required"
|
|
29
|
+
end
|
|
30
|
+
body = Input.read(path: values[:plan])
|
|
31
|
+
sha256 = Digest::SHA256.hexdigest(body)
|
|
32
|
+
unless Input.read(path: "#{values[:plan]}.sha256", max_bytes: 128).strip == sha256
|
|
33
|
+
raise ArgumentError, "Plan checksum verification failed"
|
|
34
|
+
end
|
|
35
|
+
# 外部领域回调不能改变刚验证的计划、选择或连接参数。
|
|
36
|
+
values = Configuration.freeze_tree(Configuration.copy(values))
|
|
37
|
+
document = Configuration.freeze_tree(Configuration.copy(JSON.parse(body, max_nesting: 128)))
|
|
38
|
+
plan = Configuration.freeze_tree(Configuration.copy(@adapter.select_plan(document, item: values[:item])))
|
|
39
|
+
change = @adapter.validate_plan(plan)
|
|
40
|
+
host = plan.fetch("target").fetch("host")
|
|
41
|
+
@out.puts "Target: #{plan['target']['name']}(#{host}); #{plan['scope']}; #{plan['title']}"
|
|
42
|
+
@out.puts "Impact: #{plan['impact']}"
|
|
43
|
+
@out.puts Array(plan["prerequisites"]).map { |value| "Prerequisite: #{value}" }
|
|
44
|
+
@out.puts "Plan SHA256: #{sha256}\nProposed commands:\n#{change.commands.join("\n")}\nConditional rollback (not executed automatically):\n#{change.rollback.join("\n")}"
|
|
45
|
+
token = "APPLY #{host} #{sha256[0, 12]} #{values[:item]}"
|
|
46
|
+
unless terminal.confirm(token: token, prompt: "After reviewing the service policy and maintenance window, enter #{token}; any other input cancels: ")
|
|
47
|
+
@out.puts "Cancelled; no device connection opened."
|
|
48
|
+
return 1
|
|
49
|
+
end
|
|
50
|
+
settings = @adapter.credentials(values)
|
|
51
|
+
journal = @adapter.report(values)
|
|
52
|
+
@execution = @execution_class.new(plan: plan, change: change, journal: journal, plan_sha256: sha256, item: values[:item])
|
|
53
|
+
@execution.run { |operation| @adapter.with_session(plan.fetch("target"), settings, &operation) }
|
|
54
|
+
@out.puts "Configuration readback confirmed; service acceptance is still required. Configuration was not saved to startup configuration. Log: #{journal.directory}/execution.json"
|
|
55
|
+
0
|
|
56
|
+
rescue Interrupt
|
|
57
|
+
failure("Operation interrupted")
|
|
58
|
+
130
|
|
59
|
+
rescue StandardError, LoadError => error
|
|
60
|
+
failure("Apply stopped (#{error.class.name})")
|
|
61
|
+
2
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def inspect = "#<#{self.class.name}>"
|
|
65
|
+
alias to_s inspect
|
|
66
|
+
def pretty_print(printer) = printer.text(inspect)
|
|
67
|
+
|
|
68
|
+
private
|
|
69
|
+
|
|
70
|
+
def options
|
|
71
|
+
Command.new(banner: "Usage: #{@name} apply --plan FILE --item ID [--env-file FILE] (interactive confirmation required)",
|
|
72
|
+
defaults: { directory: File.join(Dir.pwd, "#{@name}-executions"), port: 22 }, out: @out) do |parser, values|
|
|
73
|
+
parser.on("--plan FILE", "Versioned plan with an adjacent .sha256 checksum") { |value| values[:plan] = value }
|
|
74
|
+
parser.on("--item ID", "Explicitly select one change") { |value| values[:item] = value }
|
|
75
|
+
parser.on("--env-file FILE", "Credentials file; process environment takes precedence") { |value| values[:env_file] = value }
|
|
76
|
+
parser.on("--directory DIR", "Private execution journal directory") { |value| values[:directory] = value }
|
|
77
|
+
parser.on("--port N", Integer, "SSH port, default 22") { |value| values[:port] = value }
|
|
78
|
+
parser.on("-h", "--help", "Show help") { values[:help] = true }
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def failure(message)
|
|
83
|
+
if @execution&.journal_failed?
|
|
84
|
+
@output.diagnostic "Execution log finalization is unconfirmed; existing checkpoints retained."
|
|
85
|
+
end
|
|
86
|
+
detail = @execution&.started? ? "Effects are uncertain; read back before proceeding. Do not replay commands." : "No service configuration was sent."
|
|
87
|
+
@output.diagnostic "#{message}; #{detail}"
|
|
88
|
+
rescue Interrupt
|
|
89
|
+
nil
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
end
|
data/lib/ctx_cli/review.rb
CHANGED
|
@@ -32,7 +32,7 @@ module CtxCli
|
|
|
32
32
|
raise ArgumentError, "review byte budget exceeded" unless remaining.positive?
|
|
33
33
|
body = Input.read(path: path, max_bytes: [ @max_bytes, remaining ].min)
|
|
34
34
|
remaining -= body.bytesize
|
|
35
|
-
[ path, body, JSON.parse(body) ]
|
|
35
|
+
[ path, body, JSON.parse(body, max_nesting: 128) ]
|
|
36
36
|
end
|
|
37
37
|
context = @adapter.prepare(sources, options)
|
|
38
38
|
@output.text(@adapter.publish(sources, options, batch: batch, context: context))
|
data/lib/ctx_cli/version.rb
CHANGED
data/lib/ctx_cli.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ctx_cli
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.5.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Gatework contributors
|
|
@@ -23,6 +23,20 @@ dependencies:
|
|
|
23
23
|
- - ">="
|
|
24
24
|
- !ruby/object:Gem::Version
|
|
25
25
|
version: '0'
|
|
26
|
+
- !ruby/object:Gem::Dependency
|
|
27
|
+
name: digest
|
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - ">="
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '0'
|
|
33
|
+
type: :runtime
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - ">="
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '0'
|
|
26
40
|
- !ruby/object:Gem::Dependency
|
|
27
41
|
name: fileutils
|
|
28
42
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -122,6 +136,7 @@ files:
|
|
|
122
136
|
- examples/configuration.rb
|
|
123
137
|
- examples/offline.rb
|
|
124
138
|
- lib/ctx_cli.rb
|
|
139
|
+
- lib/ctx_cli/apply.rb
|
|
125
140
|
- lib/ctx_cli/collection.rb
|
|
126
141
|
- lib/ctx_cli/command.rb
|
|
127
142
|
- lib/ctx_cli/configuration.rb
|