featureparity 0.0.33 → 0.0.34

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ed664952f7dd1c088b3d534868eb06023a3dcdfe5783417288745560217ab1ee
4
- data.tar.gz: de7931594143ee7c9324a6b29968b77f60435c51af0f935ec01ea9f8347aebdc
3
+ metadata.gz: aafad86b986d2525cc70638c90b69adae68811060c936a7ed8dd509fb1daa1b6
4
+ data.tar.gz: 123666707b9d8a6df2e7cba775e7aff6856c40aa9bff4f46feeed6a6559e0d6e
5
5
  SHA512:
6
- metadata.gz: 73231f3b48feda8c832eaedaa25c58d637ffecc436be1f2518da1089c9e9747517a08b53765a1f44b9faf92174a4711f1eb371abac522a64d6a3c292ed7ac98a
7
- data.tar.gz: f7fb9b80fe7d7236523279c13d1e42b1d80cd89bd3bdf8163015abe88cbb33f13b14acb35ca95a9de9bcbddbc6d15ade21a1cb362537038c8e6b4e3ce731b5f5
6
+ metadata.gz: 7bead9325320839ed572b4a25f6e7fffe369b148be92cfce1c60c139704e8f8bcc44f54ff48bb6bda58651d9727235cd059b0288d6257657a9f7839074dd35c4
7
+ data.tar.gz: c6fc3aeb020b2535f9e1cdcc438eeab6697475218f219b3e35657c531f59be71659bfba004457f5d7a9c93e490e003dd4055b33b53ee3e48ca0c0c10e4d4a26a
data/lib/fp/cli.rb CHANGED
@@ -40,6 +40,7 @@ module Fp
40
40
  'whoami' => Commands::Whoami,
41
41
  'skill' => Commands::Skill,
42
42
  'version' => Commands::Version,
43
+ 'update' => Commands::Update,
43
44
  'help' => Commands::Help,
44
45
  'attach' => Commands::Attach,
45
46
  'attachments' => Commands::Attachments,
@@ -84,7 +85,7 @@ module Fp
84
85
 
85
86
  # Profile/config commands don't need auth. `init` is here too: it only writes
86
87
  # files into the repo, and onboarding a repo must work before anyone has a key.
87
- needs_auth = !%w[init doctor profile config repos setup whoami skill version help mark tutorial].include?(command_name)
88
+ needs_auth = !%w[init doctor profile config repos setup whoami skill version update help mark tutorial].include?(command_name)
88
89
 
89
90
  if needs_auth
90
91
  config = Config.new(profile: global_opts[:profile], api_url: global_opts[:api_url])
@@ -103,6 +104,7 @@ module Fp
103
104
  output = Output.new(json: global_opts[:json])
104
105
  command = command_class.new(client: client, output: output, config: config)
105
106
  command.run(args + passthrough)
107
+ announce_update(config, command_name, json: global_opts[:json])
106
108
  rescue Interrupt
107
109
  warn "\nAborted."
108
110
  exit 130
@@ -114,6 +116,15 @@ module Fp
114
116
 
115
117
  private
116
118
 
119
+ # At most once a day, say on stderr that a newer fp is published (Fizzy #1993).
120
+ # Never with --json: a caller reading that stream gets the envelope and nothing else.
121
+ def announce_update(config, command_name, json:)
122
+ return if json
123
+
124
+ notice = UpdateCheck.daily_notice(config.api_url, command: command_name)
125
+ warn "\n#{notice}" if notice
126
+ end
127
+
117
128
  # True when the remaining args ask for help on the command: `--help` or `-h`
118
129
  # anywhere in the args. We don't treat a lone `help` positional specially here —
119
130
  # that's a real subcommand for some commands.
@@ -7,13 +7,15 @@ module Fp
7
7
  # fp doctor [--dir PATH] [--json]
8
8
  #
9
9
  # Says whether fp will work here, and what this repo needs before its tests can report
10
- # (Fizzy #1786). Purely local: no API calls, no key needed.
10
+ # (Fizzy #1786). No key needed. Everything is read locally except the newest published
11
+ # version (Fizzy #1993), one unauthenticated lookup that is skipped when it can't be made.
11
12
  #
12
13
  # Ruby which Ruby is running fp, where the gem lives, and whether this directory
13
14
  # pins a different Ruby (.ruby-version, .tool-versions, mise.toml). A
14
15
  # version-manager shim resolves `fp` against the *pinned* Ruby, so a gem
15
16
  # installed under another one fails inside the repo with
16
17
  # `mise ERROR No version is set for shim: fp` and works from /tmp.
18
+ # Also whether a newer fp is published, and the command that installs it.
17
19
  # Config the API environment (warning off production), whether a key resolved,
18
20
  # and which .featureparity.yml applies.
19
21
  # Repo RepoDetector's summary: test runners and the command that makes each emit
@@ -28,7 +30,7 @@ module Fp
28
30
  help_flag :dir, 'Directory to check (defaults to the working directory)'
29
31
  help_example 'fp doctor'
30
32
  help_example 'fp doctor --json', 'Machine-readable, for an agent to act on'
31
- help_note "Purely local; makes no API calls, so it works without a key.\n" \
33
+ help_note "Works without a key and offline. Its one network call asks the API for the newest fp version.\n" \
32
34
  "If `fp` itself fails with `mise ERROR No version is set for shim: fp`, the shim stopped it\n" \
33
35
  'before fp could run: install the gem under the pinned Ruby (`gem install featureparity` in the repo).'
34
36
 
@@ -51,6 +53,7 @@ module Fp
51
53
  repo: RepoDetector.new(repo_root(dir)).detect
52
54
  }
53
55
  report[:agents_section] = agents_section_report(repo_root(dir))
56
+ report[:update] = UpdateCheck.status(config.api_url) unless UpdateCheck.disabled?
54
57
 
55
58
  output.success(report) { print_report(report) }
56
59
  end
@@ -187,6 +190,18 @@ module Fp
187
190
  end
188
191
  end
189
192
 
193
+ def print_update(update)
194
+ line = if update[:latest_version].nil?
195
+ 'could not check (offline, or the API is unreachable)'
196
+ elsif update[:update_available]
197
+ "#{update[:latest_version]} — newer than this one. Run `#{update[:update_command]}` " \
198
+ "(or `#{UpdateCheck::GEM_COMMAND}`)."
199
+ else
200
+ "#{update[:latest_version]} (up to date)"
201
+ end
202
+ puts " Latest fp: #{line}"
203
+ end
204
+
190
205
  def print_report(report)
191
206
  ruby = report[:ruby]
192
207
  cfg = report[:config]
@@ -195,6 +210,7 @@ module Fp
195
210
  puts "fp #{ruby[:fp_version]} on Ruby #{ruby[:version]} (#{ruby[:ruby]})"
196
211
  puts " Gem: #{ruby[:gem_path]}"
197
212
  puts " fp on PATH: #{ruby[:fp_on_path] || '(not found)'}#{ruby[:fp_on_path_is_shim] ? ' [version-manager shim]' : ''}"
213
+ print_update(report[:update]) if report[:update]
198
214
  if ruby[:pinned]
199
215
  state = ruby[:mismatch] ? '⚠ differs from the Ruby running fp' : 'matches'
200
216
  puts " Ruby pin: #{ruby[:pinned]} (#{ruby[:pinned_by]}) — #{state}"
@@ -112,6 +112,7 @@ module Fp
112
112
  repos set|get|list|unset Map surfaces to local repo paths
113
113
  setup Interactive first-time setup
114
114
  version Show version (also: fp --version, fp -v)
115
+ update [--check] Install the newest fp, or check whether one is available
115
116
  help Show this help
116
117
 
117
118
  GLOBAL FLAGS
@@ -0,0 +1,91 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'open3'
4
+
5
+ module Fp
6
+ module Commands
7
+ # fp update [--check]
8
+ #
9
+ # Installs the newest published fp (Fizzy #1993). There was no way to update from
10
+ # inside fp and nothing said one was due; `gem update featureparity` was mentioned
11
+ # once, in the changed-test upgrade notes.
12
+ #
13
+ # The latest version comes from the API's public `GET /cli/version`, so this needs no
14
+ # key. The install runs RubyGems under the Ruby that is running fp, which is the one
15
+ # whose `fp` the person just typed: in a repo that pins a Ruby, that is the pinned one.
16
+ class Update < Base
17
+ help_summary 'Install the newest fp, or check whether one is available'
18
+ help_usage 'fp update [--check]'
19
+ help_flag :check, 'Only say whether a newer fp exists; install nothing'
20
+ help_example 'fp update', 'Install the newest fp under the Ruby running this one'
21
+ help_example 'fp update --check', 'Is a newer fp published?'
22
+ help_note "Needs no API key. Same as `gem update featureparity`, or re-running the installer.\n" \
23
+ 'After an update, run `fp skill install` and `fp init --force` in each repo that uses fp, ' \
24
+ "to refresh the agent skill and the AGENTS.md section.\n" \
25
+ 'fp also says when a newer version exists, at most once a day; FP_NO_UPDATE_CHECK=1 turns that off.'
26
+
27
+ KNOWN_FLAGS = { check: :boolean }.freeze
28
+
29
+ AFTER_UPDATE = [
30
+ ['fp skill install', "refresh the agent skill in a repo that has it"],
31
+ ['fp init --force', "refresh the FeatureParity section of a repo's AGENTS.md"]
32
+ ].freeze
33
+
34
+ class << self
35
+ # Runs the install and returns [combined output, success?]. Swapped in tests.
36
+ attr_writer :installer
37
+
38
+ def installer
39
+ @installer ||= lambda do
40
+ out, status = Open3.capture2e(
41
+ Gem.ruby, '-e', 'require "rubygems/gem_runner"; Gem::GemRunner.new.run(ARGV)',
42
+ 'install', 'featureparity'
43
+ )
44
+ [out, status.success?]
45
+ end
46
+ end
47
+ end
48
+
49
+ def run(args)
50
+ opts, = parse_flags(args, KNOWN_FLAGS)
51
+ status = UpdateCheck.status(config.api_url)
52
+ latest = status[:latest_version]
53
+
54
+ unless latest
55
+ output.error("Could not read the latest fp version from #{config.api_url}. " \
56
+ "To update anyway, run `#{UpdateCheck::GEM_COMMAND}`.")
57
+ exit 1
58
+ end
59
+
60
+ unless status[:update_available]
61
+ return output.success(status.merge(updated: false)) { puts "fp #{Fp::VERSION} is the latest version." }
62
+ end
63
+
64
+ if opts[:check]
65
+ return output.success(status.merge(updated: false)) { puts UpdateCheck.message(latest) }
66
+ end
67
+
68
+ install(status)
69
+ end
70
+
71
+ private
72
+
73
+ def install(status)
74
+ puts "Installing fp #{status[:latest_version]} (you have #{Fp::VERSION})..." unless output.json?
75
+ log, ok = self.class.installer.call
76
+
77
+ unless ok
78
+ output.error("The update failed. Run `#{UpdateCheck::GEM_COMMAND}` to see why.\n#{log.to_s.lines.last(5).join}".strip)
79
+ exit 1
80
+ end
81
+
82
+ output.success(status.merge(updated: true, next_steps: AFTER_UPDATE.map(&:first))) do
83
+ puts "✓ fp is updated. `fp version` shows what's installed."
84
+ puts
85
+ puts 'Next, in each repo that uses fp:'
86
+ AFTER_UPDATE.each { |command, why| puts " #{command.ljust(18)} # #{why}" }
87
+ end
88
+ end
89
+ end
90
+ end
91
+ end
data/lib/fp/commands.rb CHANGED
@@ -35,6 +35,7 @@ require_relative 'commands/setup'
35
35
  require_relative 'commands/whoami'
36
36
  require_relative 'commands/skill'
37
37
  require_relative 'commands/version'
38
+ require_relative 'commands/update'
38
39
  require_relative 'commands/help'
39
40
  require_relative 'commands/attach'
40
41
  require_relative 'commands/attachments'
@@ -0,0 +1,103 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'net/http'
4
+ require 'uri'
5
+ require 'json'
6
+ require 'time'
7
+ require 'fileutils'
8
+
9
+ module Fp
10
+ # Says when a newer fp has been published (Fizzy #1993). Nothing told a person or an
11
+ # agent that the gem they had was behind: `GET /api/cli/version` had the answer and
12
+ # nothing read it.
13
+ #
14
+ # The lookup is one unauthenticated GET with a short timeout, and every failure is
15
+ # silent: being offline or behind must never break or slow the command someone ran.
16
+ # FP_NO_UPDATE_CHECK=1 turns all of it off.
17
+ module UpdateCheck
18
+ INTERVAL = 24 * 60 * 60
19
+ TIMEOUT = 2
20
+ CACHE_NAME = 'update_check.json'
21
+ UPDATE_COMMAND = 'fp update'
22
+ GEM_COMMAND = 'gem update featureparity'
23
+
24
+ # Commands that say it themselves, or that are about the version already.
25
+ QUIET_COMMANDS = %w[update doctor version help].freeze
26
+
27
+ module_function
28
+
29
+ def disabled?
30
+ !['', '0', 'false'].include?(ENV.fetch('FP_NO_UPDATE_CHECK', '').strip.downcase)
31
+ end
32
+
33
+ # The version the API says is published, or nil when it can't be read.
34
+ def latest_version(api_url)
35
+ uri = URI.parse("#{api_url.to_s.chomp('/')}/api/cli/version")
36
+ http = Net::HTTP.new(uri.host, uri.port)
37
+ http.use_ssl = uri.scheme == 'https'
38
+ http.open_timeout = TIMEOUT
39
+ http.read_timeout = TIMEOUT
40
+ response = http.request(Net::HTTP::Get.new(uri))
41
+ return nil unless response.code.to_i == 200
42
+
43
+ version = JSON.parse(response.body).dig('cli', 'version').to_s
44
+ Gem::Version.correct?(version) ? version : nil
45
+ rescue StandardError
46
+ nil
47
+ end
48
+
49
+ def newer?(latest, current = Fp::VERSION)
50
+ Gem::Version.new(latest) > Gem::Version.new(current)
51
+ rescue ArgumentError, TypeError
52
+ false
53
+ end
54
+
55
+ # A live answer, for `fp doctor` and `fp update`.
56
+ def status(api_url)
57
+ latest = latest_version(api_url)
58
+ {
59
+ current_version: Fp::VERSION,
60
+ latest_version: latest,
61
+ update_available: latest ? newer?(latest) : false,
62
+ update_command: UPDATE_COMMAND
63
+ }
64
+ end
65
+
66
+ def message(latest)
67
+ "fp #{latest} is available (you have #{Fp::VERSION}). Run `#{UPDATE_COMMAND}` to install it."
68
+ end
69
+
70
+ # The line to show after a command, at most once a day: nil when the last look was
71
+ # under a day ago, when CI is running fp, or when there is nothing newer. A failed
72
+ # look still counts as today's, so an offline machine waits out the timeout once.
73
+ def daily_notice(api_url, command: nil, now: Time.now)
74
+ return nil if disabled? || QUIET_COMMANDS.include?(command.to_s)
75
+ return nil unless ENV['CI'].to_s.empty?
76
+ return nil if checked_recently?(now)
77
+
78
+ latest = latest_version(api_url)
79
+ remember(now, latest)
80
+ latest && newer?(latest) ? message(latest) : nil
81
+ rescue StandardError
82
+ nil
83
+ end
84
+
85
+ def cache_file
86
+ File.join(Fp::Config::CONFIG_DIR, CACHE_NAME)
87
+ end
88
+
89
+ def checked_recently?(now)
90
+ checked_at = Time.parse(JSON.parse(File.read(cache_file))['checked_at'].to_s)
91
+ now - checked_at < INTERVAL
92
+ rescue StandardError
93
+ false
94
+ end
95
+
96
+ def remember(now, latest)
97
+ FileUtils.mkdir_p(File.dirname(cache_file))
98
+ File.write(cache_file, JSON.generate('checked_at' => now.utc.iso8601, 'latest' => latest))
99
+ rescue SystemCallError
100
+ nil
101
+ end
102
+ end
103
+ end
data/lib/fp/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Fp
4
- VERSION = '0.0.33'
4
+ VERSION = '0.0.34'
5
5
  end
data/lib/fp.rb CHANGED
@@ -9,6 +9,7 @@ require_relative 'fp/source_fingerprint'
9
9
  require_relative 'fp/junit'
10
10
  require_relative 'fp/repo_detector'
11
11
  require_relative 'fp/output'
12
+ require_relative 'fp/update_check'
12
13
  require_relative 'fp/commands'
13
14
  require_relative 'fp/cli'
14
15
 
data/skills/fp/SKILL.md CHANGED
@@ -17,6 +17,8 @@ command -v fp && fp --version
17
17
  ```
18
18
 
19
19
  If missing: `gem install featureparity` (or `bundle exec fp` inside an app that already depends on the gem).
20
+ To update fp, run `fp update` (or `gem update featureparity`); fp says on stderr, at most once
21
+ a day, when a newer version is published, and `fp doctor` shows it.
20
22
  This skill ships inside the gem; `fp skill install` refreshes an installed copy after an upgrade.
21
23
  `fp doctor` checks the install, the config and the repo without an API key. If `fp` fails
22
24
  inside a repo but works elsewhere, see Troubleshooting.
@@ -937,7 +937,8 @@ secret exists is fine: the gate skips with an explanation and stays green.
937
937
 
938
938
  ### fp doctor
939
939
 
940
- Check that fp works here, with no API key and no API calls.
940
+ Check that fp works here, with no API key. It reads everything locally except the newest
941
+ published fp version, one lookup that is skipped when the API can't be reached.
941
942
 
942
943
  ```bash
943
944
  fp doctor
@@ -951,6 +952,8 @@ fp doctor --json
951
952
  the fix: install the gem under the pinned Ruby (`mise exec ruby@<pinned> -- gem install
952
953
  featureparity`, or `gem install featureparity` in the repo), or put the running Ruby's bin
953
954
  directory first on `PATH`.
955
+ - **Latest fp:** the newest published version. When it's newer than the one running, doctor
956
+ names `fp update` (and `gem update featureparity`) to install it.
954
957
  - **Config:** the API environment (warning when it isn't production), whether a key is
955
958
  present, which `.featureparity.yml` applies, and which fp wrote the `AGENTS.md` section.
956
959
  - **Repo:** the same summary as `fp init --detect`.
@@ -1022,6 +1025,18 @@ fp skill install --path ~/my-agent/skills # any skills directory (writes <path>/
1022
1025
  fp skill path # where the bundled skill lives
1023
1026
  ```
1024
1027
 
1028
+ ### fp update
1029
+
1030
+ Install the newest fp, or check whether one is published. Needs no API key.
1031
+
1032
+ ```bash
1033
+ fp update # install the newest fp under the Ruby running this one
1034
+ fp update --check # only say whether a newer one exists
1035
+ fp update --json
1036
+ ```
1037
+
1038
+ See [Updating fp](#updating-fp) for what to do afterwards.
1039
+
1025
1040
  ### fp repos
1026
1041
 
1027
1042
  Map surfaces to local repo paths (stored locally, not in the web app).
@@ -1033,6 +1048,30 @@ fp repos get customer_android --project acme
1033
1048
  fp repos unset customer_android --project acme
1034
1049
  ```
1035
1050
 
1051
+ ## Updating fp
1052
+
1053
+ fp is a Ruby gem, so any of these installs the newest version:
1054
+
1055
+ ```bash
1056
+ fp update # from fp 0.0.34
1057
+ gem update featureparity
1058
+ curl -fsSL https://api.featureparity.dev/api/cli/install | bash # the installer again
1059
+ ```
1060
+
1061
+ Then, in each repo that uses fp:
1062
+
1063
+ ```bash
1064
+ fp skill install # refresh the agent skill, if the repo has it installed
1065
+ fp init --force # refresh the FeatureParity section of AGENTS.md
1066
+ ```
1067
+
1068
+ `fp version` shows what's installed and `fp update --check` whether a newer one exists.
1069
+ `fp doctor` shows the newest published version and, when the one running is behind, the
1070
+ command that installs it. At most once a day, an fp command that finds a newer version
1071
+ says so on stderr after its own output. It stays quiet with `--json`, when `CI` is set,
1072
+ and when `FP_NO_UPDATE_CHECK=1`. A repo that pins a Ruby has its own copy of the gem: run
1073
+ the update inside that repo so the pinned Ruby's copy is the one that changes.
1074
+
1036
1075
  ## Exit codes
1037
1076
 
1038
1077
  | Code | Meaning |
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: featureparity
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.33
4
+ version: 0.0.34
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stowzilla
@@ -131,6 +131,7 @@ files:
131
131
  - lib/fp/commands/spot_check.rb
132
132
  - lib/fp/commands/surfaces.rb
133
133
  - lib/fp/commands/tutorial.rb
134
+ - lib/fp/commands/update.rb
134
135
  - lib/fp/commands/version.rb
135
136
  - lib/fp/commands/whoami.rb
136
137
  - lib/fp/config.rb
@@ -148,6 +149,7 @@ files:
148
149
  - lib/fp/tutorial/hexhaven/test/junit_reporter.rb
149
150
  - lib/fp/tutorial/hexhaven/test/rules_test.rb
150
151
  - lib/fp/tutorial/hexhaven/test/test_helper.rb
152
+ - lib/fp/update_check.rb
151
153
  - lib/fp/version.rb
152
154
  - skills/fp/SKILL.md
153
155
  - skills/fp/references/cli.md